百度路书 设置autoView为true 无法准确自动视野调整
生活随笔
收集整理的這篇文章主要介紹了
百度路书 设置autoView为true 无法准确自动视野调整
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在官方文檔 LuShu.js 中有些代碼中?
autoView:?true,?//是否開啟自動視野調整,如果開啟那么路書在運動過程中會根據視野自動調整
其實是隨著有拐角處才會刷新 好多文獻太老了還是,,,
所以修改_move 或者 直接添加下面代碼
??????BMapLib.LuShu.prototype._move?=?function(initPos,?targetPos,?effect)?{var?pointsArr?=?[initPos,?targetPos];?//點數組var?me?=?this,//當前的幀數currentCount?=?0,//步長,米/秒timer?=?10,step?=?this._opts.speed?/?(1000?/?timer),//初始坐標init_pos?=?this._projection.lngLatToPoint(initPos),//獲取結束點的(x,y)坐標target_pos?=?this._projection.lngLatToPoint(targetPos),//總的步長count?=?Math.round(me._getDistance(init_pos,?target_pos)?/?step);//顯示折線?syj201607191107this._map.addOverlay(new?BMap.Polyline(pointsArr,?{strokeColor:?"#4BA67E",strokeWeight:?5,strokeOpacity:?0.5,}));?//?畫線//如果小于1直接移動到下一點if?(count?<?1)?{me._moveNext(++me.i);return;}me._intervalFlag?=?setInterval(function()?{//兩點之間當前幀數大于總幀數的時候,則說明已經完成移動if?(currentCount?>=?count)?{clearInterval(me._intervalFlag);//移動的點已經超過總的長度if?(me.i?>?me._path.length)?{return;}//運行下一個點me._moveNext(++me.i);}?else?{currentCount++;var?x?=?effect(init_pos.x,?target_pos.x,?currentCount,?count),y?=?effect(init_pos.y,?target_pos.y,?currentCount,?count),pos?=?me._projection.pointToLngLat(new?BMap.Pixel(x,?y));//設置markerif?(currentCount?==?1)?{var?proPos?=?null;if?(me.i?-?1?>=?0)?{proPos?=?me._path[me.i?-?1];}if?(me._opts.enableRotation?==?true)?{me.setRotation(proPos,?initPos,?targetPos);}if?(me._opts.autoView)?{if?(!me._map.getBounds().containsPoint(pos))?{me._map.setCenter(pos);console.log("在相應點位才會出發地圖邊角才會居中");}}}/**? 添加的代碼? ???**?*********************************************************/if?(me._opts.autoView)?{if?(!me._map.getBounds().containsPoint(pos))?{me._map.setCenter(pos);console.log("只要催發地圖邊角就會居中");}}/**? ? ?**?*********************************************************************///正在移動me._marker.setPosition(pos);//設置自定義overlay的位置me._setInfoWin(pos);}},?timer);};?
總結
以上是生活随笔為你收集整理的百度路书 设置autoView为true 无法准确自动视野调整的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Go 简介、应用场景
- 下一篇: PDF转WORD的工具——Solid C