Skip to content

Commit

Permalink
Compare assets on their ID field, not JS object.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dracos committed Jan 4, 2019
1 parent 774c7a8 commit b354231
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions web/cobrands/fixmystreet/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit b354231

Please sign in to comment.