Hi all,<div><br></div><div>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?<br clear="all">
<br></div><div><div><br></div><div>var map, layer, selectedFeature, selectControl, selectedFeature, sites;</div><div>function onPopupClose(evt) {</div><div> selectControl.unselect(selectedFeature);</div><div> }</div>
<div><br></div><div>function onFeatureSelect(feature) {</div><div> selectedFeature = feature;</div><div> popup = new OpenLayers.Popup.FramedCloud("chicken", </div><div> feature.geometry.getBounds().getCenterLonLat(),</div>
<div> null,</div><div> "<div style='font-size:.8em'>Site_ID: " + feature.attributes.title +"<hr />Locality: " + feature.attributes.title+"<br/>Description: " +feature.attributes+"<br/> Feature ID: "+<a href="http://feature.id">feature.id</a>+"<br/>Feature Type:"+feature.attributes.NEWSITE_ +"</div>",</div>
<div> null, true, onPopupClose);</div><div> feature.popup = popup;</div><div> map.addPopup(popup);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span> function onFeatureUnselect(feature) {</div><div> map.removePopup(feature.popup);</div><div> feature.popup.destroy();</div><div> feature.popup = null;</div>
<div> } </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>function init() {</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>map = new OpenLayers.Map ("map", </div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>controls:[</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>new OpenLayers.Control.Navigation(),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>new OpenLayers.Control.PanZoomBar(),</div><div><span class="Apple-tab-span" style="white-space:pre">                                        </span>new OpenLayers.Control.LayerSwitcher(),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>new OpenLayers.Control.Attribution()],</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>sphericalMercator: true,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>maxResolution: 156543.0399,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>numZoomLevels: 19,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>units: 'm',</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>projection: new OpenLayers.Projection("EPSG:900913"),</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>displayProjection: new OpenLayers.Projection("EPSG:4326"),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span><span class="Apple-tab-span" style="white-space:pre">                        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>var<span class="Apple-tab-span" style="white-space:pre">        </span>sites = new OpenLayers.Layer.GML (</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>"Archaeological Sites", "data/siteswatr.gml",</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>style: {pointRadius: 2.5}, </div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>projection: new OpenLayers.Projection("EPSG:4326"),</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>format: OpenLayers.Format.GML</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>map.addLayer(sites);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>sites.events.on({</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>'featureselected': onFeatureSelect,</div>
<div> <span class="Apple-tab-span" style="white-space:pre">                </span>'featureunselected': onFeatureUnselect</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>});</div><div><br></div><div>
selectControl = new OpenLayers.Control.SelectFeature(sites,</div><div> {clickout: true,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>toggle: false,</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>hover: false,</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>}</div><div> );</div><div> map.addControl(selectControl);</div><div><br></div><div> selectControl.activate();</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>if( ! map.getCenter() ){</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>sites.events.register('loadend', sites, function(){map.zoomToExtent(sites.getDataExtent())});</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>map.setCenter(null, null);</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>};</div><div>}</div><div><br></div>-- <br>Nicholas Efremov-Kendall<br>
Fulbright Student 2009-2010, Ukraine<br><a href="mailto:nefremov@artsci.wustl.edu">nefremov@artsci.wustl.edu</a><br>c/o Halyna Yerko<br>Balzaka 92a, Kv 27<br>02232<br>Kyiv, Ukraine<br>(mob) +380963576524<br>
</div>