-1

我正在使用 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.';
    }       
  }

谢谢

4

1 回答 1

1

您可以检查您的输入是否在投影范围内。此投影的可接受值为:

最小 X:-20026376.39
最小 Y:-20048966.10
最大 X:20026376.39
最大 Y:20048966.10

您可以将这些限制限制在您正在映射的区域。

于 2018-08-20T13:00:16.403 回答