[OpenLayers-Commits] r11707 - trunk/openlayers/examples

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Mar 16 05:41:39 EDT 2011


Author: crschmidt
Date: 2011-03-16 02:41:37 -0700 (Wed, 16 Mar 2011)
New Revision: 11707

Modified:
   trunk/openlayers/examples/dynamic-text-layer.html
Log:
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)


Modified: trunk/openlayers/examples/dynamic-text-layer.html
===================================================================
--- trunk/openlayers/examples/dynamic-text-layer.html	2011-03-16 02:52:43 UTC (rev 11706)
+++ trunk/openlayers/examples/dynamic-text-layer.html	2011-03-16 09:41:37 UTC (rev 11707)
@@ -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;



More information about the Commits mailing list