惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
I
InfoQ
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
Y
Y Combinator Blog
博客园_首页
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
A
About on SuperTechFans
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
C
Check Point Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Engineering at Meta
Engineering at Meta
B
Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
F
Fortinet All Blogs
月光博客
月光博客
GbyAI
GbyAI

博客园 - 左直拳

在centos上部署gitea服务器 我的2025 利用wvp-gb28181-pro国标级联实现上级观看下级摄像头 将c++程序部署到docker 安装linux时的存储设置 利用SRS拉取摄像头辅码流实现浏览器展示多路摄像头预览功能 自签名证书需要手动确认风险导致nginx转发无效问题 程序跑在docker容器里会有性能瓶颈吗? 前端vue3+后端spring boot导出数据 c++程序示例:多线程下的实例计数器 linux下变更mysql的数据文件目录 c++项目使用drogon框架提供Resful API在CPU ARM架构下崩溃问题 编写c++程序分别在x86和arm架构的ubuntu下访问CAN 接口设备 时区问题导致java程序查询无结果 ubuntu 20.04挂载固态硬盘 项目绩效域 c++中构造对象实例的两种方式及其返回值 c++中“&”符号代表引用还是取内存地址? 高级项目管理
使用Mobile Atlas Creator 2.0获取离线地图
左直拳 · 2025-12-21 · via 博客园 - 左直拳

项目部署在内网,无法上互联网,客户又不提供地图资源,咋办?只能使用离线地图了。

一、下载离线地图

离线地图从哪里来?AI推荐了好几种方式,亲测发现Mobile Atlas Creator勉强可用。

1、Mobile Atlas Creator的版本问题

Mobile Atlas Creator官网有多个版本。最新的好像是多少不记得了,但需要比较高版本的java虚拟机支持。我还在用古老的JDK8,找来找去,只有Mobile Atlas Creator2.0.0合适。

也许是版本比较低吧,Mobile Atlas Creator上的绝大部分地图源都无法使用,只有一个波兰的矢量地图可以用,但十分简约。
在这里插入图片描述
后来发现可以自己添加地图源。方法是编辑一个XML文件,放在Mobile Atlas Creator根目录下的mapsources文件夹。XML名字自定义,但XML的内容格式什么苛刻,应该与官方的文档说明严格保持一致,否则地图资源列表里连名字都出不来,更遑论加载地图资源了。

2、一个可用的地图资源

什么google也,bing也,高德也,地图全部不能在Mobile Atlas Creator下载。但是ESRI却可以。以下是一个亲测可用的for Mobile Atlas Creator的地图资源XML:

esri.xml

<customMapSource>
  <name>ESRI Imagery</name>
  <url>https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{$z}/{$y}/{$x}</url>
  <minZoom>0</minZoom>
  <maxZoom>18</maxZoom>
  <tileType>png</tileType>
</customMapSource>

扔到mapsources文件夹下
在这里插入图片描述

效果下:
在这里插入图片描述

3、下载离线地图

新建地图册,选第一个类型AFTrack(OSZ),在地图上用鼠标框选要下载的范围,添加选择区域,设置好缩放级别,即可下载。
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
下载后得到一个osz后缀的文件。这是一个压缩包,用压缩软件,比如rar就能解开。里面为按照级别(z/y/x.png)存放的图片。
在这里插入图片描述
解开后
在这里插入图片描述
在这里插入图片描述

4、Mobile Atlas Creator下载离线地图的机制与浏览器不同

我刚开始时,想的是仿照WEBA加载天地图的办法,将天地图的WMS地址赋给Mobile Atlas Creator,但实际上行不通,地图出不来。原因应该是该天地图资源只放行浏览器的请求吗,而Mobile Atlas Creator的请求机制可能不一样,就被拒了。

5、何处望神洲

我的Mobile Atlas Creator是2025年9月份下载的,当时用了163.com邮箱注册的账号,现在已经无法登录了。

二、使用离线地图

我的前端是vue3,使用openlayers来操作地图。代码如下:
在这里插入图片描述

假设底图图层定义如下

"layers": [
    {
      "title": "矢量底图",
      "url": "/sz/{z}/{x}/{y}.png",
      "type": "base",
      "visible": true
    },
    {
      "title": "影像底图",
      "url": "/sz-img/{z}/{x}/{y}.png",
      "type": "base",
      "visible": true
    }
  ],

则地图加载底图代码:

		import Map from 'ol/Map';
		import View from 'ol/View';
		import TileLayer from 'ol/layer/Tile';
		import XYZ from 'ol/source/XYZ';
		import LayerSwitcher from 'ol-layerswitcher';
		import Zoom from 'ol/control/Zoom' // 引入缩放控件
		//import { OverviewMap } from 'ol/control';
		import MousePosition from 'ol/control/MousePosition'
		import ScaleLine from 'ol/control/ScaleLine' // 引入比例尺控件
		import { fromLonLat } from 'ol/proj';

    const map = new Map({
        target: mapContainer.value,
        layers: createLayers(config.layers),//加载底图
        view: new View({
            center: fromLonLat(config.center), // 使用 fromLonLat 转换为 EPSG:3857 坐标
            zoom: config.zoom,
            projection: config.projection, // 使用WGS84坐标系
        }),
        controls: [
            new Zoom(), // 添加缩放控件
            //overviewMapControl, // 添加鹰眼控件
            mousePositionControl,
            new ScaleLine({
                target: document.getElementById('scale-line-container'),
                units: 'metric',
            }), // 添加比例尺控件
            new LayerSwitcher() //图层切换
        ],
    });

    function createLayers(layerInfos) {//加载底图方法
        const layers = [];

        layerInfos.forEach(item => {
            const layer = new TileLayer({
                source: new XYZ({
                    url: item.url,
                }),
                type: item.type, // 表示是底图
                visible: item.visible
            });
            layer.set('title', item.title);
            layers.push(layer);
        });

        return layers;
    }