OL3 在手机或平板电脑上徒手绘制多边形或线串

OL3 Draw freehand polygon or linestring on mobile or tablets

我添加了绘图交互,默认情况下徒手绘制多边形 freehandCondition 是 SHIFT 键,但是如果地图在移动设备和平板电脑中打开,我们如何绘制。

drawOptions.type = 'Polygon'; 
this.draw = new ol.interaction.Draw(drawOptions);
this.draw.on('drawend', lang.hitch(this, "drawEnd"));

我们怎么画?我可以给他们任何其他条件吗?

OL3中有几种方法可以暂停拖动平移并启用徒手绘制。这是设置 freeHandCondition 的一种方法(其中变量 shapeGeom 是 Point、LineString 或 Polygon):

function drawInteraction() {
        if (shapeGeom == 'Point') {
            draw = new ol.interaction.Draw({
                features: drawfeature,
                type: shapeGeom,
          })
        } else {
            draw = new ol.interaction.Draw({
                features: drawfeature,
                type: shapeGeom,
                freehandCondition: ol.events.condition.always,
                condition: ol.events.condition.never,
            })
        }
        map.addInteraction(draw);
    }

当您开始绘制动作时,暂停 DragPan。

map.getInteractions().forEach(function(interaction) {
        if (interaction instanceof ol.interaction.DragPan) {
            interaction.setActive(false);
        }
    }, this);

然后,绘制完特征后恢复 DragPan。

draw.on('drawend', function(event){
        map.addInteraction(new ol.interaction.DragPan)});

OL3 的 API 文档包含带有这些链接的 freeHandCondition and DragPan 元素的信息。