question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SplitMap Control with transparent layers

See original GitHub issue

The SplitMap Control does not work properly for transparent layers. For example, when adding a WMS layer with transparency (i.e., NoData area is transparent), there is a background basemap on the left blocking the layer on the right. There is still a gray background on the left even when the basemap is cleared. Ideally, the left layer with transparency would be directly overlaid on the right layer without being interfered by the basemap or gray background.

from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl, WMSLayer

m = Map(center=(40, -100), zoom=4)
m.clear_layers()

right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")
# left_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisAquaBands721CR, "2017-11-11")
naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
left_layer = WMSLayer(url=naip_url, layers='0', name='NAIP Imagery', format='image/png')

control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)
m.add_control(control)

m

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
giswqscommented, Jun 25, 2020

@martinRenou Thanks to your suggestion. I was able to make it work. Note that the script below is only a portion of a much longer Earth Engine script. Therefore, you won’t be able to run it directly.

layer_index = 0

water_image = ee.Image(water_images.toList(water_images.size()).get(layer_index))
landsat_image = ee.Image(landsat_images.toList(landsat_images.size()).get(layer_index))


left_layer = geemap.ee_tile_layer(water_image, water_vis, 'Water')
right_layer = geemap.ee_tile_layer(landsat_image, landsat_vis, 'Landsat')

Map = geemap.Map()
Map.addLayer(landsat_image, landsat_vis, 'Landsat')
Map.split_map(left_layer, right_layer)
Map

1reaction
martinRenoucommented, Jun 25, 2020

Ok now I understand. So the code that should do what you want is:

from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl, WMSLayer

m = Map(center=(40, -100), zoom=4, layers=[basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")])

naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
left_layer = WMSLayer(url=naip_url, layers='0', name='NAIP Imagery', format='image/png')

control = SplitMapControl(left_layer=left_layer)
m.add_control(control)

m

But again, it does not work and lots of errors are appearing.

It looks like this works:

from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl, WMSLayer

m = Map(center=(40, -100), zoom=4, layers=[basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")])

naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'
left_layer = WMSLayer(url=naip_url, layers='0', name='NAIP Imagery', format='image/png')

control = SplitMapControl(left_layer=left_layer, right_layer=basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11"))
m.add_control(control)

m
Read more comments on GitHub >

github_iconTop Results From Across the Web

103 split control - geemap
The split-panel map requires two layers: left_layer and right_layer . ... fmt="image/png", transparent=True, ) right_layer = folium.
Read more >
49 split control - leafmap
The split-panel map requires two layers: left_layer and right_layer . The layer instance can be a string representing a basemap, or an HTTP...
Read more >
SplitMap Control — ipyleaflet documentation - Read the Docs
SplitMapControl class, with Control as parent class. A control which allows comparing layers by splitting the map in two. ... The left layer(s)...
Read more >
QuantStack/leaflet-splitmap - GitHub
Creates a new Leaflet Control for comparing two layers or collections of layers. It does not add the layers to the map -...
Read more >
Creating a transparent portion of a control to see controls ...
In Windows Forms, you achieve transparency (or draw irregularly shaped windows) by defining a region. To quote MSDN.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found