marker的存储组---layerGroup

 1 <!DOCTYPE html>
 2 <html lang="zh">
 3     <head>
 4         <meta charset="UTF-8">
 5         <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6         <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7         <link rel="stylesheet" type="text/css" href="leaflet/leaflet.css" />
 8         <title></title>
 9         <style type="text/css">
10             body {
11                 margin: 0;
12             }
13 
14             #mapid {
15                 height: 500px;
16             }
17         </style>
18     </head>
19     <body>
20         <div id="mapid"></div>
21 
22         <script type="text/javascript" src="leaflet/leaflet.js"></script>
23 
24         <script type="text/javascript">
25             const mymapOptions = {
26                 // 地图中心
27                 center: [51.505, -0.09],
28                 // 地图的最小缩放级别
29                 minZoom: 11,
30                 // 初始化时的缩放等级
31                 zoom: 13,
32                 // 地图的最大缩放级别
33                 maxZoom: 15,
34                 // 强制让地图的缩放级别始终为这个值的倍数
35                 zoomSnap: 1,
36                 // 版权控件添加到地图中(即水印)
37                 attributionControl: false,
38                 // 是否显示zoom 缩放控件,默认是true
39                 zoomControl: true,
40             }
41 
42             const mymap = L.map('mapid', mymapOptions);
43 
44             //声明图层组,存储城市标记marker
45             var cities = L.layerGroup();
46 
47             //声明两个城市marker并添加进图层组
48             var linyi = L.marker([51.505, -0.09]).bindPopup('这里属于青岛').addTo(cities);
49             var qingdao = L.marker([51.505, -0.19]).bindPopup('这里属于临沂').addTo(cities);
50             
51             cities.addTo(mymap)
52 
53             const imageUrl = 'leaflet/images/b1-floor1-full-h.png';
54             // 获取顶部左边的边界
55             const northEast = L.latLng(mymap.getBounds()._northEast);
56             // 获取底部右边的边界
57             const southWest = L.latLng(mymap.getBounds()._southWest);
58 
59             const imageBounds = L.latLngBounds(northEast, southWest);
60             const imageOverlay = L.imageOverlay(imageUrl, imageBounds).addTo(mymap);
61         </script>
62 
63     </body>
64 </html>

 

posted @ 2022-04-19 15:32  sky-su  阅读(55)  评论(0)    收藏  举报