简体   繁体   English

如何使用 geoxml3 获取 KMZ 或 KML 文件的边界?

[英]How to get bounds of a KMZ or KML file using geoxml3?

My project involves loading multiple kmz files from a directory containing about 600+ kmz/kml files.我的项目涉及从包含大约 600 多个 kmz/kml 文件的目录中加载多个 kmz 文件。 Max of 5 files will be loaded as user moves the map and clicks a button to load related kmz files.当用户移动地图并单击按钮以加载相关的 kmz 文件时,最多将加载 5 个文件。 There will be a check to ensure that zoom is large enough so that the area covered isn't too broad.将进行检查以确保缩放足够大,以便覆盖的区域不会太宽。

To load relevant kmz/kml file, the idea is that if the placemarks from a kmz/kml fall even partially within the viewport then the file is loaded.要加载相关的 kmz/kml 文件,想法是如果来自 kmz/kml 的地标甚至部分落在视口内,则加载该文件。 To load these kmz/kml files quickly, I thought of the following steps:为了快速加载这些kmz/kml文件,我想到了以下步骤:

Step 1: Extract the bounds of each kmz/kml file separately and store it in a file.步骤1:分别提取每个kmz/kml文件的边界并存储在一个文件中。 I know how to get bounds of the viewport, map.getBounds() , and specific polygons in a kmz, geoXmlDoc.placemarks[i].polygon.bounds .我知道如何在 kmz、 geoXmlDoc.placemarks[i].polygon.bounds获取视口、 map.getBounds()和特定多边形的geoXmlDoc.placemarks[i].polygon.bounds But is there a way of getting bounds for the entire kmz file that includes all points, lines, polygons?但是有没有办法获得包含所有点、线、多边形的整个 kmz 文件的边界?

I understand this step needs to be done just once to generate the bounds file containing all kmz/kml files' bounds.我了解此步骤只需执行一次即可生成包含所有 kmz/kml 文件边界的边界文件。 I tried loading each file separately through a loop and calling getBounds of viewport but unfortunately the viewport does not exactly fit the kmz's bounds.我尝试通过循环单独加载每个文件并调用视口的 getBounds 但不幸的是视口并不完全适合 kmz 的边界。 The viewport is usually bigger.视口通常更大。

Step 2: When user moves map to new location and clicks load relevant kmz files, then only the consolidated bounds array will be checked if the viewport bounds intersects with any of the kmz bounds.第 2 步:当用户将地图移动到新位置并单击加载相关 kmz 文件时,如果视口边界与任何 kmz 边界相交,则只会检查合并的边界数组。

if (currentBounds.intersects(all_bounds_array[i])) 
{
    // load the kmz file for index i
}

Create an empty LatLngBounds object.创建一个空的LatLngBounds对象。 Ignore the map's current bounds.忽略地图的当前边界。

var bounds = new google.maps.LatLngBounds();

Loop through all the contents of the KMZ file, extending that bounds with the various coordinates in your file循环遍历 KMZ 文件的所有内容,使用文件中的各种坐标扩展边界

bounds.extend(/* your coords */);

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

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