当前位置:网站首页>How to load 100000 pieces of data in leaflet
How to load 100000 pieces of data in leaflet
2022-06-12 23:42:00 【GIS weapon warehouse】
As a GIS developer , You must have encountered this kind of problem in your work , According to business design , You need to add... To the map 1 ten thousand + Data , Data or points 、 Or a thread 、 Or face . But either way , When you add to 5000 Stripe time , The map operation will cause obvious jamming . When you add more than 1 Ten thousand times , Data loading will get stuck , The browser is stuck , After the map is loaded , Every time you move the map , Have to wait patiently for a few seconds .
This interactive experience , Users can't accept it , There are usually two solutions , One is to do in-depth user needs analysis , See what users want to see when they want to load so much data at once , This thing I want to see , Whether it can be realized through other technical methods . The other is the hard hitting technique , Study how to improve map performance . We will only discuss the second case today .
canvas Rendering mode
leaflet Two rendering modes are supported ,svg and canvas, The default is svg Rendering , This allows compatibility with lower versions of IE browser .canvas Rendering requires IE9+, Or Google 、 Firefox's advanced browser .canvas Than svg Good performance , I did a simple test myself ,svg Pattern loading 5000 A Caton condition that occurs when a picture is marked , use canvas Pattern , load 10 Million data .
Here's how to switch to canvas Pattern , There are two steps :
One , When initializing the map , Set up map Of preferCanvas The attribute is true, The code is as follows :
var map = L.map('map', {
center: [39.905963, 116.390813],
zoom: 13,
preferCanvas: true
});
This setting only applies to inheritance Path The vector layer of class is valid , Include dots (CircleMarker)、 Line (Polyline)、 Noodles (Polygon)、 round (Circle)、 rectangular (Rectangle). Mark for picture (Marker) It doesn't work .
Two 、 With plug-ins Leaflet.Canvas-Markers, promote Marker Display performance of . plug-in unit git Address :https://github.com/eJuke/Leaflet.Canvas-Markers
Leaflet.Canvas-Markers plug-in unit
Leaflet.Canvas-Markers The plug-in provides a L.canvasIconLayer class , This class is a layer , take Marker When added to this layer , This layer will be displayed as canvas Mode rendering Marker Picture in .
How to use
stay html Introduce plug-in in
<script src="leaflet.canvas-markers.js"></script>
establish canvasIconLayer Layers , Add layers to the map , Add picture tags to layers .
// Create Layer , Add to map
var ciLayer = L.canvasIconLayer({
}).addTo(map);
// Definition Marker
var marker = L.marker([58.5578, 29.0087], {
icon: icon});
// hold Marker Add to layer
ciLayer.addMarker(marker);
Be careful
There is a problem with this plugin , When the map is zoomed , The added data is not scaled synchronously , Instead, wait until the zoom is complete , Then zoom . It feels like scaling , The data is floating .
But someone has proposed a solution to this problem , And solved ( link ), Just the code has not been merged . But it doesn't matter , We can use the code that has been solved ( link )
The effect after the solution :
Complete code
summary
- leaflet Two rendering modes are supported ,svg and canvas,canvas The display performance of is obviously better than svg.
- IE9 Previous versions of browsers do not support canvas Mode rendering .
- The default is svg Mode rendering , To manually switch to canvas The way .
- The rendering mode is set to canvas after , Loading vector graphics improves performance , Loading picture tags is still inefficient .
- adopt Leaflet.Canvas-Markers Plug in to improve the display efficiency of image tags .
- Leaflet.Canvas-Markers The plug-in has bug, Need to be in github This problem has been solved on bug Version of .
Original address :http://gisarmory.xyz/blog/index.html?blog=leaflet100ThousandData
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 .
边栏推荐
- dict和set的基本操作
- 基于Three.js海上风电数字孪生三维效果
- Design a MySQL table for message queue to store message data
- PyTorch常用参数初始化方法:【均匀分布、正态(高斯)分布、Xavier、kaiming、正交矩阵、稀疏矩阵、常数、单位矩阵、零填充】
- How does idea switch the interface to Chinese
- Embedded pipeline out of the box
- [leetcode] understanding and usage of map[key]+
- Save state when viewpager is used with fragment fragmentpageradapter
- 设计消息队列存储消息数据的 MySQL 表格
- 2202-簡曆制作
猜你喜欢

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

Preparing for the Blue Bridge Cup Day11__ Basic operation of serial port communication

Teach you how to grab ZigBee packets through cc2531 and parse encrypted ZigBee packets

Redis实现短信验证码登录

For product managers, which of the two certificates, PMP and NPDP, is more authoritative?

MySQL基础篇视图的总结

SAP QM qp03 displays an inspection plan with multiple specs inspection features

Running of NCF dapr application instance

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

Alien Skin Exposure X7调色滤镜插件,RAW后期处理工具
随机推荐
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
MySQL row to column, column to row, multiple columns to one row, one row to multiple columns
The programmer has worked for 7 years. At the age of 31, he has no choice but to deliver takeout. I really don't want you to go through his journey again
测试平台系列(97) 完善执行case部分
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
Test platform series (97) perfect the case part
AWS lambda: how to store secrets to external APIs- AWS Lambda: How to store secret to external API?
2022年G3锅炉水处理考题模拟考试平台操作
Mgr and greatsql resource summary
深度学习-神经网络:卷积的实现方法【直接法(精度没损失)、GEMM(矩阵乘法,精度没损失)、FFT(傅里叶变换,精度有损失)、Winograd(精度有损失)】
Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
Cherry Blossom powder Dudu
Summary of the lowest level error types in PHP
Comprehensive analysis of C array
Running of NCF dapr application instance
Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
2022年电工(初级)操作证考试题库及在线模拟考试
Novice must see! How rust beginners write gear smart contracts (1)
移动安全必备之CS呢【NETHUNTER】
VS2015 DLIB 1916 USER_ ERROR__ inconsistent_ build_ configuration__ see_ dlib_ faq_ 1 USER_ ERROR__ inconsiste