1.首先上一段簡單的代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<!--引入css-->
<link rel="stylesheet"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<style>
#mapid { height: 180px; }
</style>
<body>
<div id="mapid"></div>
</body>
<!--引入js-->
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script>
// setView 設定視圖 設定地圖(設定其地理中心和縮放)
var mymap = L.map('mapid').setView([51.505, -0.09], 13);
// L.TileLayer():通過給定URL模板和具有選項的對象來實例化一個切片圖層
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
//用來進行屬性控制的字符串瘾敢,描述了圖層數(shù)據(jù) 就是右下角顯示的字符串
attribution: '© <a >OpenStreetMap</a> contributors'
}).addTo(mymap);
</script>
</html>