Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for WMS or TMS tiles #1610

Open
njanakiev opened this issue Jun 13, 2019 · 12 comments
Open

add support for WMS or TMS tiles #1610

njanakiev opened this issue Jun 13, 2019 · 12 comments
Labels
feature something new P3 backlog

Comments

@njanakiev
Copy link

First of all, thanks for this wonderful project!

I find the support for mapbox tiles great and fairly intuitive, but I think it would be a nice feature to support some of the standard tile formats like WMS, TMS and XYZ tiles similar to the way they are implemented in Leaflet or Openlayers. This would make it easier to use self-hosted tile servers or for example OpenStreetMap tiles.

@jonmmease
Copy link
Contributor

Thanks for the suggestion @njanakiev. The MapBox JavaScript library supports rendering external (not provided by MapBox) tiles as raster layers. We're looking into adding support for these through the Plotly API. Would this satisfy the use cases you have in mind?

@njanakiev njanakiev changed the title Support for WMS or XYZ Tiles Support for WMS or TMS Tiles Jun 18, 2019
@njanakiev
Copy link
Author

Thank you for the fast reply. Do you mean like shown in this documentation? I suppose this should support arbitrary WMS servers. What I also had in mind is support for TMS tiles as they are also fairly common. You can see how Leaflet uses WMS and TMS tiles in these examples. They also support TMS tile layers with endpoints of the form:

http://base_url/tms/1.0.0/ {tileset} / {z} / {x} / {y} .png

An OpenStreetMap tile example would look like:

https://tile.openstreetmap.org/7/63/42.png

Is this something that MapBox can also support with the raster layers?

@joshwarren
Copy link

joshwarren commented Sep 11, 2019

I think you probably can by using mapbox with a custom layer, but I haven't quite got it working yet (see here: https://plot.ly/python/mapbox-layers/).

import plotly.graph_objects as go

fig = go.Figure()

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "source": ["http://localhost:8080/myWMSServer/wms?"]
        }
      ])

fig.show()

I'm not sure if it's not working because I'm getting the source incorrect (I've tried using an address that will serve me a png map in the browser but that didn't work either) or if this idea will simply not work at all...

I'd be grateful if anyone has any suggestions.

@nicolaskruchten
Copy link
Contributor

I'm sorry our docs are not sufficiently clear on this point... The contents of the source array are passed to Mapbox.js and according to their docs, should be TileJSON-compliant. Basically this means that these URLs should have {x}, {y} and {z} placeholders OR a {bbox-epsg-3857} placeholder. We have an example in our docs with both in the same map here: https://plot.ly/python/mapbox-layers/#base-tiles-from-the-usgs-radar-overlay-from-environment-canada-no-token-needed

@maurerle
Copy link

Could you please add support for setting the scheme parameter to the mapbox_layers?
This is done for most params shown at the mapbox documentation:
https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#raster-scheme

like minzoom and maxzoom. So there is no point in leaving the scheme param as mapbox supports it.

@giswqs
Copy link

giswqs commented Dec 27, 2021

Mapbox supports adding a WMS source. It would be nice to have the same support for plotly.
https://docs.mapbox.com/mapbox-gl-js/example/wms/

@Ma-Schw
Copy link

Ma-Schw commented Nov 19, 2022

Being able to usw WMS-sources in plotly for background maps (e.g. in px.choropleth_mapbox) would greatly help in projects where it is mandatory that no data from servers in foreign countries (in this case servers from Mapbox) is requested. At least in Germany most services for background maps are WMS and not TileJSON-compliant.

In leaflet the use of WMS is already possible: https://dash-leaflet.herokuapp.com/#wsm_tile_layer

@Masoudas
Copy link

Masoudas commented May 6, 2023

@nicolaskruchten Hi, and thanks for the wonderful work you do. I'm in dire need of showing a WMS layer in mapbox as well. Any progress on this front so far? Does it need an access token? I use it offline? Also, if not, do you have an alternative?

@Masoudas
Copy link

Masoudas commented May 6, 2023

Actually, I've found a way right now to use a redirection and the mercantile library to convert xyz to a bbox for WMS layer. But for some reason when I add this redirection, mapbox shows the layer, but it somehow freezes and stops working. The code is something like this (not a working example, but you get the idea I guess):

mapbox_layers.append(
{
"below": 'traces',
"sourcetype": "raster",
# "sourceattribution": "United States Geological Survey",
"source": [
"http://0.0.0.0/my_redirection_to_wms/" + "/{z}/{y}/{x}"
]
}
)

The redirection url

@app.server.route('/my_redirection_to_wms///', methods=['GET'])
def getGISData(username: str, layers: str, z: str, x: str, y: str):
bound = mercantile.bounds(int(y), int(x), int(z))
omoor_gis = get_gis_omoor_username(username).omoorBoundary

if not omoor_gis.intersects(Point((bound.west, bound.south))) \
        and not omoor_gis.intersects(Point((bound.east, bound.north))):
    return b""

layers_list = ",".join(layers.split("0"))

redirect_url = f"{gis_wms_route}/qgis-server?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bound.west},{bound.south},{bound.east},{bound.north}&CRS=CRS:84&WIDTH=256&HEIGHT=256&LAYERS={layers_list}&FORMAT=image/png&DPI=48&MAP_RESOLUTION=48&FORMAT_OPTIONS=dpi:96&TRANSPARENT=True"

return requests.get(redirect_url).content

@makmegs
Copy link

makmegs commented Sep 4, 2023

Like @Masoudas, I also have a strong need for showing WMS layers as TMS is EXTREMELY limiting. Is there any plan to implement this or does it need a sponsor?

@alexcjohnson
Copy link
Collaborator

@makmegs this isn't currently on our roadmap but if you're interested in sponsoring we'd be happy to discuss 😄

@gvwilson gvwilson self-assigned this Jun 13, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added feature something new P3 backlog and removed plotly.js labels Aug 12, 2024
@gvwilson gvwilson changed the title Support for WMS or TMS Tiles add support for WMS or TMS tiles Aug 12, 2024
@gvwilson
Copy link
Contributor

@archmoj is this one addressed by your recent work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests