1

我们正在构建一个使用 esri 地图的 Web 应用程序。我想做的是计算两点之间的距离。这些点的坐标位于两个单独的 json 对象中。接下来,我通过解析这两个 json 对象的纬度和经度值来生成两个 esri 点。Esri 点需要空间参考,所以我将 mapView 的空间参考设置为两个点的空间参考。

问题:当我选择两个点时,它完全重写了其中一个点的纬度和经度。这导致了对这两点的荒谬计算。

这是我尝试过的

//calling the distance function

distance = this.distanceCalculator(incidentCenter, residence);

//distance calc function
  private distanceCalculator(firstPt, secondPt): any {
    //this.measureLayer.removeAll();

    // When calculating the distance betweeen two points , we need to decypher the points coming in and attach a spatial reference.
    const pointA: esri.Point = new this.Point({
      spatialReference: this.mapView$.value.spatialReference,
      latitude: firstPt.latitude,
      longitude: firstPt.longitude
    });

    //so whats happening here is that 
    const pointB: esri.Point = new this.Point({
      spatialReference: this.mapView$.value.spatialReference,
      latitude: secondPt.latitude,
      longitude: secondPt.longitude
    });


    console.log("Point a and B");
    console.log("point a: ", pointA);
    console.log("point b: ", pointB);

    // Next we call the GemoetryEngine distance function and calculate the distance between the two points.

    try {
      const miles = this.GeometryEngine.distance(pointA, pointB, 'kilometers');
      const kms = miles * this.MilesToKm;
      return kms.toFixed(2);
    } catch (e) {
      this.logger.error('Error indistanceCalculator ', e);
    }
  }

截图

选择两个点后,我注意到第二个点的纬度/经度值不正确。 在此处输入图像描述

这计算两点之间的距离为 在此处输入图像描述

实际距离应该如下(esri 小部件结果)

在此处输入图像描述

如果我要再次选择这两个点,它会生成正确的距离

在此处输入图像描述

4

1 回答 1

1

蛋蛋对我来说,我在导致这个错误的代码中设置了纬度和经度错误的一点。谢谢大家的帮助。

于 2019-02-19T17:20:10.563 回答