本文介紹了如何在 Leaflet.js 中更改地圖中心的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
以下代碼初始化傳單地圖.初始化函數(shù)根據(jù)用戶位置使地圖居中.調(diào)用initialize函數(shù)后如何改變地圖中心到新位置?
The following code initializes a leaflet map. The initialize function centers the map based on user location. How do I change the center of the map to a new position after calling the initialize function?
function initialize() {
map = L.map('map');
L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a >OpenStreetMap</a> contributors, <a >CC-BY-SA</a>, Imagery ?? <a
}).addTo(map);
map.locate({setView: true, maxZoom: 8});
}
推薦答案
例如:
map.panTo(new L.LatLng(40.737, -73.923));
這篇關(guān)于如何在 Leaflet.js 中更改地圖中心的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!