Skip to content

Commit

Permalink
fix raster layer rendering in solaraviz
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu authored and tpike3 committed Oct 12, 2024
1 parent 814d970 commit 44c4256
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 22 additions & 2 deletions mesa_geo/visualization/components/geospace_leaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def GeoSpaceLeaflet(model, agent_portrayal, view, tiles, **kwargs):
[ipyleaflet.TileLayer.element(url=map_drawer.tiles["url"])] if tiles else []
)
for layer in model_view["layers"]["rasters"]:
layers.append(ipyleaflet.ImageOverlay(element=image_to_url(layer)))
layers.append(
ipyleaflet.ImageOverlay(
url=layer["url"],
bounds=layer["bounds"],
)
)
for layer in model_view["layers"]["vectors"]:
layers.append(ipyleaflet.GeoJSON(element=layer))
ipyleaflet.Map.element(
Expand Down Expand Up @@ -163,7 +168,22 @@ def _render_layers(self, model):
else:
layer_to_render = layer.to_crs(self._crs)
layers["rasters"].append(
image_to_url(layer_to_render.values.transpose([1, 2, 0]))
{
"url": image_to_url(
layer_to_render.values.transpose([1, 2, 0])
),
# longlat [min_x, min_y, max_x, max_y] to latlong [[min_y, min_x], [max_y, max_x]]
"bounds": [
[
layer_to_render.total_bounds[1],
layer_to_render.total_bounds[0],
],
[
layer_to_render.total_bounds[3],
layer_to_render.total_bounds[2],
],
],
}
)
elif isinstance(layer, gpd.GeoDataFrame):
layers["vectors"].append(
Expand Down
10 changes: 8 additions & 2 deletions tests/test_MapModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,14 @@ def test_render_raster_layers(self):
map_module.render(self.model).get("layers"),
{
"rasters": [
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/Wj6HMwAAAAASUVORK5CYII=",
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGD4DwABBAEAgLvRWwAAAABJRU5ErkJggg==",
{
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/Wj6HMwAAAAASUVORK5CYII=",
"bounds": [[0.0, 0.0], [1.0, 1.0]],
},
{
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNgYGD4DwABBAEAgLvRWwAAAABJRU5ErkJggg==",
"bounds": [[0.0, 0.0], [1.0, 1.0]],
},
],
"total_bounds": [[0.0, 0.0], [1.0, 1.0]],
"vectors": [],
Expand Down

0 comments on commit 44c4256

Please sign in to comment.