一、代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>002-Leaflet-图层切换</title> <link rel="stylesheet" href="../leaflet/leaflet.css"> <style type="text/css"> html, body { margin: 0; padding: 0; } #map { width: 100%; height: 100vh; } </style> </head> <body> <div id="map"></div> <script src="../leaflet/leaflet.js"></script> <script> //白昼图层 let day = L.tileLayer('http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}', { attribution: '<a href="https://www.cnblogs.com/RadyGo/">我的博客</a>' }); //午夜图层 let night = L.tileLayer('http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}', { attribution: '<a href="https://www.cnblogs.com/RadyGo/">我的博客</a>' }); //地图初始化 var map = L.map('map', { layers: [day], center: new L.LatLng(39.915085, 116.3683244), zoom: 13, zoomControl: false }); //添加点位 L.marker([39.915085, 116.3683244]).addTo(map) .bindPopup('可自定义的弹框内容。') .openPopup(); //基础图层 var baseLayers = { "白昼": day, "午夜": night }; //添加图层控件到地图上 L.control.layers(baseLayers).addTo(map); </script> </body> </html>
二、效果
标签:map,116.3683244,Leaflet,002,图层,day From: https://www.cnblogs.com/RadyGo/p/17415988.html