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

时间:2016-03-14 06:33:34

标签: javascript mobile gis openlayers-3

我已经添加了绘制交互以在默认情况下绘制自由手多边形freehandCondition是SHIFT键但是如果在Mobile和Tablets中打开地图我们如何绘制。

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

我们怎样画画?是他们可以给出的任何其他条件吗?

1 个答案:

答案 0 :(得分:2)

有多种方法可以暂停拖动平移并在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文档包含这些链接的freeHandConditionDragPan元素的信息。