[OpenLayers-Users] Issues with some popups
Eric Lemoine
eric.lemoine at camptocamp.com
Sun Aug 16 13:00:16 EDT 2009
On Sunday, August 16, 2009, Nicholas Efremov-Kendall
<n.e.kendall at gmail.com> wrote:
> Hi all,
> I'm having some issues with my code, and I'm not sure where the problem lies. This code worked at one point, and I've been staring at it for too long to see the problem. Two firebug errors fire when I click on one of the POI's "feature.geometry is undefined" and "popup is undefined". Any suggestions?
>
>
> var map, layer, selectedFeature, selectControl, selectedFeature, sites;function onPopupClose(evt) { selectControl.unselect(selectedFeature); }
>
> function onFeatureSelect(feature) { selectedFeature = feature;
"featureselected" listeners do not receive a feature but an object
with a feature property referencing the selected feature. So your code
should look like this:
function onFeatureSelect(evt) {
selectedFeature = evt.feature;
...
}
cheers,
> popup = new OpenLayers.Popup.FramedCloud("chicken", feature.geometry.getBounds().getCenterLonLat(),
> null, "<div style='font-size:.8em'>Site_ID: " + feature.attributes.title +"<hr />Locality: " + feature.attributes.title+"<br/>Description: " +feature.attributes+"<br/> Feature ID: "+feature.id+"<br/>Feature Type:"+feature.attributes.NEWSITE_ +"</div>",
> null, true, onPopupClose); feature.popup = popup; map.addPopup(popup); }
> function onFeatureUnselect(feature) { map.removePopup(feature.popup); feature.popup.destroy(); feature.popup = null;
> }
> 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 sites = new OpenLayers.Layer.GML ( "Archaeological Sites", "data/siteswatr.gml",
> { style: {pointRadius: 2.5}, projection: new OpenLayers.Projection("EPSG:4326"),
> format: OpenLayers.Format.GML } );
> map.addLayer(sites);
> sites.events.on({ 'featureselected': onFeatureSelect,
> 'featureunselected': onFeatureUnselect });
>
> selectControl = new OpenLayers.Control.SelectFeature(sites, {clickout: true, toggle: false, hover: false,
> } ); map.addControl(selectControl);
> selectControl.activate();
> if( ! map.getCenter() ){ sites.events.register('loadend', sites, function(){map.zoomToExtent(sites.getDataExtent())});
> map.setCenter(null, null); };}
> --
> Nicholas Efremov-Kendall
> Fulbright Student 2009-2010, Ukraine
> nefremov at artsci.wustl.edu
> c/o Halyna Yerko
> Balzaka 92a, Kv 27
> 02232
> Kyiv, Ukraine
> (mob) +380963576524
>
>
--
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