當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。