我正在使用 openlayers 5 和 angular6。
我创建了一个简单的表单,用户可以给出 EPSG3857 坐标的 X 和 Y,提交,一个点将在那里渲染,地图将在那里缩放。我为此使用了矢量图层。
我想以某种方式检查 XY 是否是有效的 EPSG3857 坐标。
我尝试使用try/catch
块,但这在我第二次提交表单时有效。
我放了一些疯狂的 XY 6.34 2401111118651.91
,我提交了,创建了点,地图在白色背景中无处放大。我必须第二次提交相同的表格,try/catch
才能真正捕捉到错误。
我怎样才能解决这个问题并立即检查坐标?这是我写的代码
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.';
}
}
谢谢