基于Martin的全国基础底图实现

概述

前面有文章基于Martin实现MapboxGL自定义底图分享了Martin的使用,本文使用网络收集的数据实现了全国基础数据的收集和基础底图。

实现后效果

全图效果

不确定国界

局部细节

铁路

建筑物

放大后三维效果

实现

1. 数据准备

实例中包含如下数据:

  • 边界线和九段线数据
  • 省边界面数据
  • 省会城市点数据
  • 市边界面数据
  • 市中心点数据
  • 区边界面数据
  • 区中心点数据
  • 建筑物数据
  • 河流(1级、2级和5级)
  • 铁路数据
  • 公路数据
  • 机场数据

2. 数据入库

将准备好的数据导入的数据库中。

  • 可借助QGIS实现,操作步骤可参考教程QGIS工具箱导入。
  • 或借助工具PostGIS PostGIS Bundle 3 for PostgreSQL x64 12 Shapefile and DBF Loader Exporter导入到数据库中。可参考教程数据的导入
  • 或下载我分享的数据库备份文件还原

3. 修改配置文件

martin.exe同级目录下新建文件config.yaml,内容如下:

# Connection keep alive timeout [default: 75]
keep_alive: 75# The socket address to bind [default: 0.0.0.0:3000]
listen_addresses: '0.0.0.0:3000'# Set TileJSON URL path prefix. This overides the default of respecting the X-Rewrite-URL header.
# Only modifies the JSON (TileJSON) returned, martins' API-URLs remain unchanged. If you need to rewrite URLs, please use a reverse proxy.
# Must begin with a `/`.
# Examples: `/`, `/tiles`
base_path: /tiles# Number of web server workers
worker_processes: 16# Amount of memory (in MB) to use for caching tiles [default: 512, 0 to disable]
cache_size_mb: 50000# If the client accepts multiple compression formats, and the tile source is not pre-compressed, which compression should be used. `gzip` is faster, but `brotli` is smaller, and may be faster with caching.  Default could be different depending on Martin version.
preferred_encoding: gzip# Enable or disable Martin web UI. At the moment, only allows `enable-for-all` which enables the web UI for all connections. This may be undesirable in a production environment. [default: disable]
web_ui: enable# Database configuration. This can also be a list of PG configs.
postgres:# Database connection string. You can use env vars too, for example:#   $DATABASE_URL#   ${DATABASE_URL:-postgresql://postgres@localhost/db} 'postgres://<database_username>:<database_userpassword>@<hostaddress>:<port_no>/<database_name>'connection_string: 'postgresql://postgres:root@localhost:5432/lzugis'#  If a spatial table has SRID 0, then this SRID will be used as a fallbackdefault_srid: 4326# Maximum Postgres connections pool size [default: 20]pool_size: 20# Limit the number of table geo features included in a tile. Unlimited by default.# max_feature_count: 1000# Control the automatic generation of bounds for spatial tables [default: quick]# 'calc' - compute table geometry bounds on startup.# 'quick' - same as 'calc', but the calculation will be aborted if it takes more than 5 seconds.# 'skip' - do not compute table geometry bounds on startup.auto_bounds: skip# Enable automatic discovery of tables and functions.# You may set this to `false` to disable.auto_publish:# Optionally limit to just these schemasfrom_schemas:- public# Here we enable both tables and functions auto discovery.# You can also enable just one of them by not mentioning the other,# or setting it to false.  Setting one to true disables the other one as well.# E.g. `tables: false` enables just the functions auto-discovery.tables:# Optionally set how source ID should be generated based on the table's name, schema, and geometry columnsource_id_format: '{table}'# Add more schemas to the ones listed above# A table column to use as the feature ID# If a table has no column with this name, `id_column` will not be set for that table.# If a list of strings is given, the first found column will be treated as a feature ID.id_columns: gid# Boolean to control if geometries should be clipped or encoded as is, optional, default to trueclip_geom: true# Buffer distance in tile coordinate space to optionally clip geometries, optional, default to 64buffer: 64# Tile extent in tile coordinate space, optional, default to 4096extent: 4096functions:# Optionally set how source ID should be generated based on the function's name and schemasource_id_format: '{schema}.{function}'# Associative arrays of table sourcestables:table_source_id:# ID of the MVT layer (optional, defaults to table name)layer_id: my_base# Table schema (required)schema: public# Table name (required)table: province,capital,city# Geometry SRID (required)srid: 4326# Geometry column name (required)geometry_column: geom# Feature id column nameid_column: ~# An integer specifying the minimum zoom levelminzoom: 0# An integer specifying the maximum zoom level. MUST be >= minzoommaxzoom: 10# The maximum extent of available map tiles. Bounds MUST define an area# covered by all zoom levels. The bounds are represented in WGS:84# latitude and longitude values, in the order left, bottom, right, top.# Values may be integers or floating point numbers.bounds: [ -180.0, -90.0, 180.0, 90.0 ]# Tile extent in tile coordinate spaceextent: 4096# Buffer distance in tile coordinate space to optionally clip geometriesbuffer: 64# Boolean to control if geometries should be clipped or encoded as isclip_geom: true# Geometry typegeometry_type: GEOMETRY# List of columns, that should be encoded as tile properties (required)properties:gid: int4# Associative arrays of function sourcesfunctions:function_source_id:# Schema name (required)schema: public# Function name (required)function: function_zxy_query# An integer specifying the minimum zoom levelminzoom: 0# An integer specifying the maximum zoom level. MUST be >= minzoommaxzoom: 30# The maximum extent of available map tiles. Bounds MUST define an area# covered by all zoom levels. The bounds are represented in WGS:84# latitude and longitude values, in the order left, bottom, right, top.# Values may be integers or floating point numbers.bounds: [ -180.0, -90.0, 180.0, 90.0 ]
sprites:paths:# all SVG files in this dir will be published as a "my_images" sprite source# - ./icons   sources:# SVG images in this directory will be published as a "my_sprites" sprite sourceicons: ./icons      
mbtiles:paths:# scan this whole dir, matching all *.mbtiles files# - /dir-path# specific mbtiles file will be published as mbtiles2 source- ./world_cities.mbtilessources:# named source matching source name to a single file# mb-src1: /path/to/mbtiles1.mbtiles       
# Font configuration
fonts:# A list of *.otf, *.ttf, and *.ttc font files and dirs to search recursively.- ./font/msyh.ttf

5. 启动服务

cmd命令窗口中输入命令.\martin.exe --config ./config.yaml启动。

6. 前端调用

前端调用服务的完整代码如下:

<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title><link href="./public/lib/mapbox-gl.css" rel="stylesheet" /><style>html,body,#map {width: 100%;height: 100%;inset: 0;overflow: hidden;background-color: #efefef;}</style>
</head><body><div id="map" class="map"></div><script src="./public/lib/mapbox-gl.js"></script><script>const url = 'http://localhost:3000/catalog'fetch(url).then(res => res.json()).then(res => {const { tiles, fonts } = reslet sources = {}, fontsArray = Object.keys(fonts)Object.keys(tiles).forEach(tile => {sources[tile] = {type: "vector",tiles: [`http://127.0.0.1:3000/${tile}/{z}/{x}/{y}`],}})var style = {version: 8,name: "Mapbox Streets",sprite: "http://127.0.0.1:3000/sprite/icons",glyphs: `http://127.0.0.1:3000/font/${fontsArray.join(',')}/{fontstack}/{range}.pbf`,sources: sources,layers: [// 背景图层{id: 'background',type: 'background',paint: {'background-color': '#fff'}},// 省填充{id: "base_province_fill",type: "fill",source: "base_province","source-layer": "base_province",paint: {"fill-color": "#f7f7f7","fill-opacity": 0.8,},},// 建筑物填充{id: "theme_building",type: "fill",source: "theme_building","source-layer": "theme_building",minzoom: 13,maxzoom: 14.4,paint: {"fill-color": "#eeeeee","fill-opacity": 1,},},// 建筑物拉伸{id: "theme_building_extrusion",type: "fill-extrusion",source: "theme_building","source-layer": "theme_building",minzoom: 13,paint: {"fill-extrusion-color": "#eeeeee","fill-extrusion-opacity": 0.6,'fill-extrusion-height': 25},},// 建筑物描边{id: "theme_building_border",type: "line",source: "theme_building","source-layer": "theme_building",minzoom: 13,maxzoom: 14.5,paint: {"line-color": "#eee","line-opacity": 1,},},// 建筑物标注{"id": "theme_building_label","type": "symbol","source": "theme_building",'source-layer': 'theme_building',minzoom: 14.5,'layout': {'text-field': ['get', 'name'],'text-size': 12,'text-allow-overlap': false,'text-justify': 'center',"text-font": ["Microsoft YaHei"]},paint: {'text-color': '#a3a3a3','text-halo-color': '#fff','text-halo-width': 1.2,}},// 省边界{id: "base_province",type: "line",source: "base_province","source-layer": "base_province",paint: {"line-color": "#989ea7","line-width": 0.5,'line-opacity': 1,},},// 城市边界{id: "base_city",type: "line",source: "base_city","source-layer": "base_city",minzoom: 6,paint: {"line-color": "#b6ccd8","line-width": 0.5,'line-opacity': 0.75,},},// 区县边界{id: "base_county",type: "line",source: "base_county","source-layer": "base_county",minzoom: 8.2,paint: {"line-color": "#b6ccd8","line-width": 0.3,'line-opacity': 0.8,},},// 一级水域面{id: "theme_hyd1_p",type: "fill",source: "theme_hyd1_p","source-layer": "theme_hyd1_p",minzoom: 6,paint: {"fill-color": "#b2cefe","fill-opacity": 1,},},// 二级水域面{id: "theme_hyd2_p",type: "fill",source: "theme_hyd2_p","source-layer": "theme_hyd2_p",minzoom: 6,paint: {"fill-color": "#b2cefe","fill-opacity": 1,},},// 一级水域线{id: "theme_hyd1_l",type: "line",source: "theme_hyd1_l","source-layer": "theme_hyd1_l",paint: {"line-color": "#b2cefe","line-width": 1,},},// 5级水域线{id: "theme_hyd5_l",type: "line",source: "theme_hyd5_l","source-layer": "theme_hyd5_l",minzoom: 8.4,paint: {"line-color": "#b2cefe","line-width": 0.8,},},// 路网{id: "theme_road",type: "line",source: "theme_road","source-layer": "theme_road",minzoom: 6,paint: {"line-color": "#ffac4d","line-width": 1,},},// 铁路{id: "theme_railway",type: "line",source: "theme_railway","source-layer": "theme_railway",minzoom: 8.4,paint: {"line-color": "#bec4cd","line-width": 2,},},// 铁路白色{id: "theme_railway_bg",type: "line",source: "theme_railway","source-layer": "theme_railway",minzoom: 8.4,paint: {"line-color": "#fff","line-width": 1.5,},},// 铁路间隔{id: "theme_railway_interval",type: "line",source: "theme_railway","source-layer": "theme_railway",minzoom: 8.4,paint: {"line-color": "#bec4cd","line-width": 1.5,"line-dasharray": [3, 3]},},// 国界线虚线{id: "base_boundry",type: "line",source: "base_boundry_l","source-layer": "base_boundry_l",filter: ["==", "type", 1],paint: {"line-color": "#e04747","line-width": 2,"line-dasharray": [3, 3]},},// 国界线{id: "base_boundry_l",type: "line",source: "base_boundry_l","source-layer": "base_boundry_l",filter: ["!=", "type", 1],paint: {"line-color": "#e04747","line-width": 2,},},// 九段线{id: "base_nineline",type: "line",source: "base_nineline","source-layer": "base_nineline",paint: {"line-color": "#e04747","line-width": 3,},},// 机场{"id": "theme_airport","type": "symbol","source": "theme_airport",'source-layer': 'theme_airport',minzoom: 8.2,'layout': {'icon-image': 'airport','icon-size': 0.55,'icon-allow-overlap': true,},paint: {'icon-color': '#f00',}},// 区县名称{"id": "base_county_c","type": "symbol","source": "base_county_c",'source-layer': 'base_county_c',minzoom: 8.2,filter: ['!=', ['get', 'district'], '北京'],'layout': {'icon-image': 'capital','icon-size': 0.32,'icon-allow-overlap': false,'text-field': ['get', 'district'],'text-size': 10,'text-allow-overlap': false,'text-justify': 'center','text-offset': [0, 1.3],"text-font": ["Microsoft YaHei"]},paint: {'text-color': 'rgb(80, 80, 80)','text-halo-color': '#fff','text-halo-width': 1.4,}},// 城市名称{"id": "base_city_c","type": "symbol","source": "base_city_c",'source-layer': 'base_city_c',minzoom: 6,filter: ['!=', ['get', 'district'], '北京'],'layout': {'icon-image': 'capital','icon-size': 0.35,'icon-allow-overlap': false,'text-field': ['get', 'district'],'text-size': 11,'text-allow-overlap': false,'text-justify': 'center','text-offset': [0, 1.3],"text-font": ["Microsoft YaHei"]},paint: {'text-color': 'rgb(80, 80, 80)','text-halo-color': '#fff','text-halo-width': 1.8,}},// 省会城市{"id": "base_capital","type": "symbol","source": "base_capital",'source-layer': 'base_capital',filter: ['!=', ['get', 'name'], '北京'],maxzoom: 5.9,'layout': {'icon-image': 'capital','icon-size': 0.38,'icon-allow-overlap': false,'text-field': ['get', 'name'],'text-size': 12,'text-allow-overlap': false,'text-justify': 'center','text-offset': [0, 1.5],"text-font": ["Microsoft YaHei"]},paint: {'text-color': 'rgb(80, 80, 80)','text-halo-color': '#fff','text-halo-width': 1.8,}},// 首都{"id": "base_capital_beijing","type": "symbol","source": "base_capital",'source-layer': 'base_capital',filter: ['==', ['get', 'name'], '北京'],'layout': {'icon-image': 'star','icon-size': 0.5,'icon-allow-overlap': false,'text-field': ['get', 'name'],'text-size': 14,'text-allow-overlap': false,'text-justify': 'center','text-offset': [0, 1.6],"text-font": ["Microsoft YaHei"]},paint: {'text-color': 'rgb(255, 0, 0)','text-halo-color': '#fff','text-halo-width': 1.6,'icon-color': '#f00',}},],};var map = new mapboxgl.Map({container: "map", // container IDstyle: style,center: [107.11040599933166, 34.26271532332011], // starting position [lng, lat]zoom: 3,minZoom: 3,doubleClickZoom: false,hash: false,localFontFamily: true,logoPosition: "bottom-right",});window.map = map})</script>
</body></html>

资源下载

相关资源上传到了CSDN,请异步到https://download.csdn.net/download/GISShiXiSheng/90417459下载。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/22494.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网页版的俄罗斯方块

1、新建一个txt文件 2、打开后将代码复制进去保存 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>俄…

HTML之JavaScript DOM简介

HTML之JavaScript DOM简介 DOM对象是一个树形对象 DOM树上的结点类型分类&#xff1a; 元素节点 element 标签属性节点 attribute 属性文本节点 text 双标签中间的文本 HTML代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UT…

【MATLAB例程】RSSI/PLE定位与卡尔曼滤波NLOS抑制算法,附完整代码

本 MATLAB 代码实现了基于接收信号强度指示(RSSI)和路径损耗模型(PLE)的定位算法,并结合卡尔曼滤波技术进行非视距(NLOS)干扰抑制。通过模拟真实运动轨迹,代码展示了如何在存在NLOS干扰的情况下进行有效的定位。订阅专栏后,可阅读完整代码,可直接运行 文章目录 运行结…

使用IDEA提交SpringBoot项目到Gitee上

登录Gitee并新建仓库 创建本地仓库 提交本地代码到本地仓库 提交本地代码到远程仓库

LLM Agent:PaSa

阅读原文 LLM Agent&#xff1a;PaSa 以 PaSa&#xff08;Paper Search&#xff09;为例&#xff0c;接下来将介绍由 LLM 驱动的先进的论文搜索智能体。PaSa 能够自主做出一系列决策&#xff0c;包括调用搜索工具、阅读论文以及选择相关参考文献&#xff0c;最终为复杂的学术…

Linux提权之脏牛Dirty COW CVE-2016-5195 (四)

CVE-2016-5195&#xff08;Dirty Cow脏牛&#xff09; 脏牛提权的利用方式不同于其他的内核溢出提权&#xff0c;这里单独记录 脏牛是一个非常经典的内核提权漏洞&#xff0c;存在Linux内核中已经有长达9年的时间&#xff0c;在2007年发布的Linux内核版本中就已经存在此漏洞&…

基于SpringBoot+vue+uniapp的智慧旅游小程序+LW示例参考

系列文章目录 1.基于SSM的洗衣房管理系统原生微信小程序LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统LW参考示例 3.基于SpringBootVue的企业人事管理系统LW参考示例 4.基于SSM的高校实验室管理系统LW参考示例 5.基于SpringBoot的二手数码回收系统原生微信小程序LW参考示…

【微服务】深入解析spring aop原理

目录 一、前言 二、AOP 概述 2.1 什么是AOP 2.2 AOP中的一些概念 2.2.1 aop通知类型 2.3 AOP实现原理 2.3.1 aop中的代理实现 2.4 静态代理与动态代理 2.4.1 静态代理实现 三、 jdk动态代理与cglib代理 3.1 jdk动态代理 3.1.1 jdk动态代理模拟实现 3.2 CGLIB 代理…

vxe-table 如何实现跟 Excel 一样的数值或金额的负数自动显示红色字体

vxe-table 如何实现跟 Excel 一样的数值或金额的负数自动显示红色字体&#xff0c;当输入的值为负数时&#xff0c;会自动显示红色字体&#xff0c;对于数值或者金额输入时该功能就非常有用了。 查看官网&#xff1a;https://vxetable.cn gitbub&#xff1a;https://github.co…

C++:dfs,bfs各两则

1.木棒 167. 木棒 - AcWing题库 乔治拿来一组等长的木棒&#xff0c;将它们随机地砍断&#xff0c;使得每一节木棍的长度都不超过 5050 个长度单位。 然后他又想把这些木棍恢复到为裁截前的状态&#xff0c;但忘记了初始时有多少木棒以及木棒的初始长度。 请你设计一个程序…

MATLAB学习之旅:从入门到基础实践

在当今科技飞速发展的时代,MATLAB作为一款强大的数学软件,犹如一把神奇的钥匙,能够打开众多领域的大门。无论是工程计算、数据分析,还是算法开发、可视化呈现,MATLAB都展现出了无与伦比的魅力。今天,就让我们踏上这段奇妙的MATLAB学习之旅,从最基础的部分开始,逐步探索…

verilog笔记

Verilog学习笔记&#xff08;一&#xff09;入门和基础语法BY电棍233 由于某些不可抗拒的因素和各种的特殊原因&#xff0c;主要是因为我是微电子专业的&#xff0c;我需要去学习一门名为verilog的硬件解释语言&#xff0c;由于我是在某西部地区的神秘大学上学&#xff0c;这所…

基于SpringBoot的城乡商城协作系统【附源码】

基于SpringBoot的城乡商城协作系统 效果如下&#xff1a; 系统登陆页面 系统管理员主页面 商品信息管理页面 系统用户主页面 社区交流页面 用户充值页面 订单提交页面 商品信息页面 研究背景 随着互联网技术的飞速发展&#xff0c;电子商务在我国城乡地区的普及程度越来越高…

tortoiseSVN 如何克隆项目到本地

导入项目成功&#xff0c;如下图&#xff1a;

1.1 go环境搭建及基本使用

golang下载地址&#xff1a; Download and install - The Go Programming Language (google.cn) 验证安装是否成功&#xff1a; go version 查看go环境 go env 注意&#xff1a;Go1.11版本之后无需手动配置环境变量,使用go mod 管理项目&#xff0c;也不需要把项目放到GO…

使用Ubuntu搭建Java部署环境

White graces&#xff1a;个人主页 &#x1f649;专栏推荐:Java入门知识&#x1f649; &#x1f439;今日诗词:小舟从此逝&#xff0c;江海寄余生&#x1f439; ⛳️点赞 ☀️收藏⭐️关注&#x1f4ac;卑微小博主&#x1f64f; ⛳️点赞 ☀️收藏⭐️关注&#x1f4ac;卑微小…

从零搭建微服务项目Pro(第1-1章——Quartz实现定时任务模块)

前言&#xff1a; 在企业项目中&#xff0c;往往有定时任务发布的需求&#xff0c;比如每天晚9点将今日数据备份一次&#xff0c;或每月一号将上月的销售数据邮件发送给对应的工作人员。显然这些操作不可能是人工到时间点调用一次接口&#xff0c;需要编写专门的模块完成任务的…

深蓝学院自主泊车第3次作业-IPM

目录 1 题目介绍2 求解 1 题目介绍 已知鱼眼相机的参数&#xff0c; image_width&#xff0c;表示图像的宽度image_height&#xff0c;表示图像的高度 ξ \xi ξ&#xff0c;表示鱼眼相机参数 k 1 k_1 k1​、 k 2 k_2 k2​&#xff0c;表示径向相机参数 p 1 p_1 p1​、 p 2 p…

中兴G7615AV5

参考文献&#xff1a; G7615AV5 光猫新版固件通过修改备份配置文件固化Telnet 中兴7615AV5光猫配置指南 前言&#xff1a;&#xff08;不如咸鱼30远程全权搞定&#xff0c;花小钱办大事&#xff09;截至2025年2月22号&#xff0c;这个设备开启Telnet只能去咸鱼找别人远程开&…

记录:Docker 安装记录

今天在安装 ollama 时发现无法指定安装目录&#xff0c;而且它的命令行反馈内容很像 docker &#xff0c;而且它下载的模型也是放在 C 盘&#xff0c;那么如果我 C 盘空间不足&#xff0c;就装不了 deepseek-r1:70b &#xff0c;于是想起来之前安装 Docker 的时候也遇到过类似问…