嗨,我正在嘗試找到一種在 Mapbox 中按國家代碼完全顯示國家/地區的方法。
我正在使用country-iso-to- coordinates 通過 country-iso 代碼獲取坐標
例如 userCountry = "FR" (France) 以 2.213749, 46.227638 作為中心點。這可行,但我也希望縮放級別適合該國的邊界。例如,法國在縮放級別 4.3 時看起來很完美,而像美國或中國這樣的大國需要 ~2.2 的縮放級別。
data() {
return {
accessToken: 'xxxxx',
mapStyle: 'mapbox://styles/psteger/cl0y1upof001f16sxix3n00oe',
center: [10, 51],
zoom: 4.3,
minZoom: 2.2,
maxZoom: 14,
markers: [],
params: {
access_token: 'xxxxx',
country: 'de',
language: 'en'
}
}
},
mounted() {
const coordinates = IsoToLatLong[this.userCountry];
this.center = [coordinates.coordinate[1], coordinates.coordinate[0]]
},
如何在不手動嘗試為每個國家/地區撰寫串列的情況下找到顯示整個國家/地區的有效縮放級別?是否有包含每個國家/地區比例的軟體包,以便我可以計算縮放級別,或者 mapbox 的 API 可以按國家/地區的邊界設定縮放級別?
謝謝你的幫助!
uj5u.com熱心網友回復:
我建議使用country-bounding-boxes這將允許您使用以下方法:
import boundingBoxes from 'country-bounding-boxes/bounding-boxes.json';
export default {
// ...
methods: {
zoomToCountry(isoCode) {
this.map.fitBounds(boundingBoxes[isoCode][1]);
}
}
}
這是一個非常基本的作業演示。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446449.html
標籤:javascript Vue.js Vuejs2 地图框 地图盒-gl
上一篇:清空ref物件時不觸發watch
