OpenLayers Vector Layer最大功能数

时间:2011-12-08 15:18:38

标签: vector limit openlayers clear layer

我想知道是否可以限制你在vectorylayer上绘制的功能数量。如果我已经绘制了多边形,然后去绘制另一个多边形,它将删除第一个特征。

如果没有,是否可以向矢量图层添加一个监听器,以便在点击绘图时可以删除所有功能?

感谢!!!

2 个答案:

答案 0 :(得分:1)

您无法在矢量图层上设置最大数量的功能,但它有很多事件可以注入您自己的逻辑。以下是可用的活动:

"beforefeatureadded", "beforefeaturesadded",
"featureadded", "featuresadded", "beforefeatureremoved",
"beforefeaturesremoved", "featureremoved", "featuresremoved",
"beforefeatureselected", "featureselected", "featureunselected", 
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
"vertexmodified", "vertexremoved", "sketchstarted",
"sketchmodified", "sketchcomplete", "refresh"

例如,您可以使用“beforefeatureadded”:

your_vectror_layer.events.on({'beforefeatureadded': function(){
  //Remove first feature or whatever you want to do
}});

答案 1 :(得分:0)

你可以创建一个按钮,当你点击它时,它将删除你的矢量图层中的所有功能:

  

map.layers [1] .removeAllFeatures();

这里1是我的图层的id(我的矢量图层是OSM图层之后的第二个图标)

祝你好运!