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

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

您好!我现在需要动态改变百度地图折线的颜色,请问有什么解决方案吗?因为根据地图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 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题