[英]How can I distinguish two different vector layers in OpenLayers?
In my design there's a checkbox which removes all vector layers with the following code. 在我的设计中,有一个复选框可使用以下代码删除所有矢量层。
// When I check that checkbox:
var layers = map.getLayersByClass('OpenLayers.Layer.Vector');
for(var j=0; j < layer_vectors.length; j++){
map.removeLayer(layer_vectors[j]);
}
Which works fine. 哪个工作正常。 I need to remove all with this way because there're many vector layers which contain polygons.
我需要通过这种方式删除所有内容,因为有许多包含多边形的矢量层。
What if I have two different group of vector layers? 如果我有两组不同的向量层怎么办? How can I remove only one of them by that checkbox?
如何通过该复选框仅删除其中之一?
Can we set something like a "data-layertype" attribute as in normal html elements? 我们可以像普通的html元素一样设置“ data-layertype”属性吗? How can I distinguish two different layers after I get them with getLayersByClass?
使用getLayersByClass获取两个不同的图层后,如何区分它们?
Thanks 谢谢
OK I solved this problem. 好,我解决了这个问题。 I set whole group with the same name each time when I create the vector layer and when I remove the layers I distinguish them with their ".name" attribute.
每次创建矢量图层时,都将整个组设置为相同的名称,并且在删除图层时,将它们的“ .name”属性加以区分。
for(var j=0; j < layer_vectors.length; j++){
if(layer_vectors[j].name == "group_name"){
map.removeLayer(layer_vectors[j]);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.