高德地图中新建矩形进行图形编辑时无法编辑成功的bug AMap.MouseTool,AMap.RectangleEditor,AMap.Rectangle

高德地图中新建矩形进行图形编辑时无法编辑成功的bug

 

 

在高德地图中使用AMap.MouseTool API绘制矩形,再使用AMap.RectangleEditor API进行矩形的更改拖动修改点,图形无变化。

提交高德工单后未解决问题

解决方法:

1、使用AMap.Rectangle创建的矩形可以进行编辑。思路为用户绘制完成保存,再删除地图上的图形。调用绘制完成的矩形范围,用AMap.Rectangle API绘制一个图形进行编辑。同时编辑时要关闭AMap.MouseTool

2、让用户再绘制的时候无法编辑只能删除后重新绘制。编辑的时候用AMap.Rectangle重新创建矩形进行编辑。

以下为图片错误的demo (注意!复制到高德api文档中运行。绘制一个矩形,点击关闭绘制拖动编辑点即可还原上图。)

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" type="text/css">
    <style>
      html,body,#container{
        height: 100%
      }
      .input-item{
        height: 2.2rem;
      }
      .btn{
        width: 6rem;
        margin: 0 1rem 0 2rem;
      }
      .input-text{
        width: 4rem;
        margin-right:1rem;
      }
    </style>
    <title>鼠标工具绘制</title>
  </head>
  <body>
    <div id='container'></div>
    <div class='info'>操作说明:圆和矩形通过拖拽来绘制,其他覆盖物通过点击来绘制</div>
    <div class="input-card" style='width: 24rem;'>
        <div class="input-item">
          <input type="radio" name='func' checked="" value='marker'><span class="input-text">画点</span>
          <input type="radio" name='func' value='polyline'><span class="input-text">画折线</span>
          <input type="radio" name='func' value='polygon'><span class="input-text" style='width:5rem;'>画多边形</span>
        </div>
        <div class="input-item">
          <input type="radio" name='func' value='rectangle'><span class="input-text">画矩形</span>
          <input type="radio" name='func' value='circle'><span class="input-text">画圆</span>
        </div>
        <div class="input-item">
            <input id="clear" type="button" class="btn" value="清除" />
          <input id="close" type="button" class="btn" value="关闭绘图" />
        </div>
    </div>
    <script src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&plugin=AMap.MouseTool,AMap.RectangleEditor"></script>
    <script type="text/javascript">
    var map = new AMap.Map('container',{
        zoom:14
    });

    var mouseTool = new AMap.MouseTool(map); 
    //监听draw事件可获取画好的覆盖物
    var overlays = [];
      var data=null;
    mouseTool.on('draw',function(e){
        overlays.push(e.obj);
      data = e.obj
    }) 
    
    function draw(type){
      switch(type){
        case 'marker':{
            mouseTool.marker({
              //同Marker的Option设置
            });
            break;
        }
        case 'polyline':{
            mouseTool.polyline({
              strokeColor:'#80d8ff'
              //同Polyline的Option设置
            });
            break;
        }
        case 'polygon':{
            mouseTool.polygon({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Polygon的Option设置
            });
            break;
        }
        case 'rectangle':{
            mouseTool.rectangle({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Polygon的Option设置
            });
            break;
        }
        case 'circle':{
            mouseTool.circle({
              fillColor:'#00b0ff',
              strokeColor:'#80d8ff'
              //同Circle的Option设置
            });
            break;
        }
      }
    }
    var radios = document.getElementsByName('func');
    for(var i=0;i<radios.length;i+=1){
        radios[i].onchange = function(e){

          draw(e.target.value)
        }
    }
    draw('marker')

    document.getElementById('clear').onclick = function(){
        map.remove(overlays)
        overlays = [];
    }  
    document.getElementById('close').onclick = function(){
         var rectangleEditor = new AMap.RectangleEditor(map,data)
         rectangleEditor.open()
    }
    </script>
  </body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值