简体   繁体   English

在Leaflet.js中使用的Geojson编码

[英]Geojson encoding for using in Leaflet.js

I've spotted that a geojson encoding utility is now available, geobuf . 我发现,一个GeoJSON的编码工具现已推出, geobuf

I've played around with the ( python module version ) and have been able to encode a geojson file to pbf and then decode back to geojson. 我玩过( python模块版本 ),已经能够将geojson文件编码为pbf,然后再解码回geojson。 I can't figure out how to do this within leaflet.js. 我不知道如何在leaflet.js中执行此操作。 I'm hoping this might be a way to encode and deliver large geojson files but I can't find any example as to how to use and implement it in leaflet.js. 我希望这可能是一种编码和传递较大的geojson文件的方法,但我找不到在leaflet.js中如何使用和实现它的任何示例。

Can anyone shed light on how to use geobuf to encode a geojson file and use it with leaflet.js? 任何人都可以阐明如何使用geobuf编码geojson文件并将其与leaflet.js一起使用吗?

You need to convert Geobuf to plain GeoJSON in the browser. 您需要在浏览器中将Geobuf转换为普通的GeoJSON Make a geobuf browser build , include it in a <script> tag (as you do with Leaflet), and then: 制作一个geobuf浏览器版本 ,将其包含在<script>标记中(与Leaflet一样),然后:

var layer = L.geoJson( geobuf.decode( new Pbf(data) ) ).addTo(map);

From leaflet docs : 从传单文档

L.geoJson(geojsonFeature).addTo(map);

Where geojsonFeature is the actual geoJSON 其中geojsonFeature是实际的geoJSON

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

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