当前位置:网站首页>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 .
边栏推荐
- Leetcode 2200. 找出数组中的所有 K 近邻下标(可以,一次过)
- Shardingsphere-proxy-5.0.0 deployment table implementation (I)
- Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding
- 2022起重机械指挥上岗证题目模拟考试平台操作
- CS for mobile security [nethunter]
- Zhengzhou University of light industry -- development and sharing of harmonyos pet health system
- Pytorch中的梯度累加【在实验时,由于GPU显存限制,遇到batch_size不能再增大的情况。为解决该问题,使用梯度累加方法】
- Enterprise wechat H5_ Authentication, PC website, enterprise wechat scanning code, authorized login
- Industry reshuffle, a large number of programmers are going to lose their jobs? How can we break the current workplace dilemma
- Develop a web office suite from scratch (5): mouse hover over text
猜你喜欢

M_ 8: Design a MySQL table for message queue to store message data

Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022

〖Kubernetes指南④〗Pod快速入门

Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation

RT thread quick start - experience RT thread

Ast, really fragrant

2022年电工(初级)操作证考试题库及在线模拟考试

2202-簡曆制作

array

2022 questions d'examen pour le personnel de gestion de la sécurité de l'unit é de gestion des produits chimiques dangereux et examen de simulation en ligne
随机推荐
Mgr and greatsql resource summary
2022年G3锅炉水处理考题模拟考试平台操作
同花顺开证券账户怎么样?到底安不安全呢
[opencv learning] use the Tesseract OCR movement to recognize numbers
模型过拟合-解决方案(二):Dropout
如何利用华为云容灾解决方案替代灾备一体机
Leetcode 2200. Find all k nearest neighbor subscripts in the array (yes, one pass)
如何实现OSM地图本地发布并自定义配图
CS for mobile security [nethunter]
dict和set的基本操作
Sequence maximum return
M_8:设计消息队列存储消息数据的 MySQL 表格
自动获取结构体内部成员变量的位置偏移
2202-简历制作
array
SAP UI5 如何通过 manifest.json 文件定义第三方库依赖关系
〖Kubernetes指南⑤〗Label快速入门
Dry goods sharing | BitSet application details
Redis realizes SMS verification code login
Online examination questions for September examination of financial management