Skip to content

Commit d2e5b92

Browse files
committed
Add UCesiumUrlTemplateRasterOverlay
1 parent ba15e90 commit d2e5b92

File tree

3 files changed

+290
-1
lines changed

3 files changed

+290
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2+
3+
#include "CesiumUrlTemplateRasterOverlay.h"
4+
5+
#include "CesiumCustomVersion.h"
6+
#include "CesiumGeometry/QuadtreeTilingScheme.h"
7+
#include "CesiumGeospatial/GlobeRectangle.h"
8+
#include "CesiumGeospatial/Projection.h"
9+
#include "CesiumRasterOverlays/UrlTemplateRasterOverlay.h"
10+
11+
#include "CesiumRuntime.h"
12+
13+
std::unique_ptr<CesiumRasterOverlays::RasterOverlay>
14+
UCesiumUrlTemplateRasterOverlay::CreateOverlay(
15+
const CesiumRasterOverlays::RasterOverlayOptions& options) {
16+
if (this->TemplateUrl.IsEmpty()) {
17+
// Don't create an overlay with an empty base URL.
18+
return nullptr;
19+
}
20+
21+
CesiumRasterOverlays::UrlTemplateRasterOverlayOptions urlTemplateOptions;
22+
23+
urlTemplateOptions.minimumLevel = MinimumLevel;
24+
urlTemplateOptions.maximumLevel = MaximumLevel;
25+
26+
urlTemplateOptions.tileWidth = this->TileWidth;
27+
urlTemplateOptions.tileHeight = this->TileHeight;
28+
29+
const CesiumGeospatial::Ellipsoid& ellipsoid = options.ellipsoid;
30+
31+
if (this->Projection ==
32+
ECesiumUrlTemplateRasterOverlayProjection::Geographic) {
33+
urlTemplateOptions.projection =
34+
CesiumGeospatial::GeographicProjection(ellipsoid);
35+
} else {
36+
urlTemplateOptions.projection =
37+
CesiumGeospatial::WebMercatorProjection(ellipsoid);
38+
}
39+
40+
if (bSpecifyTilingScheme) {
41+
CesiumGeospatial::GlobeRectangle globeRectangle =
42+
CesiumGeospatial::GlobeRectangle::fromDegrees(
43+
RectangleWest,
44+
RectangleSouth,
45+
RectangleEast,
46+
RectangleNorth);
47+
CesiumGeometry::Rectangle coverageRectangle =
48+
CesiumGeospatial::projectRectangleSimple(
49+
*urlTemplateOptions.projection,
50+
globeRectangle);
51+
urlTemplateOptions.coverageRectangle = coverageRectangle;
52+
urlTemplateOptions.tilingScheme = CesiumGeometry::QuadtreeTilingScheme(
53+
coverageRectangle,
54+
RootTilesX,
55+
RootTilesY);
56+
}
57+
58+
return std::make_unique<CesiumRasterOverlays::UrlTemplateRasterOverlay>(
59+
TCHAR_TO_UTF8(*this->MaterialLayerKey),
60+
TCHAR_TO_UTF8(*this->TemplateUrl),
61+
std::vector<CesiumAsync::IAssetAccessor::THeader>(),
62+
urlTemplateOptions,
63+
options);
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2+
3+
#pragma once
4+
5+
#include "CesiumRasterOverlay.h"
6+
#include "Components/ActorComponent.h"
7+
#include "CoreMinimal.h"
8+
#include "CesiumUrlTemplateRasterOverlay.generated.h"
9+
10+
/**
11+
* Specifies the type of projection used for projecting a URL template
12+
* raster overlay.
13+
*/
14+
UENUM(BlueprintType)
15+
enum class ECesiumUrlTemplateRasterOverlayProjection : uint8 {
16+
/**
17+
* The raster overlay is projected using Web Mercator.
18+
*/
19+
WebMercator,
20+
21+
/**
22+
* The raster overlay is projected using a geographic projection.
23+
*/
24+
Geographic
25+
};
26+
27+
/**
28+
* A raster overlay that loads tiles from a templated URL.
29+
*/
30+
UCLASS(ClassGroup = (Cesium), meta = (BlueprintSpawnableComponent))
31+
class CESIUMRUNTIME_API UCesiumUrlTemplateRasterOverlay
32+
: public UCesiumRasterOverlay {
33+
GENERATED_BODY()
34+
35+
public:
36+
/**
37+
* @brief The URL containing template parameters that will be substituted when
38+
* loading tiles.
39+
*
40+
* The following template parameters are supported:
41+
* - `{x}` - The tile X coordinate in the tiling scheme, where 0 is the
42+
* westernmost tile.
43+
* - `{y}` - The tile Y coordinate in the tiling scheme, where 0 is the
44+
* nothernmost tile.
45+
* - `{z}` - The level of the tile in the tiling scheme, where 0 is the root
46+
* of the quadtree pyramid.
47+
* - `{reverseX}` - The tile X coordinate in the tiling scheme, where 0 is the
48+
* easternmost tile.
49+
* - `{reverseY}` - The tile Y coordinate in the tiling scheme, where 0 is the
50+
* southernmost tile.
51+
* - `{reverseZ}` - The tile Z coordinate in the tiling scheme, where 0 is
52+
* equivalent to `urlTemplateOptions.maximumLevel`.
53+
* - `{southDegrees}` - The southern edge of the tile in geodetic degrees.
54+
* - `{eastDegrees}` - The eastern edge of the tile in geodetic degrees.
55+
* - `{northDegrees}` - The northern edge of the tile in geodetic degrees.
56+
* - `{westProjected}` - The western edge of the tile in projected coordinates
57+
* of the tiling scheme.
58+
* - `{southProjected}` - The southern edge of the tile in projected
59+
* coordinates of the tiling scheme.
60+
* - `{eastProjected}` - The eastern edge of the tile in projected coordinates
61+
* of the tiling scheme.
62+
* - `{northProjected}` - The northern edge of the tile in projected
63+
* coordinates of the tiling scheme.
64+
* - `{width}` - The width of each tile in pixels.
65+
* - `{height}` - The height of each tile in pixels.
66+
*/
67+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
68+
FString TemplateUrl;
69+
70+
/**
71+
* The type of projection used to project the imagery onto the globe.
72+
* For instance, EPSG:4326 uses geographic projection and EPSG:3857 uses Web
73+
* Mercator.
74+
*/
75+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
76+
ECesiumUrlTemplateRasterOverlayProjection Projection =
77+
ECesiumUrlTemplateRasterOverlayProjection::WebMercator;
78+
79+
/**
80+
* Set this to true to specify the quadtree tiling scheme according to the
81+
* specified root tile numbers and projected bounding rectangle. If false, the
82+
* tiling scheme will be deduced from the projection.
83+
*/
84+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cesium")
85+
bool bSpecifyTilingScheme = false;
86+
87+
/**
88+
* If specified, this determines the number of tiles at the
89+
* root of the quadtree tiling scheme in the X direction.
90+
*
91+
* Only applicable if "Specify Tiling Scheme" is set to true.
92+
*/
93+
UPROPERTY(
94+
EditAnywhere,
95+
BlueprintReadWrite,
96+
Category = "Cesium",
97+
meta = (EditCondition = "bSpecifyTilingScheme", ClampMin = 1))
98+
int32 RootTilesX = 1;
99+
100+
/**
101+
* If specified, this determines the number of tiles at the
102+
* root of the quadtree tiling scheme in the Y direction.
103+
*
104+
* Only applicable if "Specify Tiling Scheme" is set to true.
105+
*/
106+
UPROPERTY(
107+
EditAnywhere,
108+
BlueprintReadWrite,
109+
Category = "Cesium",
110+
meta = (EditCondition = "bSpecifyTilingScheme", ClampMin = 1))
111+
int32 RootTilesY = 1;
112+
113+
/**
114+
* The west boundary of the bounding rectangle used for the quadtree tiling
115+
* scheme. Specified in longitude degrees in the range [-180, 180].
116+
*
117+
* Only applicable if "Specify Tiling Scheme" is set to true.
118+
*/
119+
UPROPERTY(
120+
Category = "Cesium",
121+
EditAnywhere,
122+
BlueprintReadWrite,
123+
meta =
124+
(EditCondition = "bSpecifyTilingScheme",
125+
ClampMin = -180.0,
126+
ClampMax = 180.0))
127+
double RectangleWest = -180;
128+
129+
/**
130+
* The south boundary of the bounding rectangle used for the quadtree tiling
131+
* scheme. Specified in latitude degrees in the range [-90, 90].
132+
*
133+
* Only applicable if "Specify Tiling Scheme" is set to true.
134+
*/
135+
UPROPERTY(
136+
Category = "Cesium",
137+
Category = "Cesium",
138+
EditAnywhere,
139+
BlueprintReadWrite,
140+
meta =
141+
(EditCondition = "bSpecifyTilingScheme",
142+
ClampMin = -90.0,
143+
ClampMax = 90.0))
144+
double RectangleSouth = -90;
145+
146+
/**
147+
* The east boundary of the bounding rectangle used for the quadtree tiling
148+
* scheme. Specified in longitude degrees in the range [-180, 180].
149+
*
150+
* Only applicable if "Specify Tiling Scheme" is set to true.
151+
*/
152+
UPROPERTY(
153+
Category = "Cesium",
154+
EditAnywhere,
155+
BlueprintReadWrite,
156+
meta =
157+
(EditCondition = "bSpecifyTilingScheme",
158+
ClampMin = -180.0,
159+
ClampMax = 180.0))
160+
double RectangleEast = 180;
161+
162+
/**
163+
* The north boundary of the bounding rectangle used for the quadtree tiling
164+
* scheme. Specified in latitude degrees in the range [-90, 90].
165+
*
166+
* Only applicable if "Specify Tiling Scheme" is set to true.
167+
*/
168+
UPROPERTY(
169+
Category = "Cesium",
170+
EditAnywhere,
171+
BlueprintReadWrite,
172+
meta =
173+
(EditCondition = "bSpecifyTilingScheme",
174+
ClampMin = -90.0,
175+
ClampMax = 90.0))
176+
double RectangleNorth = 90;
177+
178+
/**
179+
* Minimum zoom level.
180+
*
181+
* Take care when specifying this that the number of tiles at the minimum
182+
* level is small, such as four or less. A larger number is likely to result
183+
* in rendering problems.
184+
*/
185+
UPROPERTY(
186+
EditAnywhere,
187+
BlueprintReadWrite,
188+
Category = "Cesium",
189+
meta = (ClampMin = 0))
190+
int32 MinimumLevel = 0;
191+
192+
/**
193+
* Maximum zoom level.
194+
*/
195+
UPROPERTY(
196+
EditAnywhere,
197+
BlueprintReadWrite,
198+
Category = "Cesium",
199+
meta = (ClampMin = 0))
200+
int32 MaximumLevel = 25;
201+
202+
/**
203+
* The pixel width of the image tiles.
204+
*/
205+
UPROPERTY(
206+
EditAnywhere,
207+
BlueprintReadWrite,
208+
Category = "Cesium",
209+
meta = (ClampMin = 64, ClampMax = 2048))
210+
int32 TileWidth = 256;
211+
212+
/**
213+
* The pixel height of the image tiles.
214+
*/
215+
UPROPERTY(
216+
EditAnywhere,
217+
BlueprintReadWrite,
218+
Category = "Cesium",
219+
meta = (ClampMin = 64, ClampMax = 2048))
220+
int32 TileHeight = 256;
221+
222+
protected:
223+
virtual std::unique_ptr<CesiumRasterOverlays::RasterOverlay> CreateOverlay(
224+
const CesiumRasterOverlays::RasterOverlayOptions& options = {}) override;
225+
};

0 commit comments

Comments
 (0)