如何在地图上添加多个绘图交互

时间:2018-06-20 11:02:39

标签: openlayers

我有一个OpenLayer映射,我希望能够在其上绘制Point或LineString(freeHand),而无需先指定所需的绘图类型。 ie:用户应该能够单击地图并添加一个点,或者使用mousedown-拖动-mouseup绘制手绘LineString。

我可以像这样向地图添加两个不同的交互:

const freeDrawing = new Draw({
      source: this.drawingLayer.getSource(),
      type: 'LineString',
      freehand: true,
      features: this.drawingFeatures,
      minPoints: 0,
      clickTolerance: 0
});

const pointDrawing = new Draw({
      source: this.drawingLayer.getSource(),
      type: 'Point',
      features: this.drawingFeatures
});

map.addInteraction(pointDrawing);
map.addInteraction(freeDrawing);

如果我一个接一个地绘制几个LineString,这很好用。但是,每当我创建一个Point然后想要绘制LineString时,LineString就会从mouseup而不是mousedown上开始。

有没有更好的方法来实现这一目标?

0 个答案:

没有答案