Openlayers write and save a KML based on your map

前端 未结 3 1650
时光说笑
时光说笑 2021-02-04 17:43

Is it possible to write and save a KML from OpenLayers? Anyone know of an example of exporting one?

3条回答
  •  盖世英雄少女心
    2021-02-04 18:04

    IF you are using Openlayers 3 or 4, you will find that the syntax of previous (2012) answers does not work anymore.

    This does:

            function GetKMLFromFeatures(features) {
                var format = new ol.format.KML();
                var kml = format.writeFeatures(features, {featureProjection: 'EPSG:3857'});
                return kml;
            }
            function GetGeoJSONFromFeatures(features) {
                var format = new ol.format.GeoJSON();
                var geoJSON = format.writeFeatures(features, {featureProjection: 'EPSG:3857'});
                return geoJSON;
            }
            function GetFeaturesFromLayer(layer) {
                var source = layer.getSource();
                var features = source.getFeatures();
                return features;
            }
    

提交回复
热议问题