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

Documentation on adding tile layers #120

Closed
digitaltopo opened this issue Jun 22, 2017 · 27 comments
Closed

Documentation on adding tile layers #120

digitaltopo opened this issue Jun 22, 2017 · 27 comments

Comments

@digitaltopo
Copy link

Is there any documentation on how to add a tile layer to the map?

have tried

M.add_layer("layername","http://tiles{0-3}.basemap.com/url/{z}/{x}/{y}.png")

But it looks like the layer that gets added is requesting:
http://localhost:8888/notebooks/notebooks/null/9/8/4.png etc

@kotfic
Copy link
Contributor

kotfic commented Jun 22, 2017

@digitaltopo Try running:

M.add_layer(None, name="layername",
            vis_url="http://tiles{0-3}.basemap.com/url/{z}/{x}/{y}.png")

This should add a layer to the map which has no data associated with it.

@digitaltopo
Copy link
Author

digitaltopo commented Jun 22, 2017

Thank you, this works for the most part although the tile subdomains are being parsed as %7B0-3%7D and an extra set of /z/x/y.png is being added to the end of the base url.

Leaving off the /{z}/{x}/{y}.png} in the base url makes this work, as geonotebook is adding it by itself:

http://tiles0.basemap.com/url

How can we pass the subdomain range?

@aashish24
Copy link
Member

aashish24 commented Jun 22, 2017

@digitaltopo
Copy link
Author

digitaltopo commented Jun 22, 2017

I tried {s} as well, and it's still encoding the {s}.

@manthey
Copy link

manthey commented Jun 22, 2017

Can you try running

M.add_layer(None, name="layername",
            vis_url="http://tiles{s}.basemap.com/url/{z}/{x}/{y}.png",
            vis_params={layer_type: "osm"})

Without the layer_type parameter it auto-adds the /{z}/{x}/{y}.png and uses the rest as is rather than as a template.

To set the subdomains after that, you should be able to add

M.layers["layername"].subdomains("0123")

or

M.layers["layername"].subdomains(["0", "1", "2", "3"])

If you don't set the subdomains, they default to ["a", "b", "c"].

@jbeezley
Copy link

The M.layers["layername"] object is from the python API, which doesn't expose a way to set subdomains. That would have to be added to the RPC spec to call the javascript method on the layer object to work.

@aashish24
Copy link
Member

I tried {s} as well, and it's still encoding the {s}.

I see so I guess something is not send rightfully to GeoJS.

@jbeezley would you like to look into it bit more?

@jbeezley
Copy link

As I mentioned, setting the subdomains in a way supported by geojs would require extending the RPC spec. Even better, we could add support for the {a-c} syntax in url template strings; the openlayers renderer should work with this kind of template parameter without any changes.

@manthey
Copy link

manthey commented Jun 22, 2017

It'd be quick to extend the url template syntax. Until then, a url with an explicit subdomain can be used; it won't benefit from the distribution across subdomains, but it will work.

@aashish24
Copy link
Member

@jbeezley @manthey roger that. @jbeezley @manthey are you interested/has time to extend the RPC spec? Ping me over the email if you have questions on non-technical related matters.

@manthey
Copy link

manthey commented Jun 22, 2017

I'm extending what we accept as subdomain template strings in geojs, and should have a PR there shortly. Currently, if you use the vis_params={layer_type: "osm"} and a string with a fixed subdomain (e.g., vis_url="http://tiles0.basemap.com/url/{z}/{x}/{y}.png"), I believe it will work right now. The templated ranges will be supported once the PR is merged in geojs and we update the geojs version in geonotebook.

@manthey
Copy link

manthey commented Jun 22, 2017

Reference OpenGeoscience/geojs#715.

@aashish24
Copy link
Member

@digitaltopo we have fixed the issue on the Javascript side of things (thanks to @manthey and @jbeezley ). Could you please try the latest version of the GeoNotebook (master as of few minutes ago)? and provide us any feedback.

@digitaltopo
Copy link
Author

digitaltopo commented Jul 7, 2017

Thanks @aashish24 et all!

  1. I have updated GeoNotebook (pulled master branch, ran install scripts) but still seem to be seeing the same behavior:

Here is my code:

# Basemap Base Url
basemapUrl = "https://tiles{0-3}.domain.com/pathtotiles/{z}/{x}/{y}.png"

# Query Parameters
basemapQueryParams = {"api_key": MY_API_KEY}

# Base Map Vis Parameters
basemapVisParams = {"layer_type": "osm"}

# Add the basemap layer
M.add_layer(None, name="basemap", 
            vis_url=basemapUrl, 
            vis_params=basemapVisParams,
            query_params=basemapQueryParams)

In my network tab, I'm still seeing the following issues:

  • Curly braces in the basemap url are being encoded, resulting in: ...%7Bz%7D/%7Bx%7D/%7By%7D...
  • The z/x/y.png suffix is appended to the url again: ...%7Bz%7D/%7Bx%7D/%7By%7D.png/3/8/4.png
  • The subdomain prefixes are also being encoded, and apparently not parsed: https://tiles%7B0-1%7D...
  • The query_params don't seem to be added to the requests
  1. Additionally, when I tried passing a base url using a fixed subdomain, and left off the z/x/y.png:

https://tiles1.domain.com/pathtotiles

I get imagery responses, but the resulting tiles displayed on the map are all wrong, and it looks like it's requesting images with a variety of Z values while I am not zooming (I'm looking at network requests while panning the map).

This results in a pretty funny looking map :)

screenshot_2017-07-07_13-55-32

These may be two separate issues.
I'm going to dig around the source and see if I can figure out what's going on. Appreciate any help!

@aashish24
Copy link
Member

@digitaltopo sorry to hear this @manthey any ideas why would it not work as expected (see 1. above)

@manthey
Copy link

manthey commented Jul 11, 2017

@digitaltopo This works for me:

M.add_layer(None, name="layername",
            vis_url="http://tile.stamen.com/toner-lite/{z}/{x}/{y}.png",
            layer_type="osm")

Note that instead of vis_params=, we specify layer_type=.

@manthey
Copy link

manthey commented Jul 11, 2017

@kotfic I don't see how query_params gets processed in any way -- it looks like the created layer has a query_params property, but the NoDataLayer doesn't set it from the add_layer function, and setting it after layer creation doesn't update the javascript side of things. Maybe I'm missing something.

@digitaltopo
Copy link
Author

@manthey Thanks!

  1. Adding layer_type="osm" as an argument itself did the trick.

For any future reference, layer_type is it's own parameter instead of a property on vis_params. Thanks for clearing that up!

  1. The subdomain still has issues, it seems that the only valid input that's being respected is {s}, anything else gets encoded, and therefore isn't making it to GeoJS's subdomain parser, so I'm unable to use a subdomain like {1-3}. It appears that using {s} results only in subdomains a,b,c.

  2. @manthey @kotfic I don't see query_params in the NoDataLayer either:

class NoDataLayer(GeonotebookLayer):
    def __init__(self, name, remote, vis_url, **kwargs):
        super(NoDataLayer, self).__init__(name, remote, None, **kwargs)
        self.vis_url = vis_url

@manthey
Copy link

manthey commented Jul 11, 2017

On a docker version build from current master, subdomains work for me:

M.add_layer(None, name="layername",
            vis_url="http://{b-c}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            layer_type="osm")

only gets tiles from the b and c subdomains, and {1-3} asks for tiles from subdomains 1, 2, 3.

How did you update your deployment? If you are running locally, what version does npm list show for geojs?

@digitaltopo
Copy link
Author

I'm running locally, I pulled git master branch .

"geojs": "^0.12.2" in /geonotebook/js/package.json

@jbeezley
Copy link

To update the client code, you will need to rerun client build. The exact procedure depends on how you installed it. If you did a normal install, it should be sufficient to rerun pip install .. If you did a development install, then you'll want to go into the js subdirectory and run npm install && npm run build.

@digitaltopo
Copy link
Author

Thanks @jbeezley this is the process I followed. At this point the OSM style layer works for me as expected.

I'm only unable to specify custom subdomains like {1-3}. Using {s} in the url produces a-c subdomains but my tile server uses tiles1.domain tiles2.domain etc. When passing anything other than {s} I'm seeing requests that look like this: https://tiles%7B1-3%7D.domain...

The same is true when I use the example @manthey posted above:

"http://{b-c}.tile.openstreetmap.org/{z}/{x}/{y}.png" --->
http://%7Bb-c%7D.tile.openstreetmap.org/4/6/8.png
results in url encoded {s}

while
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" -->
http://b.tile.openstreetmap.org/14/13015/5547.png
works as expected.

Can you give any background on how the vis_url gets passed to geojs, as it seems that somewhere the contents of {s} are being url encoded if a custom subdomain scheme is used.

@jbeezley
Copy link

My guess is that for some reason you are not getting the newest version geojs in your build. There are occasions where npm install won't actually update to the correct package versions. You can check the version that is installed by running npm ls geojs in the js subdirectory. If it still has a version < 0.12.2, then you might try deleting the node_modules directory and reinstalling.

@digitaltopo
Copy link
Author

To be clear what version should I expect? Geojs is listed as ^0.12.2. I'll reinstall and rebuild.

@jbeezley
Copy link

The latest is 0.12.2.

@digitaltopo
Copy link
Author

@jbeezley Thanks! Got it all working now. When reinstalling I used the --upgrade --force-reinstall flags for pip install. Maybe this was the oversight on my part. Thank you all for your support!

@jbeezley
Copy link

Great! I forgot that pip will refuse to upgrade if there wasn't a version change.

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

No branches or pull requests

5 participants