When I add a MultiPolygon geometry which has been draw by an user on my map, the geometry not displaying at the place where i draw it. It display at a different place.
I send the geometry to my api which his goal is to add the geometry in my postgre Databse. So in my API :
var geom = req.body.geom
var geom2 = "ST_GeomFromText('" + geom + "',2154)"
pool.query( 'INSERT INTO potentiel_foncier_ccry (nature, geom, nbr_lgmt) VALUES ('+ mysql.escape(nature)+','+geom2+','+mysql.escape(logement)+')'
In my function which display my data :
foncier2.getSource().addFeatures(foncier2.getSource().getFormat().readFeatures(
myGeoJSON, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}));
foncier2.getSource().refresh();
foncier2.getSource().changed();
map.getView().fit(foncier2.getSource().getExtent());
}
The problem comes from the Projection ? In my Database I am force to store my geometry in EPSG:2154.
Example I draw here :
After add the geometry in the database when i want to display it, It display on the sea :
Ps : I work with OpenLayer 5.3.0.