Skip to content

Commit d35e2c5

Browse files
authored
Fix split_map gray background when using vector layers (#1300)
When using split_map with a GeoJSON layer on one side and a raster on the other, dragging the swipe divider showed a gray background behind the vector layer. This duplicates the raster TileLayer from the opposite side as a background for the vector side, so the GeoJSON is always overlaid on the raster imagery.
1 parent 12620ff commit d35e2c5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

leafmap/leafmap.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,29 @@ def split_map(
21512151
raise ValueError(
21522152
f"right_layer must be one of the following: {', '.join(basemaps.keys())} or a string url to a tif file."
21532153
)
2154+
if isinstance(left_layer, ipyleaflet.GeoJSON) and isinstance(
2155+
right_layer, ipyleaflet.TileLayer
2156+
):
2157+
bg = ipyleaflet.TileLayer(
2158+
url=right_layer.url,
2159+
name=right_layer.name,
2160+
attribution=right_layer.attribution,
2161+
max_zoom=right_layer.max_zoom,
2162+
)
2163+
left_layer = [bg, left_layer]
2164+
2165+
if isinstance(right_layer, ipyleaflet.GeoJSON) and isinstance(
2166+
left_layer, (ipyleaflet.TileLayer, list)
2167+
):
2168+
source = left_layer[0] if isinstance(left_layer, list) else left_layer
2169+
bg = ipyleaflet.TileLayer(
2170+
url=source.url,
2171+
name=source.name,
2172+
attribution=source.attribution,
2173+
max_zoom=source.max_zoom,
2174+
)
2175+
right_layer = [bg, right_layer]
2176+
21542177
control = ipyleaflet.SplitMapControl(
21552178
left_layer=left_layer, right_layer=right_layer
21562179
)
@@ -7515,6 +7538,29 @@ def split_map(
75157538
raise ValueError(
75167539
f"right_layer must be one of the following: {', '.join(basemaps.keys())} or a string url to a tif file."
75177540
)
7541+
if isinstance(left_layer, ipyleaflet.GeoJSON) and isinstance(
7542+
right_layer, ipyleaflet.TileLayer
7543+
):
7544+
bg = ipyleaflet.TileLayer(
7545+
url=right_layer.url,
7546+
name=right_layer.name,
7547+
attribution=right_layer.attribution,
7548+
max_zoom=right_layer.max_zoom,
7549+
)
7550+
left_layer = [bg, left_layer]
7551+
7552+
if isinstance(right_layer, ipyleaflet.GeoJSON) and isinstance(
7553+
left_layer, (ipyleaflet.TileLayer, list)
7554+
):
7555+
source = left_layer[0] if isinstance(left_layer, list) else left_layer
7556+
bg = ipyleaflet.TileLayer(
7557+
url=source.url,
7558+
name=source.name,
7559+
attribution=source.attribution,
7560+
max_zoom=source.max_zoom,
7561+
)
7562+
right_layer = [bg, right_layer]
7563+
75187564
control = ipyleaflet.SplitMapControl(
75197565
left_layer=left_layer, right_layer=right_layer
75207566
)

0 commit comments

Comments
 (0)