Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 560
madc Avatar asked Jan 21 '26 11:01

madc


1 Answers

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.

like image 118
Myra Avatar answered Jan 23 '26 00:01

Myra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!