我正在使用kml
文件來顯示具有自定義邊界線的地圖。該kml文件是從某個網站下載的。在該文件中,在placemark
標記內沒有用於顯示圖標的標記point
。例如:如何動態更新kml文件/圖層?
<Placemark>
<name>Spot 2</name>
<description>.....</description>
<styleUrl>....</styleUrl>
<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>
.........
</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
</Placemark>
這就是placemark
標籤包含在我的kml文件中。我需要,
1)如何爲所有placemark
標記添加point
標記。有什麼辦法可以動態添加嗎?我的kml文件有5000個以上的地標。 2)點標記座標將指向多邊形的中心。
即)我需要以下
<Placemark>
<name>Spot 2</name>
<description>.....</description>
<styleUrl>....</styleUrl>
<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>
.........
</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
<Point>
<coordinates>144.253,-36.6632,0</coordinates>
</Point>
</Placemark>
注:
我使用geoxml3分析器可以顯示在谷歌地圖KML層。
這是我的html文件,
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>KML Layers</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/trunk/ProjectedOverlay.js"></script>
<script>
function initialize() {
var usa = new google.maps.LatLng(41.875696,-87.624207);
var mapOptions = {
zoom: 4,
center: usa,
mapTypeId: google.maps.MapTypeId.HYBRID
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var myParser = new geoXML3.parser({
map: map
});
var kml = myParser.parse('http://localhost/test/DFWNorth.kml');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
這是我的樣本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">
<Document>
<name>Real Estate Portal USA Parcels</name>
<open>1</open>
<Style id="parcel">
<LineStyle>
<color>ff48a7ff</color>
<width>1</width>
</LineStyle>
<PolyStyle>
<outline>1</outline>
<color>00ffffff</color>
</PolyStyle>
</Style>
<Style id="hl_parcel">
<IconStyle>
<scale>0.3</scale>
<Icon>
<href>http://bus.w.pw/R.png</href>
</Icon>
</IconStyle>
<LabelStyle>
<color>9900ffff</color>
<scale>1</scale>
</LabelStyle>
<LineStyle>
<color>ff00ffff</color>
<width>1.5</width>
</LineStyle>
<PolyStyle>
<outline>1</outline>
<color>5f000000</color>
</PolyStyle>
</Style>
<Folder>
<open>1</open>
<name>Selected Parcels</name>
<Placemark>
<name><![CDATA[1100 N 27TH Ave]]></name>
<description>
............
</description>
<styleUrl>#hl_parcel</styleUrl>
<MultiGeometry>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>-97.032117983752471,32.928768626517076 -97.024643584146915,32.923035186813181 -97.024619516424863,32.923056622674181 -97.023311876445746,32.922172553473487 -97.023027365973348,32.921986354508512 -97.022978167636879,32.921954156605246 -97.022101518923066,32.921458657105333 -97.021852382220004,32.921328433111441 -97.021603007761968,32.921212207649802 -97.021353262564418,32.921103685381986 -97.020040739077089,32.92059307329437 -97.019977072943703,32.920561642411542 -97.019978949582082,32.920357989560173 -97.019981935486342,32.920034178750491 -97.032338461906804,32.92018039810069 -97.03217983292177,32.928807043604458 -97.032117983752471,32.928768626517076</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</MultiGeometry>
</Placemark>
.........
...........
您是否需要KML中多邊形中心的座標?由於您使用的是geoxml3,因此您可以計算多邊形邊界的中心並動態地在其中放置標記。 – geocodezip
如何使用geoxml3計算多邊形的中心?請向我展示一些參考資料 –
請發佈您正在嘗試修改的代碼的[最小,完整,測試和可讀示例](http://stackoverflow.com/help/mcve)。 – geocodezip