ArcGIS的API:绘制圆定影中心

问题描述 投票:2回答:1

我使用ArcGIS API V4.8和绘图工具绘制在我的地图圈。

1个问题,我注意到当我画一个圆,圆运动中心当我移动我的鼠标调整圆,而不是固定在第一个鼠标点击启动点:

enter image description here

我怎么不管修复中心我怎么动圆的半径?缺什么在我的代码?

  const options = {view, layer: tempGraphicsLayer, pointSymbol, polylineSymbol, polygonSymbol}
  let sketchViewModel = new SketchViewModel(options)

  let drawCircleButton = document.getElementById('circleButton')
  drawCircleButton.onclick = function () {
    clear()
    isDrawLine = false
    sketchViewModel.create('polygon', {mode: 'click'})
    sketchViewModel.create('circle')
  }

编辑:

我发现了一个类似的sample,选择绘制圆工具,开始在地图上绘制一个圆,你会发现,当您移动鼠标的移动圈的中心,我希望它修复中心取代。

当中心用鼠标移动一起移动的问题是,绘制的圆是不准确的,因为我要开始我想要的圆心,圆可以向外扩展,但该中心不应该移动。

arcgis-js-api
1个回答
2
投票

这是因为圆,在给定的例子中,是正方形对象内被拉伸。基本上您的起始点和结束点所代表的角落,而不是中心点与所述圆的外层。所以每次扩大圈子对象时,它从一个角扩大,而其余部分沿着鼠标拖动。

visual example

有这门课程的解决方法。我做的可能的方式吸引用户从固定中心点的圆圈一个小样本代码。

https://jsfiddle.net/wLd46g8k/9/

基本上我用所谓的圈子,在这里你传递一个起点,半径在ArcGIS JS API 4.x的构造。在我的例子,我计算出这两个点的半径。

function drawCircle(){//draws the circle
        graphicsLayer.graphics.removeAll();
        var graphic = new Graphic({
            geometry: new Circle({//circle constructor
            center: startPoint,//pass the pointer-down event X Y as a starting point
            radius: Math.floor(Math.sqrt(Math.pow(startPoint.x - endPoint.x, 2) + Math.pow(startPoint.y - endPoint.y, 2)))
          }), //calculates endpoint distance from the startpoint and pass it as a radius
          symbol: {//circle design
            type: "simple-fill",
            color: "orange",
            style: "solid",
            outline:{
                color:"darkorange",
              width:4
            }
          }
        });

        graphicsLayer.graphics.add(graphic);//adds the circle
      };
© www.soinside.com 2019 - 2024. All rights reserved.