Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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 } ) );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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