簡體   English   中英

保存交互繪制開放圖層

[英]Save interaction draw openlayers

有人可以提示我如何保存在openlayers 3中繪制的交互圖嗎? 我可以使用json嗎? 有人可以提供一個簡單的例子嗎?

謝謝!

var features = yourLayer.getSource().getFeatures();
var newForm = new ol.format.GeoJSON();
var featColl = newForm.writeFeaturesObject(features);

然后,將其保存到JSON:

function exportJson(featuresCollection) {
    var txtArray = [];
    txtArray.push(JSON.stringify(featuresCollection));

// Here I use the saveAs library to export the JSON as *.txt file

    var blob = new Blob(txtArray, {type: 'text/json;charset=utf8'});
    saveAs(blob, layerName + ".txt")
};

exportJson(featColl);

加載JSON:

var vectorLayer = new ol.layer.Vector({
  source: new ol.source.GeoJSON({
    projection: 'EPSG:3857',
    url: 'yourFile.json'
  })
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM