@@ -173,6 +173,59 @@ std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) {
173173 z);
174174}
175175
176+ std::vector<UnwrappedTileID> tileCoverWithLOD (const TransformState& state, int32_t z, int32_t minZ) {
177+ assert (state.valid ());
178+
179+ const double w = state.getSize ().width ;
180+ const double h = state.getSize ().height ;
181+
182+ const auto offset = state.getCenterOffset ();
183+ constexpr double zoomDiff = 1.0 ;
184+ constexpr double coefLOD[] = {
185+ 0.55 * zoomDiff / (zoomDiff + 1 ),
186+ 0.55 * (zoomDiff + 1 ) / (zoomDiff + 2 ),
187+ 0.55 * (zoomDiff + 2 ) / (zoomDiff + 3 )
188+ };
189+ // Tangens of field of view above center.
190+ const double tanFov = (h * 0.5 + offset.y ) / (1.5 * h);
191+
192+ std::vector<UnwrappedTileID> result;
193+ double top = 0.0 ;
194+ double bottom = 0.0 ;
195+
196+ for (size_t i = 0 ; top < h && i <= std::extent<decltype (coefLOD)>::value; i++, z--) {
197+ if (z == minZ || i == std::extent<decltype (coefLOD)>::value) {
198+ top = h; // final pass, get all to the top.
199+ } else {
200+ const double treshold = state.getPitch () ? : (h * 0.5 + offset.y );
201+ top = std::min (h, treshold );
202+ top = state.getPitch ()
203+ ? std::min (h, h * 0.5 - offset.y + h * coefLOD[i] / (tanFov * std::tan (state.getPitch ())))
204+ : h;
205+ }
206+ std::vector<UnwrappedTileID> cover = tileCover (
207+ TileCoordinate::fromScreenCoordinate (state, z, { 0 , top }).p ,
208+ TileCoordinate::fromScreenCoordinate (state, z, { w, top }).p ,
209+ TileCoordinate::fromScreenCoordinate (state, z, { w, bottom }).p ,
210+ TileCoordinate::fromScreenCoordinate (state, z, { 0 , bottom }).p ,
211+ TileCoordinate::fromScreenCoordinate (state, z, { w/2 , h/2 }).p ,
212+ z);
213+ bottom = top;
214+ if (i == 0 ) {
215+ if (top == h) {
216+ return cover;
217+ }
218+ std::swap (result, cover);
219+ continue ;
220+ }
221+ result.insert (
222+ result.end (),
223+ std::make_move_iterator (cover.begin ()),
224+ std::make_move_iterator (cover.end ()));
225+ }
226+ return result;
227+ }
228+
176229std::vector<UnwrappedTileID> tileCover (const Geometry<double >& geometry, int32_t z) {
177230 std::vector<UnwrappedTileID> result;
178231 TileCover tc (geometry, z, true );
0 commit comments