Reputation: 994
i try to store features of a OpenLayers Map Layer to a database and therefore I try to write the features objects into a GeoJSON object. But I get an Unsupported GeoJSON type: undefined
error when I try to read the object. Here what i tried:
const testFeature = new Feature({
geometry: new Point([0, 0]),
name: 'Test Point '
});
const geoJsonObject = new GeoJSON();
geoJsonObject.writeFeaturesObject(testFeature);
console.log(geoJsonObject);
const importObject = new GeoJSON().readFeatures(geoJsonObject);
console.log(importObject);
The first log of the "geoJsonObject":
{
"dataProjection": {
"code_": "EPSG:4326",
"units_": "degrees",
"extent_": [
-180,
-90,
180,
90
],
"worldExtent_": [
-180,
-90,
180,
90
],
"axisOrientation_": "neu",
"global_": true,
"canWrapX_": true,
"defaultTileGrid_": null,
"metersPerUnit_": 111319.49079327358
},
"defaultFeatureProjection": null
}
Here the error from the log of the importObject:
Unsupported GeoJSON type: undefined
OpenLayers Version: 6.2.1 Docs: https://openlayers.org/en/latest/apidoc/module-ol_format_GeoJSON-GeoJSON.html#writeFeature
Thanks!
Upvotes: 0
Views: 2082
Reputation: 17952
As well as needing an array of features with writeFeaturesObject your use of geoJsonObject was wrong
const geoJsonObject = new GeoJSON().writeFeaturesObject([testFeature]);
console.log(geoJsonObject);
const importObject = new GeoJSON().readFeatures(geoJsonObject);
console.log(importObject);
Upvotes: 2