当前位置:网站首页>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 .
边栏推荐
- Hongmeng starts 2
- 妙才周刊 - 5
- 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
- Automatically obtain the position offset of member variables inside the structure
- 如何利用华为云容灾解决方案替代灾备一体机
- [opencv learning] perspective transformation matrix
- [North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system
- Alien skin exposure X7 color filter plug-in, raw post-processing tool
- 移动安全必备之CS呢【NETHUNTER】
- Find out the data that can match the keyword key in field 1 or field 2 in the database table. If you want to display the matching data in field 1 first
猜你喜欢

Design a MySQL table for message queue to store message data

Redis实现短信验证码登录

Zhengzhou University of light industry -- development and sharing of harmonyos pet health system

Industry reshuffle, a large number of programmers are going to lose their jobs? How can we break the current workplace dilemma

Leetcode 2200. 找出数组中的所有 K 近邻下标(可以,一次过)

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

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

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)

Enterprise wechat H5_ Authentication, H5 application web page authorization login to obtain identity

Tableau
随机推荐
AWS lambda: how to store secrets to external APIs- AWS Lambda: How to store secret to external API?
How about opening a securities account in flush? Is it safe or not
Test platform series (97) perfect the case part
[leetcode] understanding and usage of map[key]+
启牛帮开通的股票账户是安全可信的吗?
Design MySQL table structure for message queue to store information data
Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
Ast, really fragrant
设计消息队列存储信息数据的MySQL表结构
It is meaningful to define genus, and D can use it to explain semantics
Shardingsphere-proxy-5.0.0 deployment table implementation (I)
For product managers, which of the two certificates, PMP and NPDP, is more authoritative?
leaflet如何优雅的展示重叠点位的气泡窗口
Based on three JS offshore wind power digital twin 3D effect
2022起重机械指挥上岗证题目模拟考试平台操作
Hongmeng starts 2
设计消息队列存储消息数据的 MySQL 表格
2022 operation of simulated examination platform for hoisting machinery command certificate
Find out the data that can match the keyword key in field 1 or field 2 in the database table. If you want to display the matching data in field 1 first
自动获取结构体内部成员变量的位置偏移