NDEVR
API Documentation
WebMercatorTiledImageManager.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: NDEVR
28File: WebMercatorTiledImageManager
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/ProgressInfo.h>
34#include <NDEVR/MercatorImageManager.h>
35#include <NDEVR/Pointer.h>
36#include <NDEVR/QueueBuffer.h>
37#include <NDEVR/Dictionary.h>
38#include <NDEVR/UUID.h>
39#include <QImage>
40class QNetworkAccessManager;
41namespace NDEVR
42{
62
119
123 class OpenStreetMapWebMercatorTileService : public WebMercatorTileService
124 {
125 public:
126 OpenStreetMapWebMercatorTileService() = default;
127 virtual ~OpenStreetMapWebMercatorTileService() = default;
128 OpenStreetMapWebMercatorTileService(const OpenStreetMapWebMercatorTileService& other) = default;
129 OpenStreetMapWebMercatorTileService(OpenStreetMapWebMercatorTileService&& other) = default;
130 OpenStreetMapWebMercatorTileService& operator=(const OpenStreetMapWebMercatorTileService& other) = default;
131 OpenStreetMapWebMercatorTileService& operator=(OpenStreetMapWebMercatorTileService&& other) = default;
132
137 String getUrl(WebMercatorTile tile, const MercatorImageRequest& request) const final override;
142 UUID getUUID(WebMercatorTile tile, const MercatorImageRequest& request) const final override;
148 Buffer<WebMercatorTile::DPI> getSupportedDPIs() const final override;
149 };
150
159
164 {
165 public:
167 enum class TileLocation
168 {
170 e_north_east,
171 e_south_west,
172 e_south_east,
173 e_north_west,
174 };
175
182 static fltp08 EPSG4326(uint01 dim, fltp08 lon_deg, uint01 z, fltp08 scale_factor = 1.0);
183
190 fltp08 tile_x_to_EPSG4326_lon_deg(uint04 x, uint04 z, TileLocation location, fltp08 scale_factor = 1.0) const;
197 fltp08 tile_x_to_EPSG4326_lon_deg(uint04 x, uint04 z, fltp08 percent_x, fltp08 scale_factor = 1.0) const;
198
205 fltp08 tile_y_to_EPSG4326_lat_deg(uint04 y, uint04 z, TileLocation location, fltp08 scale_factor = 1.0) const;
212 fltp08 tile_y_to_EPSG4326_lat_deg(uint04 y, uint04 z, fltp08 percent_y, fltp08 scale_factor = 1.0) const;
213
219 static Bounds<2, fltp08> TileSpace(Bounds<2, fltp08> lat_long_bounds, Vector<2, uint04> size, fltp08 scale_factor = 1.0);
224 static uint01 CalcZoom(Bounds<2, fltp08> lat_long_bounds_wgs84_dd, Vector<2, uint04> size);
225
226 public:
230 };
231
236 {
237 public:
241 static void Initialize();
242
250 bool getTile(const WebMercatorTileRequest& request);
255 virtual bool postRequest(const MercatorImageRequest& request, std::function<void(const MercatorImage&)> finished_callback) override;
259 virtual bool postRequest(const AerialImageRequest& request) override;
264 bool getImage(const MercatorImageRequest& request, std::function<void(const MercatorImage&)> finished_callback);
265 public:
274 void setDevicePixelRatio(fltp08 device_pixel_ratio) override { m_device_pixel_ratio = device_pixel_ratio; };
275 protected:
279 bool getImage(const AerialImageRequest& request);
283 void finish(const String& id, const WebMercatorTileRequest& request);
287 bool hasPendingRequest(const UUID& id) const;
292 void finish(bool success, const MercatorImageRequest& request, std::function<void(const MercatorImage&)> finished_callback);
300 QNetworkAccessManager* m_network_manager = nullptr;
301 UUID m_wgs_84 = Constant<UUID>::Invalid;
302 friend class MercatorProcessThread;
303#if NDEVR_SUPPORTS_THREADING
304 MercatorProcessThread* m_thread;
305#endif
307 };
308}
309
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:54
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
Provides coordinate conversion utilities between EPSG:4326 (WGS84) and tile coordinates.
TileLocation
Specifies a position within a map tile.
fltp08 tile_x_to_EPSG4326_lon_deg(uint04 x, uint04 z, TileLocation location, fltp08 scale_factor=1.0) const
Converts a tile X coordinate to longitude in degrees.
static uint01 CalcZoom(Bounds< 2, fltp08 > lat_long_bounds_wgs84_dd, Vector< 2, uint04 > size)
Calculates the optimal zoom level for a geographic bounds and pixel size.
static EPSG4326TileHelper & DefaultHelper()
Returns the singleton helper instance.
fltp08 tile_y_to_EPSG4326_lat_deg(uint04 y, uint04 z, TileLocation location, fltp08 scale_factor=1.0) const
Converts a tile Y coordinate to latitude in degrees.
static fltp08 EPSG4326(uint01 dim, fltp08 lon_deg, uint01 z, fltp08 scale_factor=1.0)
Converts a geographic coordinate to tile space.
fltp08 tile_x_to_EPSG4326_lon_deg(uint04 x, uint04 z, fltp08 percent_x, fltp08 scale_factor=1.0) const
Converts a tile X coordinate to longitude using a fractional position.
static Bounds< 2, fltp08 > TileSpace(Bounds< 2, fltp08 > lat_long_bounds, Vector< 2, uint04 > size, fltp08 scale_factor=1.0)
Computes the tile space bounds for a geographic bounding box.
fltp08 tile_y_to_EPSG4326_lat_deg(uint04 y, uint04 z, fltp08 percent_y, fltp08 scale_factor=1.0) const
Converts a tile Y coordinate to latitude using a fractional position.
Buffer< WebMercatorTile::DPI > getSupportedDPIs() const final override
Returns the DPI values supported by this service.
String getUrl(WebMercatorTile tile, const MercatorImageRequest &request) const final override
Builds the URL for fetching a specific tile.
GoogleLayer
The available Google Maps layer types.
@ e_hybrid
Satellite imagery with road overlay.
UUID getUUID(WebMercatorTile tile, const MercatorImageRequest &request) const final override
Returns a unique identifier for a specific tile request.
GoogleWebMercatorTileService(GoogleLayer layer)
Constructs a Google tile service for the specified layer.
Buffer< WebMercatorTile::Resolution > getSupportedResolutions() const final override
Returns the tile resolutions supported by this service.
GoogleLayer m_layer
The active Google Maps layer.
static uint04 URLFeatureCode(ArialFeatureList item)
Returns the URL feature code for an aerial feature list item.
void buildSecrets(WebMercatorTile tile, String &secret_1, String &secret_2) const
Builds authentication secret strings for a tile request.
String m_secret
The authentication secret for tile requests.
MercatorImageManager()
Constructor.
void setDevicePixelRatio(fltp08 device_pixel_ratio) override
Sets the device pixel ratio for high-DPI displays.
static MercatorWebImageManager & DefaultManager()
Returns the singleton default manager instance.
bool hasPendingRequest(const UUID &id) const
Checks whether a request with the given ID is pending.
void executePendingRequest(const UUID &id)
Executes the next pending tile request for the given ID.
bool getTile(const WebMercatorTileRequest &request)
Fetches a single map tile.
void finish(bool success, const MercatorImageRequest &request, std::function< void(const MercatorImage &)> finished_callback)
Handles completion of a full image composition.
static void Initialize()
Initializes the global tile services and network manager.
ProgressInfo m_progress
Tracks progress of ongoing tile fetch operations.
virtual bool postRequest(const MercatorImageRequest &request, std::function< void(const MercatorImage &)> finished_callback) override
Posts an image request with a completion callback.
bool getImage(const AerialImageRequest &request)
Fetches a composed image for the given aerial request.
virtual bool postRequest(const AerialImageRequest &request) override
Posts an aerial image request.
fltp08 devicePixelRatio() const
Returns the current device pixel ratio.
MercatorProcessThread * m_thread
The background processing thread for tile requests.
UUID m_wgs_84
The WGS84 coordinate system UUID.
void finish(const String &id, const WebMercatorTileRequest &request)
Handles completion of a single tile fetch.
Dictionary< UUID, UUID > m_image_get_id
Maps image request IDs to tile service IDs.
fltp08 m_device_pixel_ratio
The device pixel ratio for high-DPI rendering.
Dictionary< UUID, QImage > m_image_buffers
Partially composed tile images per request ID.
bool getImage(const MercatorImageRequest &request, std::function< void(const MercatorImage &)> finished_callback)
Fetches a composed image from tiles with a completion callback.
QNetworkAccessManager * m_network_manager
The Qt network access manager for HTTP requests.
Dictionary< UUID, QueueBuffer< WebMercatorTileRequest > > m_pending_web_requests
Queued tile requests per request ID.
DynamicPointer< WebMercatorTileService > defaultService(AerialImageMode mode) const override
Returns the default tile service for the given aerial image mode.
MercatorWebImageManager()
Constructs the MercatorWebImageManager.
Buffer< WebMercatorTile::DPI > getSupportedDPIs() const final override
Returns the DPI values supported by this service.
Buffer< WebMercatorTile::Resolution > getSupportedResolutions() const final override
Returns the tile resolutions supported by this service.
String getUrl(WebMercatorTile tile, const MercatorImageRequest &request) const final override
Builds the URL for fetching a specific tile.
UUID getUUID(WebMercatorTile tile, const MercatorImageRequest &request) const final override
Returns a unique identifier for a specific tile request.
Used with InfoPipe to signal that the system will be using progress.
The core String class for the NDEVR API.
Definition String.h:95
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
WebMercatorTileService()=default
Default constructor.
The primary namespace for the NDEVR SDK.
ArialFeatureList
Contains a list of common features that may be provided by Aerial tile services.
@ e_center
Center text both horizontally and vertically.
Definition Font.h:327
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
AerialImageMode
enum specifying what type of image to fetch.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Contains the information for requesting a 2D top-down view of a geographic location to be used with a...
Contains the information for requesting a 2D top-down view of a geographic location to be used with a...
Information output from a specific Aerial Tile request.
Contains the reply data from a Web Mercator tile fetch request.
Vector< 2, uint04 > tile_location
The tile grid location.
QImage image
The fetched tile image.
bool success
Whether the tile fetch was successful.
Encapsulates a request for a single Web Mercator map tile.
WebMercatorTileRequest(MercatorImageRequest request, WebMercatorTile tile)
Constructs a tile request from an image request and tile identifier.
MercatorImageRequest request
The parent image request parameters.
WebMercatorTileRequest()
Default constructor.
WebMercatorTile tile
The tile coordinates and zoom level.
std::function< void(WebMercatorTileReply &reply)> finished_callback
Callback invoked when the tile fetch completes.
A Web Mercator map tile descriptor containing coordinates, zoom level, and display settings.