hzlhlove 2014-01-02 22:11 采纳率: 100%
浏览 1078
已采纳

百度地图折线覆盖物变颜色

您好!我现在需要动态改变百度地图折线的颜色,请问有什么解决方案吗?因为根据地图api,不能给折线设置一个例如id的属性,然后根据这个id去定位到该折线。如果有人有好的方案,麻烦您指教下,谢谢!

  • 写回答

2条回答 默认 最新

  • stu liu 2014-01-03 15:04
    关注

    有多个你用个数组存起来不就好了么
    [code="java"]
    <!DOCTYPE html>



    body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}

    改变覆盖物状态


    // 覆盖物全部放入自定义map,以id作为Key var oVMap = new Map(); var map = new BMap.Map("allmap"); var point = new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 13); var polyline = new BMap.Polyline([ new BMap.Point(116.399, 39.910), new BMap.Point(116.405, 39.920), new BMap.Point(116.425, 39.900) ], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5}); map.addOverlay(polyline); oVMap.put('polyline-1',polyline); var polyline2 = new BMap.Polyline([ new BMap.Point(116.499, 39.910), new BMap.Point(116.505, 39.920), new BMap.Point(116.525, 39.900) ], {strokeColor:"red", strokeWeight:6, strokeOpacity:0.5, id:'my_polyine'}); map.addOverlay(polyline2); oVMap.put('polyline-2',polyline2); var circle = new BMap.Circle(new BMap.Point(116.433, 39.915),500); map.addOverlay(circle); oVMap.put('circle-1',circle); // 改变覆盖物状态 function change(){ var temp; // 第一个折线颜色改为绿色 temp = oVMap.get('polyline-1'); if(temp){ temp.setStrokeColor('green'); } // 第二个折线颜色改为黄色 temp = oVMap.get('polyline-2'); if(temp){ temp.setStrokeColor('yellow'); } // 改变圆的半径 temp = oVMap.get('circle-1'); if(temp){ temp.setRadius(700); } } // 自定义map function Map(){ this.data = new Array(); // 添加 this.put = function(_key,_value){ if(this.containsKey(_key)){ this.remove(_key); } this.data.push({key:_key,value:_value}); }; // 取值 this.get = function(_key){ var rtn = null; try { for(var i=0;i<this.data.length;i++){ if(this.data[i].key==_key){ rtn = this.data[i].value; break; } } } catch (e) { rtn = null; } return rtn; }; // 删除 this.remove = function(_key){ var btn = false; try { for(var i=0;i<this.data.length;i++){ if(this.data[i].key == _key){ this.data.splice(i,1); return true; } } } catch (e) { btn = false; } return btn; }; // 判断是否存在key this.containsKey = function(_key) { var bln = false; try { for (i = 0; i < this.data.length; i++) { if (this.data[i].key == _key) { bln = true; break; } } } catch (e) { bln = false; } return bln; } // 清空 this.clear = function(){ this.data = new Array(); } }

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵