Skip to content

Commit

Permalink
Add endpoint.remove to be called from page.unload
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Aug 12, 2024
1 parent 16c5f05 commit a68b32c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/assets/javascripts/index/directions-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
}
};

endpoint.remove = function () {
if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
delete endpoint.geocodeRequest;
removeLatLng();
delete endpoint.value;
input.val("");
map.removeLayer(endpoint.marker);
};

function getGeocode() {
var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox;
Expand Down
7 changes: 4 additions & 3 deletions app/assets/javascripts/index/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ OSM.Directions = function (map) {
$(".directions_form").hide();
$("#map").off("dragend dragover drop");

endpoints[0].remove();
endpoints[1].remove();

map
.removeLayer(popup)
.removeLayer(polyline)
.removeLayer(endpoints[0].marker)
.removeLayer(endpoints[1].marker);
.removeLayer(polyline);
};

return page;
Expand Down

0 comments on commit a68b32c

Please sign in to comment.