有人可以给我一个提示,如何保存我在openlayers 3中绘制的交互图纸?我可以用json吗?任何人都能提供一个简单的例子吗?
谢谢!
答案 0 :(得分:0)
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'
})
});