Skip to content

Commit

Permalink
fix: remove old map layers before rendering new layers
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu committed Mar 22, 2024
1 parent b717971 commit a256729
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mesa_geo/visualization/templates/js/MapModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ const MapModule = function (view, zoom, map_width, map_height, tiles, scale_opti
}
}

let mapLayers = []
let hasFitBounds = false
this.renderLayers = function (layers) {
mapLayers.forEach(layer => {layer.remove()})
mapLayers = []

layers.rasters.forEach(function (layer) {
L.imageOverlay(layer, layers.total_bounds).addTo(Lmap)
const rasterLayer = L.imageOverlay(layer, layers.total_bounds).addTo(Lmap)
mapLayers.push(rasterLayer)
})
layers.vectors.forEach(function (layer) {
L.geoJSON(layer).addTo(Lmap)
const vectorLayer = L.geoJSON(layer).addTo(Lmap)
mapLayers.push(vectorLayer)
})
if (!hasFitBounds && !customView && layers.total_bounds.length !== 0) {
Lmap.fitBounds(layers.total_bounds)
Expand Down Expand Up @@ -66,6 +72,8 @@ const MapModule = function (view, zoom, map_width, map_height, tiles, scale_opti

this.reset = function () {
agentLayer.remove()
mapLayers.forEach(layer => {layer.remove()})
mapLayers = []
}
}

Expand Down

0 comments on commit a256729

Please sign in to comment.