I am using openlayers 5 along with angular6.
I have created a simple form that user can give a X and Y of EPSG3857 coordinates, submit and a point will be rendered there and the map will zoom there. I am using a vector layer for that.
I want to check if the XY are valid EPSG3857 coordinates somehow.
I tried using a try/catch
block, but this works the second time I submit the form.
I put some crazy XY like 6.34 2401111118651.91
, I submit, the point is created and the map zooms in nowhere, in a white background. I have to submit the same form a second time, for the try/catch
to actually catch the error.
How can I fix that and check the coords right away? This is the code I wrote
coordsSubmitted(){
let point = [this.coordsForm.controls.coordsx.value, this.coordsForm.controls.coordsy.value];
try {
this.coordFeature.setGeometry(new Point(point));
this.coordsource.addFeatures([this.coordFeature]) ;
this.olmap.getView().animate({
center: point,
duration: 2500,
zoom:10
});
} catch (error) {
this.coordsFormErrorMsg = 'Error. Only EPSG 3857 coords.';
}
}
Thanks