ArcGIS API for JavaScript4.18之手动绘制多边形

一、创建Draw实例

const draw = new Draw({
  view: 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);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值