FR:Creating your own tiles

From OpenStreetMap Wiki
Jump to navigation Jump to search

Créer vos propres tuiles est une excellente façon d'utiliser les données OpenStreetMap. In fact it helps the project if more people do this, since it is a great way to demonstrate the flexibility of OpenStreetMap (you can create your own map style, and render your certain tags more prominently) and it means less load on our tile serving infrastructure.

Les Tiles sont de petits carrés de carte qui, typiquement sont assemblés les uns aux autres par le navigateur Web grace à une bibliothèque javascript, pour afficher une "carte glissante" ("slippy map") (Voir Deploying your own Slippy Map pour les options).

Afficher un ensemble de tuiles peut impliquer tout simplement de créer quelques dossiers remplis d'images de tuiles sur votre serveur web, en utilisant les conventions de nommage Les conventions de nommage de tuiles. Cependant, il existe plusieurs stratégies de génération et de mise en cache à envisager (en particulier pour les grandes surfaces, ou les ensemble de tuiles couvrant le monde) et aussi plusieurs rendu possibilités pour créer des images de carte.

Créer des tuiles en utilisant Mapnik et generate_tiles.py

Cette méthode est utilisée par exemple par OSM cycle map. Its main advantage is that nothing needs to run on the webserver - it just needs a directory of image files. So, for example, you can install all the software on your home PC, and transfer the tiles to your webhost when you're finished.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • When everything works, use generate_tiles.py to create 1000s of tiles in a special hierarchy of folders
  • Copy/move tiles into your webserver's document root.
  • Change the OpenLayers instance to use your own tileserver instead of the main one

C'est également l'approche proposée par le projet osmtilemaker qui propose une procédure détaillée pour générer ses tuiles à l'aide de Docker.

Creating tiles using Mapnik and mod_tile

This is the new system deployed on the main OSM map in 2008. It uses a custom C implementation to efficiently serve tiles from the disk and schedule rendering requests.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Compile and install mod_tile
  • Run the rendering daemon and ensure it can write to the tile storage directory
  • Configure your Apache server to load and run the module
  • Change the OpenLayers instance to point to your server like this: http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example#Extensions

Creating tiles using Mapnik and Mysql/Ruby/Python

This solution which was in use on the main OSM map for almost all of 2007. The tiles were served by a ruby script which fetched the tiles from a MySQL database. If the tile was old or missing then the database would be updated to mark the tile for rendering. A background script would scan the database and render the tiles using a python script.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Copy the scripts from SVN tile.openstreetmap.org
  • Setup a tile database in MySQL using the schema.sql file
  • Setup mod_ruby to run the cat_tile.rb script on your web server
  • Setup mod_rewrite with a rule to call the ruby script:
 RewriteRule ^//(-?[0-9]+)/(-?[0-9]+)/(-?[0-9]+).png  /ruby/cat_tile.rb?x=$2&y=$3&z=$1 [PT,T=image/png]
  • Periodically run the render_some_tiles.rb script to fulfill the tile rendering requests
  • Change the OpenLayers instance to point to your server instead of the pre-rendered tiles.

Creating tiles using Mapnik and tilecache

This is the method lets you generate the map as you view it instead of requiring any pre-rendering. This method can struggle at higher load levels if too many people try to look at unrendered tiles simultaneously. You need pretty much full control over your webserver in order to install everything.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Set up tilecache to render tiles on-demand
  • Change the OpenLayers instance to use your own tilecache server instead of the pre-rendered tiles.

Another "HOWTO deploy you mapnik slippy map" with real-time rendering

Howto real time rendering

Creating tiles with Osmarender/Tiles@Home

Download the latest tiles@home client from SVN (it is called tilesGen.pl). Change the configuration file to include "LocalSlippymap=DirectoryName", and specify a DirectoryName that you want to contain the generated tiles. Whenever you now process a tileset (by running perl tilesGen.pl xy xxxx yyyy, where xxxx and yyyy are the x and y coordinates of the level-12 tile you want to render), tilesGen.pl will create the tiles under the DirectoryName in a directory structure suitable for serving the tiles through a web server. The first directory element will be the layer prefix (as configured in layers.conf, in case you have more than one layer!), then you'll have a zoom level, then the x coordinate, and then a file "y.png".

You will need the script lowzoom.pl to create tiles for zoom levels 11 and smaller from the tiles you have generated. Unsure whether/how this works with LocalSlippymap.

Displaying your Tiles

Map Application (UI)

Whether you use Mapnik or Osmarender to generate the tiles, you will need a web interface to browse them.

The logic that does the zooming and panning is usually implemented in Javascript. You can either use OpenLayers, or you could also use the Google API to access the tiles. In both cases you will have to somehow add your layer to the list of layers available for selection, and adding your layer will require specifying the web server and base path - the interface will then add /zoom/x/y.png depending on which tile it needs (See Slippy map tilenames)

We use the OpenLayers javascript for our our main map and also at informationfreeway.org. The OpenLayers 'Getting Started' doc explains how to initialize a 'map' object in javascript. To make this work with our tiling scheme, you need a 'TMS' layer and bit more javascript logic. See our OpenLayers Simple Example. For more slippy map features (supporting layer selector, permalinks, etc) you might like to poke around in the javascript source of informationfreeway.org

Using Maperitive

Maperitive has a command for generating tiles which can be invoked both through the GUI and through scripting (so it can be automated). The tiling scheme is compatible with OpenLayers.

See also:

Maps on a Stick
OpenStreetMap-in-a-Box

Notes

Links