[OpenLayers-Users] click to select, highlight feature example

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Tue Jun 16 11:58:50 EDT 2009


Hi all,

another novice error probably. I'm trying to replicate the function of the
click to select, highlight selected example. I essentially copy/pasted the
example into my code, but I'm perplexed as to why I don't have the select on
click feature activated? The highlighting works fine, but nothing happens
when I click. My current set up is very close to the example, except I use a
local gml rather than the vectors from the wkt geometry.
here's my code, and I'm using the web-url for the code.

var map, controls;
function init() {
            map = new OpenLayers.Map ("map",
                    {
                    controls:[
                    new OpenLayers.Control.Navigation(),
                    new OpenLayers.Control.PanZoomBar(),
                    new OpenLayers.Control.LayerSwitcher(),
                    new OpenLayers.Control.Attribution()],
                sphericalMercator: true,
                maxExtent: new
OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                maxResolution: 156543.0399,
                numZoomLevels: 19,
                units: 'm',
                projection: new OpenLayers.Projection("EPSG:900913"),
                displayProjection: new OpenLayers.Projection("EPSG:4326"),
                    }
            );
            var myBaseLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
        "http://labs.metacarta.com/wms/vmap0", {layers: 'basic', projection:
"myproj"} );
         map.addLayer(myBaseLayer);

         var topo = new OpenLayers.Layer.GML("Topography", "data/test4.gml",
{
  projection: new OpenLayers.Projection("EPSG:4326")});
         map.addLayer(topo);
// Selection and hoverstate controls
          var report = function(e) {
                OpenLayers.Console.log(e.type, e.feature.id);
            };

            var highlightCtrl = new OpenLayers.Control.SelectFeature(topo, {
                hover: true,
                highlightOnly: true,
                renderIntent: "temporary",
                eventListeners: {
                    beforefeaturehighlighted: report,
                    featurehighlighted: report,
                    featureunhighlighted: report
                }
            });

   var selectCtrl = new OpenLayers.Control.SelectFeature(topo,
                {clickout: true}
            );

            map.addControl(highlightCtrl);
              map.addControl(selectCtrl);

            highlightCtrl.activate();
            selectCtrl.activate();

            if( ! map.getCenter() ){
            topo.events.register('loadend', topo,
function(){map.zoomToExtent(topo.getDataExtent())});
            map.setCenter(null, null);
            };
            }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090616/886fd4ed/attachment.html


More information about the Users mailing list