protomaps / basemaps

Basemap PMTiles generation and cartographic styles for OpenStreetMap data and more
https://maps.protomaps.com/
Other
378 stars 49 forks source link

Style Data for the Base Maps? Raster? #187

Closed coogle closed 9 months ago

coogle commented 11 months ago

I apologize if this isn't the proper place to ask this, but as a relative newbie to this project I couldn't figure out the answer I was looking for here.

I am trying to integrate protomaps via AWS Lambda function into a Flutter application (following https://docs.protomaps.com/deploy/aws). I think I've done a decent job of getting the server itself working as I can make requests and get .mvt files back from my lambda function, but I am not sure what I need to actually tie this into my map widget. It seems to require some sort of style JSON -- here's the relevant part of an example taken provided for one of the commercial vendors:

  Future<Style> _readStyle() => StyleReader(
          uri:
              'https://tiles.stadiamaps.com/styles/osm_bright.json?api_key={key}',
          apiKey: stadiaMapsApiKey,
          logger: const Logger.console())
      .read();

It seems to me I need this style JSON file for these base maps, if I am understanding it correctly? I see some code in the various repos for styles, but how to use it, etc. is unclear. Are there styles available somewhere I'm missing? The docs reference them but they are all blank pages (mostly, at least).

Secondary question: If I understand correctly pmtiles can also be used for raster tiles, correct? Is there any documentation for creating a raster tileset (in case I can't get the vector tiles working with my system in the short term)? When I try to make a request for .png files (for example) I get back an error saying only .mvt is available.

bdon commented 11 months ago

Go to https://maps.protomaps.com/ and choose "get Style JSON" and inline that JSON into your application. This lets you customize it as well.

Because the JSON is static I don't see huge value in embedding the style into the Lambda API. The other option if you're using JS is to load the style object from NPM but I don't think that is relevant to Flutter.

PMTiles are static archives of tiles, vector or raster. If you want to store raster tiles you need to generate those raster tiles somewhere. Converting from vector to raster tiles requires a rasterizer like Mapnik or MapLibre GL Native which is computationally heavy and outside the scope of this project.

prusswan commented 11 months ago

It would be convenient if the style.json for the respective default styles is also provided as part of the API (would make it easier to use with https://maputnik.github.io). One workaround to get a hosted style json, is to use the daily builds https://maps.protomaps.com/builds/ -> Compare in Maperture -> something like https://build-metadata.protomaps.dev/style@2.0.0-alpha.0+theme@light+tiles@20230925.json

bdon commented 11 months ago

@prusswan in many cases it's easier to "assemble" a style JavaScript object (not JSON) by grabbing the layers from e.g. https://unpkg.com/protomaps-themes-base@2.0.0-alpha.0/dist/layers/light.json and providing your own sources key.

That doesn't address the case of Maputnik, etc though. What I may do is just spin up an editor interface with the right style.json preloaded? Is there another case for needing a style.json?

I have that as part of the hosted API with API keys too:

https://api.protomaps.com/styles/v2/dark.json?key=KEY

prusswan commented 11 months ago

I have that as part of the hosted API with API keys too:

That's neat and exactly what @coogle and I was looking for. Would be great to mention in the docs (e.g. https://protomaps.com/other), especially for users familiar with Mapbox/OpenMapTiles etc. Did not know about protomaps-themes-base as I only found this repo and thought users were expected to build the style.json themselves

Is there another case for needing a style.json?

Other than the online maputnik, I use it for working with other map clients and libraries where it is convenient to download/reference a style that already exists and just override the tile url or strip out the parts I don't need

bdon commented 9 months ago

I listed out the hosted style endpoints at https://protomaps.com/other

The styles as part of the open source project have source code at https://github.com/protomaps/basemaps/tree/main/styles and also are compiled into layers objects like this: http://unpkg.com/protomaps-themes-base@2.0.0-alpha.5/dist/layers/dark.json - seems easiest to let you assemble your own Style object with the correct sources keys. Let me know if you find a better way!