[OpenLayers-Users] How to trigger an event on feature selection

Nipuni Piyabasi Perera nipuni880917 at gmail.com
Wed Aug 14 05:31:26 PDT 2013


Hi,

I need an even to be triggered when a feature is selected on the map. I
used following code for it. But it does not work. Can someone please tell
what may be the issue?

var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] :
OpenLayers.Layer.Vector.prototype.renderers;

var layer = new OpenLayers.Layer.Vector("Scratchpad", {
    renderers: renderer
});

var toolbar = new OpenLayers.Control.EditingToolbar(layer);
    toolbar.addControls([new OpenLayers.Control.ModifyFeature(layer, {
        title: "Select feature"
    })]);

    map = new OpenLayers.Map('map_element_1', {
        controls: [
            toolbar,
            new OpenLayers.Control.PanZoomBar(),
            new OpenLayers.Control.PanPanel()
        ],
        layers: [
            new OpenLayers.Layer.WMS(
                "OSM", "http://maps.opengeo.org/geowebcache/service/wms",
                {layers: "openstreetmap", format: "image/png"}
            ),
            new OpenLayers.Layer.WMS(
                "OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
                {layers: 'basic'}
            ),
            layer
        ],
        zoom: 4
    });

    layer.events.on({
        'featureselected': function (feature) {
            document.getElementById('test').innerHTML = 'abc';
        },
        'featureunselected': function (feature) {
        }
    });

Thanks,
Nipuni
-- 
Nipuni Piyabasi Perera
Undergraduate
Department of Computer Science And Engineering
University of Moratuwa
Sri Lanka
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130814/96312108/attachment.html>


More information about the Users mailing list