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


JavaScript ArcGIS PolylineDrawAction用法及代码示例


基本信息

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

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

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

类: esri/views/draw/PolylineDrawAction

继承: PolylineDrawAction > DrawAction > Accessor

自从:用于 JavaScript 4.5 的 ArcGIS API

用法说明

此类使用不同的事件生成一组顶点,以使用 Draw 创建新的 Polyline 几何图形。当调用draw.create("polyline")时,将返回对该类的引用。您可以侦听 PolylineDrawAction 实例上的事件,该实例允许用户创建满足开发人员指定条件的折线。

例子:

function enableCreatePolyline(draw, view) {
  let action = draw.create("polyline");

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

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

  // listen to PolylineDrawAction.cursor-update
  // fires when the pointer moves over the view
  action.on("cursor-update", function (evt) {
    createPolylineGraphic(evt.vertices);
  });

  // listen to PolylineDrawAction.draw-complete
  // event to create a graphic when user double-clicks
  // on the view or presses the "C" key
  action.on("draw-complete", function (evt) {
    createPolylineGraphic(evt.vertices);
  });
}

function createPolylineGraphic(vertices){
  view.graphics.removeAll();
  let polyline = {
    type: "polyline", // autocasts as Polyline
    paths: vertices,
    spatialReference: view.spatialReference
  };

  let graphic = new Graphic({
    geometry: polyline,
    symbol: {
      type: "simple-line", // autocasts as SimpleLineSymbol
      color: [4, 90, 141],
      width: 3,
      cap: "round",
      join: "round"
    }
 });
 view.graphic.add(graphic);
}

相关用法


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