当前位置:网站首页>Is divicon still used in leaflet in H5 era?
Is divicon still used in leaflet in H5 era?
2022-06-12 23:42:00 【GIS weapon warehouse】
I wrote an article some time ago 《leaflet How to load 10 All the data 》 The article , One of the students responded that Canvas-Markers Plugin does not support DivIcon. Let's have a chat today , Why this plug-in doesn't support DivIcon, And how to use H5 Of Canvas characteristic , Make previous use of DivIcon In order to achieve label and Text annotation function .
Old rules , First on the renderings :
Label function

Text annotation function

Why not support DivIcon
Canvas-Markers The purpose of plug-ins is to solve , Performance issues of mass data presentation , It uses H5 in Canvas Drawing in the way of drawing Marker, Improved display performance . But the plug-in only supports Icon, I won't support it DivIcon.
I don't support , Because DivIcon The implementation principle of is in HTML Add... To the page DOM Elements , And pan on the map 、 Constantly changing as you zoom DOM Attribute of element , And a lot of additions and modifications DOM Elements can slow down the browser's display performance , There are such phenomena as stuck .
If you use Canvas-Markers It's still in use after DivIcon, It is equivalent to upgrading the network to Gigabit bandwidth , Still using the 100 megabyte router before . At this moment DivIcon It's going to be like the 100 megabyte router , Become the narrowest place in the whole passage , Become a bottleneck .
If not DivIcon This old router , Is there a new router ?
Yes ! But it depends on the situation .
At work , use DivIcon Usually to achieve Label function and Text annotation function
Label function :

Text annotation function :

In both cases ,leaflet There are Canvas The solution to the problem .
Label function
Mentioned above ,Canvas-Markers Plug ins currently only support Icon Type of icon , Look at the code and you'll see , Actually , It USES Icon It's just Icon Think of it as a Object To use , It's only for transmitting ginseng , Not to use Icon Internal functions . because Icon Internal , Also created a img Type of DOM Elements , It and DivIcon equally , A large number of additions will affect the browser's display performance .
Canvas-Markers Plug in through Icon Get the image's address and the image's offset position and other parameters , And then use Canvas The way to draw pictures .
The label consists of two parts , Background box and text , The background box is usually a picture .Canvas-Markers The plug-in has been able to load images , We just need to make it support words again , And can control the style and position of the text , You can implement the tag function .
open Canvas-Markers Plug in code , Add a method to draw text in the position below .

Three more places in the picture below , Add the call of the new method above

In this way, the tag function can be realized , See the effect

Performance aspect , The biggest support 10 About ten thousand data .
Text annotation function
I am here github On the search leaflet+text keyword , Look at the top of the results 20 Code base , eureka LabelTextCollision This plugin .
LabelTextCollision The purpose of plug-in creation is , It is to realize the automatic avoidance function of text annotation , The way to do it is Canvas, The text annotation function is the problem it solves by the way .

When testing , Found a problem with it ,1 Ten thousand data , When you zoom out of the map , The display is very smooth , But when you zoom in on the map , It's going to get stuck , And the bigger the map is , The more powerful the stuck one is .
Usually when loading large amounts of data , The smaller the map, the more stuck it is , The bigger the map, the smoother it is . But this plug-in is just the opposite , Why is this ?
Personal speculation , It's a problem , Most of the data is not filtered according to the screen display range , If you don't filter, you'll add data out of the screen .
This plug-in is because it avoids text display , The smaller the map , The more data is displayed on the screen , The more text you automatically avoid , The less text is displayed , The more fluent the presentation is .
The more you zoom in on the map , The more scattered the data is displayed on the screen , The less text there is to avoid automatically , The more text is displayed , If there is no screening at this time , The show will get more and more stuck .
Take a look at the code , Confirmed my conjecture , It's true that we didn't find , Code that restricts what is displayed outside the screen area .
Then we'll add , Add the judgment of the screen display range in two places in the figure below , Display only the data currently visible .

Try again , ha-ha , Get it done

Tested under , After optimization , Can be loaded 5 About ten thousand data .
More scenes
The above lists DivIcon Two common usage scenarios , And how to use it Canvas Way to improve presentation performance , If you have DivIcon Other use scenarios of , Leave a comment below , Let's talk about solutions .
summary
- Canvas-Markers The purpose of plug-ins is to solve , Performance issues in mass data presentation .
- DivIcon The principle of implementation is in HTML Add... To the page DOM Elements , Add and modify a lot of DOM Elements can slow down browser presentation performance .
- From the point of view of improving display performance ,Canvas-Markers Plug ins should not support DivIcon.
- use DivIcon, It is usually for the realization of label function and text annotation function , Both functions have Canvas The solution to the problem .
- Yes Canvas-Markers Plug in to optimize , Add text interface , Can replace DivIcon Realize the tag function .
- LabelTextCollision The plug-in can realize the automatic avoidance function of text annotation , It is to use Canvas How to achieve , Can replace DivIcon Realize the function of text annotation .
- LabelTextCollision Plug in when the map is zoomed in , You can only show 1 About ten thousand data , After optimization, we can achieve 5 About ten thousand data .
Online example
Label function http://gisarmory.xyz/blog/index.html?demo=diviconError-CanvasMarker
Text annotation function http://gisarmory.xyz/blog/index.html?demo=diviconError-LabelTextCollision
Source code
Label function http://gisarmory.xyz/blog/index.html?source=diviconError-CanvasMarker
Text annotation function http://gisarmory.xyz/blog/index.html?source=diviconError-LabelTextCollision
Original address :http://gisarmory.xyz/blog/index.html?blog=diviconError
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 .
边栏推荐
- Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
- Tsinghua University image source will cause tensorflow GPU installation failure
- Chapter 8 - shared model JUC
- LeetCode 146. LRU cache
- NCF 的Dapr应用实例的运行
- 测试平台系列(97) 完善执行case部分
- CS for mobile security [nethunter]
- 模型过拟合-解决方案(二):Dropout
- Lower interest rates lead to higher bond prices
- [North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system
猜你喜欢
![CS for mobile security [nethunter]](/img/25/ad99256a1eebb09f639e95d00756a5.jpg)
CS for mobile security [nethunter]

Running of NCF dapr application instance

Leetcode1601: the maximum number of building change requests that can be reached (difficult)

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

MySQL基础篇视图的总结

Using baserecyclerviewadapterhelper to implement tree structure

Based on three JS offshore wind power digital twin 3D effect

Redis realizes SMS verification code login

MYSQL 行转列、列转行、多列转一行、一行转多列

应用最广泛的动态路由协议:OSPF
随机推荐
Leetcode 2200. 找出数组中的所有 K 近邻下标(可以,一次过)
Summary of the lowest level error types in PHP
Model over fitting - solution (II): dropout
Alien Skin Exposure X7调色滤镜插件,RAW后期处理工具
基于Three.js海上风电数字孪生三维效果
數組
深度学习-神经网络:卷积的实现方法【直接法(精度没损失)、GEMM(矩阵乘法,精度没损失)、FFT(傅里叶变换,精度有损失)、Winograd(精度有损失)】
[literature translation - Part] revealing the structure of clinical EEG signals by self supervised learning (SSL and RP principles / data / preprocessing)
Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022
Start blogging
设计消息队列存储信息数据的MySQL表结构
[redis sentinel] failed listening on port 26379 (TCP) & sentinel mode no response problem solved
同花顺开证券账户怎么样?到底安不安全呢
[kubernetes guide ④] pod quick start
人脸检测:MTCNN
Abstract methods and abstract classes
Software development tools [3] theoretical basis of software development tools
Modify the text color of the menu on the right of toobar
Teach you how to grab ZigBee packets through cc2531 and parse encrypted ZigBee packets
应用最广泛的动态路由协议:OSPF