[OpenLayers-Users] select features - diffrent handler per layer

Christian Ledermann christian.ledermann at gmail.com
Tue Aug 9 10:04:14 EDT 2011


Hello,

I have a map with 2 vector layers.

when i click on a marker the executed code should be different
depending on the layer the marker is on.
e.g one layer (Basin Details) which should display a popup when a
marker is clicked
second layer (Basin Cluster) should zoom in to the center of the
cluster when clicked:


       function onFeatureUnselect(event) {
                map.removePopup(map.popups[0]);
        };

        function onPopupClose(evt) {
                map.removePopup(map.popups[0]);
        };
        var lt = String.fromCharCode(60);
        var gt = String.fromCharCode(62);

        function onFeatureSelect(event) {
            var feature = event.feature;
            var content = lt + "h2" + gt + feature.attributes.name +
lt + "/h2" + gt + feature.attributes.description;
            popup = new OpenLayers.Popup.FramedCloud("chicken",

feature.geometry.getBounds().getCenterLonLat(),
                                     new OpenLayers.Size(100,100),
                                     content,
                                     null, true, onPopupClose);
            feature.popup = popup;
            map.addPopup(popup);
        }


        var bd_kml = map.getLayersByName('Basin Detail');
        if (bd_kml.length > 0) {
            var bdLayer = bd_kml[0];

            selectControl = new OpenLayers.Control.SelectFeature(
                    [bdLayer],
                    {
                        clickout: true,
                        multiple: false,
                        hover: false,
                    }
                );
            map.addControl(selectControl);
            selectControl.activate();
            bdLayer.events.on({"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect});
        };

        function onClusterFeatureSelect(event) {
            var lonlat = event.feature.geometry.getBounds().getCenterLonLat();
            var currZoom = this.map.getZoom();
            var newZoom = currZoom + 3;
            this.map.setCenter(lonlat, newZoom);
        }

        var bc_kml = map.getLayersByName('Basin Cluster');
        if (bc_kml.length > 0) {
            var bcLayer = bc_kml[0];

            clusterSelectControl = new OpenLayers.Control.SelectFeature(
                    [bcLayer],
                    {
                        clickout: true,
                        multiple: false,
                        hover: false,
                    }
                );
            map.addControl(clusterSelectControl);
            clusterSelectControl.activate();
            bcLayer.events.on({"featureselected": onClusterFeatureSelect});
        };


-----------------------------------------------------------------------------------------------------------

The problem is that only the last event handler fires the previous gets ignored.
Am I restricted to just one active OpenLayers.Control.SelectFeature?








-- 
Best Regards,

Christian Ledermann

Nairobi - Kenya
Mobile : +254 702978914

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>


More information about the Users mailing list