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


JavaScript ArcGIS MultipointDrawAction用法及代碼示例


基本信息

以下是所在類或對象的基本信息。

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

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

類: esri/views/draw/MultipointDrawAction

繼承: MultipointDrawAction > DrawAction > Accessor

自從:用於 JavaScript 4.6 的 ArcGIS API

用法說明

此類使用視圖事件生成一組坐標,以使用 Draw 創建新的 Multipoint 幾何圖形。當調用 draw.create("multipoint") 方法時,將返回對 MultipointDrawAction 的引用。您可以偵聽 MultipointDrawAction 實例上的事件,這允許用戶創建滿足應用程序指定條件的多點。

已知限製

目前,MultipointDrawAction 僅在 MapView 中受支持。

例子:

function enableCreateMultipoint(draw, view) {
  let action = draw.create("multipoint");

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

  // Fires when the user clicks, or presses the "F" key on the view
  // Can also fire when the "R" key is pressed to redo.
  action.on("vertex-add", function (evt) {
    createMultipointGraphic(evt.vertices);
  });

  // Fires when the "Z" key is pressed to undo the last added point
  action.on("vertex-remove", function (evt) {
    createMultipointGraphic(evt.vertices);
  });

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

function createMultipointGraphic(vertices) {
  view.graphics.removeAll();

  let multipoint = new Multipoint({
    points: vertices,
    spatialReference: view.spatialReference
  });

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

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 MultipointDrawAction。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。