简体   繁体   English

将多边形合并到Google Maps API 3中

[英]Incorporating polygons into Google Maps API 3

Part of my web application will allow users to click on a certain territory of a map and have it highlight that section in the Google Maps that I have on the page. 我的Web应用程序的一部分将允许用户单击地图的特定区域,并突出显示页面上我在Google Maps中的该部分。 This is pretty standard on a lot of websites, but I'm having a hard time with the amount of data that's there. 这在很多网站上都是很标准的,但是我很难处理那里的数据量。

I'm trying to generate data from http://global.mapit.mysociety.org/ , which provides me several output options for actual coordinates that I want to turn into polygons, but exporting the WKT, GeoJSON, or the KML is HUGE - 700-900 KB for EACH instance, and I don't understand how this website is able to incorporate these polygons without loading this data, (Chrome doesn't show any item over 50 KB being loaded.) 我正在尝试从http://global.mapit.mysociety.org/生成数据,这为我要转换为多边形的实际坐标提供了多个输出选项,但是导出WKT,GeoJSON或KML的过程非常庞大-每个实例700-900 KB,而且我不明白该网站如何能够在不加载此数据的情况下合并这些多边形(Chrome浏览器不会显示任何加载超过50 KB的项目。)

What I'm doing NOW: 我现在正在做什么:

I downloaded a few of the WKT files, then used PHP to translate that into a javascript string so : 我下载了一些WKT文件,然后使用PHP将其转换为javascript字符串,因此:

var coordinates = [
new google.maps.LatLng(1.1, 1.2),
...
new google.maps.LatLng(1.1, 1.2)
];

I did this with about 10 locations, saved my file, and it was 9 MB - all from these super long coordinates strings... 我在大约10个位置执行了此操作,保存了文件,总共9 MB-全部来自这些超长coordinates字符串...

How do I do this more efficiently, as this is obviously not the way to incorporate polygon data into a dynamic map load? 如何有效地执行此操作,因为显然这不是将面数据合并到动态地图加载中的方法?

Don't translate it on serverside, the string new google.maps.LatLng will blow up your file. 不要在服务器端进行翻译,字符串new google.maps.LatLng会炸毁您的文件。

When you use eg geoJSON you may load the polygon via loadGeoJson . 当使用例如geoJSON时,您可以通过loadGeoJson加载多边形。

The linked page uses geoJSON to draw the polygons(eg http://global.mapit.mysociety.org/area/686972.html loads these data: http://global.mapit.mysociety.org/area/686972.geojson?simplify_tolerance=0.0001 ~100KB) 链接页面使用geoJSON绘制多边形(例如, http ://global.mapit.mysociety.org/area/686972.html加载以下数据: http ://global.mapit.mysociety.org/area/686972.geojson ? simple_tolerance = 0.0001〜100KB)

Another option would be to encode each single polygon(polyline) on serverside and reassemble/decode the polygons via JS. 另一个选择是在服务器端对每个多边形(折线)进行编码,然后通过JS重新组合/解码多边形。 See https://developers.google.com/maps/documentation/utilities/polylinealgorithm and https://developers.google.com/maps/documentation/javascript/reference#encoding for more details. 有关更多详细信息,请参见https://developers.google.com/maps/documentation/utilities/polylinealgorithmhttps://developers.google.com/maps/documentation/javascript/reference#encoding

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

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