function writeFeatureToGeoJSON(feature, sourceCode, targetCode) {
try {
var view = map.getView();
if (!feature) {
return null;
}
var format = new ol.format.GeoJSON();
var geoJson = format.writeFeatureObject(feature, {
featureProjection: targetCode || view.getProjection(),
dataProjection: sourceCode || view.getProjection(),
});
return geoJson;
} catch (e) {
return null;
}
}