問題背景:
規劃駕車線路的時候,使用uni的include-points
指定可視范圍的時候,會很極限。導致marker不能完全顯示。
解決方法
- 給地圖顯示范圍添加padding (推薦)
<mapid="myMap":markers="markers":polyline="polyline":longitude="curLongitude":latitude="curLatitude"@markertap="markertap"></map>
onLoad((e) => {uni.createMapContext('myMap', this).includePoints({padding: [120, 110, 120, 110],points: [{ latitude: startCityLat.value, longitude: startCityLog.value },{ latitude: endCityLat.value, longitude: endCityLog.value }]});
});
- 或者獲取并修改縮放地圖(記得設置中心點)
const appMapRef = ref('');
appMapRef.value = uni.createMapContext('myMap');
appMapRef.value.getScale({success: (res) => {console.log('縮放', res);mapScale.value = res.scale - 1;console.log('mapScale.value', mapScale.value);}});
uni文檔:點擊這里
1的效果圖: