1.1、概述
声明一下,都是搞开发的,不想说废话,直接上教程,教你一步一步实现使用开源的openmaptiles来实现构建中国地图的瓦片,当初公司需要,全网找不到一点资料的,为了搞这个,花了很大的成本,请大家也理解我一下。
1.2、下载china-latest.osm.pbf
(1)下载地址
Geofabrik Download Server,下载非常的慢,需要的请私聊我,我当初租阿里云服务器下载的。
ru
这网站有每个国家的osm.pbf文件,需要的自己下载,下载这个文件的目的就是为了拿去生成china.mbtiles文件。
1.3、准备一台服务器
(1)服务器配置要求
大于 16H 32G
(2)安装好docker和docker-compose
docker安装步骤:
# 1、卸载旧的版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 2、需要的安装包
yum install -y yum-utils
# 3、设置镜像的仓库,默认是从国外的,不推荐
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 推荐使用国内的
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 跟新yum软件包索引
yum makecache fast
# 4、安装docker相关的 docker-ce 社区版 ee 企业版
yum install -y docker-ce docker-ce-cli containerd.io
# 5、启动docker
systemctl start docker
开机启动
systemctl enable docker
# 6、使用docker version查看是否安装成功
docker version
docker-compose安装:
1、下载
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
2、赋予权限
sudo chmod +x /usr/local/bin/docker-compose
3、查看是否安装成功
docker-compose --version
1.4、下载安装 openmaptiles
git clone https://github.com/openmaptiles/openmaptiles.git
cd openmaptiles
make
1.5、上传 china-latest.osm.pbf
在openmaptiles目录下新建一个data文件夹,然后将china-latest.osm.pbf上传到data目录下,并修改名称为china.osm.pbf
1.6、修改openmaptiles目录下一些文件的默认配置
(1)修改 .env 文件
主要修改:BBOX、MIN_ZOOM、MAX_ZOOM、MBTILES_FILE、MAX_PARALLEL_PSQL、COPY_CONCURRENCY
# This file defines default environment variables for all images
# 参考文档:https://github.com/openmaptiles/openmaptiles/blob/master/QUICKSTART.md#req
# Layers definition and meta data
TILESET_FILE=openmaptiles.yaml
# Use 3-part patch version to ignore patch updates, e.g. 5.0.0
TOOLS_VERSION=6.1
# Make sure these values are in sync with the ones in .env-postgres file
PGDATABASE=openmaptiles
PGUSER=openmaptiles
PGPASSWORD=openmaptiles
PGHOST=postgres
PGPORT=5432
# BBOX may get overwritten by the computed bbox of the specific area:
# make generate-bbox-file
# By default, the Makefile will use the content of data/$(area).bbox file if it exists.
BBOX=73.63,16.03,147.53,53.58
# Which zooms to generate with make generate-tiles-pg
MIN_ZOOM=0
MAX_ZOOM=22
# `MID_ZOOM` setting only works with `make generate-tiles-pg` command. Make sure MID_ZOOM < MAX_ZOOM.
# See https://github.com/openmaptiles/openmaptiles-tools/pull/383
# MID_ZOOM=11
# Use true (case sensitive) to allow data updates
DIFF_MODE=false
# Some area data like openstreetmap.fr can contain invalid references
# that must be cleaned up before using it for borders -- set it to true.
BORDERS_CLEANUP=false
# The current setup assumes this file is placed inside the data/ dir
MBTILES_FILE=china.mbtiles
# This is the current repl_config.json location, pre-configured in the tools Dockerfile
# Makefile and quickstart replace it with the dynamically generated one, but we keep it here in case some other method is used to run.
IMPOSM_CONFIG_FILE=/usr/src/app/config/repl_config.json
# import-borders temp files - set them here to defaults, and override in the Makefile based on the area
BORDERS_CLEANUP_FILE=data/borders/cleanup.pbf
BORDERS_PBF_FILE=data/borders/filtered.pbf
BORDERS_CSV_FILE=data/borders/lines.csv
# Number of parallel processes to use when importing sql files
MAX_PARALLEL_PSQL=32
# Number of parallel threads to use when generating vector map tiles
COPY_CONCURRENCY=32
# Variables for generate tiles using tilelive-pgquery
PGHOSTS_LIST=
1.7、开始执行
cd openmaptiles
make generate-bbox-file area=china
nohup ./quickstart.sh china &
tail -fn 500 nohup.out
1.8、注意
编译需要很久,中途可能回因为网络不好而失败,因为需要下载很多的地理位置到postgres数据中,最后生成一个china.mbtiles文件
1.9、启动china.mbtiles文件
(1)增加样式和字体,打包已放在百度网盘
/root/map_4g/:china.mbtile和样式存放的文件夹
docker run --rm -it -v /root/map_4g/:/data -p 8081:80 maptiler/tileserver-gl
如果你觉得不明白,请私聊我,你们的支持就是我对我最大的鼓励,这个编译离线地图相对很复杂,如果想直接获取现成的文件,请私聊我。