arcgis for javascript 4.7 区域框选并统计区域中的标注点信息

自定义多边形需要用到的js类库

require(["esri/widgets/Sketch/SketchViewModel" ], function (SketchViewModel) 

构造多边形:

var pointSymbol = { // symbol used for points
                    type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
                    style: "square",
                    color: "#8A2BE2",
                    size: "16px",
                    outline: { // autocasts as new SimpleLineSymbol()
                        color: [255, 255, 255],
                        width: 3 // points
                    }
                }
                var polylineSymbol = { // symbol used for polylines
                    type: "simple-line", // autocasts as new SimpleLineSymbol()
                    color: "#8A2BE2",
                    width: "4",
                    style: "dash"
                }

                var polygonSymbol = { // symbol used for polygons
                    type: "simple-fill", // autocasts as new SimpleFillSymbol()
                    color: "rgba(138,43,226, 0.8)",
                    style: "solid",
                    outline: {
                        color: "white",
                        width: 1
                    }
                }

view.when(function () {
                    // create a new sketch view model
                      var tempGraphicsLayer = new GraphicsLayer();
                    var sketchViewModel = new SketchViewModel({
                        view: view,
                        layer: tempGraphicsLayer,
                        pointSymbol: pointSymbol,
                        polylineSymbol: polylineSymbol,
                        polygonSymbol: polygonSymbol
                    });
                    setUpClickHandler();
                    sketchViewModel.on("draw-complete", addGraphic);
                    sketchViewModel.on("update-complete", addGraphic);
                    sketchViewModel.on("update-cancel", addGraphic);
                    function addGraphic(evt) {
                        var geometry = evt.geometry;
                        var symbol;
                        // Choose a valid symbol based on return geometry
                        switch (geometry.type) {
                            case "point":
                                symbol = pointSymbol;
                                break;
                            case "polyline":
                                symbol = polylineSymbol;
                                break;
                            default:
                                symbol = polygonSymbol;
                                break;
                        }
                        // Create a new graphic; add it to the GraphicsLayer
                        var polygonGraphic = new Graphic({
                            geometry: geometry,
                            symbol: symbol
                        });
                        tempGraphicsLayer.add(polygonGraphic);
                        // Remove stored reference to the updated graphic
                        // Required in 'update-complete' callback specifically
                        updateGraphic = null;
                    }
                    function setUpClickHandler() {
                        view.on("click", function (evt) {
                            view.hitTest(evt).then(function (response) {
                                var results = response.results;
                                    // Found a valid graphic
                                var polygon = polygonGraphic.geometry; //polygon
                                    if (Layer.visible) {
                                        for (var i = 0; i < Layer.graphics.items.length; i++) {    //遍历你在图层里添加的标记集合
                                            var point = Layer.graphics.items[i].geometry;    
                                            if (polygon.contains(point)) {
                                                //点在面中
                                            }
                                        }
                                    }
                                    if (results.length && results[results.length - 1].graphic) {
                                        // Check if we're already editing a graphic
                                        if (!updateGraphic) {
                                            // Save a reference to the graphic we intend to update
                                            updateGraphic = results[results.length - 1].graphic;
                                            // Remove the graphic from the GraphicsLayer
                                            // Sketch will handle displaying the graphic while being updated
                                            tempGraphicsLayer.remove(updateGraphic);
                                            sketchViewModel.update(updateGraphic.geometry);
                                        }
                                    }

                                }
                            });
                        });
                    }

触发事件

sketchViewModel.create("polygon");
清除
sketchViewModel.reset();
tempGraphicsLayer.removeAll();



  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值