Der Blitz GMap Editor ermöglicht es Ihnen, KML zu exportieren (verwendet den Zeichenmanager, um sie zu erstellen und zu bearbeiten, aber Sie könnten Ihren eigenen Code verwenden).
Beispiel
Zu KML-Code von Blitz GMap Editor. Abhängig von xmlwriter.js
this.toKML = function() {
var result = mapToObject();
var xw = new XMLWriter('UTF-8');
xw.formatting = 'indented'; // Einrückungen und Zeilenumbrüche hinzufügen
xw.indentChar = ' '; // Mit Leerzeichen einrücken
xw.indentation = 2; // 2 Leerzeichen pro Ebene hinzufügen
xw.writeStartDocument();
xw.writeStartElement('kml');
xw.writeAttributeString("xmlns", "http://www.opengis.net/kml/2.2");
xw.writeStartElement('Document');
for (var i = 0; i < result.overlays.length; i++) {
xw.writeStartElement('Placemark');
xw.writeStartElement('name');
xw.writeCDATA(result.overlays[i].title);
xw.writeEndElement();
xw.writeStartElement('description');
xw.writeCDATA(result.overlays[i].content);
xw.writeEndElement();
if (result.overlays[i].type == "marker") {
xw.writeStartElement('Point');
xw.writeElementString('extrude', '1');
xw.writeElementString('altitudeMode', 'relativeToGround');
xw.writeElementString('coordinates', result.overlays[i].position.lng.toString() + "," + result.overlays[i].position.lat.toString() + ",0");
xw.writeEndElement();
} else if (result.overlays[i].type == "polygon" || result.overlays[i].type == "rectangle" || result.overlays[i].type == "circle") {
xw.writeStartElement('Polygon');
xw.writeElementString('extrude', '1');
xw.writeElementString('altitudeMode', 'relativeToGround');
if (result.overlays[i].type == "rectangle") {
// its a polygon
xw.writeStartElement('outerBoundaryIs');
xw.writeStartElement('LinearRing');
xw.writeStartElement("coordinates");
xw.writeString(result.overlays[i].bounds.sw.lng + "," + result.overlays[i].bounds.sw.lat + ",0");
xw.writeString(result.overlays[i].bounds.ne.lng + "," + result.overlays[i].bounds.sw.lat + ",0");
xw.writeString(result.overlays[i].bounds.ne.lng + "," + result.overlays[i].bounds.ne.lat + ",0");
xw.writeString(result.overlays[i].bounds.sw.lng + "," + result.overlays[i].bounds.ne.lat + ",0");
xw.writeEndElement();
xw.writeEndElement();
xw.writeEndElement();
}
if (result.overlays[i].type == "circle") {
// its a polygon, approximate a circle by a circular 64 sided polygon.
xw.writeStartElement('outerBoundaryIs');
xw.writeStartElement('LinearRing');
xw.writeStartElement("coordinates");
var d2r = Math.PI / 180; // Grad in Radianten
var r2d = 180 / Math.PI; // Radianten in Grad
var earthsradius = 6378137; // 6378137 ist der Radius der Erde in Metern
var dir = 1; // im Uhrzeigersinn
var points = 64;
// Radius in Breite/Länge finden
var rlat = (result.overlays[i].radius / earthsradius) * r2d;
var rlng = rlat / Math.cos(result.overlays[i].center.lat * d2r);
var extp = new Array();
if (dir == 1) {
var start = 0;
var end = points + 1
} // hier wird ein Extra hinzugefügt, um sicherzustellen, dass wir die Linie verbinden
else {
var start = points + 1;
var end = 0
}
for (var j = start;
(dir == 1 ? j < end : j > end); j = j + dir) {
var theta = Math.PI * (j / (points / 2));
ey = result.overlays[i].center.lng + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
ex = result.overlays[i].center.lat + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
xw.writeString(ey + "," + ex + ",0");
}
xw.writeEndElement();
xw.writeEndElement();
xw.writeEndElement();
} else {
for (var j = 0; j < result.overlays[i].paths.length; j++) {
if (j == 0) {
xw.writeStartElement('outerBoundaryIs');
} else {
xw.writeStartElement('innerBoundaryIs');
}
xw.writeStartElement('LinearRing');
xw.writeStartElement("coordinates");
for (var k = 0; k < result.overlays[i].paths[j].length; k++) {
xw.writeString(result.overlays[i].paths[j][k].lng + "," + result.overlays[i].paths[j][k].lat + ",0");
}
xw.writeEndElement();
xw.writeEndElement();
xw.writeEndElement();
}
}
xw.writeEndElement();
} else if (result.overlays[i].type == "polyline") {
xw.writeStartElement('LineString');
xw.writeElementString('extrude', '1');
xw.writeElementString('altitudeMode', 'relativeToGround');
xw.writeStartElement("coordinates");
for (var j = 0; j < result.overlays[i].path.length; j++) {
xw.writeString(result.overlays[i].path[j].lng + "," + result.overlays[i].path[j].lat + ",0");
}
xw.writeEndElement();
xw.writeEndElement();
}
xw.writeEndElement(); // END PlaceMarker
}
xw.writeEndElement();
xw.writeEndElement();
xw.writeEndDocument();
var xml = xw.flush(); // XML-String generieren
xw.close(); // Writer bereinigen
xw = undefined; // Verhindern, dass Besucher ihn nutzen, er ist geschlossen
// XML setzen
document.getElementById('kmlString').value = xml;
}