@@ -173,6 +173,56 @@ std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) {
173
173
z);
174
174
}
175
175
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.5 * zoomDiff / (zoomDiff + 1 ),
186
+ 0.5 * (zoomDiff + 1 ) / (zoomDiff + 2 ),
187
+ 0.5 * (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 * coefLOD[i] / (tanFov * std::tan (state.getPitch ())) : 0.0 ;
201
+ top = std::min (h, treshold + h * 0.5 - offset.y );
202
+ }
203
+ std::vector<UnwrappedTileID> cover = tileCover (
204
+ TileCoordinate::fromScreenCoordinate (state, z, { 0 , top }).p ,
205
+ TileCoordinate::fromScreenCoordinate (state, z, { w, top }).p ,
206
+ TileCoordinate::fromScreenCoordinate (state, z, { w, bottom }).p ,
207
+ TileCoordinate::fromScreenCoordinate (state, z, { 0 , bottom }).p ,
208
+ TileCoordinate::fromScreenCoordinate (state, z, { w/2 , h/2 }).p ,
209
+ z);
210
+ bottom = top;
211
+ if (i == 0 ) {
212
+ if (top == h) {
213
+ return cover;
214
+ }
215
+ std::swap (result, cover);
216
+ continue ;
217
+ }
218
+ result.insert (
219
+ result.end (),
220
+ std::make_move_iterator (cover.begin ()),
221
+ std::make_move_iterator (cover.end ()));
222
+ }
223
+ return result;
224
+ }
225
+
176
226
std::vector<UnwrappedTileID> tileCover (const Geometry<double >& geometry, int32_t z) {
177
227
std::vector<UnwrappedTileID> result;
178
228
TileCover tc (geometry, z, true );
0 commit comments