From 6d15280fddfa7a229d451fd4e7e87d4c79cded62 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Fri, 21 Oct 2016 05:33:45 +0300 Subject: [PATCH] Fix location hash behaviour of search form --- frontend/app/map/search/search.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/frontend/app/map/search/search.js b/frontend/app/map/search/search.js index 9ffd57f9..4e8b3a03 100644 --- a/frontend/app/map/search/search.js +++ b/frontend/app/map/search/search.js @@ -13,6 +13,7 @@ scope.search = function(noZoom) { scope.searchResults = null; + scope.activeResult = null; scope.loadedSearchString = ""; clearRenders(); @@ -42,18 +43,19 @@ }).catch(function(err) { map.messages.showMessage("danger", err); }); - } + } else + map.mapEvents.$emit("searchchange"); }; scope.showResult = function(result, noZoom) { - if(scope.showAll) { + if(scope.showAll && scope.searchResults.length > 1) { if(!noZoom) _flyToBounds(layerGroup.getBounds()); result.marker ? result.marker.openPopup() : result.layer.openPopup(); } else { clearRenders(); - renderResult(scope.loadedSearchString, scope.searchResults, result, true, layerGroup); + renderResult(scope.loadedSearchString, scope.searchResults, result, true, layerGroup, noZoom); if(!noZoom) { if(result.lat && result.lon && result.zoom) @@ -136,7 +138,7 @@ scope.searchResults = results; if(results && results.length > 0) - scope.showAll ? scope.showAllResults(noZoom) : scope.showResult(scope.searchResults[0], noZoom); + (scope.showAll && results.length > 1) ? scope.showAllResults(noZoom) : scope.showResult(scope.searchResults[0], noZoom); } function parseFiles(files) { @@ -229,7 +231,7 @@ return ret; } - function renderResult(query, results, result, showPopup, layerGroup) { + function renderResult(query, results, result, showPopup, layerGroup, noZoom) { if(!result.lat || !result.lon || (result.geojson && result.geojson.type != "Point")) { // If the geojson is just a point, we already render our own marker result.layer = L.geoJson(result.geojson, { pointToLayer: function(geoJsonPoint, latlng) { @@ -274,10 +276,12 @@ } if(showPopup) { - if(result.marker) - result.marker.openPopup(); - else if(result.layer) - result.layer.openPopup(); + var popupLayer = result.marker || result.layer; + if(popupLayer) { + if(noZoom) + popupLayer._popup.options.autoPan = false; + popupLayer.openPopup(); + } } } @@ -340,6 +344,9 @@ $timeout(function() { $timeout(function() { // $compile only replaces variables on next digest popup.update(); + + // Might have been set to false in renderResult() if noZoom + popup.options.autoPan = true; }); }); } @@ -348,7 +355,7 @@ el.show(); if(scope.searchResults) { - if(scope.showAll) + if(scope.showAll && scope.searchResults.length > 1) scope.showAllResults(); else if(scope.searchResults.length > 0) scope.showResult(scope.activeResult || scope.searchResults[0]); @@ -387,7 +394,7 @@ getCurrentSearchForHash: function() { if(el.is(":visible")) { - if(!scope.showAll && scope.activeResult && scope.activeResult.id) + if(((scope.searchResults && scope.searchResults.length == 1) || !scope.showAll) && scope.activeResult && scope.activeResult.id) return [ scope.activeResult.id ]; else if(scope.loadedSearchString) return [ scope.loadedSearchString ];