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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user