From ba888f5c7d5ae453e27973e1e57f3c6e0e4f3711 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 1 Nov 2022 02:09:51 +0300 Subject: [PATCH] Remove query result geometry when unloading the page --- app/assets/javascripts/index/query.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/index/query.js b/app/assets/javascripts/index/query.js index c81d035fb..e44db9fdf 100644 --- a/app/assets/javascripts/index/query.js +++ b/app/assets/javascripts/index/query.js @@ -39,17 +39,21 @@ OSM.Query = function (map) { } }); + function showResultGeometry() { + var geometry = $(this).data("geometry"); + if (geometry) map.addLayer(geometry); + $(this).addClass("selected"); + } + + function hideResultGeometry() { + var geometry = $(this).data("geometry"); + if (geometry) map.removeLayer(geometry); + $(this).removeClass("selected"); + } + $("#sidebar_content") - .on("mouseover", ".query-results li.query-result", function () { - var geometry = $(this).data("geometry"); - if (geometry) map.addLayer(geometry); - $(this).addClass("selected"); - }) - .on("mouseout", ".query-results li.query-result", function () { - var geometry = $(this).data("geometry"); - if (geometry) map.removeLayer(geometry); - $(this).removeClass("selected"); - }) + .on("mouseover", ".query-results li.query-result", showResultGeometry) + .on("mouseout", ".query-results li.query-result", hideResultGeometry) .on("mousedown", ".query-results li.query-result", function () { var moved = false; $(this).one("click", function (e) { @@ -363,6 +367,7 @@ OSM.Query = function (map) { page.unload = function (sameController) { if (!sameController) { disableQueryMode(); + $("#sidebar_content .query-results li.query-result.selected").each(hideResultGeometry); } }; -- 2.39.5