javascript - maplibre-gl-js : load offline (local) glyphs, sprites 和 mbtiles - HTML 网站

标签 javascript html offline maplibre-gl

我目前正在编写一个带有嵌入式 Javascript 的简单 HTML 页面,以可视化本地 mbtiles,包括本地 glyphssprites

html index.html 是:

...
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="670a06170b0e0515024a000b27554956495e" rel="noreferrer noopener nofollow">[email protected]</a>/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82efe3f2eeebe0f0e7afe5eec2b0acb3acbb" rel="noreferrer noopener nofollow">[email protected]</a>/dist/maplibre-gl.css" rel="stylesheet" />
...
<body>
<div id="map"></div>
</body>
<script type="module" src="./index.js" async defer></script>

javascript index.js 是:

var map = new maplibregl.Map({
    container: 'map',
    style:
        'styles/style.json',
    center: [174.746344, -36.8899343],
    zoom: 11.15
});

目标是加载一个 style.json 文件,该文件将定义 mbtilesspritesglyphs 本地位置。

我目前正在使用 OSM Bright 样式,该样式在我的计算机上本地复制到 style.json 文件中,目标是通过本地文件交换与远程文件的任何连接:

字形

"glyphs": "./glyphs/{fontstack}/{range}.pbf",

它对于字形效果很好

Sprite

"sprite": "./sprites/sprite",

我有以下错误: 无法解析 URL“./sprites/sprite”

mbtiles

"sources": {
    "openmaptiles": {
      "type": "vector",
      "url": "./mbtiles/country.mbtiles"
    }
  },

我收到以下错误:错误:意外的标记“S”,“SQLite for”...不是有效的 JSON

我在这里肯定缺少一些协议(protocol),并且到目前为止我找不到我的问题的任何答案,知道:

asset://sprites/sprite
or
mbtiles://country.mbtiles

但这不起作用(对于字形也不起作用,但看起来无论如何都没有必要)

因此,任何帮助将不胜感激,特别是我有兴趣知道这是否可以通过我正在使用的 maplibre-gl.js 库实现,因为这可能是不可能的。如果是这样的话,如果有必要,我希望使用 mapbox-gl.js 提供类似的答案,但仍然使用本地(离线)文件。

换句话说,主要目标是使用maplibre(不是mapbox - 至少如果可能的话)运行一个网站(而不是应用程序),并且只包含本地文件。

感谢您的任何反馈。

最佳答案

我知道可能会迟到,但尽管如此:
据我所知,mbtiles://协议(protocol)仅适用于 maplibre-gl,不适用于 maplibre-gl-js。
所以我使用了pbf文件。您可以使用 mbutil 从 mbtiles 文件中获取它们或来自 osm.pbf 文件 tilemaker .
在使用tilemaker从osm.pbf转换之前,您应该将config-openmaptiles.json中的字段“compress”修改为“none”,否则 map 将不会渲染。

对我来说,只有“glyphs”适用于相对路径,但“sprite”和“tiles”适用于完整路径,例如http://...(但我只尝试了python3嵌入的http.server和uvicorn) 这是我从 style.json 中摘录的:

  "sources": {
    "openmaptiles": {
      "type": "vector",
      "tiles": ["http://localhost:8000/data/tiles/{z}/{x}/{y}.pbf"],
      "minzoom": 0,
      "maxzoom": 14
    }
  },
  "sprite": "http://localhost:8000/data/sprites/bright-v8",
  "glyphs": "data/glyphs/{fontstack}/{range}.pbf",

“tiles”路径应位于方括号中,如果您希望过度缩放工作,则应提供 map 的“maxzoom”(据我所知,14 是许多 map 的默认值)。

关于javascript - maplibre-gl-js : load offline (local) glyphs, sprites 和 mbtiles - HTML 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73698512/

相关文章:

html - 使用 HTML5 视频标签播放本地(硬盘)视频文件?

android - MapBox GL Android : Offline Maps from custom tile source downloaded but not used

javascript - ReactJS 和 material-ui

javascript - 根据选择重新加载面板中的不同 HTML 控件

javascript - 为什么我不必将 `import` `anti:fake` 放入我的 Meteor 源文件中?

ios - ios10 safari 的 html 页面中的视频元素是否有限制

html - 如何显示带有两个不同大小/颜色边框的超链接图像?

javascript - 如何从 javascript 中的倒计时方法返回 boolean 值

javascript - 用于发送 Twilio SMS 消息的 AngularJS 服务

ios - 如何禁用 Firebase 实时数据库 iOS 离线写入