基于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.mzph.cn/web/70414.shtml

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

相关文章

新版Tomcat MySQL IDEA 安装配置过程遇到的问题

一、IDEA闪退 打不开了 IDEA环境变量路径不对 二、Tomcat 一闪而过 主要是JDK环境变量不对 三、MySQL 重新安装、是否备份以及默认盘问题 看清楚教程基本没问题&#xff1a;Windows 安装配置及卸载MySQL8超详细保姆级教程_mysql8卸载-CSDN博客

链表_两两交换链表中的节点

链表_两两交换链表中的节点 一、leetcode-24二、题解1.引库2.代码 一、leetcode-24 两两交换链表中的节点 给你一个链表&#xff0c;两两交换其中相邻的节点&#xff0c;并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题&#xff08;即&#xff0c;只能…

DAY08 List接口、Collections接口、Set接口

学习目标 能够说出List集合特点1.有序2.允许存储重复的元素3.有带索引的方法(练习 add,remove,set,get) 能够使用集合工具类Collections类:static void sort(List<T> list) 根据元素的自然顺序 对指定列表按升序进行排序。static <T> void sort(List<T> lis…

Zookeeper(58)如何在Zookeeper中实现分布式锁?

在 Zookeeper 中实现分布式锁是一种常见的用例。Zookeeper 提供了强一致性、高可用性的分布式协调服务&#xff0c;使得它非常适合用来实现分布式锁。以下是详细的步骤和代码示例&#xff0c;展示如何在 Zookeeper 中实现分布式锁。 1. Zookeeper 分布式锁的基本原理 Zookeep…

帆软报表FineReport入门:简单报表制作[扩展|左父格|上父格]

FineReport帮助文档 - 全面的报表使用教程和学习资料 数据库连接 点击号>>JDBC 选择要连接的数据库>>填写信息>>点击测试连接 数据库SQLite是帆软的内置数据库, 里面有练习数据 选择此数据库后,点击测试连接即可 数据库查询 方法一: 在左下角的模板数据集…

后台管理系统-项目初始化

认识vue-admin **核心交付:** 为什么要基于现成架子二次开发 什么是二次开发:基于已有的代码(项目工程,脚手架)开进行新功能的开发 所以看懂已有的框架中的既有代码,变得很重要了 1. 背景知识 后台管理系统是一种最常见的应用模式,不同的管理系统之间有很多相似的地方…

DAY07 Collection、Iterator、泛型、数据结构

学习目标 能够说出集合与数组的区别数组:1.是引用数据类型的一种2.可以存储多个元素3.数组的长度是固定的 int[] arr1 new int[10]; int[] arr2 {1,2,3};4.数组即可以存储基本类型的数据,又可以存储引用数据类型的数据int[],double[],String[],Student[]集合:1.是引用数据类…

VLM(视觉语言模型)与DeepSeek R1(奖励机制)如何结合

VLM&#xff08;视觉语言模型&#xff09;与DeepSeek R1&#xff08;奖励机制&#xff09;如何结合 flyfish VLM的传统训练依赖于监督学习&#xff08;直接拟合问答对&#xff09;&#xff0c;而规则奖励函数通常用于强化学习&#xff08;通过试错和奖励反馈优化策略&#xf…

从零开始构建一个语言模型中vocab_size(词汇表大小)的设定规则

从零开始构建一个语言模型就要设计一个模型框架,其中要配置很多参数。在自然语言处理任务中,vocab_size(词汇表大小) 的设定是模型设计的关键参数之一,它直接影响模型的输入输出结构、计算效率和内存消耗。 本文是在我前文的基础上讲解的:从零开始构建一个小型字符级语言…

计算机网络之物理层——基于《计算机网络》谢希仁第八版

(꒪ꇴ꒪ )&#xff0c;Hello我是祐言QAQ我的博客主页&#xff1a;C/C语言&#xff0c;数据结构&#xff0c;Linux基础&#xff0c;ARM开发板&#xff0c;网络编程等领域UP&#x1f30d;快上&#x1f698;&#xff0c;一起学习&#xff0c;让我们成为一个强大的攻城狮&#xff0…

实时股票行情接口与WebSocket行情接口的应用

实时股票行情接口与WebSocket行情接口的应用 实时股票行情接口是量化交易和投资决策的核心工具之一&#xff0c;行情接口的种类和功能也在不断扩展。介绍几种常见的行情接口&#xff0c;包括实时股票行情接口、Level2行情接口、WebSocket行情接口以及量化行情接口&#xff0c;…

图论 之 BFS

文章目录 3243.新增道路查询后的最短距离1311.获取你好友已观看的视频 BFS:广度优先搜索&#xff08;BFS&#xff09; 是一种常用的算法&#xff0c;通常用于解决图或树的遍历问题&#xff0c;尤其是寻找最短路径或层级遍历的场景。BFS 的核心思想是使用队列&#xff08;FIFO 数…

ollama stream“:True django如何返回数据

在使用 Django 框架开发 Web 应用时&#xff0c;如果你想要通过 Ollama 流式返回数据&#xff0c;你可以通过 Django 的 HttpResponse 或者 StreamingHttpResponse 来实现。Ollama 主要用于处理文本生成任务&#xff0c;如聊天机器人、自动完成等&#xff0c;通常这些任务会产生…

为什么要用 const 和 let,而不是 var?

JavaScript 中有三种方式声明变量&#xff1a;var、let 和 const。其中&#xff0c;var 是早期版本的 JavaScript 中的标准&#xff0c;但随着 ECMAScript 6&#xff08;ES6&#xff09;引入了 let 和 const&#xff0c;var 的种种问题也显现出来。今天&#xff0c;我们将探讨为…

从零开始玩转TensorFlow:小明的机器学习故事 2

你好&#xff0c;TensorFlow&#xff01;——从零开始的第一个机器学习程序 1. 为什么要写这个“Hello, TensorFlow!”&#xff1f; 无论学习什么新语言或新框架&#xff0c;“Hello World!”示例都能帮助我们快速确认开发环境是否就绪&#xff0c;并掌握最基本的使用方式。对…

【Java八股文】10-数据结构与算法面试篇

【Java八股文】10-数据结构与算法面试篇 数据结构与算法面试题数据结构红黑树说一下跳表说一下&#xff1f;LRU是什么&#xff1f;如何实现&#xff1f;布隆过滤器怎么设计&#xff1f;时间复杂度&#xff1f; 排序算法排序算法及空间复杂度 数据结构与算法面试题 数据结构 红…

Docker换源加速(更换镜像源)详细教程(2025.2最新可用镜像,全网最详细)

文章目录 前言可用镜像源汇总换源方法1-临时换源换源方法2-永久换源&#xff08;推荐&#xff09;常见问题及对应解决方案1.换源后&#xff0c;可以成功pull&#xff0c;但是search会出错 补充1.如何测试镜像源是否可用2.Docker内的Linux换源教程 换源速通版&#xff08;可以直…

华为云deepseek大模型平台:deepseek满血版

华为云硅基流动使用Chatbox接入DeepSeek-R1满血版671B 1、注册&#xff1a; 华为云deepseek大模型平台注册&#xff1a;https://cloud.siliconflow.cn/i/aDmz6aVN 说明&#xff1a;填写邀请码的话邀请和被邀请的账号都会获得2000 万 Tokens&#xff1b;2个帐号间不会与其他关联…

抓包工具是什么?

抓包工具是一种用于捕获和分析网络数据包的软件或硬件设备。它可以帮助用户监控网络通信过程&#xff0c;查看网络中传输的数据内容、协议类型、源地址、目的地址等信息。以下是关于抓包工具的一些详细解释&#xff1a; 1. 主要功能 捕获数据包&#xff1a;抓包工具能够实时捕…

51c大模型~合集71

我自己的原文哦~ https://blog.51cto.com/whaosoft/12260659 #大模型推理加速技术的学习路线 EfficientQAT 可以在 41 小时内在单个 A100-80GB GPU 上完成对 2-bit Llama-2-70B 模型的量化感知训练。与全精度模型相比&#xff0c;精度仅下降了不到 3%&#xff08;69.48 v…