Heres my code to add an SelectControl with Popup for an existing layer add startup




// Popup für Marker
window.selectControl = new OpenLayers.Control.SelectFeature([markerLayer]);

    'featureselected' : onFeatureSelect,
    'featureunselected' : onFeatureUnselect

I skipping the code of "onFeatureSelect()" and "onFeatureUnselect()" ...

This is working very well.

Now i want to add additional new layers (OpenLayers.Marker as content) to show on the map (also working well) with the same functionality (showing popups...).

If I copy the code above and apply on the new layers the app is not working anymore...

Next try:

Adding the new Layer with setLayer() Method:


But no success...

Thanks !

  • Julien's answer seems to be correct. Just one comment - if you are creating all your layers at once, you can skip setLayer and use window.selectControl = new OpenLayers.Control.SelectFeature([markerLayer, newLayer]); Oct 11 '13 at 20:17

You are doing the right thing, but concat() doesn't return you what you think.

The correct way of doing this is:


If you want to use the layers in your selectFeature variable, then make sure you use the right one. If you have only one layer, the selectControl.layers will be null and you have to use selectControl.layer instead. So your code should look like this (untested):

if(selectControl.layers) {
} else {
    window.selectControl.setLayer([selectControl.layer, newLayer]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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