当前位置: 首页 > news >正文

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

前文链接: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.lryc.cn/news/346597.html

相关文章:

  • 如何在Java项目中使用Spring Boot快速连接达梦数据库(DM)
  • QT中的容器
  • 安卓手机APP开发__屏幕兼容性概述
  • Java实现自定义注解,实现不需要token 验证就可以访问接口
  • SpringBoot集成Minio
  • Colab/PyTorch - 003 Transfer Learning For Image Classification
  • 数据结构深入理解--栈
  • Maven 的仓库、周期和插件
  • parallels desktop19最新免费Mac电脑虚拟机软件
  • 波动性悖论:为何低风险股票长期跑赢高风险对手?
  • 环信设置头像昵称(安卓android)版
  • Rust:用 Warp 库实现 Restful API 的简单示例
  • 【SpringBoot】 什么是springboot(一)?如何搭建springboot项目?
  • 从loss角度理解LLM涌现能力
  • debian apt 更改阿里源
  • Spring Cloud | “微服务“ 架构 与 Spring Cloud
  • win10禁止自动更新的终极方法
  • 笨方法自学python(二)-注释
  • wireshark的安装使用及相关UDP、TCP、 ARP
  • 【软考】模拟考卷错题本2024-05-11
  • VMware虚拟机提示内存不足
  • 视频批量剪辑指南:一键合并视频并添加背景音乐,高效便捷
  • 讲讲C++四种类型转换
  • 探索LLM在广告领域的应用——大语言模型的新商业模式和新个性化广告的潜力
  • MBR与GPT分区表
  • OGG几何内核开发-BRepAlgoAPI_Fuse与BRep_Builder.MakeCompound比较
  • C语言 | Leetcode C语言题解之第67题二进制求和
  • 油泼辣子在食品类别可以申请成商标不!
  • 深入探索MySQL视图
  • C语言逻辑语句