Der Blitz GMap Editor ermöglicht es Ihnen, KML zu exportieren (verwendet den Zeichen-Manager, um sie zu erstellen und zu bearbeiten, aber Sie könnten auch Ihren eigenen Code verwenden).
Beispiel
Zum KML-Code aus dem Blitz GMap Editor. Abhängig von xmlwriter.js
this.toKML = function() {
var result = mapToObject();
var xw = new XMLWriter('UTF-8');
xw.formatting = 'indented'; // Einrückung und Zeilenumbrüche hinzufügen
xw.indentChar = ' '; // Einrückung mit Leerzeichen
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") {
// Es ist ein 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") {
// Es ist ein Polygon, ein Kreis wird durch ein kreisförmiges 64-Eck approximiert
xw.writeStartElement('outerBoundaryIs');
xw.writeStartElement('LinearRing');
xw.writeStartElement("coordinates");
var d2r = Math.PI / 180; // Grad zu Bogenmaß
var r2d = 180 / Math.PI; // Bogenmaß zu 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
} // ein zusätzliches hier stellt sicher, 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)); // Zentrum a + Radius x * cos(theta)
ex = result.overlays[i].center.lat + (rlat * Math.sin(theta)); // Zentrum 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(); // ENDE PlaceMarker
}
xw.writeEndElement();
xw.writeEndElement();
xw.writeEndDocument();
var xml = xw.flush(); // generiere den XML-String
xw.close(); // Bereinige den Writer
xw = undefined; // Lassen Sie die Besucher nicht darauf zugreifen, er ist geschlossen
// setze das XML
document.getElementById('kmlString').value = xml;
}