I used tiledownloader to download offline tiles. Now with the new policy acces of mapquest this would be difficult.

I found http://osm2vectortiles.org/downloads/ to download some files but they are in .mbtiles

How is it possible to work with .mbtiles in openlayers 3? Should i convert them first? In case of yes, how is that possible?

  • I response to the answer of Klokan Technologies. I managed to unpack a random small mbtiles vector tile map from osm2vectortiles.org and load it locally in a browser using npm http-server, based on this openlayers example. However I still have to questions: - In the previous answer is is mentioned that the vector tiles down to zoom level 14 contains all street data with details of zoomlevel 20. However, when I zoom in to level 15+ I get (of course) 404 file not found errors. I can limit the zoom by setting `tileGrid: ol.tileg – Johannes Dec 29 '16 at 12:14

The OSM2VectorTiles link you mentioned offers a download of VECTOR tiles for OpenStreetMap. There are no RASTER .png inside the MBTiles, instead, there are ProtoBuf (PBF) tiles in. This is MBTiles similar to the one generated by MapBox Studio Classic.

If you want raster tiles (PNG/JPEG) for use in OpenLayers or Leaflet, then you need to install a server which turns the vector tiles into raster tiles on demand.

Easiest maybe:

Read the documentation of these tools on how to use them. We at KlokanTech.com have developed these tools to switch from MapQuest and MapBox to our own hosted OpenStreetMaps - and we are releasing it as open-source to anybody. Check our talk at FOSS4G 2016 (late August 2016).

In case you want to use vector tiles directly (the .pbf files) - for example in native mobile apps, MapBox GL JS or OpenLayers (like http://openlayers.org/en/latest/examples/mapbox-vector-tiles.html) then hosting is easier - as you can either simply "unpack" the .pbf from the MBTiles or install a basic utility extracting these files on demand. BTW the vector tiles down to zoom level 14 contains all street data with details of zoomlevel 20).

The example of such utilities:

other approaches are mentioned at Self-hosting Mapbox vector tiles

  • is it possible to download the raster tiles from tileserver gl so I don't have to rely on that every time? – LBes Aug 15 at 10:48

It is possible. And easy:

  1. Download MBUtil.
  2. Unzip the downloaded folder (mbutil-master)
  3. Rename the file mb-util to mb-util.py
  4. Put your .mbtiles files into the mbutil-master folder
  5. Open your command prompt in the mbutil-master folder
  6. Execute the following command:

    mb-util.py yourTiles.mbtiles theNewFolderThatWillBeCreated

    This will leave you with a new folder with many subfolders, containing hundreds or thousands of tiles in image format

  7. Copy this newly created folder onto your server, or anywhere where your OpenLayers application can access it, and include the tiles like this:

    new ol.layer.Tile({
            source: new ol.source.XYZ({
            url: "pathToYourFolderThatWasCreated/{z}/{x}/{y}.png"
        })
    })
    

Like this, for example:

var map = new ol.Map({
    target: 'mapDIV',
    layers: [
        new ol.layer.Tile({
                source: new ol.source.XYZ({
                url: "pathToYourFolderThatWasCreated/{z}/{x}/{y}.png"
            })
        })
    ],
    ...

There we go, now you got your own local (and offline) tiles :-)

  • Thx works perfect untill step 7, there is something wrong with the .png files.. 'i couldn't open them in paint for example "this is not a valid bitmap file, or its format is not currently supported" – niels Jul 14 '16 at 12:25
  • Very strange. Does the tool create many subfolders? One for each zoom level + folders within those folders? Have you tried opening them in OL3? Maybe it is just Paint has a problem... – BritishSteel Jul 14 '16 at 12:31
  • yes, this is my result in OL3 if a open the .png file , a blank image gyazo.com/73498e39a79c70f4d6802747d57a8311 – niels Jul 14 '16 at 12:33
  • If i look at the details of the png file I haven't in the tab 'image' no dimesions, width,height or bit depth These values are left empty.. I think that's the reason... – niels Jul 14 '16 at 12:44
  • Hm, strange. I would try running MBUtilagain to see if something went wrong there. Or downloading the tiles anew. Perhaps osm2vectortiles prepares the MBTiles in a way that MBUtil cannot deal with. Although this is improbable it is the only thing I can think of right now. I have used MBUtil many times with MBTiles that I created with TileMill and it always worked. – BritishSteel Jul 14 '16 at 13:22

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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