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