基于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.pswp.cn/web/70414.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/70414.shtml
英文地址,請注明出處:http://en.pswp.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…