離線地圖解決方案一

離線地圖使用私有OSM Server做爲Tile服務器, 前端使用Openlayer渲染地圖數據. 共實踐了兩種安裝環境(準確來講是三種, 可是放棄了在Redhat 6.5的部署...).html

#Ubuntu 16.04 安裝介紹前端

環境

名稱 說明
OS ubuntu 16.04 x64

參考 https://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/node

安裝說明

除一下兩點外, 均可以按照參考文檔安裝.python

  1. 安裝Mapnik部分

能夠經過apt安裝, 不用從源碼編譯.nginx

apt install libmapnik-dev libmapnik3.0 mapnik-utils mapnik-vector-tile python-mapnik python3-mapnik
sudo apt install libmapnik-dev libmapnik3.0 mapnik-utils mapnik-vector-tile python-mapnik python3-mapnik
  1. 配置mod_tile部分
vim /usr/local/etc/renderd.conf
plugins_dir=/usr/lib/mapnik/3.0/input

值修改成mapnik-config --input-plugins的結果.git

CentOS 7安裝介紹

環境

名稱 說明
OS CentOS 7.2 x64
HTTP server httpd

安裝過程主要流程參考Manually building a tile server (14.04),這個網站是針對Ubuntu 14.04寫的,可是須要安裝的軟件基本相同,能夠參考這個教程安裝配置OSM Server。這裏如無特殊說明的話,均在root用戶下操做。github

安裝epel-release & 更新系統軟件

yum install epel-release
yum update

安裝 PostgreSQL DB.

參考這裏 or:web

  1. 安裝postgresql 9.5的repo並安裝postgresql 9.5
rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
yum install postgresql95 postgresql95-server postgresql95-libs postgresql95-contrib postgresql95-devel
  1. 初始化數據庫並啓動數據庫
/usr/pgsql-9.5/bin/postgresql95-setup initdb
service postgresql-9.5 start
  1. 設置開機啓動
chkconfig postgresql-9.5 on
  1. 添加用戶

這裏添加的用戶名爲usergis,能夠按需替換,後續的usergis都要替換。sql

adduser -m usergis
passwd usergis
  1. 建立數據庫gis
sudo -u postgres -i
createuser usergis
createdb -E UTF8 -O usergis gis
exit

安裝postgis

根據安裝的postgresql版本選擇postgis軟件,這裏postgresql使用的是9.5的版本,因此採用postgis2_95,95是postgresql的版本號。數據庫

  1. 在postgresql上搭建postgis
yum install postgis2_95 postgis2_95-client
sudo -u postgres -i
\c gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO usergis;
ALTER TABLE spatial_ref_sys OWNER TO usergis;
\q
exit

安裝osm2pgsql

安裝過程儘可能採用GitHub上osm2pgsql的安裝介紹,這裏說明一下依賴的安裝。

進入osm2pgsql目錄,建立build目錄並cd build/

yum install cmake
yum install expat
yum install expat-devel
yum install bzip
yum install bzip2
yum install bzip2-devel
yum install zlib-devel
yum install geos-devel
yum install proj-devel
yum install liblua-devel
yum install lua-devel
yum install boost-devel

依賴安裝完成後就能夠開始編譯了

cmake ..
make
make install

安裝Mapnik library

同osm2pgsql同樣,咱們也儘可能follow官方安裝流程,點這裏。 這裏說一下依賴的安裝。

這裏咱們使用branch爲2.2.x,你也可使用最新版本。切換方法:

git branch 2.2 origin/2.2.x
git checkout 2.2 -f

若是使用3.x的版本,mapnik庫文件的安裝位置可能發生改變,在後邊配置renderd.conf的時候須要根據mapnik-config --input-plugins來配置。

安裝依賴

yum install freetype-config
yum install libicu-devel
yum install harfbuzz-devel
yum install freetype-devel
yum install libjpeg-devel libpng-devel libtiff-devel libxml2-devel
yum install python-devel

這裏mapnik的lib安裝在/usr/local/lib/libmapnik.so.2.2,須要將此目錄包含在ld的search path中,建立/編輯/etc/ld.so.conf,加入一行/usr/local/lib

ldconfig

而後能夠愉快的開始編譯安裝了。安裝完成後參考官方文檔測試mapnik能夠正常被python搜索到便可。

安裝mod_tile

同上參考官方安裝手冊,點這裏。這裏介紹依賴的安裝。

安裝依賴:

yum install httpd-devel

開始編譯安裝吧。

Stylesheet configuration

安裝過程參考*Manually building a tile server (14.04)*的說明便可,這裏咱們的Web Server爲httpd,so 啓動服務的時候須要相應修改。須要注意的是在上文這一節結尾的make.py部分,有部分依賴須要安裝。

yum search carto
yum install libcairo
yum install cairo
yum install nodejs
yum install npm

高版本的nodejs已經內置了npm,不須要單獨安裝。這裏咱們使用的是默認repo中0.10.x的版本。

npm i -g carto
npm i -g millstone

以後就能夠執行./make.py了。

搞定Web Server

基本參考*Manually building a tile server (14.04)*的配置便可,其中module的配置文件的存放位置爲/etc/httpd/conf.modules.d/,能夠建立mod_tile的配置文件00-mod_tile.conf放到此目錄,內容以下:

LoadModule tile_module /usr/lib64/httpd/modules/mod_tile.so

可使用locate指令肯定mod_tile.so文件的位置,固然執行locate以前須要執行updatedb來更新文件索引。

配置VirtualHost

建立文件vim /etc/httpd/conf.d/tile_server.conf,內容以下便可:

<VirtualHost *:9000>
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost

LoadTileConfigFile /usr/local/etc/renderd.conf
ModTileRenderdSocketName /var/run/renderd/renderd.sock
# Timeout before giving up for a tile to be rendered
ModTileRequestTimeout 0
# Timeout before giving up for a tile to be rendered that is otherwise missing
ModTileMissingRequestTimeout 30

DocumentRoot /var/www/test_openlayer
</VirtualHost>

重啓http服務後,訪問宿主http://host:9000/osm_tiles/0/0/0.png能看到圖片即代表成功。

Appendix I

File: /usr/local/etc/renderd.conf

[renderd]
socketname=/var/run/renderd/renderd.sock
num_threads=4
tile_dir=/var/lib/mod_tile
stats_file=/var/run/renderd/renderd.stats

[mapnik]
plugins_dir=/usr/local/lib/mapnik/input
font_dir=/usr/local/lib/mapnik/fonts
font_dir_recurse=1

[default]
URI=/osm_tiles/
TILEDIR=/var/lib/mod_tile
XML=/usr/local/share/maps/style/OSMBright/OSMBright.xml
HOST=localhost
TILESIZE=256
;HTCPHOST=proxy.openstreetmap.org
;** config options used by mod_tile, but not renderd **
;MINZOOM=0
MAXZOOM=18
;TYPE=png image/png
;DESCRIPTION=This is a description of the tile layer used in the tile json request
;ATTRIBUTION=&copy;<a href=\"http://www.openstreetmap.org/\">OpenStreetMap</a> and <a href=\"http://wiki.openstreetmap.org/wiki/Contributors\">contributors</a>, <a href=\"http://opendatacommons.org/licenses/odbl/\">ODbL</a>
;SERVER_ALIAS=http://localhost/
;CORS=http://www.openstreetmap.org
;ASPECTX=1
;ASPECTY=1
;SCALE=1.0
相關文章
相關標籤/搜索