[OpenLayers-Users] click to select, highlight feature example
Eric Lemoine
eric.lemoine at camptocamp.com
Tue Jun 16 16:39:05 EDT 2009
On Tuesday, June 16, 2009, Nicholas Efremov-Kendall
<n.e.kendall at gmail.com> wrote:
> 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.
Looking at your code I have no idea what's wrong. Have you try
removing the hover (highlightOnly) control to see if the click control
then works?
>
> 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);
> };
> }
>
>
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
More information about the Users
mailing list