Loading local TileFile layer in pydeck

857 Views Asked by At

Am trying to load a local TileFile layer in pydeck(0.5) in jupyter notebook I am using the following code:

    import pydeck as pdk
    data ='https://localhost:/home/user/myfolder/tiles/{z}/{x}/{y}.png`

    layer = pdk.Layer(
      'TileLayer',  # `type` positional argument is here
      data=data
      )

    # Set the viewport location
    view_state = pdk.ViewState(
      longitude=50,
      latitude=50,
      zoom=0,
      min_zoom=0,
      max_zoom=5,
      pitch=40.5,
      bearing=-27.36)

    # Combined all of it and render a viewport
    r = pdk.Deck(layers=[layer], initial_view_state=view_state)
    r.to_html('TileLayer-example.html'

This just creates a blank view window in Jupyter where it should show an image. If I take launch the TileLayer-example.html independently into a browser I also get a blank window, However browser (Firefox) console output is as follows:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:/home/user/myfolder/tiles/0/0/0.png. (Reason: CORS request did not succeed).

TypeError: NetworkError when attempting to fetch resource. tile-layer.js:18:56
    value tile-layer.js:18
    value tile-layer.js:136
    t tile-2d-header.js:90
    u runtime.js:45
    _invoke runtime.js:271
    e runtime.js:97
    Babel 2
        r
        u

I am not sure if the problem is CORS related (calling a local file) or if my data path is just plain wrong? I have tried may variants on path but all seem to have the same console warning issues.

Any suggestions for simple safe ways around the CoRs problem, or suggestions for accessing local TileFiles in PyDeck would be much appreciated

1

There are 1 best solutions below

0
On

For other folk currently looking to implement TileLayer in Pydeck. It appears TileLayer is not yet documented or currently supported in pydeck and can only be achieved with a custom layer see this github issue and this suggested workaround with a custom layer

With respect to the CoRs issue of trying to display a local file resource in the browser when called from a URL. if you are looking for a quick fix to do a test/debug then in Firefox: the suggestions here help. For Firefox specifically they suggest the following:

go to about:config search for privacy.file_unique_origin set it to false.

Note this is a security risk so reset it to true after debugging.

The only workable solution currently seems to be to put the tilefile in the working directory from which your deck project is launched