使用MapBox GL JS即时将GeoJSON转换为矢量图块? [英] Converting GeoJSON to Vector Tiles on the fly w/ MapBox GL JS?

查看:146
本文介绍了使用MapBox GL JS即时将GeoJSON转换为矢量图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的地图的源文件是GeoJSON,但是它非常大且非常慢.有没有一种方法可以使用MapBox GL JS即时将其转换为矢量图块?(加载GeoJSON,将文件预处理为矢量图块,并显示使用矢量图块作为底图.)看来矢量图块要快得多.

My map's source file is GeoJSON, but it is very large and very slow. Is there a way to convert this to vector tiles on the fly using MapBox GL JS? (Load the GeoJSON, pre-process the file into vector tiles, and show use the vector tiles as the base map.) It seems that vector tiles are much faster.

我已经尝试了所有可以使用的GeoJSON-VT教程和示例,例如 MapBox网站上的那个,但是它只是说GeoJSON-VT是在后台运行的,因此并没有太大帮助.其他的大多数适用于Leaflet,而不适用于MapBox GL JS.

I've tried all the GeoJSON-VT tutorials and examples that I could, like the one on MapBox's site, but it just says that GeoJSON-VT works under the hood, so it isn't much help. The others mostly apply to Leaflet, not MapBox GL JS.

与此同时,我发现的每个使用大型数据集的示例都总是通过矢量图块来这样做:

Meanwhile, every example I find that uses a large dataset always does so via vector tiles:

map.addSource('x', {
        "type": "vector",
        "url": "url"
    });

作为参考,我正在使用以下方法加载文件:

For reference, I am loading my file using this method:

map.addSource('x', {
        type: 'geojson',
        data: 'file.geojson'
    });

推荐答案

如果您的GeoJSON文件是静态的,则可以使用关于图块),也可以使用 .mbtiles 文件(

In case your GeoJSON file is static, you could use mapbox/tippecanoe to convert the GeoJSON to an .mbtiles file. You could then either upload the file to Mapbox as a tileset (about tilesets) or you could serve your own vector tile source from a web server using the .mbtiles file (reference implementation).

如果您的GeoJSON文件更具动态性,事情会变得更加复杂.我从未使用过它,但是 Mapbox Dataset API可能是一个很好的解决方案.

If your GeoJSON file is more dynamic, things get a little bit more complicated. I have never used it, but Mapbox Dataset API might be a good solution for that.

这篇关于使用MapBox GL JS即时将GeoJSON转换为矢量图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆