google maps api v3导出当前地图的kml文件 [英] google maps api v3 exporting kml file of current map

查看:373
本文介绍了google maps api v3导出当前地图的kml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个谷歌地图组件,允许用户绘制多边形,线条和标记。现在我想实现一个按钮,允许用户导出他/她在地图中绘制的东西的kml文件。



任何建议,最好的方法这样做。



您的意见和贡献是高度赞赏的

解决方案

我将把我的想法归纳为用户绘制的存储坐标,然后当点击输出KML按钮时,格式化保存的协调数据并将其放置在要复制的文本区域(除非有方法提示下载?)



以下是用户在完成绘图时保存数据的方法元素:



http://jsfiddle.net/8bwG2/



(我不知道检测编辑的好方法。)



首先,添加每个绘图类型(线,多边形,标记)的事件侦听器,在完成时触发。您需要为每种类型单独的事件侦听器。这是Polylines的一个,每个听众将返回刚刚完成的绘图元素的类型。

  google.maps.event。 addDomListener(drawingManager,'polylinecomplete',function(line){
path = line.getPath();
document.getElementById(action)value + =#polyline\\\
;
for(var i = 0; i document.getElementById(action)。value + = path.getAt(i)+\\\
;
}
});

我把坐标直接放在一个共享的textarea中,但是它们应该变成一个数组数组,一个变量用于多边形,一个用于折线,一个用于折线。



从这些内部变量读取时,将Google Maps LatLng转换为KML格式长,纬,高度。最后,当KML被请求时,循环遍历标记,行和多边形变量,以生成KML格式的元素,如点坐标,LineString和Polygon-outerBoundaryIs


I have a google map component in my application that allows the user to draw polygons, lines, and marker. Now I want to implement a button that allows the user to export a kml file of the stuff that he/she draw in the map.

Any suggestion for the best approach to do so.

Your comments and contribution is highly appreciated

解决方案

I'll summarize my idea as storing coordinates as the user draws, then when the "Output KML" button is clicked, format the saved coordinate data and place it in a textarea to be copied (unless there's a way to prompt as a download?).

Here's how I save data when the user completes a drawing element:

http://jsfiddle.net/8bwG2/

(I don't know a good way of detecting edits.)

First, add event listeners for each drawing type (line, polygon, marker), to fire when it is complete. You need a separate event listener for each type. Here's one for Polylines, and each listener will return the type of drawing element that was just completed.

    google.maps.event.addDomListener(drawingManager, 'polylinecomplete', function(line) {
        path = line.getPath();
        document.getElementById("action").value += "#polyline\n";
        for(var i = 0; i < path.length; i++) {
          document.getElementById("action").value += path.getAt(i) + "\n";
        }
    });

I am placing the coordinates straight into a shared textarea but they should instead go into an array of arrays variable, with one variable for polygons, one for polylines and one for markers.

When reading from these internal variables, convert the Google Maps LatLngs to KML format long,lat,altitude. You will have to get creative with each element's name and description.

Finally, when the KML is requested, loop through the markers, line, and polygon variable to generate KML formatted elements, such as Point-coordinates, LineString, and Polygon-outerBoundaryIs

这篇关于google maps api v3导出当前地图的kml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆