File indexing completed on 2025-01-19 06:43:39
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2016 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #include "TileIterator.h" 0007 0008 #include "GeoSceneMercatorTileProjection.h" 0009 0010 #include <QDebug> 0011 0012 namespace Marble { 0013 0014 TileIterator::const_iterator const TileIterator::s_end = TileIterator(); 0015 0016 const TileIterator &TileIterator::operator*() 0017 { 0018 return *this; 0019 } 0020 0021 bool TileIterator::operator!=(const TileIterator::const_iterator &other) const 0022 { 0023 return m_state != other.m_state; 0024 } 0025 0026 TileIterator::const_iterator &TileIterator::operator++() 0027 { 0028 if (m_state.x() >= m_bounds.right()) { 0029 m_state.setX(m_bounds.left()); 0030 if (m_state.y() < m_bounds.bottom()) { 0031 ++m_state.ry(); 0032 } else { 0033 *this = s_end; 0034 } 0035 } else { 0036 ++m_state.rx(); 0037 } 0038 return *this; 0039 } 0040 0041 TileIterator::TileIterator(const GeoDataLatLonBox &latLonBox, int zoomLevel) 0042 { 0043 const GeoSceneMercatorTileProjection tileProjection; 0044 0045 m_bounds = tileProjection.tileIndexes(latLonBox, zoomLevel); 0046 } 0047 0048 TileIterator::const_iterator TileIterator::begin() const 0049 { 0050 TileIterator iter = *this; 0051 iter.m_state = iter.m_bounds.topLeft(); 0052 return iter; 0053 } 0054 0055 TileIterator::const_iterator TileIterator::end() const 0056 { 0057 return s_end; 0058 } 0059 0060 int TileIterator::x() const 0061 { 0062 return m_state.x(); 0063 } 0064 0065 int TileIterator::y() const 0066 { 0067 return m_state.y(); 0068 } 0069 0070 int TileIterator::total() const 0071 { 0072 return m_bounds.width() * m_bounds.height(); 0073 } 0074 0075 TileIterator::TileIterator() : 0076 m_state(-1, -1) 0077 { 0078 // nothing to do 0079 } 0080 0081 }