<!DOCTYPE html>
<html>
<head>
<title>Leaflet1</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"></script>
<style TYPE="text/css">
body {
margin: 0px;
padding: 0px;
}
/**
* 单独设置mapid为100%不显示,可能float坍塌
*/
html,
body,
#mapDiv {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="mapDiv">
</div>
</body>
<script>
//地图地址
//var url = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
var url = 'C:/Users/yzh/Desktop/tiles/{z}/{x}/{y}.png';
var attr =
' Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>';
var leafletMap = L.map('mapDiv').setView([36, 120], 6);
//图层
L.tileLayer(url, {
maxZoom: 12,
attribution: attr,
id: 'mapbox.streets'
}).addTo(leafletMap);
//标记点
var marker = L.marker([36, 120]).addTo(leafletMap).bindPopup("<b>Hello world!</b><br />I am a popup.111111");
marker.on('mouseover', function(){marker.openPopup()});
marker.on('mouseout', function(){marker.closePopup()});
// //圆
// L.circle([36, 121], 500, {
// color: 'red',
// fillColor: '#f03',
// fillOpacity: 0.5
// }).addTo(leafletMap).bindPopup("I am a circle.");
// //多边形
// L.polygon([
// [36.509, 120.08],
// [36.503, 120.06],
// [36.51, 120.047]
// ]).addTo(leafletMap).bindPopup("I am a polygon222.");
//弹出面板
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(leafletMap);
}
//添加click事件
leafletMap.on('click', onMapClick);
</script>
</html>