mercator.h
Go to the documentation of this file.
1 /* Copyright 2018-2019 TomTom N.V., 2014 Gareth Cross
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7 http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14 
15 #pragma once
16 
17 #include <cmath>
18 
20 static constexpr int MAX_BLOCKS = 8;
21 
23 static constexpr int MAX_ZOOM = 22;
24 
31 inline float zoomToResolution(double lat, int zoom)
32 {
33  float constexpr METER_PER_PIXEL_ZOOM_0 = 156543.034;
34 
35  float const lat_rad = lat * M_PI / 180;
36  return METER_PER_PIXEL_ZOOM_0 * std::cos(lat_rad) / (1 << zoom);
37 }
38 
42 inline int zoomToMaxTiles(int zoom)
43 {
44  return (1 << zoom) - 1;
45 }
46 
50 inline double getTileWH(double const latitude, int const zoom)
51 {
52  // this constant origins from how the base resolution is calculated
53  // see https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
54 
55  // TODO: actually this not needed and could be removed from both formulas, since they cancel out each other;
56  // it origins from most tile map applications directly rendering images with pixel dimensions;
57  // in here we have OpenGL, pixel do not matter, only meters
58  int constexpr tile_w_h_px = 256;
59 
60  // meter/pixel
61  auto const resolution = zoomToResolution(latitude, zoom);
62  // gives tile size (with and height) in meter
63  double const tile_w_h_m = tile_w_h_px * resolution;
64 
65  return tile_w_h_m;
66 }
int zoomToMaxTiles(int zoom)
Definition: mercator.h:42
static constexpr int MAX_BLOCKS
Max number of adjacent blocks to support.
Definition: mercator.h:20
double getTileWH(double const latitude, int const zoom)
Definition: mercator.h:50
static constexpr int MAX_ZOOM
Max zoom level to support.
Definition: mercator.h:23
float zoomToResolution(double lat, int zoom)
Definition: mercator.h:31


rviz_satellite
Author(s): Gareth Cross , Andre Schröder
autogenerated on Thu May 4 2023 02:31:43