OpenLayer export kml

BergJava

Aktives Mitglied
Hallo zusammen,
ich arbeite mit OpenLayer um Linien und Polygone, Placemarks einfacher einzufügen in die OSM Karte.
Gibt es eine Lösung von Openlayer wie ich diese exportieren kann als kml.file entweder direkt auf den Server oder zum speichern (Blob) direkt auf den Client

Habe hier mir mal was zusammengestellt (aus dem Internet) was als Beispiel dient, aber leider so nicht funktioniert:
Java:
  var projection = ol.proj.get('EPSG:3857');
    var format = new ol.format.KML({
        'maxDepth': 10,
        'extractStyles': true,
        'internalProjection': projection,
        'externalProjection': projection
    });
var newfeatures = [];
var vectorSource = vector.getSource();
vectorSource.forEachFeature(function(feature) {
        var clone = feature.clone();
        clone.setId(feature.getId());  // clone does not set the id
        clone.getGeometry().transform(projection, 'EPSG:3857');
        newfeatures.push(clone);
});
//console.log(newfeatures);
var string = new ol.format.KML().writeFeatures(newfeatures[0]);
//console.log(string);
   
      var jSon = JSON.stringify(string);
$.ajax( { type : 'POST',
          data : {data: jSon },
          url  : 'test.php',             
          success: function ( data ) {
            alert( data );              
          },
          error: function ( xhr ) {
            alert( "error" );
          }
        });
 

Zurück
Oben