关键词搜索

源码搜索 ×
×

Leaflet工作笔记-多个标签在地图显示不关闭

发布2020-02-09浏览5337次

详情内容

就是这个例子:

网页一进去就是被打开的。并且多个标签同时显示。

要实现这种效果,需要如下设置:

1.设置bindPopup时把autoClose设置为false,这样点开一个就不会关闭另外一个了。

2.在所有脚本设置好了,通过fire函数传入'click',再指定坐标,可以在页面加载后,就显示了。

源码如下:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Quick Start - Leaflet</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="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
  9. <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
  10. <script src="https://cdn.bootcss.com/echarts/4.4.0-rc.1/echarts.min.js"></script>
  11. <script src="https://www.echartsjs.com/examples/vendors/echarts-gl/echarts-gl.js"></script>
  12. </head>
  13. <body>
  14. <div id="mapid" style="width: 600px; height: 400px;"></div>
  15. <script>
  16. var mymap = L.map('mapid').setView([51.505, -0.09], 13);
  17. L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  18. maxZoom: 18,
  19. attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
  20. '<a href="https://creativecommons.org/licenses/by-sahttps://cdn.jxasp.com:9143/image/2.0/">CC-BY-SA</a>, ' +
  21. 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  22. id: 'mapbox/streets-v11'
  23. }).addTo(mymap);
  24. //L.marker([51.5, -0.09]).addTo(mymap).bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();
  25. let popupContent = '<div style="width:200px;height:200px" id="popupTest"</div>';
  26. let testLay = L.circleMarker([51.5,-0.09],{
  27. radius: 8,
  28. fillColor: "#ff7800",
  29. color: "#000",
  30. weight: 1,
  31. opacity: 1,
  32. fillOpacity: 0.8
  33. }).addTo(mymap);
  34. testLay.bindPopup(popupContent, {autoClose: false});
  35. let popupContent2 = '<div style="width:200px;height:200px" id="popupTest2"</div>';
  36. let testLay2 = L.circleMarker([51.5,-0.08],{
  37. radius: 8,
  38. fillColor: "#ff7800",
  39. color: "#000",
  40. weight: 1,
  41. opacity: 1,
  42. fillOpacity: 0.8,
  43. }).addTo(mymap);
  44. testLay2.bindPopup(popupContent2, {autoClose: false});
  45. testLay.on('popupopen', function (e) {
  46. var myChart = echarts.init(document.getElementById('popupTest'));
  47. let hours = [ '1a', '2a', '3a', '4a', '5a'];
  48. let days = ['Saturday'];
  49. let option = {
  50. xAxis3D: {
  51. type: 'category',
  52. data: hours
  53. },
  54. yAxis3D: {
  55. type: 'category',
  56. data: days
  57. },
  58. zAxis3D: {
  59. type: 'value'
  60. },
  61. grid3D: {
  62. viewControl: {
  63. // autoRotate: true
  64. },
  65. light: {
  66. main: {
  67. shadow: true,
  68. quality: 'ultra',
  69. intensity: 1.5
  70. }
  71. }
  72. },
  73. tooltip: {},
  74. legend: {
  75. data: ['一档', '二档','三档','四档','五档']
  76. },
  77. series: [
  78. {
  79. type: 'bar3D',
  80. name: "一档",
  81. data: [[0, 2, 20], [1, 2, 2], [2, 2, 2], [3, 2, 2], [4, 2, 2]],
  82. stack: 'stack',
  83. shading: 'lambert',
  84. emphasis: {
  85. label: {
  86. show: true
  87. }
  88. }
  89. },
  90. {
  91. type: 'bar3D',
  92. name: "二档",
  93. data: [[0, 2, 2], [1, 2, 20], [2, 2, 2], [3, 2, 2], [4, 2, 2]],
  94. stack: 'stack',
  95. shading: 'lambert',
  96. emphasis: {
  97. label: {
  98. show: false
  99. }
  100. }
  101. }
  102. ]
  103. }
  104. myChart.setOption(option);
  105. });
  106. testLay2.on('popupopen', function (e) {
  107. var myChart = echarts.init(document.getElementById('popupTest2'));
  108. let hours = [ '1a', '2a', '3a', '4a', '5a'];
  109. let days = ['Saturday'];
  110. let option = {
  111. xAxis3D: {
  112. type: 'category',
  113. data: hours
  114. },
  115. yAxis3D: {
  116. type: 'category',
  117. data: days
  118. },
  119. zAxis3D: {
  120. type: 'value'
  121. },
  122. grid3D: {
  123. viewControl: {
  124. // autoRotate: true
  125. },
  126. light: {
  127. main: {
  128. shadow: true,
  129. quality: 'ultra',
  130. intensity: 1.5
  131. }
  132. }
  133. },
  134. tooltip: {},
  135. legend: {
  136. data: ['一档', '二档','三档','四档','五档']
  137. },
  138. series: [
  139. {
  140. type: 'bar3D',
  141. name: "一档",
  142. data: [[0, 2, 20], [1, 2, 2], [2, 2, 2], [3, 2, 2], [4, 2, 2]],
  143. stack: 'stack',
  144. shading: 'lambert',
  145. emphasis: {
  146. label: {
  147. show: true
  148. }
  149. }
  150. },
  151. {
  152. type: 'bar3D',
  153. name: "二档",
  154. data: [[0, 2, 2], [1, 2, 20], [2, 2, 2], [3, 2, 2], [4, 2, 2]],
  155. stack: 'stack',
  156. shading: 'lambert',
  157. emphasis: {
  158. label: {
  159. show: false
  160. }
  161. }
  162. }
  163. ]
  164. }
  165. myChart.setOption(option);
  166. });
  167. testLay.fire('click', {
  168. latlng: [51.5,-0.09]
  169. });
  170. testLay2.fire('click', {
  171. latlng: [51.5,-0.08]
  172. });
  173. </script>
  174. </body>

 

相关技术文章

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

提示信息

×

选择支付方式

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