简体   繁体   English

将2500个geoJSON多边形渲染到传单地图上

[英]Render 2500 geoJSON polygons onto a leaflet map

I've been searching but cannot seem to find a solution. 我一直在寻找,但似乎无法找到解决方案。

I have a GeoJSON file which is 170mb in size. 我有一个170mb大小的GeoJSON文件。 It contains about 2500 polygons. 它包含大约2500个多边形。 Somehow I need to render it to a leaflet map. 不知何故,我需要将它渲染到传单地图。 Evidently at that size I have no chance. 很明显,我没有机会。

What will the easiest way to render this data? 呈现此数据的最简单方法是什么? Am I able to create a complete transparent png which can simply be rendered over the world map. 我能够创建一个完整的透明png,可以简单地在世界地图上渲染。 The huge size is due to the complexity and the number of polygons. 巨大的尺寸是由于多边形的复杂性和数量。 At this point I don't need it to be interactive. 在这一点上,我不需要它是互动的。

Thanks, Brian 谢谢,Brian

The easiest way is to create your own map tiles based on that data. 最简单的方法是根据该数据创建自己的地图图块。 There are a couple of ways of achieving this but my suggestion is that you use TileMill . 有几种方法可以达到这个目的,但我的建议是你使用TileMill It's free and very easy to use. 它是免费的,非常容易使用。 So, basically you would: 所以,基本上你会:

  • Use TileMill and specify your GeoJSON file as the data-source 使用TileMill并将GeoJSON文件指定为数据源

  • Configure how the map should be displayed (like the color of the polygons) with a special CSS-like language inside TileMill 使用TileMill中特殊的类似CSS的语言配置地图的显示方式(如多边形的颜色)

  • Generate the tiles 生成瓷砖

  • Load a new TileLayer in your Leaflet map that references your files 在Leaflet映射中加载一个引用文件的新TileLayer

I've actually written a tutorial some time ago that uses a .shp instead of a GeoJson, but should be similar enough: 我实际上在不久前编写了一个使用.shp而不是GeoJson的教程,但应该足够相似:

http://build-failed.blogspot.pt/2012/03/custom-map-tiles-part-2-tilemill.html http://build-failed.blogspot.pt/2012/03/custom-map-tiles-part-2-tilemill.html

I cannot argue with psousa's recommendation. 我无法与psousa的建议争论。 For a straightforward presentation, TileMill is a great idea. 对于简单的演示,TileMill是一个好主意。

However, if you want to overlay your polygons onto another map, I reckon the only way is by using Mike Bostock's TopoJSON and D3. 但是,如果你想将你的多边形叠加到另一个地图上,我认为唯一的方法是使用Mike Bostock的TopoJSON和D3。

The main TopoJSON page: https://github.com/mbostock/topojson/wiki 主要的TopoJSON页面: https//github.com/mbostock/topojson/wiki

An example at the scale you are talking about: http://bl.ocks.org/mbostock/4206573 您正在谈论的规模的一个例子: http//bl.ocks.org/mbostock/4206573

You'll have to shop around Mike's excellent examples on github to see how to combine leaflet with a D3 overlay. 你将不得不购买迈克在github上的优秀例子,看看如何将传单与D3叠加相结合。

I'm currently doing this successfully with hundreds of complex polygons. 我目前正在成功完成数百个复杂的多边形。 Haven't had the need to break into the thousands ... yet. 没有必要突破成千上万......但是。

There is also geojson-vt , which apparently can to the tiling serverless on-the-fly - after a bit of loading time. 还有geojson-vt ,在加载一段时间之后,显然可以在无服务器上进行 无人值守

来自GitHub的演示GIF

Just another humble suggestion. 只是另一个卑微的建议。 I had successfully done loading 10000+ polygons and querying attributes by rolling out my own Geoserver and PostgreSQL DB + PostGIS instance and producing a WMS (not WFS), as you can see in the image. 通过推出我自己的Geoserver和PostgreSQL DB + PostGIS实例并生成WMS(而不是WFS),我已成功完成加载10000多个多边形和查询属性,如图所示。

10000多个多边形

But it is not straightforward to implement, especially if the geojson data is the original (and only) data 但实现起来并不简单,特别是如果geojson数据是原始(且唯一)数据

In that regard I would second psousa's answer to use TileMill. 在这方面,我将第二个psousa的答案使用TileMill。

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

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