简体   繁体   English

Openlayers:不同矢量图层上的标记

[英]Openlayers: Marker on different vector layers

I have an OpenLayers map with two vector layers. 我有一个带有两个矢量图层的OpenLayers地图。 Both of them contain marker. 它们都包含标记。

With help of the following link, I managed to get a select-handler on both layers. 借助以下链接,我设法在两个层上获得了一个选择处理程序。 http://openlayers.org/dev/examples/select-feature-multilayer.html http://openlayers.org/dev/examples/select-feature-multilayer.html

This select-handler fires the same function for marker on both layers. 此select-handler为两个图层上的标记激发相同的函数。 But how can I differ, on which layer the selected is positioned? 但是,我如何区分选定的图层?

In OpenLayers,handler event triggers on single viewport or map canvas.Therefore,you should attach event (feature selection and feature unselection) on each layer.If you follow the code,in example page,it is so clear that they use the same event but different places where you may alter your own code. 在OpenLayers中,处理程序事件在单个视口或地图画布上触发。因此,您应该在每个图层上附加事件(特征选择和特征取消选择)。如果您按照代码,在示例页面中,它是如此清晰,以至于它们使用相同的事件但是你可以改变你自己的代码的地方不同。

vectors1.events.on({
            "featureselected": function(e) {
                showStatus("selected feature "+e.feature.id+" on Vector Layer 1");
            },
            "featureunselected": function(e) {
                showStatus("unselected feature "+e.feature.id+" on Vector Layer 1");
            }
        });

for vectors2 the same event is attached.If you're looking for which layer the feature is placed as above code says so. 对于vectors2,附加了相同的事件。如果您正在寻找放置该功能的图层,则上面的代码就是这样说的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM