Good day,
I have final changes of feature on draw.on("drawend") also on drawend i try to export feature
var feature = event.feature;
var cache = [];
jsonFeature = JSON.stringify(
feature,
function(key, value) {
if (typeof value === "object" && value !== null) {
if (cache.indexOf(value) !== -1) {
return;
}
cache.push(value);
}
return value;
}
);
cache = null;
and trying to pass it to RPC layer to save to database, but after converting it back to Object i get errors
var clone = JSON.parse(jsonFeature);
vectorSource.addFeature(clone);
Uncaught TypeError: feature.getId is not a function
How can i correctly pass feature or split feature into array to save it into DB via PHP and then return it back from DB to ol.source.Vector with all styles, images, canvas, coordinates, etc.?
Every feature contains it's own styling, some of them, like marker, have image and some, like arrowLine, have canvas of arrows head at LineString event.feature.getGeometry().getLastCoordinate();
** Edit **
Found solution by using ol.format.KML
var kml = new ol.format.KML();
var jsonFeature = kml.writeFeatures([feature]);
but still is some problems:
- can't save circle - Uncaught TypeError: Cannot read property 'call' of undefined
- polygon that concatenates to last coordinate (arrow head) doesn't exists in xml, i guess i need somehow merge LineString with Polygon
- i draw element in canvas and placing it on LineString, after convertation to ol.format.KML i receive bad XML where canvas is converted into
<href>100</href>
and after reading this part i receive error about URL