许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  ArcGIS API for JS 4.x点、线、面、圆、矩形的绘制教程

ArcGIS API for JS 4.x点、线、面、圆、矩形的绘制教程

阅读数 23
点赞 0
article_banner

用的"esri/views/draw/Draw"

var draw=new Draw({view:view});
var graphicsLayer=new GraphicsLayer();
map.add(graphicsLayer);

画点

        function drawPoint(view,graphicsLayer,draw){
        require([
            "esri/Graphic",
        ], function(
            Graphic,
        ){
            graphicsLayer.removeAll();
            var action = draw.create("point");
            action.on("draw-complete",draw1);
            function draw1(event) {
                var point = {
                    type: "point",
                    x: event.coordinates[0],
                    y: event.coordinates[1],
                    spatialReference: view.spatialReference
                };
                var markerSymbol={
                    type:"simple-marker",
                    color:[255,0,0],
                    outline:{
                        color:[255,255,255],
                        width:2
                    }
                };
                var inputPoint = new Graphic({
                    geometry: point,
                    symbol: markerSymbol
                });
                graphicsLayer.add(inputPoint);
            }
        })
    }

画线

            graphicsLayer.removeAll();
            var action = draw.create("polyline",{mode: "click"});

            action.on(["vertex-add","cursor-update","draw-complete"],draw1);

            function draw1(event) {
                graphicsLayer.removeAll();
                    var line={
                        type: "polyline",
                        paths: event.vertices,
                        spatialReference: view.spatialReference
                    };
                    var lineSymbol={
                        type:"simple-line",
                        color:[255,0,0],
                        width: 4,
                        cap: "round",
                        join: "round"
                    };
                    var inputPolyline = new Graphic({
                        geometry: line,
                        symbol: lineSymbol
                    });
                    graphicsLayer.add(inputPolyline);
                    
            }

画面

            graphicsLayer.removeAll();
            var action = draw.create("polygon",{mode: "click"});

            action.on(["vertex-add","cursor-update","draw-complete"],draw1);

            function draw1(event) {
                graphicsLayer.removeAll();
                var line={
                    type: "polygon",
                    rings: event.vertices,
                    spatialReference: view.spatialReference
                };
                var lineSymbol={
                    type:"simple-fill",
                    color:[255, 255, 255, 0.7],
                    style: "solid",
                    outline: {
                        color: "red",
                        width: 1
                    }
                    };
                var inputPolygon = new Graphic({
                    geometry: line,
                    symbol: lineSymbol
                });
                graphicsLayer.add(inputPolygon);
            }

画圆

            graphicsLayer.removeAll();
            var action = draw.create("circle");

            action.on(["vertex-add","cursor-update","draw-complete"],draw1);
            function draw1(event) {
                graphicsLayer.removeAll();
                var vertices=event.vertices;
                if(vertices.length<2){
                    return;
                }
                var center=new Point({
                    x:vertices[0][0],
                    y:vertices[0][1],
                    spatialReference: view.spatialReference
                });
                var dis=center.distance(new Point({
                    x:vertices[1][0],
                    y:vertices[1][1],
                    spatialReference: view.spatialReference
                }));
                var line= new Circle({
                    type: "circle",
                    center:center,
                    radius:dis,
                    spatialReference: view.spatialReference
                });
                var lineSymbol={
                    type:"simple-fill",
                    color:[255, 255, 255, 0.2],
                    style: "solid",
                    outline: {
                        color: "red",
                        width: 1
                    }
                };
                var inputPolygon = new Graphic({
                    geometry: line,
                    symbol: lineSymbol
                });
                graphicsLayer.add(inputPolygon);
            }

画矩形

graphicsLayer.removeAll();
            var action = draw.create("rectangle");

            action.on(["vertex-add","cursor-update","draw-complete"],draw1);
            function draw1(event) {
                graphicsLayer.removeAll();
                var vertices=event.vertices;
                if(vertices.length<2){
                    return;
                }
                var rings=[[vertices[0],[vertices[1][0],vertices[0][1]],vertices[1],[vertices[0][0],vertices[1][1]]]];
                var line={
                    type: "polygon",
                    rings: rings,
                    spatialReference: view.spatialReference
                };
                var lineSymbol={
                    type:"simple-fill",
                    color:[255, 255, 255, 0.7],
                    style: "solid",
                    outline: {
                        color: "red",
                        width: 1
                    }
                };
                var inputPolygon = new Graphic({
                    geometry: line,
                    symbol: lineSymbol
                });
                graphicsLayer.add(inputPolygon);
            }



免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空