RU:Развёртывание собственной Подвижной Карты (Slippy Map)

From OpenStreetMap Wiki
Jump to navigation Jump to search

broom

Help (89606) - The Noun Project.svg

Хотите разместить данные OpenStreetMap на своем сайте?

Вы можете встроить нашу карту в свою страницу, также как и карты Google, Яндекс, Bing или Yahoo! Но для большей гибкости OpenStreetMap дает вам уникальную возможность создать свои фрагменты карты, с каким угодно оформлением на основе наших данных.

Поместите нашу карту на ваш сайт

Это самый легкий шаг, и вы должны убедиться, что сможете сделать это перед тем, как пытаться сделать что-нибудь ещё. Это можно сделать:

  • Используя OpenLayers. Посмотрите исходный код страницы OSM, чтобы увидеть такой (пример).
  • Используя Mapstraction.
  • Используя API Яндекс.Карты.
  • Используя Google Maps.
  • Используя Zoom_zoom_zoom_map (хорошее масштабирование изображения в случае, если фрагменты карты (тайлы) есть в кэше)

Ваша карта может использовать любые тайлы сервера OSM, хотя имейте в виду, что здесь нет никаких гарантий доступности или качества (если вы ожидаете у себя напряженный трафик, пожалуйста обсудите сначала эту проблему с командой проекта).

Лучшие библиотеки и API JavaScript для создания карт - обзор javascript библиотек для отображения тайловых карт.

Создание собственных квадратов

Если вы хотите сделать карту по-своему — например, с дорогами других цветов и другой толщины — вы можете сделать ее сами. Используйте для этого Mapnik или Osmarender (который встроен в сценарии Tiles@home).

Создание тайлов(квадратов изображений, отображающих карту) используя Mapnik и скрипт generate_tiles.py

Для примера, этот метод используется OSM cycle map. Его главное преимущество в том, что ничего не нужно для его запуска на веб сервере, за исключением наличия некой директории с изображениями. Для примера, вы можете установить весь необходимый софт на свой домашний ПК и затем перекинуть тайлы на ваш вебхост, когда вы их закончите.

  • 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

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

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.

Создание частей карты используя Mapnik и tilecache

Этот метод позволяет вам выполнять визуализацию карты в момент её просмотра и не требует предварительной визуализации. В случае, когда много людей одновременно пытаются просмотреть фрагменты карты (тайлы), визуализация которых ещё не была выполнена, этот метод позволяет справляться с такой нагрузкой. Вы только должны обладать полным контролем над вашим web-сервером, чтобы иметь возможность устанавливать то, что вам нужно.

  • Скачайте файл планеты с planet.openstreetmap.org
  • Импортируйте в базу данных PostGIS используя osm2pgsql
  • Установите mapnik и test используя osm.xml и generate_image.py
  • Установите tilecache для того, чтобы выполнять визуализацию тайлов по требованию
  • Change the OpenLayers instance to use your own tilecache server instead of the pre-rendered tiles.

Другой "Как развернуть вашу mapnik карту" с визуализацией в режиме реального времени

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.

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

Примечание

Fedora Users

  • Fedora users can use the packages and follow the instructions provided by Keith Sharp to build a slippy map.
  • Debian/Ubuntu пользователи могут использовать следующие инструкции [1].