当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS PointDrawAction用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/views/draw/PointDrawAction"], (PointDrawAction) => { /* code goes here */ });

ESM: import PointDrawAction from "@arcgis/core/views/draw/PointDrawAction";

类: esri/views/draw/PointDrawAction

继承: PointDrawAction > DrawAction > Accessor

自从:用于 JavaScript 4.5 的 ArcGIS API

用法说明

此类使用视图事件生成一组坐标,以使用 Draw 创建新的 Point 几何图形。当调用 draw.create("point") 方法时,将返回对 PointDrawAction 的引用。侦听 PointDrawAction 的 cursor-update 和 draw-complete 事件来处理点几何体的创建。

例子:

function enableCreatePoint(draw, view) {
  let action = draw.create("point");

  // PointDrawAction.cursor-update
  // Give a visual feedback to users as they move the pointer over the view
  action.on("cursor-update", function (evt) {
    createPointGraphic(evt.coordinates);
  });

  // PointDrawAction.draw-complete
  // Create a point when user clicks on the view or presses "C" key.
  action.on("draw-complete", function (evt) {
    createPointGraphic(evt.coordinates);
  });
}

function createPointGraphic(coordinates){
  view.graphics.removeAll();
  let point = {
    type: "point", // autocasts as /Point
    x: coordinates[0],
    y: coordinates[1],
    spatialReference: view.spatialReference
  };

  let graphic = new Graphic({
    geometry: point,
    symbol: {
      type: "simple-marker", // autocasts as SimpleMarkerSymbol
      style: "square",
      color: "red",
      size: "16px",
      outline: { // autocasts as SimpleLineSymbol
        color: [255, 255, 0],
        width: 3
      }
    }
  });
  view.graphics.add(graphic);
}

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 PointDrawAction。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。