Leaflet工作笔记-多个标签在地图显示不关闭
生活随笔
收集整理的這篇文章主要介紹了
Leaflet工作笔记-多个标签在地图显示不关闭
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
就是這個例子:
網頁一進去就是被打開的。并且多個標簽同時顯示。
要實現這種效果,需要如下設置:
1.設置bindPopup時把autoClose設置為false,這樣點開一個就不會關閉另外一個了。
2.在所有腳本設置好了,通過fire函數傳入'click',再指定坐標,可以在頁面加載后,就顯示了。
源碼如下:
<!DOCTYPE html> <html> <head><title>Quick Start - Leaflet</title><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" /><link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/><script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script><script src="https://cdn.bootcss.com/echarts/4.4.0-rc.1/echarts.min.js"></script><script src="https://www.echartsjs.com/examples/vendors/echarts-gl/echarts-gl.js"></script></head> <body><div id="mapid" style="width: 600px; height: 400px;"></div> <script>var mymap = L.map('mapid').setView([51.505, -0.09], 13);L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {maxZoom: 18,attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +'Imagery ? <a href="https://www.mapbox.com/">Mapbox</a>',id: 'mapbox/streets-v11'}).addTo(mymap);//L.marker([51.5, -0.09]).addTo(mymap).bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();let popupContent = '<div style="width:200px;height:200px" id="popupTest"</div>';let testLay = L.circleMarker([51.5,-0.09],{radius: 8,fillColor: "#ff7800",color: "#000",weight: 1,opacity: 1,fillOpacity: 0.8}).addTo(mymap);testLay.bindPopup(popupContent, {autoClose: false});let popupContent2 = '<div style="width:200px;height:200px" id="popupTest2"</div>';let testLay2 = L.circleMarker([51.5,-0.08],{radius: 8,fillColor: "#ff7800",color: "#000",weight: 1,opacity: 1,fillOpacity: 0.8,}).addTo(mymap);testLay2.bindPopup(popupContent2, {autoClose: false});testLay.on('popupopen', function (e) {var myChart = echarts.init(document.getElementById('popupTest'));let hours = [ '1a', '2a', '3a', '4a', '5a'];let days = ['Saturday'];let option = {xAxis3D: {type: 'category',data: hours},yAxis3D: {type: 'category',data: days},zAxis3D: {type: 'value'},grid3D: {viewControl: {// autoRotate: true},light: {main: {shadow: true,quality: 'ultra',intensity: 1.5}}},tooltip: {},legend: {data: ['一檔', '二檔','三檔','四檔','五檔']},series: [{type: 'bar3D',name: "一檔",data: [[0, 2, 20], [1, 2, 2], [2, 2, 2], [3, 2, 2], [4, 2, 2]],stack: 'stack',shading: 'lambert',emphasis: {label: {show: true}}},{type: 'bar3D',name: "二檔",data: [[0, 2, 2], [1, 2, 20], [2, 2, 2], [3, 2, 2], [4, 2, 2]],stack: 'stack',shading: 'lambert',emphasis: {label: {show: false}}}]}myChart.setOption(option);});testLay2.on('popupopen', function (e) {var myChart = echarts.init(document.getElementById('popupTest2'));let hours = [ '1a', '2a', '3a', '4a', '5a'];let days = ['Saturday'];let option = {xAxis3D: {type: 'category',data: hours},yAxis3D: {type: 'category',data: days},zAxis3D: {type: 'value'},grid3D: {viewControl: {// autoRotate: true},light: {main: {shadow: true,quality: 'ultra',intensity: 1.5}}},tooltip: {},legend: {data: ['一檔', '二檔','三檔','四檔','五檔']},series: [{type: 'bar3D',name: "一檔",data: [[0, 2, 20], [1, 2, 2], [2, 2, 2], [3, 2, 2], [4, 2, 2]],stack: 'stack',shading: 'lambert',emphasis: {label: {show: true}}},{type: 'bar3D',name: "二檔",data: [[0, 2, 2], [1, 2, 20], [2, 2, 2], [3, 2, 2], [4, 2, 2]],stack: 'stack',shading: 'lambert',emphasis: {label: {show: false}}}]}myChart.setOption(option);});testLay.fire('click', {latlng: [51.5,-0.09]});testLay2.fire('click', {latlng: [51.5,-0.08]});</script></body>?
總結
以上是生活随笔為你收集整理的Leaflet工作笔记-多个标签在地图显示不关闭的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL笔记-CURRENT_TIME
- 下一篇: Qt文档阅读笔记-构造WebSocket