QGraphicsView实现简易地图8『缓存视口周边瓦片』

embedded/2024/9/24 16:29:55/

前文链接:QGraphicsView实现简易地图7『异步加载-多瓦片-无底图』
前7篇的地图加载,都采用最少瓦片数量的算法,即用最少数量的瓦片覆盖视口,以获得最快的加载速度。但是这样会带来一个问题,那就是每当移动地图时,视口周边的瓦片才会加载,这样会造成地图的延时甚至卡顿,而这会令用户感到非常反感。为此,需要在之前的算法上进行改进,即加载覆盖视口的最少瓦片后,立即加载视口周边瓦片。
1、动态演示效果

2、获取视口及周边瓦片代码:以视口宽高的一半向四周扩展

QRect CommonUtility::getViewAndAroundTileCoords(int tempTileTop, int tileLeft, int tempTileBottom, int tileRight, int level, vector<TileCoord> &vecTileCoord)
{// <1> 视口for (int row = tempTileTop; row <= tempTileBottom; ++row){for (int col = tileLeft; col <= tileRight; ++col){vecTileCoord.push_back(TileCoord(col, row));}}int mapSize = pow(2, level);int tileW = tileRight - tileLeft + 1;int tileH = tempTileBottom - tempTileTop + 1;int tempTileT, tempTileL, tempTileB, tempTileR;int tileT, tileL, tileB, tileR;// <2> 上侧tileT = tempTileT = qMax(tempTileTop - tileH / 2, 0);tempTileB = tempTileTop - 1;tempTileL = qMax(tileLeft - tileW / 2, 0);	tempTileR = qMin(tileRight + tileW / 2, mapSize - 1);for (int row = tempTileT; row <= tempTileB; ++row){for (int col = tempTileL; col <= tempTileR; ++col){vecTileCoord.push_back(TileCoord(col, row));}}// <3> 下侧tempTileT = tempTileBottom + 1;tileB = tempTileB = qMin(tempTileBottom + tileH / 2, mapSize - 1);tempTileL = qMax(tileLeft - tileW / 2, 0);tempTileR = qMin(tileRight + tileW / 2, mapSize - 1);for (int row = tempTileT; row <= tempTileB; ++row){for (int col = tempTileL; col <= tempTileR; ++col){vecTileCoord.push_back(TileCoord(col, row));}}// <4> 左侧tileL = tempTileL = qMax(tileLeft - tileW / 2, 0);tempTileR = tileLeft - 1;for (int row = tempTileTop; row <= tempTileBottom; ++row){for (int col = tempTileL; col <= tempTileR; ++col){vecTileCoord.push_back(TileCoord(col, row));}}// <5> 右侧tempTileL = tileRight + 1;tileR = tempTileR = qMin(tileRight + tileW / 2, mapSize - 1);for (int row = tempTileTop; row <= tempTileBottom; ++row){for (int col = tempTileL; col <= tempTileR; ++col){vecTileCoord.push_back(TileCoord(col, row));}}return QRect(tileL, tileT, (tileR - tileL + 1), (tileB - tileT + 1));
}



http://www.ppmy.cn/embedded/32665.html

相关文章

【Linux】Linux下使用ps命令的详尽指南

我把我唱给你听 把你纯真无邪的笑容给我吧 我们应该有快乐的 幸福的晴朗的时光 我把我唱给你听 用我炙热的感情感动你好吗 岁月是值得怀念的留恋的 害羞的红色脸庞 谁能够代替你呀 趁年轻尽情的爱吧 最最亲爱的人啊 路途遥远我们在一起吧 &#x1f3b5; 叶…

办公数据分析利器:Excel与Power Query透视功能

数据分析利器&#xff1a;Excel与Power Query透视功能 Excel透视表和Power Query透视功能是强大的数据分析工具&#xff0c;它们使用户能够从大量数据中提取有意义的信息和趋势&#xff0c;可用于汇总、分析和可视化大量数据。 本文通过示例演示Power Query透视功能的一个小技…

JVM-01

JVM&#xff08;Java虚拟机&#xff09;是Java平台的核心组件之一&#xff0c;它是一个虚拟计算机&#xff0c;可以执行Java字节码文件。JVM解释并执行Java字节码&#xff0c;并提供了其他功能&#xff0c;如内存管理和垃圾回收。 JVM的基本功能包括以下几个方面&#xff1a; …

基于MQTT通信开发的失物招领小程序

项目架构设计 这个项目采用前后端分离的方式&#xff0c;重新设计了两条链路来支撑程序的信息获取和传递 前端的小程序页面再启动页面渲染时&#xff0c;直接通过DBAPI从后端数据库获取信息&#xff0c;直接渲染在小程序中项目中给DBAPI的定位是快速从后端获取信息&#xff0…

Debian系统的开机启动和进程看护

1.推荐的做法 - systemctl systemctl&#xff0c;这种做法需要事先编辑一个.service的脚本放在/etc/systemd/system&#xff0c;这里有一个例子&#xff1a; [Unit] DescriptionGuide Rtsp Server - using mediamtx Afternetwork.target[Service] Typesimple WorkingDirecto…

RabbitMQ之消费者批量消费

为什么要用消费端批量消费&#xff1f; 在一些业务场景下&#xff0c;我们希望使用 Consumer 批量消费消息&#xff0c;提高消费速度。可以通过对 SimpleRabbitListenerContainerFactory 进行配置实现批量消费能力 >配置类 Configuration public class ConsumerConfigurati…

VISO流程图之子流程的使用

子流程的作用 整个流程图的框图多而且大&#xff0c;进行分块&#xff1b;让流程图简洁对于重复使用的流程&#xff0c;可以归结为一个子流程图&#xff0c;方便使用&#xff0c;避免大量的重复性工作&#xff1b; 新建子流程 方法1&#xff1a; 随便布局 框选3 和4 &#…

深入理解 GMP:使用GNU多精度库进行高精度计算

目录标题 1. GMP库简介2. GMP库的核心功能3. 安装GMP库在Unix-like系统上&#xff1a;在macOS上&#xff1a;在Windows上&#xff1a; 4. GMP的优势和应用5. gmp-6.2.1特性和优化安装GMP 6.2.1使用GMP 6.2.1进行编程 6. 总结 高精度计算在科学研究、金融分析、加密算法以及任何…