I’ve been using Plotly in combination with Mapbox a lot, however sometimes Mapbox just doesn’t do the job, e.g. when it comes to high resolution satellite images (which Mapbox only provides for very limited regions) or very accurately georeferenced images.
There exists an open source map/tile server/proxy, which is used a lot in the GIS community, called MapProxy. It would be awesome if Plotly could also work together with MapProxy, however I didn’t get that working yet.
MapProxy supports (dependent on the configuration) WMS, WMS-C, WMTS and TMS. When searching for the support of data sources other than Mapbox in Plotly I always end up with this page here: Mapbox map layers in Python
But I haven’t been able to modify the source correctly so that it is compatible to MapProxy.
For testing purposes: here’s a freely available instance of MapProxy: MapProxy Demo
It is possible to pull data in somewhat, see my example code:
#!/usr/bin/env python3
"""MapProxy / Plotly Test."""
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(rows=1, cols=1)
fig.add_trace(
go.Scattermapbox(
lat=[50.73427, 50.73428],
lon=[7.10883, 7.10884],
mode='markers',
)
)
fig.update_layout(
mapbox_style="white-bg",
mapbox_layers=[
{
"below": 'traces',
"sourcetype": "raster",
"sourceattribution": "None",
"source": [
"https://stadtplan.troisdorf.de/mapproxy/service?LAYERS=osm&FORMAT=image%2Fpng&SRS=EPSG%3A3857&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&BBOX=790830.77026886,6573673.6153899,792162.6934319,6574988.0132481&WIDTH=608&HEIGHT=600"
]
},
])
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.write_html('test.html', auto_open=True)
However of course that doesn’t provide the desired results since MapProxy requires a bounding box while the Plotly Mapbox plot wants to refer to a x/y+zoom tile.
Is there an option to get make both work together directly? Or a way to convert it?