当前位置:网站首页>How leaflet gracefully displays the bubble window of overlapping points
How leaflet gracefully displays the bubble window of overlapping points
2022-06-12 23:43:00 【GIS weapon warehouse】
Don't talk much , The first effect :
Effect 1 :

Effect two :

In normal work , This kind of problem is often encountered , Two or more points completely coincide , The mouse cannot click to the covered point , So you can't see its bubble information . I've seen that some students' ways of dealing with it are , Modify point coordinates directly , Let the points no longer coincide , So you can click to each point . We will not comment on the advisability of this method .
Today we will discuss from two other dimensions , How to solve this problem .
Scheme 1 PopupListLayer:
The way to deal with this scheme is , Click to get all the points that coincide with the point , Then integrate what needs to be shown in the bubble , Add switch function , Achieve the effect of switching display all bubble information

The core code is as follows :

We encapsulate this method as a plug-in , After the plug-in is referenced , The above effect can be achieved in two simple steps .
First step : initialization popupListLayer
var popupListLayer = new L.popupListLayer().addTo(map)
The second step : Pass the point and bubble content to popupListLayer
popupListLayer.addMarker(marker, contentHTML)

Option two PopupLayoutLayer:
This scheme is mainly used for reference in GIT Found on leaflet-tooltip-layout This plugin . By dealing with L.tooltip() Location relationship , Realize multi bubble information display , At the same time, try to avoid covering between bubbles . The scheme supports displaying bubbles by clicking points and displaying all bubbles at the same time .
Show bubbles by clicking on the dots

Show all the bubbles at the same time
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-fXO8PPzH-1607591923545)(https://blogimage.gisarmory.xyz/202011300101.png)]
We encapsulate this method as a plug-in , After the plug-in is referenced , This can be achieved in three simple steps .
First step : initialization popupLayoutLayer. To see all the bubbles , Need to showAll Parameter set to true, The default is false, Click to see the bubble information .
var popupLayoutLayer = new L.popupLayoutLayer({
showAll: true // true, Show all bubbles ; The default is false, Click to see bubbles ,
}).addTo(map)
The second step : Pass the point and bubble content to popupLayoutLayer
popupLayoutLayer.addMarker(marker, contentHTML)
The third step : There are two kinds of situations: Click to view bubbles and display all bubbles
1、 Click to view bubbles . Add click event , Add bubbles to the click event
popupLayoutLayer.on('click', function(evt) {
})
2、 Show all the bubbles , Need to showAll Parameter set to true
popupLayoutLayer.showPopup()

summary
- When you add points to a map , It is often encountered that the coordinates of points coincide , Can't click to the covered point , So you can't see its bubble information .
- Solution 1 , quote
PopupListLayerplug-in unit , Display by switching content . - Solution 2 , quote
PopupLayoutLayerplug-in unit , By dealing withL.tooltip()Location relationship , Achieve moretooltipShow at the same time , Click ontooltipShow details . PopupLayoutLayerPlug in support The bubble information is displayed by clicking on the coincidence point , as well as At the same time, all the bubble information is displayed .
Online example
PopupListLayer Toggle display of bubbles
PopupLayoutLayer Show all bubbles
PopupLayoutLayer Click to show bubbles
Reference Content
https://github.com/ZijingPeng/leaflet-tooltip-layout
Original address :http://gisarmory.xyz/blog/index.html?blog=LeafletPopupLayoutLayer.
Focus on 《GIS Zeughaus 》 official account , The first time to get more high quality GIS article .

This article adopts Creative Commons signature - Noncommercial use - Share in the same way 4.0 International licensing agreement Licensing . Welcome to reprint 、 Use 、 Re release , But be sure to keep the signature of the article 《GIS Zeughaus 》( Include links : http://gisarmory.xyz/blog/), Not for commercial purposes , Based on this revised work must be released with the same license .
边栏推荐
- Pytorch common parameter initialization methods: [uniform distribution, normal (Gaussian) distribution, Xavier, Kaiming, orthogonal matrix, sparse matrix, constant, identity matrix, zero filling]
- 2022 electrician (elementary) operation certificate examination question bank and online simulation examination
- array
- Chapter 8 - shared model JUC
- 2202-簡曆制作
- 利率降低导致债券价格上涨
- Ast, really fragrant
- Deep feature synthesis and genetic feature generation, comparison of two automatic feature generation strategies
- [opencv learning] perspective transformation matrix
- 2022 R2 mobile pressure vessel filling test questions and online simulation test
猜你喜欢

Case sharing of online real queuing system reconfiguration -- practical part

深度学习-神经网络:卷积的实现方法【直接法(精度没损失)、GEMM(矩阵乘法,精度没损失)、FFT(傅里叶变换,精度有损失)、Winograd(精度有损失)】

设计消息队列存储消息数据的 MySQL 表格

CST learning: four element array design of circular patch antenna (III) array formation and parallel excitation
![[recommended collection] easy to understand graphic network knowledge - Part 1](/img/5a/dc9f1fd6cfdc1350f757b70e368fe3.png)
[recommended collection] easy to understand graphic network knowledge - Part 1

Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data

Operation of simulation test platform for G3 boiler water treatment test questions in 2022

TCP与UDP

基于Three.js海上风电数字孪生三维效果

Deep learning neural network: implementation method of convolution [direct method (no loss of precision), GEMM (matrix multiplication, no loss of precision), FFT (Fourier transform, loss of precision)
随机推荐
你真的会用PostGIS中的buffer缓冲吗?
Tsinghua University image source will cause tensorflow GPU installation failure
测试平台系列(97) 完善执行case部分
LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路
2022 electrician (elementary) operation certificate examination question bank and online simulation examination
启牛帮开通的股票账户是安全可信的吗?
Modify the text color of the menu on the right of toobar
〖Kubernetes指南④〗Pod快速入门
2022 R2 mobile pressure vessel filling test questions and online simulation test
KConfig
CST learning: four element array design of circular patch antenna (II) array formation and combination results
Summary of the lowest level error types in PHP
How does idea switch the interface to Chinese
array
PostgreSQL 中文社区黑龙江分会和辽宁分会成立啦!
Embedded pipeline out of the box
TCP与UDP
Basic operations of dict and set
[North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system
Save state when viewpager is used with fragment fragmentpageradapter