无法呈现矢量砖(.mbtiles)与文件传单

问题描述 投票:2回答:1

我想呈现一些本地存储和基于矢量的瓷砖从OpenMapTile下载。我这样做的原因是因为我的最终应用将只无法连接到互联网的计算机上运行。

我已阅读就是否小叶可以使基于矢量的瓷砖很多不同的东西,但它似乎可以从一些例子。

It seems that it is not possible with Vector Grid that only does raster tilesit is possible with Leaflet.TileLayer.MBTiles

于是,我就只是这样做,但在一个空白页尝试时,它总是跌倒......我对地图的控制器,但它只是不显示任何内容。这是我的MWE。

<!DOCTYPE html>
<html>
<head>

    <title>VectorGrid.Protobuf example</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />

</head>
<body style='margin:0'>

    <div id="map" style="width: 100vw; height: 100vh; background: white"></div>

    <script type="text/javascript"  src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
    <script type="text/javascript"  src="https://unpkg.com/[email protected]"></script>

    <script src="https://unpkg.com/[email protected]/js/sql.js"></script>

    <!--<script src="https://unpkg.com/leaflet.tilelayer.mbtiles@latest/Leaflet.TileLayer.MBTiles.js"></script>-->
    <script src="Leaflet.TileLayer.MBTiles.js"></script>


    <!-- <script type="text/javascript" src="../dist/Leaflet.VectorGrid.bundled.js"></script> -->
    <script>

            var vectorTileStyling = {

            water: {
                fill: true,
                weight: 1,
                fillColor: '#06cccc',
                color: '#06cccc',
                fillOpacity: 0.2,
                opacity: 0.4,
            },
            admin: {
                weight: 1,
                fillColor: 'pink',
                color: 'pink',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            waterway: {
                weight: 1,
                fillColor: '#2375e0',
                color: '#2375e0',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            landcover: {
                fill: true,
                weight: 1,
                fillColor: '#53e033',
                color: '#53e033',
                fillOpacity: 0.2,
                opacity: 0.4,
            },
            landuse: {
                fill: true,
                weight: 1,
                fillColor: '#e5b404',
                color: '#e5b404',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            park: {
                fill: true,
                weight: 1,
                fillColor: '#84ea5b',
                color: '#84ea5b',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            boundary: {
                weight: 1,
                fillColor: '#c545d3',
                color: '#c545d3',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            aeroway: {
                weight: 1,
                fillColor: '#51aeb5',
                color: '#51aeb5',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            road: { // mapbox & nextzen only
                weight: 1,
                fillColor: '#f2b648',
                color: '#f2b648',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            tunnel: {   // mapbox only
                weight: 0.5,
                fillColor: '#f2b648',
                color: '#f2b648',
                fillOpacity: 0.2,
                opacity: 0.4,
//                  dashArray: [4, 4]
            },
            bridge: {   // mapbox only
                weight: 0.5,
                fillColor: '#f2b648',
                color: '#f2b648',
                fillOpacity: 0.2,
                opacity: 0.4,
//                  dashArray: [4, 4]
            },
            transportation: {   // openmaptiles only
                weight: 0.5,
                fillColor: '#f2b648',
                color: '#f2b648',
                fillOpacity: 0.2,
                opacity: 0.4,
//                  dashArray: [4, 4]
            },
            transit: {  // nextzen only
                weight: 0.5,
                fillColor: '#f2b648',
                color: '#f2b648',
                fillOpacity: 0.2,
                opacity: 0.4,
//                  dashArray: [4, 4]
            },
            building: {
                fill: true,
                weight: 1,
                fillColor: '#2b2b2b',
                color: '#2b2b2b',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            water_name: {
                weight: 1,
                fillColor: '#022c5b',
                color: '#022c5b',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            transportation_name: {
                weight: 1,
                fillColor: '#bc6b38',
                color: '#bc6b38',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            place: {
                weight: 1,
                fillColor: '#f20e93',
                color: '#f20e93',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            housenumber: {
                weight: 1,
                fillColor: '#ef4c8b',
                color: '#ef4c8b',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            poi: {
                weight: 1,
                fillColor: '#3bb50a',
                color: '#3bb50a',
                fillOpacity: 0.2,
                opacity: 0.4
            },
            earth: {    // nextzen only
                fill: true,
                weight: 1,
                fillColor: '#c0c0c0',
                color: '#c0c0c0',
                fillOpacity: 0.2,
                opacity: 0.4
            },


            // Do not symbolize some stuff for mapbox
            country_label: [],
            marine_label: [],
            state_label: [],
            place_label: [],
            waterway_label: [],
            poi_label: [],
            road_label: [],
            housenum_label: [],


            // Do not symbolize some stuff for openmaptiles
            country_name: [],
            marine_name: [],
            state_name: [],
            place_name: [],
            waterway_name: [],
            poi_name: [],
            road_name: [],
            housenum_name: [],
        };


        // Monkey-patch some properties for nextzen layer names, because
        // instead of "building" the data layer is called "buildings" and so on
        vectorTileStyling.buildings  = vectorTileStyling.building;
        vectorTileStyling.boundaries = vectorTileStyling.boundary;
        vectorTileStyling.places     = vectorTileStyling.place;
        vectorTileStyling.pois       = vectorTileStyling.poi;
        vectorTileStyling.roads      = vectorTileStyling.road;



        var map = L.map('map');


        //var openmaptilesUrl = "https://free-{s}.tilehosting.com/data/v3/{z}/{x}/{y}.pbf.pict?key={key}";
        var openmaptilesUrl = "http://127.0.0.1:8080/2017-07-03_france_toulouse.mbtiles";



        var openmaptilesVectorTileOptions = {
            rendererFactory: L.canvas.tile,
            attribution: '<a href="https://openmaptiles.org/">&copy; OpenMapTiles</a>, <a href="http://www.openstreetmap.org/copyright">&copy; OpenStreetMap</a> contributors',
            vectorTileLayerStyles: vectorTileStyling,
            subdomains: '0123',
            key: 'UmmATPUongHdDmIicgs7',
            maxZoom: 14
        };

        var mb = L.tileLayer.mbTiles(openmaptilesUrl).addTo(map);
        /*var openmaptilesPbfLayer = L.vectorGrid.protobuf(openmaptilesUrl, openmaptilesVectorTileOptions).addTo(map);*/


        map.setView({ lat: 47.040182144806664, lng: 9.667968750000002 }, 0);


        /*L.control.layers({
            OpenMapTiles: openmaptilesPbfLayer,
        }, {}, {collapsed: false}).addTo(map);*/




    </script>
</body>
</html>

既然我已经很难找到Leaflet.TileLayer.MBTiles,https://gitlab.com/IvanSanchez/Leaflet.TileLayer.MBTiles/blob/master/Leaflet.TileLayer.MBTiles.js是一个版本,您可以下载

作为一个例砖,可以使用this one(从OpenMapTiles专注于法国图卢兹直接下载,因为它是一个相当小的mbtile文件)。

我真的不明白是什么问题。它来到我的脑海里,这很可能是小叶无法读取矢量砖,在这种情况下,我认为我可以尝试让我最终的光栅像素块,将它们转换,但我无法找到一个方法来做到这一点。我不知道最好的解决办法是什么......这似乎有些人设法使其与矢量和栅格瓦片,但我似乎as explained on StackOverflow不能找到一种方法,使之在我自己的工作而努力这个链接后是不是很详细。

预先感谢您的帮助。

javascript leaflet geospatial tiles vector-graphics
1个回答
0
投票

试试这个变化:

var openmaptilesUrl = "http://127.0.0.1:8080/2017-07-03_france_toulouse.mbtiles";

为了这:

var openmaptilesUrl = "./2017-07-03_france_toulouse.mbtiles";

和存储您的mbtiles文件到您的网站的根旁边的index.html

© www.soinside.com 2019 - 2024. All rights reserved.