简体   繁体   English

传单导入 GeoJson

[英]Leaflet import GeoJson

I'm developing an angular application with leaflet and i have to show many municipality about my country:我正在开发一个带有传单的角度应用程序,我必须向我的国家展示许多市政当局:

在此处输入图片说明

To do this and make navigation efficient, i needed to split my json file in multiple files and put them in assets folder:为了做到这一点并使导航高效,我需要将我的 json 文件拆分为多个文件并将它们放在资产文件夹中:

在此处输入图片说明

and to show layer in mai I'm using angular HttpClient in the following way:并在 mai 中显示层,我使用 angular HttpClient 以下列方式:

this.http.get('assets/shp/Comuni.geojson').subscribe((json: any) => {
 L.geoJSON(this.json).addTo(map);
});

the size of my asset folder has become almost a gigabyte, and i need to store this files in a external repository, like a server.我的资产文件夹的大小几乎变成了 1 GB,我需要将这些文件存储在外部存储库中,例如服务器。 Any suggestion about this?对此有何建议? What is the correct way to handle this kind to situation?处理这种情况的正确方法是什么?

You can convert the geoJSON files to topoJSON which are way smaller than geojson and the conversion allows you to incrementally simplify a dataset.您可以将 geoJSON 文件转换为比 geojson 小得多的 topoJSON,并且转换允许您逐步简化数据集。

To convert you can install topojson要转换,您可以安装 topojson

npm install -g topojson

and convert it as follow并将其转换如下

topojson -o topo.json geoJSON.json

This will save you a lot of size.这将为您节省很多尺寸。

I bet it's something wrong with yours geoJson files.我敢打赌你的 geoJson 文件有问题。 Maybe they are overdetalized.也许他们被过度详细化了。 For example look at Canada.geojson it has size near 400 kb for whole the second largest country in the world.例如, 看看 Canada.geojson,它的大小接近 400 kb,整个世界第二大国家。 You can try service like https://mapshaper.org/ to simply your data.您可以尝试使用https://mapshaper.org/ 之类的服务来简化您的数据。

and i need to store this files in a external repository, like a server.我需要将此文件存储在外部存储库中,例如服务器。 Any suggestion about this?对此有何建议?

[...] [...]

I know that my files are overdetalized, but i need to show smaller parts of a municipality, and the i need to this detail.我知道我的文件超额了,但我需要展示一个自治市的较小部分,我需要这个细节。

Well, there are 2 approaches.嗯,有两种方法。 And it mainly has to do with the type of data you want to receive in the front-end.它主要与您希望在前端接收的数据类型有关。 You want vector data (eg GeoJSON)?您想要矢量数据(例如 GeoJSON)? Or maybe raster tiles (eg WMS)?或者也许是光栅图块(例如 WMS)?

1st approach - Vector Data第一种方法 - 矢量数据

You definitely cannot store/load all your data at once.您绝对不能一次存储/加载所有数据。 You should store them at an external server and get more data with appropriate requests.您应该将它们存储在外部服务器上,并通过适当的请求获取更多数据。 For example, you could initially only load a simplified GeoJSON for all municipalities in a low zoom level, and when the user chooses / pans to a certain municipality, request from the server a GeoJSON with higher detail.例如,您最初只能以低缩放级别为所有城市加载简化的 GeoJSON,当用户选择/平移到某个城市时,从服务器请求具有更高细节的 GeoJSON。 However, developing a pyramid-like structure for multiple zoom levels etc, would not be easy.然而,为多个缩放级别等开发类似金字塔的结构并不容易。 So, you have to consider if this approach can work in your case.因此,您必须考虑这种方法是否适用于您的情况。

2st approach - Raster Data第二种方法 - 栅格数据

You can forget about GeoJSON and develop a GeoServer.您可以忘记 GeoJSON 并开发一个 GeoServer。 http://geoserver.org/ You will have all your spatial data in the back-end and choose to serve only raster tiles in your front-end using eg a WMS. http://geoserver.org/您将在后端拥有所有空间数据,并选择使用 WMS 等仅在前端提供栅格切片。 It may sound like extra hassle but on the other hand, you will not have to worry about oversized GeoJSONs etc.这听起来可能很麻烦,但另一方面,您不必担心过大的 GeoJSONs 等。

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

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