本文介紹了如何在 Leaflet.js 中更改地圖中心的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
以下代碼初始化傳單地圖.初始化函數根據用戶位置使地圖居中.調用initialize函數后如何改變地圖中心到新位置?
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));
這篇關于如何在 Leaflet.js 中更改地圖中心的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!