openlayers / ol-mapbox-style

Use Mapbox Style objects with OpenLayers
https://unpkg.com/ol-mapbox-style/dist/examples/index.html
BSD 2-Clause "Simplified" License
338 stars 119 forks source link

Projection support for vector sources #226

Open orangemug opened 5 years ago

orangemug commented 5 years ago

I wanted to use vector tiles with another projection other than EPSG:3857, so here's my take on how we could add support for that.

Support two new fields ol:projection/ol:extent, extentions to the mapbox-gl style spec. So an example source would look like this

{
  "sources": {
    "us_states": {
      "type": "vector",
      "tiles": ["https://orangemug.github.io/vector-tiles-projection-test/vectortiles/EPSG102003/{z}/{x}/{y}.pbf"],
      "ol:projection": "102003",
      "ol:extent": [
        -2357180.9345227931626141,
        -1295390.5666783656924963,
        2257301.1407301435247064,
        1560376.8365237235557288
      ],
      "minZoom": 0,
      "maxZoom": 2
    }
  }
}

The idea of namespacing with ol:extent instead of just extent is presumably the spec might support extent in future in a different format.

There is a branch which supports this new extension over at https://github.com/openlayers/ol-mapbox-style/compare/master...orangemug:feature/add-projections, happy to raise a PR if you like the approach.

I've also added this to a Maputnik branch, you can see a demo action and see a write up here https://github.com/maputnik/editor/pull/529 .

Let me know your thoughts

orangemug commented 4 years ago

Hi @ahocevar I wonder if there is any interest in adding the functionality mentioned this ticket? It seems to work really well in Maputnik with projections enabled (see demo). I'm happy to help in any way I can to get projections supported.

mike-000 commented 4 years ago

Maptiler has sample code https://cloud.maptiler.com/maps/ (login to get access to the code) using tiles designed for non-EPSG:3857 projections where the tilegrid options are hardcoded. Ordnance Survey have an EPSG:27700 example which creates the tilegrid from the json https://github.com/OrdnanceSurvey/OS-Data-Hub-API-Demos/blob/master/OSVectorTileAPI/OpenLayers/map.js