简体   繁体   English

如何在OpenLayers中区分两个不同的矢量层?

[英]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.

相关问题 Openlayers:不同矢量图层上的标记 - Openlayers: Marker on different vector layers 来自两个不同来源的两个图层的 OpenLayers 地图缩放不同。 OpenLayers 可以改变缩放级别的行为吗? - OpenLayers map with two layers from two different sources zoom differently. Can OpenLayers change how zoom levels behave? 如何使用 Leaflet 发布矢量图层? - How can I publish vector layers with Leaflet? 堆叠div和openlayers矢量层 - Stacking divs and openlayers vector layers 如何在OpenLayers 3中为矢量源(GPX)分配徽标? - How can i assign a logo to the vector source (GPX) in OpenLayers 3? 使用openlayers时,如何确保两个图层中的标记都已显示 - with openlayers , how do i make sure the markers in TWO layers are all dsiplayed 如何在OpenLayers的一个地图中使用带有lat-lon图层的Mapnik-Backgroundlayer? - How can I use a Mapnik-Backgroundlayer with lat-lon layers in one map with OpenLayers? 如何在OpenLayers中彼此独立地移动两层? - How to move two layers independently from each other in OpenLayers? 我如何在OpenLayers3中的两点之间绘制lineString - How can i draw a lineString between two point in OpenLayers3 OpenLayers:如何在地图div的流体CSS渲染后重新对齐鼠标坐标和矢量层 - OpenLayers: How to re-align mouse coordinates and vector layers after fluid css rendering of map div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM