You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地PMTiles地图主窗口不显示但Firefox开发者工具可预览求助

本地部署PMTiles矢量瓦片地图无法显示的问题

我按照Protomaps方案制作并发布矢量瓦片,使用官方的MapLibre示例测试成功,生成了正常显示的地图(样式粗糙但流程可行):
使用示例生成的地图截图

随后尝试本地部署同一PMTiles文件,不依赖在线库和样式表,但项目无法正常运行。奇怪的是,Firefox开发者工具中hover地图div时能看到地图预览,但主窗口无任何内容:
前端无法显示但开发者工具可预览的截图

项目代码如下:

main.js文件

import 'maplibre-gl/dist/maplibre-gl.css'
import maplibregl from 'maplibre-gl'

import * as pmtiles from 'pmtiles'

let protocol = new pmtiles.Protocol()
maplibregl.addProtocol("pmtiles",protocol.tile)

let PMTILES_URL = "http://localhost:80/taranto.pmtiles";

const p = new pmtiles.PMTiles(PMTILES_URL);

protocol.add(p);

p.getHeader().then(h => {
    const map = new maplibregl.Map({
    container: 'map',
    zoom: h.maxZoom-2,
    center: [h.centerLon, h.centerLat],
    style: {
            version:8,
            sources: {
                      "example_source": {
                          type: "vector",
                          url: "pmtiles://" + PMTILES_URL,
                          attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>'
                          }
                     },
            layers: [
                        {
                         "id":"landuse",
                         "source": "example_source",
                         "source-layer":"landuse",
                         "type": "fill",
                         "paint": {
                                   "fill-color": "steelblue"
                                  }
                      },
                        {
                         "id":"transportation",
                         "source": "example_source",
                         "source-layer":"transportation",
                         "type": "line",
                         "paint": {
                                   "line-color": "black"
                                  }
                      },
                        {
                         "id":"mask",
                         "source": "example_source",
                         "source-layer":"mask",
                         "type": "fill",
                         "paint": {
                                   "fill-color": "white"
                                  }
                      }
                    ]
                   }
                });
                map.showTileBoundaries = true;
            })

index.html文件

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
   
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
    <title>Maplibre App</title>
  </head>
  <body>
    <div id="map"></div>
    <script type="module" src="/main.js"></script>
  </body>
</html>

恳请帮忙排查该问题,感谢!

内容的提问来源于stack exchange,提问作者user1632812

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 06:06:10