QGraphicsView实现简易地图1『加载离线瓦片地图』

最简单粗暴的加载方式,将每一层级的所有瓦片地图全部加载
注:该方式仅能够在瓦片地图层级较低时使用,否则卡顿!!!

瓦片地图数据来源:水经注-高德地图-卫星地图
瓦片地图瓦片大小:256 * 256像素
瓦片地图坐标投影:GCJ02 Web 墨卡托投影

1、动态演示效果:

2、静态展示图片:

核心代码

1、场景粗暴加载瓦片地图
QGraphicsView实现简易地图1『加载离线瓦片地图』_第1张图片

void MapScene::wheelEvent(QGraphicsSceneWheelEvent *wheelEvent)
{
	wheelEvent->delta() > 0 ? ++m_curLevel : --m_curLevel;
	clear();

	double len = PIXMAP_SIZE * pow(2, m_curLevel);
	setSceneRect(QRect(0, 0, len, len));
	updateScene();

	QGraphicsScene::wheelEvent(wheelEvent);
}
void MapScene::updateScene()
{
	QString dirPath = QString("F:/MapData/GaoDeMap/Map/MapPng/L0%1").arg(m_curLevel + 1);
	int size = pow(2, m_curLevel);
	for (int row = 0; row < size; ++row)
	{
		for (int col = 0; col < size; ++col)
		{
			QString fileName = QString("%1/Map_%2-%3.png").arg(dirPath)
				.arg(QString::number(row + 1).rightJustified(2, '0')).arg(QString::number(col + 1).rightJustified(2, '0'));
			QPixmap pixmap(fileName);
			QGraphicsPixmapItem *item = new QGraphicsPixmapItem(pixmap);
			item->setPos(PIXMAP_SIZE * col, PIXMAP_SIZE * row);
			addItem(item);
		}
	}
}

你可能感兴趣的:(项目,qt,c++,开发语言)