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


JavaScript ArcGIS PolygonDrawAction用法及代碼示例


基本信息

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

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

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

類: esri/views/draw/PolygonDrawAction

繼承: PolygonDrawAction > DrawAction > Accessor

自從:用於 JavaScript 4.5 的 ArcGIS API

用法說明

此類使用不同的事件生成一組頂點,以使用 Draw 創建新的 Polygon 幾何圖形。當調用draw.create("polygon")時,返回對PolygonDrawAction的引用。您可以偵聽 PolylineDrawAction 實例上的事件,該實例允許用戶創建滿足開發人員指定條件的折線。

例子:

function enableCreatePolygon(draw, view) {
  let action = draw.create("polygon");

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

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

  // Fires when the pointer moves over the view
  action.on("cursor-update", function (evt) {
    createPolygonGraphic(evt.vertices);
  });

  // Add a graphic representing the completed polygon
  // when user double-clicks on the view or presses the "C" key
  action.on("draw-complete", function (evt) {
    createPolygonGraphic(evt.vertices);
  });
}

function createPolygonGraphic(vertices){
  view.graphics.removeAll();
  let polygon = {
    type: "polygon", // autocasts as Polygon
    rings: vertices,
    spatialReference: view.spatialReference
  };

  let graphic = new Graphic({
    geometry: polygon,
    symbol: {
      type: "simple-fill", // autocasts as SimpleFillSymbol
      color: "purple",
      style: "solid",
      outline: {  // autocasts as SimpleLineSymbol
        color: "white",
        width: 1
      }
    }
  });
  view.graphics.add(graphic);
}

相關用法


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