MAP组件 有添加覆盖物的方法吗?
发布于 6 年前 作者 junyuan 15363 次浏览 来自 问答

找了半天,只有polyline这个属性。可是MAP的参数只是初始化时加载一次。

如果我想实时获取坐标,并进行地图画线,试了下是不行的。

有没有类似百度的添加覆盖物的方法

var polyline = new BMap.Polyline([    
   new BMap.Point(116.399, 39.910),    
   new BMap.Point(116.405, 39.920)    
 ],    

{strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5}    );    

map.addOverlay(polyline);

强烈希望增加此功能

4 回复

@追小命

这个是MAP组件加载时,才有效的。不能做到更新

@jeff

感谢,已经搞定了。

点击这个按钮后,会触发画轨迹的方法

carGo: function () {

     start = true;

     timer = setInterval(this.drawLine,5000);//绘制轨迹

  },

//获得了坐标,动态绑定map的参数,就可以实时画轨迹了

drawLine : function() {

      var that = this;

       wx.getLocation( {

        type: ‘gcj02’,

        success: function( res ) {

            var polyline = that.data.polyline[0];

            var points = polyline.points;

            var obj = new Object();

            obj[“longitude”] =  res.longitude;

            obj[“latitude”] =  res.latitude;

            points.push(obj);

            console.info(that);

            console.info(new Date());

            polyline[“points”] = points;

            console.info(polyline);

            that.setData({

              polyline: [polyline],

              location: {

                longitude: res.longitude,

                latitude: res.latitude

              }

            });

        }

      });

  }

可以data里设置帮顶polyline啊

有markers/controls/polylines/circles等,可以通过数据绑定来做更新。

譬如

markers="{{markerArray}}"

更新:

pageObj.setData(markerArray: [

{

}

];

回到顶部