繁体   English   中英

无法使用Openlayers支付pbf(地图框矢量图块)

[英]Not able to dispay pbf(mapbox vector tile) using openlayers

我正在尝试显示我自己创建的矢量tile(.pbf),它们不会在检查元素的控制台上正确显示。 我用一个简单的例子,HTML文件,在dispaying他们: 这里

我只是更改了网址,以在本地服务器而不是mapbox服务器上查找矢量切片。

当我尝试从mapbox服务器显示pbf文件时,它会显示出来。 我也下载了这些mapbox pbf文件,并从本地服务器提供了相同的文件,并显示它们。

但是我不能使用tippecanoe从geojson文件创建的pbf文件由openlayers显示。生成的pbf文件是正确的,因为我可以使用mapbox js脚本对其进行处理。 我有问题,服务器的内容编码也是gzip。 可以从此处下载示例pbf文件,该文件未通过附加代码显示,而是通过tileserver-gl(mapbox脚本)显示

码:

<!DOCTYPE html>
<html>
<head>
    <title>Mapbox Vector Tiles</title>
    <link rel="stylesheet"href="https://openlayers.org/en/v4.5.0/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.5.0/build/ol.js"></script>
    <script src="https://openlayers.org/en/v4.5.0/examples/resources/mapbox-streets-v6-style.js"></script>
    <script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
    <style>
        .map {
            background: #f8f4f0;
        }
    </style>
</head>
<body>
<div id="map" class="map"></div>
<script>
    var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';

    var map = new ol.Map({
        layers: [
            new ol.layer.VectorTile({
                declutter: true,
                source: new ol.source.VectorTile({
                    attributions: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' +
                    '© <a href="https://www.openstreetmap.org/copyright">' +
                    'OpenStreetMap contributors</a>',
                    format: new ol.format.MVT(),

                    url: 'http://localhost:8000/tippecanoe_tiles/' + '{z}/{x}/{y}.pbf'
                    //url: 'https://{a-d}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/' +
                    //          '{z}/{x}/{y}.vector.pbf?access_token=' + key

                }),
                style: createMapboxStreetsV6Style(ol.style.Style, ol.style.Fill, ol.style.Stroke, ol.style.Icon, ol.style.Text)
            })
        ],
        target: 'map',
        view: new ol.View({
            center: [0, 0],
            zoom: 2
        })
    });
</script>
</body>
</html>

您使用的是OpenLayers 4.5,而不是OpenLayers 5.X,请尝试上传您的OpenLayers版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM