diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-01-04 17:12:43 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-01-04 17:43:03 +0000 |
commit | b3542314ac6480505b9939b2e46715a19dab8d49 (patch) | |
tree | 76fa788e6ee92e627a42e92bac7d22fcc77aa2ae | |
parent | 774c7a813da709fb46fca1a65d5c192d72266e14 (diff) |
Compare assets on their ID field, not JS object.
As the selected feature is a clone (so it survives e.g. layer reloading
from server after a pan), we need to compare the asset ID field instead
to see if we already have a match, to prevent a double select().
This also fixes a bug where an auto-selected asset would, after picking
a different asset, reshow the selected pin image onmouseout, due to the
way OL was storing old hover state internally.
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index b83f07359..0134991e9 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -425,10 +425,20 @@ function layer_visibilitychanged() { function layer_loadend() { this.select_nearest_asset(); // Preserve the selected marker when panning/zooming, if it's still on the map - if (selected_feature !== null && !(selected_feature in this.selectedFeatures)) { - var replacement_feature = this.find_matching_feature(selected_feature, this); - if (!!replacement_feature) { - this.get_select_control().select(replacement_feature); + if (selected_feature !== null) { + // Can't use (selected_feature in this.selectedFeatures) as it's a clone + var found = false; + for (var i=0; i < this.selectedFeatures.length; i++) { + if (this.assets_have_same_id(selected_feature, this.selectedFeatures[i])) { + found = true; + break; + } + } + if (!found) { + var replacement_feature = this.find_matching_feature(selected_feature, this); + if (!!replacement_feature) { + this.get_select_control().select(replacement_feature); + } } } } |