glenrobertson / leaflet-tilelayer-geojson

Leaflet TileLayer for GeoJSON tiles
Other
250 stars 79 forks source link

Provide a way to fetch GeoJSON tiles with constant area regardless of zoomlevel #10

Closed t-8ch closed 10 years ago

t-8ch commented 11 years ago

As GeoJSON does't change its information with different zoom levels it would be nice to fix this single layer to one zoomlevel and therefore one absolute tile size. This would reduce apirequests if the user is using a high zoomleven and is scrolling much.

nrenner commented 11 years ago

I implemented this at my development fork. See the example: tiles higher than zoom level 7 are resized and use zoom 7 tiles.

The fork is still work in progress and I plan to discuss if and what to merge back once all features are implemented and some cleanup and refactoring is done.

The implementation is in TileLayer.Overzoom.js, with hooks in TileLayer.GeoJSON.js (search for "_updateZoom"), and configured as Layer option, e.g. "serverZooms: [13]".

An optional TileCache.js reuses parsed tile data when zooming in (search "_tileCache" in TileLayer.GeoJSON.js, otherwise it relies on Browser request caching.

t-8ch commented 11 years ago

Thanks a ton @nrenner. This works like a charm! You were even to decipher the stuff I wrote last night.

One quick note: I had to exclude require('./TileLayer.Ajax.Binary.js'); from index.js or else the it could parse the response from the server.

nrenner commented 11 years ago

Good to hear you got it working. The request stuff definitely needs some refactoring. Thanks for the feedback.

glenrobertson commented 10 years ago

Sorry for taking months to get to this. I'm going to close this issue as it sounds like @nrenner has a solution. Also I would prefer this library to keep this library minimal, so it serves GeoJSON tiles based on whatever is returned by the server, instead of adding assumptions that the GeoJSON won't change across zoom levels. For example, if you were serving a :us: map, you might serve state polygons at higher zoom levels, and county/block polygons at lower zoom levels.

Thanks @t-8ch / @nrenner !

nrenner commented 10 years ago

Leaflet now has a maxNativeZoom option for TileLayer that renders part of my solution obsolete and works with this library out of the box when clipTiles: false. It also works with tile clipping when using this._getTileSize() instead of this.options.tileSize, but sometimes shows artifacts. See modified example gist and it's changes (needs CDN Leaflet, although same version?).

What is still missing is that you actually don't want to remove and reload tiles (even when cached) that are already loaded. There is some work in a fork of mine, don't know how this would apply here.