1

I've been trying to get some GeoJSON polygon data to show up on a Leaflet map, but the endpoint I'm fetching the data from answers to the format /api/{z}/{x}/{y}.geojson. Leaflet has support for GeoJSON (as well as slicing GeoJSON via the VectorGrid plugin) but only takes Slippy Map tiles in png format, like:

L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
  attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  maxZoom: 18,
  id: 'mapbox.streets',
  accessToken: <access token>
}).addTo(map);

What's the best way to read in GeoJSON from a tile endpoint like this in Leaflet?

1

Looks like you are looking for the Leaflet GeoJSON Tile Layer plugin:

Renders GeoJSON tiles on an L.GeoJSON layer.

[…] shows how to render a GeoJSON Tile Layer for a tile endpoint at http://tile.example.com/{z}/{x}/{y}.json

There are also many other Leaflet plugins that might fit your need.

| improve this answer | |
  • Thanks for your answer! While this technically works, it's been deprecated past Leaflet 1.0.0 (or at least, I couldn't get it to work on Leaflet latest, but 0.7.x worked without a problem). I was hoping that there was a newer tiling plugin that could handle it. – Shyam Pinnipati Mar 16 '18 at 17:32
  • If you can provide a public tile source for test, maybe we could have a look. – ghybs Mar 16 '18 at 20:34
  • FWIW I have published a Proof of Concept of a plugin version for Leaflet 1+ in the plugin repo issue #39 – ghybs Mar 23 '18 at 10:14
  • Nice! Shame you can't find a proper tileserver to test it out on though... I was using a private tileserver when I encountered this issue, so I unfortunately can't share it. – Shyam Pinnipati Mar 24 '18 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.