gpt4 book ai didi

javascript - 写入 kml 文件 : How send kml string to kml file?

转载 作者:行者123 更新时间:2023-11-29 22:07:52 29 4
gpt4 key购买 nike

我有一个在 map 上绘制并生成 kml 字符串的项目。我想通过 ajax 请求将其发送到 kml 文件。

$.ajax({
type: 'PUT',
url: 'myurl.kml',
data: kmlString,
success() {
//say it succeeded
}
});

因为我的 kml 数据嵌套在引号内,就像这样,

'<xml.....</kml>'

kml 文件提示由于引号导致语法不正确(这是真的)。​​

我想过将数据作为 json 对象而不是字符串传递,就像这样,

{'mapData': 'mykmldata'}

但数据仍然用引号括起来。

将我的数据导入不带引号的 kml 文件的最佳方法是什么? Google map API v3 似乎在任何地方都没有“字符串到 kml”功能,尽管我觉得在这种情况下这将是 Elixir 。

我注意到 Google Earth API 有一个 parseKml 函数,它与谷歌地图兼容吗?

最佳答案

第三方 KML 解析器 geoxml3有一个“parseKmlString”方法,该方法将从字符串中获取有效的 KML 并解析它以创建 native Google Maps Javascript API v3 对象。

例子:从此文件中获取 KML: http://www.geocodezip.com/geoxml3_test/kml/MA_cities.kml

片段:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Massachusetts Cities</name>
<Folder>
<Placemark>
<name>Boston</name>
<description>Boston is the capital of and largest city in Massachusetts. The Boston Massacre and the Boston Tea Party occurred in Boston and led to the American Revolution.</description>
<LookAt>
<longitude>-71.05977300312775</longitude>
<latitude>42.35843100531216</latitude>
<altitude>0</altitude>
<heading>-2.107386233340164e-009</heading>
<tilt>0</tilt>
<range>34426.00143998101</range>
<altitudeMode>relativeToGround</altitudeMode>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin9</styleUrl>
<Point>
<altitudeMode>absolute</altitudeMode>
<coordinates>-71.05977300312775,42.35843100531217,3.1482280535562</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Worcester</name>
<description>Worcester is known as the &quot;Heart of the Commonwealth&quot; due to its location in central Massachusetts, thus, a heart is the official symbol of the city.</description>
<LookAt>
<longitude>-71.80229299737233</longitude>
<latitude>42.2625930065606</latitude>
<altitude>0</altitude>
<heading>1.76716070878667e-009</heading>
<tilt>0</tilt>
<range>17233.50055269895</range>
<altitudeMode>relativeToGround</altitudeMode>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#msn_ylw-pushpin0</styleUrl>
<Point>
<altitudeMode>absolute</altitudeMode>
<coordinates>-71.80229299737233,42.26259300656061,145.2545892926215</coordinates>
</Point>
</Placemark>
</Folder>
</Document>
</kml>

将其粘贴到本页的 KML 文本框中:

http://www.geocodezip.com/blitz-gmap-editor/test5.html

它显示来自 KML 的标记。

关于javascript - 写入 kml 文件 : How send kml string to kml file?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19913837/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com