简体   繁体   中英

Openlayers: Marker on different vector layers

I have an OpenLayers map with two vector layers. 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

This select-handler fires the same function for marker on both layers. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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