我有一个用例,我需要让多个用户同时在地图的选定区域上绘图。这是我到目前为止所尝试的内容。 创建了一个地图并添加了一个按钮来选择绘图区域。这部分不一定是并发的。以下是按钮点击事件的一部分。
var myVectorLayer = new ol.layer.Vector(
{
source: new ol.source.Vector({wrapX: false})
});
//add layer to the map
map.addLayer(myVectorLayer);
//create a new interaction
var interaction1 = new ol.interaction.Draw({
source: myVectorLayer.getSource(),
type: /** @type {ol.geom.GeometryType} */ 'Polygon',
freehand: true
});
map.addInteraction(interaction1);
点击该按钮后,每个用户都可以获得自己的矢量图层,并且可以通过绘图交互选择他打算处理的区域。 在所有用户选择了区域之后,他们应该能够同时绘制他们的区域。我显示一个附加到每个区域的工具箱,每个工具箱都有一个按钮,用于向地图添加绘图交互。继承人之间的互动。
var interaction = new ol.interaction.Draw({
source: layer.getSource(),
type: /** @type {ol.geom.GeometryType} */ 'Polygon',
freehandCondition: function (evt) {
var coord = evt.coordinate;
var myArea = layer.getSource().getFeatures()[0];//area is the first feature of the layers feature collection
var y = myArea.getGeometry().intersectsCoordinate(coord);
return ol.events.condition.noModifierKeys(evt) && y;
}
});
图层是用户正在处理的图层。 freehandCondition的作用是,获取图层中的第一个特征,即用户选择的绘图区域,如果浏览器事件坐标位于该区域内,则返回true。如果我逐个绘制形状,这很有效。但是,当我在触摸设备上的两个区域执行此操作时,它有时会起作用,有时并不起作用。有没有人试图用openlayers做到这一点?它甚至可能吗?