当前位置:网站首页>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 .
边栏推荐
- 华为云会议初体验【华为云至简致远】
- 36 krypton's debut | "osogena" won nearly ten million angel rounds of financing. The original DLR scientists of German Aerospace Research and development system modeling and simulation CAE software PA
- Summary of MySQL foundation view
- 2022 electrician (elementary) operation certificate examination question bank and online simulation examination
- [kubernetes guide ④] pod quick start
- Message queue directory
- Running of NCF dapr application instance
- Comprehensive analysis of C array
- SAP QM qp03 displays an inspection plan with multiple specs inspection features
- [opencv learning] small ticket recognition based on perspective transformation and OCR recognition
猜你喜欢

Running of NCF dapr application instance

2202 - production de CV

2022 operation of simulated examination platform for hoisting machinery command certificate

數組

Leetcode 2164. 对奇偶下标分别排序(可以,一次过)

MySQL基础篇视图的总结
![Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding](/img/a2/186439a6d50339ca7f299a46633345.png)
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding

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

Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!

Chapter 8 - shared model JUC
随机推荐
测试平台系列(97) 完善执行case部分
Gradient accumulation in pytorch [during the experiment, due to the limitation of GPU video memory, the batch\u size can no longer be increased. To solve this problem, the gradient accumulation method
Unprecedented analysis of Milvus source code architecture
2022起重机械指挥上岗证题目模拟考试平台操作
Tsinghua University image source will cause tensorflow GPU installation failure
Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!
2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試
InfoQ 极客传媒 15 周年庆征文|简述构建微服务架构的四大挑战
Software development tools [3] theoretical basis of software development tools
DETR(Detection with Transformers) 学习笔记
36 krypton's debut | "osogena" won nearly ten million angel rounds of financing. The original DLR scientists of German Aerospace Research and development system modeling and simulation CAE software PA
[opencv learning] perspective transformation matrix
Matters of parent-child class construction method in inheritance
〖Kubernetes指南⑤〗Label快速入门
Develop a web office suite from scratch (5): mouse hover over text
Detr (detection with transformers) learning notes
Hongmeng starts 2
如何实现OSM地图本地发布并自定义配图
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding
Cherry Blossom powder Dudu