0

I have multiple layers in OpenLayers: three vector layers, one google map layer, and a marker layer. I registered feature selected event to all three vector layers (which works fine, but btw is that a good practice to register events one by one?). When I registered the click event for marker layer, it doesn't respond.

var marker = new OpenLayers.Marker(position, icon);
marker.events.register('click', marker, function(e){
    // Do something...
});
markerLayer.addMarker(marker);

I wondered if it was caused by the problem of layer order. I tried setting ZIndex for layers, but it didn't work.

1 Answer 1

1

There is no problem in registering events one by one. The problem is the amount of events registered. As more events more time to process them.

You must check what stuff is turned on map. Several controls that can be attached to the map maybe stopping the click event.

You can put the layer as the last layer on map, so it should be the highest.

If you do not want to register each layer event you can use the OpenLayers.Control.SelectFeature that can monitor several layers together.

  map.addControl(  new OpenLayers.Control.SelectFeature( [ vector1, vector2, markers ], { autoActivate: true } ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.