From b00dc40ff064f35b878c5416ae0cd96f7384097d Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 29 Jan 2025 15:59:49 +0300 Subject: [PATCH] Abort loading when data layer is removed --- app/assets/javascripts/index/layers/data.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/layers/data.js b/app/assets/javascripts/index/layers/data.js index e1246ca6c9..3cc8f61357 100644 --- a/app/assets/javascripts/index/layers/data.js +++ b/app/assets/javascripts/index/layers/data.js @@ -1,6 +1,6 @@ OSM.initializeDataLayer = function (map) { - var loadedBounds; - var dataLayer = map.dataLayer; + let dataLoader, loadedBounds; + const dataLayer = map.dataLayer; dataLayer.setStyle({ way: { @@ -32,6 +32,8 @@ OSM.initializeDataLayer = function (map) { }); dataLayer.on("remove", function () { + if (dataLoader) dataLoader.abort(); + dataLoader = null; map.off("moveend", updateData); $("#browse_status").empty(); map.fire("overlayremove", { layer: this }); @@ -77,8 +79,6 @@ OSM.initializeDataLayer = function (map) { .text(I18n.t("browse.start_rjs.feature_error", { message: message })))))); } - var dataLoader; - function getData() { var bounds = map.getBounds(); var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();