就是这个例子:
网页一进去就是被打开的。并且多个标签同时显示。
要实现这种效果,需要如下设置:
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-sahttps://cdn.jxasp.com:9143/image/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>