function writeFeatureToWKT(feature, sourceCode, targetCode) {
try {
var view = map.getView();
if (!feature) {
return null;
}
var format = new ol.format.WKT();
var wkt = format.writeFeature(feature, {
featureProjection: targetCode || view.getProjection(),
dataProjection: sourceCode || view.getProjection(),
});
return wkt;
} catch (e) {
return null;
}
}