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


JavaScript ArcGIS Sketch update事件用法及代码示例


基本信息

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

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

ESM: import Sketch from "@arcgis/core/widgets/Sketch";

类: esri/widgets/Sketch

继承: Sketch > Widget > Accessor

自从:用于 JavaScript 4.10 的 ArcGIS API

用法说明

Sketch update事件的定义如下:

update


当用户开始更新图形、正在主动更新图形并完成更新图形时触发。

属性:

类型说明
graphics Graphic[]

正在更新的图形数组。

state String

事件的状态。

可能的值

说明
start 选择要更新图形时,状态更改为start
active 状态为 active 而图形正在更新且 toolEventInfo 参数不是 null
complete 图形更新后状态更改为complete

可能的值"start"|"active"|"complete"

aborted Boolean

指示更新操作是否已中止。如果用户按下退出键,或者在 update 事件的 state 更改为 complete 之前调用 update()、create() 或 cancel() 方法,则设置为 true

tool String

更新操作工具的名称。

可能的值"move"|"transform"|"reshape"

type String

事件的类型。

值永远是"update".

toolEventInfo UpdateToolEventInfo

返回与所选图形正在进行的更新操作及其所处阶段相关的附加信息。当 update 事件的 state 更改为 complete 时,此参数的值将更改为 null

例子:

// Listen to sketch's update event to show relevant data in a chart
// as the graphics are being moved
sketch.on("update", onMove);

// Point graphics at the center and edge of the buffer polygon are being moved.
// Recalculate the buffer with updated geometry and run the query stats using
// the updated buffer and update the chart.
function onMove(event) {
  // If the edge graphic is moving, keep the center graphic
  // at its initial location. Only move edge graphic to resize the buffer.
  if (event.toolEventInfo && event.toolEventInfo.mover.attributes.edge) {
    const toolType = event.toolEventInfo.type;
    if (toolType === "move-start") {
      centerGeometryAtStart = centerGraphic.geometry;
    }
    // keep the center graphic at its initial location when edge point is moving
    else if (toolType === "move" || toolType === "move-stop") {
      centerGraphic.geometry = centerGeometryAtStart;
    }
  }

  // the center or edge graphic is being moved, recalculate the buffer
  const vertices = [
    [centerGraphic.geometry.x, centerGraphic.geometry.y],
    [edgeGraphic.geometry.x, edgeGraphic.geometry.y]
  ];

  // client-side stats query of features that intersect the buffer
  calculateBuffer(vertices);

  // user is clicking on the view... call update method with the center and edge graphics
  if (event.state === "complete") {
    sketch.update({
      tool: "move",
      graphics: [edgeGraphic, centerGraphic]
    });
  }
}

相关用法


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