关键词搜索

源码搜索 ×
×

Leaflet文档阅读笔记-Zoom levels笔记

发布2019-09-10浏览5146次

详情内容

目录

 

官方解析

博主例子


 

官方解析

把地图放缩锁定到0级

  1. var map = L.map('map', {
  2. minZoom: 0,
  3. maxZoom: 0
  4. });
  5. var cartodbAttribution = '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/attribution">CARTO</a>';
  6. var positron = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
  7. attribution: cartodbAttribution
  8. }).addTo(map);
  9. map.setView([0, 0], 0);

下面这个是从视角从地图中某个点移动到另外一个效果(有点animation,但官方说flyTo是smooth animation)

  1. L.control.scale().addTo(map);
  2. setInterval(function(){
  3. map.setView([0, 0]);
  4. setTimeout(function(){
  5. map.setView([60, 0]);
  6. }, 2000);
  7. }, 4000);

L.Control.Scale当处于高层级的时候,这种移动是不明显的。

 

下面是自定义缩放策略

  1. var map = L.map('map', {
  2. zoomSnap: 0.25
  3. });

 

博主例子

这里提供了使用setInterval结合setZoom、flyTo、setView的地图效果

效果还是可以的,先来个静态图!

源码如下:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Test7</title>
  5. <meta charset="utf-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
  8. <link rel="stylesheet" href="leaflet.css" />
  9. <script src="leaflet.js"></script>
  10. <script src="leaflet-tilelayer-wmts-src.js"></script>
  11. <script src="echarts.js"></script>
  12. <style>
  13. html, body {
  14. height: 100%;
  15. margin: 0;
  16. }
  17. #map {
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .chart{
  22. width: 600px;
  23. height: 300px;
  24. background-color: #fff;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id='map'></div>
  30. <script type="text/javascript">
  31. var ign = new L.TileLayer.WMTS( "http:// XXX.XXX.XXX.XXX:8080/geoserver/gwc/service/wmts" ,
  32. {
  33. layer: 'GG_9:gg_9',
  34. tilematrixset: "EPSG:900913",
  35. Format : 'image/png',
  36. TileMatrix: 'EPSG:900913:8'
  37. }
  38. );
  39. var map = L.map('map', {
  40. minZoom: 4,
  41. maxZoom: 8
  42. }).setView([32, 118], 7);
  43. var popup = L.popup();
  44. function onMapClick(e) {
  45. popup
  46. .setLatLng(e.latlng)
  47. .setContent("You clicked the map at " + e.latlng.toString())
  48. .openOn(map);
  49. }
  50. map.on('click', onMapClick);
  51. L.control.scale({'position':'bottomleft','metric':true,'imperial':false}).addTo(map);
  52. map.addLayer(ign);
  53. map.invalidateSize(true);
  54. L.control.scale().addTo(map);
  55. //添加的数据
  56. /*
  57. setInterval(function(){
  58. map.setView([32, 118]);
  59. setTimeout(function(){
  60. map.setView([39.9, 116.4]);
  61. }, 3000)
  62. }, 2000);
  63. */
  64. /*
  65. setInterval(function(){
  66. map.setZoom(7);
  67. setTimeout(function(){
  68. map.setZoom(4);
  69. }, 2000);
  70. }, 1000);
  71. */
  72. //使用flyTo
  73. setInterval(function(){
  74. map.flyTo([32, 118]);
  75. setTimeout(function(){
  76. map.flyTo([39.9, 116.4]);
  77. }, 3000)
  78. }, 2000);
  79. //添加的数据
  80. </script>
  81. </body>
  82. </html>

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载