3

I edited an .osm file and a style file (osmarender.xml) some time ago and included it in an Android project (using osmosis and the Mapsforge library). Works fine and looks good. Now I would like to reuse these files in a web project using OpenLayers (or Leaflet?).

Using this example (https://wiki.openstreetmap.org/wiki/OpenLayers_osm_file_example) I was able to display my (very local, but still 23 MB) map, however, it was all in yellow (no styles applied, of course) and it was rendered on top of the OSM base map.

I want to do the following: 1. Display my map only (no other base map needed or wanted). 2. Display it fast (yet allowing for panning and zooming). 3. Display it using my styles (defined in the osmarender.xml). 4. Display it only as far as it goes (stop panning close to the borders of the bounding box).

Can I do this with OpenLayers (and probably osmosis or some rendering tool)? And if so, how (just about)?

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
kalabalik
  • 3,792
  • 2
  • 21
  • 50

3 Answers3

3

You could just pre-render all required tiles using Maperitive, TileMill or a similar application. It can't get any faster. Also take a look at the various rendering softwares for OSM.

scai
  • 20,297
  • 4
  • 56
  • 72
  • Okay, just tried Maperitive, but it doesn't parse my XML style file. Will now try TileMill. Would Mapnik also be an option? – kalabalik Oct 30 '15 at 10:20
  • Yes, of course. But it will require more work to set it up. – scai Oct 30 '15 at 10:35
  • Okay, problem seems to be that I am on Ubuntu 15.10 which officially is just a week old or so. The corresponding ppa for TileMill does not work for me. So I tried the new Mapbox Studio Classic which, however, does not read osm files. Now I will go back to Maperative (which read my map at least) and try to get it to write my data into a different format (not sure if this feature is provided. – kalabalik Oct 30 '15 at 11:17
  • No chance. Maperitive just produces bitmaps, SVGs or tiles. Any other suggestions? – kalabalik Oct 30 '15 at 11:23
  • Which is perfect since you need tiles. Just generate a directory full of tiles using Maperitive and then specify the path to this directory as tile source in OpenLayers. That's all. – scai Oct 30 '15 at 11:50
  • Maybe there is a way to convert an osmarender style file to a format Maperitive is able to read. But I fear that's not within the scope of my knowledge. – scai Oct 30 '15 at 12:19
  • Yes, actually that is what I have just started to look into, WHILE I am waiting for an older Ubuntu to install on a virtual box, so I can run TileMill on it. So currently, writing a new style file is only the last option. – kalabalik Oct 30 '15 at 12:29
  • Okay, TileMill is running now. Am I correct in going on the database detour, i.e. turning my osm file into a database so TileMill is able to read it? And why hasn't someone come up with a more convenient tool for osm data? – kalabalik Oct 30 '15 at 13:40
  • Yes, that's correct as far as I know. There are several different programs available all with their pros and cons but rendering a map isn't a trivial task. – scai Oct 30 '15 at 13:58
  • I am fed up for the day and will procede some other time, but thanks a lot for your help! – kalabalik Oct 30 '15 at 15:20
  • You are welcome. Consider upvoting/accepting my answer if it helps/solves your problem :) – scai Oct 30 '15 at 15:33
0

MOBAC (2.0 Alpha 4) and Mapsforge Tile Server can render raster tiles based on a mapsforge style and map file. The tiles/server can be used in other applications like Leaflet or OpenLayers.

Not sure how stable and mature these are though, MOBAC is still alpha and MTS had an issue with clipped labels and no Windows support.

See also mapsforge OSM Wiki page.

0

Aarg ... Mapsforge Tile Server is a good hint, however, the answer is much easier as I found out today.

If you have a working Android map application based on the Mapsforge library you can have this application produce tiles and store them on your mobile device. From there you can copy them and reuse them in a web project with OpenLayers, for example.

The Android code (with Mapsforge 0.5.2) is in my case as follows:

TileCache tileCache = AndroidUtil.createTileCache(activity, "mapcache",
            mapView.getModel().displayModel.getTileSize(), this.getScreenRatio(),
            mapView.getModel().frameBufferModel.getOverdrawFactor());

It writes the tiles in the "mapcache" directory.

Anyway, thank you very much for the help of both of you!

kalabalik
  • 3,792
  • 2
  • 21
  • 50