From 87215daa545b29e0069fcc3c5ec5e1ad1318176b Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 16 Mar 2011 09:41:37 +0000 Subject: [PATCH] The dynamic text layer uses an onPopupClose which looks to the layer and first calls unselect on the selectfeaturecontrol. However, this fails if the feature in question is no longer in the map -- for example, if you zoom in or otherwise change positions. (The selected feature no longer exists, so you call close on a feature which no longer has a layer object.) This change to the examples by Jorix fixes this behavior in the example. Note that many people use similar functionalities in their code, so this likely means that what we *should* do is armor unselect() against being called with a feature with a null layer, but that involves a longer discussion -- do we still fire onUnselect? Do we still fire the unselect events? is there other cleanup we need to do? etc. -- so this is changing the example to demonstrate one way to armor application code against the problem. Thanks to jorix for the suggestion on the example fix. (See #3046) (See #2515) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11707 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/dynamic-text-layer.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/dynamic-text-layer.html b/examples/dynamic-text-layer.html index 48fcd83760..3c3f701b13 100644 --- a/examples/dynamic-text-layer.html +++ b/examples/dynamic-text-layer.html @@ -41,7 +41,13 @@ // Needed only for interaction, not for the display. function onPopupClose(evt) { // 'this' is the popup. - selectControl.unselect(this.feature); + var feature = this.feature; + if (feature.layer) { // The feature is not destroyed + selectControl.unselect(feature); + } else { // After "moveend" or "refresh" events on POIs layer all + // features have been destroyed by the Strategy.BBOX + this.destroy(); + } } function onFeatureSelect(evt) { feature = evt.feature; @@ -53,7 +59,7 @@ null, true, onPopupClose); feature.popup = popup; popup.feature = feature; - map.addPopup(popup); + map.addPopup(popup, true); } function onFeatureUnselect(evt) { feature = evt.feature;