maptiler / tileserver-gl

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
https://tileserver.readthedocs.io/en/latest/
Other
2.19k stars 632 forks source link

How to serve multi mbtiles #368

Open wsf1990 opened 5 years ago

wsf1990 commented 5 years ago

Hi guys, I want to serve multi mbtiles in a directory which contains a lot of mbtiles file.And ervery one can be fetched by name like: http://localhsot:[port]/file1. Can our great lib do this?

newtorob commented 5 years ago

Would also be interested in finding out about this, tried to run with multi-mbtile files but it only went with the first option when running it.

brendan33 commented 4 years ago

If no .mbtiles are present in the working directory then it will download the Zurich tileset and serve that. If there are 1 or more .mbtiles when it will serve 1 tileset only (the first one maybe?) Therefore to serve more than 1 .mbtiles you need to create a config.json and specify all the .mbtiles there

r0hitsharma commented 4 years ago

Check out https://github.com/maptiler/tileserver-gl/pull/455

tzographos commented 1 year ago

@LR-brendan Specifying a config.json like below does not work for me. "data": { "tiles1": { "mbtiles": "tiles1.mbtiles" }, "tiles2": { "mbtiles": "tiles2.mbtiles" } }

My style.json has this: "sources": { "openmaptiles": { "type": "vector", "url": "mbtiles://{tiles1}" //I can select only 1 mbtile here; } } How can I reference multiple mbtiles in the style?

acalcutt commented 1 year ago

a config file with mutiple mbtiles would looks something this https://github.com/acalcutt/wifidb-tileserver-gl/blob/master/tileserver-gl/configs/config-3.1.1.json

tzographos commented 1 year ago

@acalcutt The problem is not with the config.json file, but with style.json. I need to have multiple mbtiles for the same source. What do you specify in it?

    "landcover": {
      "url": "https://api.maptiler.com/tiles/landcover/tiles.json?key=123",
      "type": "vector"
    },
    "openmaptiles": {               <-- for this source, I want multiple mbtiles
      "type": "vector",
      "url": "mbtiles://{v3}"       <--- here I can only specify one
    }
acalcutt commented 1 year ago

My styles referenced in the config are here if you wanted to look, though they are somewhat specific to me https://github.com/acalcutt/wifidb-tileserver-gl/tree/master/tileserver-gl/styles

but it looks like this https://github.com/acalcutt/wifidb-tileserver-gl/blob/master/tileserver-gl/styles/WDB_OSM/style.json#L48-L80

acalcutt commented 1 year ago

I don't think you can have multiple mbtiles with the same name, but you can definitely have multiple names and multiple layers that use both of the sources (not in the same layer, but separate layers).

BenOnTrack commented 1 year ago

Hi, I have the exact same issue. I would like to tie multiple mbtiles to the same source. Why ? Because all these mbtiles have the same layers, and I would like to be able to define only once my layers style, that should apply to all those mbtiles. See https://stackoverflow.com/questions/74846966/serving-multiple-mbtiles-that-have-the-same-style When using pbf, there is a way to do "tiles": [ "tiles1/{z}/{x}/{y}.pbf", "tiles2/{z}/{x}/{y}.pbf"] for the same source. Are you sure there is no similar solution for mbtiles ?

acalcutt commented 1 year ago

I'd welcome a PR to add support for multiple sources. I know I've seen Martin do something like this https://github.com/maplibre/martin#composite-sources

nyurik commented 1 year ago

It's a competition :)

BenOnTrack commented 1 year ago

What would you recommend ? Openmaptiles app https://openmaptiles.org/mobile-app/ allows to download offline cities/regions one by one; so I assume they either:

?

acalcutt commented 1 year ago

I'm not 100% sure what the best approach would be since I don't complely understand the code involved.

Looking at how the code works, I felt like maybe in config.json where the mbtiles get defined, we could make it accept multiple mbtiles, something like

   "data":{
      "combined_mbtiles":{
         "mbtiles":"file1.mbtiles"
         "mbtiles":"file2.mbtiles"
      },
    }

Then serve_data.js could continue to use the data name ('combined_mbtiles' in the example) like it does now. I'd imagine in server_data.js we could look at merging the contents of the mbtiles file at the pbf level...

BenOnTrack commented 1 year ago

Hi, Do we have any feedbacks on this request ? @tzographos did you manage a way to specify multiple mbtiles under the same source name ? I'm still curious how people handle their style without this. Imagine you have a mbtiles for North America, with a massive style that defines all your layers. Now you want to add to your map South America (generated with the same tile maker - hence same layer sources), how would you do ? Double your massive style once again to accommodate this new source ? A workaround is to append the mbtiles together (tipecanoe) but it's not really efficient.

Any support would be appreciated

acalcutt commented 1 year ago

With tileserver-gl the only 3 options are really like mentioned above,

1.) Modify your style to have layers from each or your sources. for example, if you have two sources you basically have to make a copy of each layer, for each source you have.

or

2.) Merge sparse tiles together with something like tile-join into a single mbtiles file. the issue with this approach is if there is overlap between the files, it is not made to merge them together.

or

3.) Make planet mbtiles files to begin with, which I'm sure isn't an option for all uses and datatypes, but for OSM at least planetiler makes it easy (if you have the space)


For your example, of having a North America and a South America, I would likely go the #2 route of merging them into a single file so you can use your complex style without modification

I also have another example from my own wifidb project, where I actually dynamically generate various layers in php, and injecting that into the map., which could be another option. This is not the prettiest, but it does give a lot of control https://github.com/acalcutt/WifiDB/blob/master/wifidb/wifidb/opt/map.php https://github.com/acalcutt/WifiDB/blob/master/wifidb/wifidb/lib/createGeoJSON.inc.php

Also, like I mentioned Martin does have a feature like this and they have mbtiles support now, so it may be possible there. I would love to see some ideas to add this into tileserver.

BenOnTrack commented 1 year ago

thanks for your comment - i've really liked the idea of "combined_mtiles" posted in a previous comment.

  1. I understand this approach, but my idea was to split the map by countries, and I'm not sure how tileserver-gl can handle a style.json of thousands of lines - knowing all these styles would be 100% identical between all layer-source, I really thought there would be a better workaround - i'll need to dig into Martin at some point
  2. I thought about that - but do you have any idea if later on it's possible to "remove" mbtiles from the merge ? for instance, I'm running out of space, I want to remove a bunch of countries from my "master" mbtiles
  3. unfortunately as you pointed, it's going to be a storage issue
kernant commented 8 months ago

What you’d need to do is combine the original source data and create tiles from that .pbf file. Mbtiles are not meant to be combined.