[OpenLayers-Users] Issues with some popups

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Sun Aug 16 08:02:43 EDT 2009


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;
            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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090816/b771e8f1/attachment.html


More information about the Users mailing list