I have a script who export measurement on potree from an users to a geojsonformat. After, I'm trying to Post those geojson data from "Potree" to my database (postgresql). First, i am using an ajax query "Post" to my php page. But it keep's sending me this error.
function export_to_postgis(){
var measurement=viewer.scene.measurements[0];
var geojsonString = Potree.GeoJSONExporter.toString(measurement);
alert(geojsonString);
//var geojson = JSON.parse(geojsonString); // I already try to parse it but it gives me the same result
$.ajax({
url: 'export_to_postgis.php',
data: 'geojsonString',
dataType: 'json',
async: false,
type: "post",
success: function (geojsonString, status, xhr) {
alert('Data Send');
alert(geojsonString + " " + status + " " + xhr); // n'affiche rien
},
error: function (req, status, error) {
alert(req + " " + status + " " + error);
}
});
My geojson data :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
494306.5990009308,
5419823.199999809,
297.87900018692017
]
},
"properties": {
"name": "Point"
}
}
]
}
This work but it's not what i need
function export_to_postgis(){
var measurement=viewer.scene.measurements[0];
var geojsonString = Potree.GeoJSONExporter.toString(measurement);
alert(geojsonString);
//alert(typeof geojsonString); // String
var geojson = JSON.parse(geojsonString); // String to object
var x = geojson.features[0].geometry.coordinates[0]; // Coordonnées en X
var y = geojson.features[0].geometry.coordinates[1]; // Coordonnées en Y
var z = geojson.features[0].geometry.coordinates[2]; // Coordonnées en Z
var name = geojson.features[0].properties["name"]; // Point
$.ajax({
type: "POST",
url: 'export_to_postgis.php',
//dataType: "text", // json ==> ne fonctionne pas
//data: geojson,//JSON.stringify(geojson),
//data: {'geojson' : $('#geojson').val() },
data: {"name": name, "x": x, "y": y, "z": z},
success: function (data, status, xhr) {
alert('Data Send');
},
error: function (req, status, error) {
alert(req + " " + status + " " + error);
}
});