ArcGIS API for JavaScript SketchViewModel实现增加点、线、面、矩形、圆形与删除功能

ArcGIS API for JavaScript SketchViewModel实现增加点、线、面、矩形、圆形与删除功能,第1张

目录

分布实现

1、添加控件按钮

2、调用SketchViewModel为图形添加Symbol

3、添加激发事件

4、功能实现

5、添加清空页面的删除功能

整体代码参考:


分布实现 1、添加控件按钮

     
    
    
    
    
    
2、调用SketchViewModel为图形添加Symbol
var sketchViewModel = new SketchViewModel({
    view:view,
    layer: tempGraphicsLayer,
    pointSymbol:{
        type:"simple-marker",
        style:"square",
        color:"#8A2BE2",
        size:"16px",
        outline:{
            color:[255,255,255],
            width:3
        }
    },
    polylineSymbol:{
        type:"simple-line",
        color:"#8A2BE2",
        width:"4",
        style:"dash"
    },
    polygonSymbol:{
         type:"simple-fill",
         color:"rgba(138,43,226,0.8)",
         style:"solid",
         outline:{
              color:"white",
              width:1
         }
    }
})
3、添加激发事件
sketchViewModel.on("create-complete", function(event){
    const graphic = new Graphic({
        geometry:event.geometry,
        symbol:sketchViewModel.graphic.symbol
    });
    tempGraphicsLayer.add(graphic);
});
4、功能实现
var drawPointButton = document.getElementById("pointButton");
drawPointButton.onclick = function(){
    sketchViewModel.create("point");
    setActiveButton(this);
};

var drawlineButton = document.getElementById("polylineButton");
drawlineButton.onclick = function(){
    sketchViewModel.create("polyline");
    setActiveButton(this);
};

var drawpolygonButton = document.getElementById("polygonButton");
drawpolygonButton.onclick = function(){
    sketchViewModel.create("polygon");
    setActiveButton(this);
};

var drawrectangleButton = document.getElementById("rectangleButton");
drawrectangleButton.onclick = function(){
    sketchViewModel.create("rectangle");
    setActiveButton(this);
};

var drawcircleButton = document.getElementById("circleButton");
drawcircleButton.onclick = function(){
    sketchViewModel.create("circle");
    setActiveButton(this);
};
5、添加清空页面的删除功能
sketchViewModel.on("create-complete", addGraphic);
function addGraphic(event){
    const graphic = new Graphic({
         geometry: event.geometry,
         symbol:sketchViewModel.graphic.symbol
    });
    tempGraphicsLayer.add(graphic);
};
document.getElementById("resetButton").onclick=function(){
    tempGraphicsLayer.removeAll();
    sketchViewModel.reset();
}
整体代码参考:

    
        
        
        geometry
        
        
        
        
    
    
        
            
                 
                
                
                
                
                
            
        
    

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/924775.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存