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.

Question: add bounds to TileLayers?

See original GitHub issue

psuedo code example

MIN_ZOOM = 8
MIN_LEVEL = 12
MAX_LEVEL = 17

map = folium.Map(location=center, zoom_start=14)
for i in range(0, 5):
    map.add_tile_layer(max_zoom=MAX_LEVEL, min_zoom=MIN_ZOOM, tiles=styles[i])
...
for track in gpx_tracks:
    fg = folium.FeatureGroup(name=track.name)
    url = 'http://0.0.0.0:5000/smarttile/{customname}'.format(customname=make_word(track.name))
    tl = folium.TileLayer(
        tiles=url + '/{z}/{x}/{y}.png',
        attr='myself',
        min_zoom=MIN_LEVEL, max_zoom=MAX_LEVEL,
        name=name,
    )
    fg.add_child(tl)
    map.add_child(fg)

Problem description

This is a question. (And I am quite new at this. )

I am reading several gpx tracks (traces from hikes) and wants to generate tiles for these tracks on demand, and display it/them on a map.

Since a track has a bounding box, I would like to only request tiles for the inside of that bounding box, and I would like to be able to display several (mostly) disjoint tracks/areas.

Below is pseudo code of what I am trying to do, I tried to add something like this: “folium.FitBounds([track.corner1, track.corner2])” but I did not get it to work like expected.

Is it possible to do what I want to do?

Expected Output

Output of folium.__version__

$ python3
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import folium
>>> folium.__version__
'0.6.0'

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
frdrk345commented, Sep 17, 2018

Well, doing the trivial change of adding the line with bounds in the javascript here below seemed to do the trick.

Is the example below here clear enough?

var feature_group_1ba35654fa5c4977bb4a09a04b24c94c = L.featureGroup(
                ).addTo(map_5560a7df2b1947dbbe5a1b59bd6155b7);

   var tile_layer_329ab03da4f5427c875b29d836f65d20 = L.tileLayer(
        'http://0.0.0.0:5000/smarttile/track63636/{z}/{x}/{y}.png',
        {
        "attribution": "Fredrik Skold",
        "detectRetina": false,
        "maxNativeZoom": 17,
        "maxZoom": 17,
        "minZoom": 12,
	"bounds": [[58.2989015803, 15.7834048849], [58.321642857, 15.8565335535]],
        "noWrap": false,
        "subdomains": "abc"
}).addTo(feature_group_1ba35654fa5c4977bb4a09a04b24c94c);

The same thing in unified diff format (different coordinates since they belong to different tracks):

$ diff -u  folium-v0.html folium-v1.html 
--- folium-v0.html	2018-09-17 22:55:15.973001000 +0200
+++ folium-v1.html	2018-09-17 23:13:13.293001000 +0200
@@ -435,6 +435,7 @@
         "maxNativeZoom": 17,
         "maxZoom": 17,
         "minZoom": 12,
+	"bounds": [[58.51589, 15.521916], [58.517519, 15.52672]],
         "noWrap": false,
         "subdomains": "abc"
 }).addTo(feature_group_0090825d1fa34f88832b6826fca58a91);

I don’t think I am up to speed so I can do the changes in folium by myself, but I would be very interested in testing a poll request for this.

0reactions
ocefpafcommented, Sep 17, 2018

Ok, so should I take my current code and let it generate a webpage, and when investigate the leaflet documentation and try to see if I manually can edit the wbepage/javascript code to see if I can do what I want to do?

That is a start. If you figure that out we can probably wrap it into folium.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XY bounds for L.tileLayer in CRS.Simple - GIS Stack Exchange
But I don't know how to do L.tileLayer with this bounds (coordinates) [1468.9700 ... I trying to resolve my problem, but it don't...
Read more >
Leaflet WMS Tile Layer bounds set - geoserver - Stack Overflow
I want to limit my wms tile layers with a region. I saw a parameter in the WMSTileLayer bounds, however it can't be...
Read more >
TileLayer - deck.gl
The TileLayer is a composite layer that makes it possible to visualize very large datasets ... Each tile has a pre-defined bounding box...
Read more >
Constrain bounds of TileLayer · Issue #888 - GitHub
Would it be possible to add a property to the TileLayer that will constrain its bounds? The lack of constraint poses a problem...
Read more >
ol/layer/Tile~TileLayer - OpenLayers
The bounding extent for layer rendering. The layer will not be rendered outside of this extent. zIndex, number | undefined. The z-index for...
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