Several click controls. Should a layer be added to the map before you can add a control?

This code works fine as it is, but it seems to depend on which layers are added to the map before adding controls. Is this always the case, or am I doing something wrong?

var highlightCtrl = new OpenLayers.Control.SelectFeature([a,b], { hover: true, highlightOnly: true, renderIntent: "temporary", eventListeners: { featurehighlighted: make_popup, featureunhighlighted: kill_popup } }); var selectControl = new OpenLayers.Control.SelectFeature([a,b,c,d], { clickout: true, toggle: false, multiple: false, hover: false }); map.addLayer(a); map.addLayer(b); map.addLayer(c); map.addLayer(d); map.addControl(highlightCtrl); map.addControl(selectControl); highlightCtrl.activate(); selectControl.activate(); 
+4
source share
1 answer

No, it does not depend on adding layers to the map before adding controls. As you can see from in this example . You can add a SelectFeature control and activate it before adding a layer to the map.

corresponding code snippet:

 var selectControl = new OpenLayers.Control.SelectFeature(vectorLayer, { hover: false, highlightOnly: false, toggle: false, renderIntent: "select" }); map.addControl(selectControl); selectControl.activate(); map.addLayer(vectorLayer); //<-- layer added at the end 
+1
source

Source: https://habr.com/ru/post/1401824/


All Articles