tile_id.cpp
Go to the documentation of this file.
1 /* Copyright 2018-2019 TomTom N.V.
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 #include "tile_id.h"
16 
17 #include <boost/algorithm/string/replace.hpp>
18 #include <boost/functional/hash/hash.hpp>
19 namespace
20 {
26 std::string toString(double num)
27 {
28  std::stringstream ss;
29  ss.imbue(std::locale::classic());
30  ss.precision(6);
31  ss << std::fixed << num;
32  return ss.str();
33 }
34 }
35 std::string tileURL(TileId const& tile_id)
36 {
37  auto url = tile_id.tile_server;
38 
39  // compute latitude and longitude from tile coordinates
40  const auto wgs = toWGSCoordinate(tile_id.coord, tile_id.zoom);
41 
42  // substitute placeholders
43  boost::replace_all(url, "{lat}", toString(wgs.lat));
44  boost::replace_all(url, "{lon}", toString(wgs.lon));
45  boost::replace_all(url, "{x}", std::to_string(tile_id.coord.x));
46  boost::replace_all(url, "{y}", std::to_string(tile_id.coord.y));
47  boost::replace_all(url, "{z}", std::to_string(tile_id.zoom));
48 
49  return url;
50 }
51 
52 size_t std::hash<TileId>::operator()(TileId const& tile_id) const
53 {
54  size_t seed{};
55  boost::hash_combine(seed, tile_id.tile_server);
56  boost::hash_combine(seed, tile_id.coord.x);
57  boost::hash_combine(seed, tile_id.coord.y);
58  boost::hash_combine(seed, tile_id.zoom);
59  return seed;
60 }
std::string tileURL(TileId const &tile_id)
Definition: tile_id.cpp:35
std::string tile_server
Definition: tile_id.h:33
TileCoordinate coord
Definition: tile_id.h:34
WGSCoordinate toWGSCoordinate(TileCoordinateGeneric< NumericType > coord, int zoom)
Definition: coordinates.h:83
int zoom
Definition: tile_id.h:35
size_t operator()(TileId const &tile_id) const
Definition: tile_id.cpp:52
Definition: tile_id.h:31


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