Skip to content

Commit ca5f79c

Browse files
Fix for raster dem encoding override in style.json (maplibre#3570)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7d46c00 commit ca5f79c

28 files changed

+347
-285
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ list(APPEND INCLUDE_FILES
311311
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/light.hpp
312312
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/position.hpp
313313
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/property_value.hpp
314+
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/raster_dem_options.hpp
314315
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/rotation.hpp
315316
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/source.hpp
316317
${PROJECT_SOURCE_DIR}/include/mbgl/style/conversion/tileset.hpp
@@ -378,6 +379,7 @@ list(APPEND INCLUDE_FILES
378379
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/geojson_source.hpp
379380
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/image_source.hpp
380381
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/raster_dem_source.hpp
382+
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/tile_source.hpp
381383
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/raster_source.hpp
382384
${PROJECT_SOURCE_DIR}/include/mbgl/style/sources/vector_source.hpp
383385
${PROJECT_SOURCE_DIR}/include/mbgl/style/sprite.hpp
@@ -690,6 +692,7 @@ list(APPEND SRC_FILES
690692
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/light.cpp
691693
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/position.cpp
692694
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/property_value.cpp
695+
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/raster_dem_options.cpp
693696
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/rotation.cpp
694697
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/source.cpp
695698
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/stringify.hpp
@@ -815,12 +818,11 @@ list(APPEND SRC_FILES
815818
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/image_source_impl.cpp
816819
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/image_source_impl.hpp
817820
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/raster_dem_source.cpp
821+
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/tile_source.cpp
818822
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/raster_source.cpp
819-
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/raster_source_impl.cpp
820-
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/raster_source_impl.hpp
823+
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/tile_source_impl.cpp
824+
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/tile_source_impl.hpp
821825
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/vector_source.cpp
822-
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/vector_source_impl.cpp
823-
${PROJECT_SOURCE_DIR}/src/mbgl/style/sources/vector_source_impl.hpp
824826
${PROJECT_SOURCE_DIR}/src/mbgl/style/style.cpp
825827
${PROJECT_SOURCE_DIR}/src/mbgl/style/style_impl.cpp
826828
${PROJECT_SOURCE_DIR}/src/mbgl/style/style_impl.hpp

bazel/core.bzl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ MLN_CORE_SOURCE = [
345345
"src/mbgl/style/conversion/light.cpp",
346346
"src/mbgl/style/conversion/position.cpp",
347347
"src/mbgl/style/conversion/property_value.cpp",
348+
"src/mbgl/style/conversion/raster_dem_options.cpp",
348349
"src/mbgl/style/conversion/rotation.cpp",
349350
"src/mbgl/style/conversion/source.cpp",
350351
"src/mbgl/style/conversion/stringify.hpp",
@@ -450,12 +451,11 @@ MLN_CORE_SOURCE = [
450451
"src/mbgl/style/sources/image_source_impl.cpp",
451452
"src/mbgl/style/sources/image_source_impl.hpp",
452453
"src/mbgl/style/sources/raster_dem_source.cpp",
454+
"src/mbgl/style/sources/tile_source.cpp",
453455
"src/mbgl/style/sources/raster_source.cpp",
454-
"src/mbgl/style/sources/raster_source_impl.cpp",
455-
"src/mbgl/style/sources/raster_source_impl.hpp",
456+
"src/mbgl/style/sources/tile_source_impl.cpp",
457+
"src/mbgl/style/sources/tile_source_impl.hpp",
456458
"src/mbgl/style/sources/vector_source.cpp",
457-
"src/mbgl/style/sources/vector_source_impl.cpp",
458-
"src/mbgl/style/sources/vector_source_impl.hpp",
459459
"src/mbgl/style/style.cpp",
460460
"src/mbgl/style/style_impl.cpp",
461461
"src/mbgl/style/style_impl.hpp",
@@ -696,6 +696,7 @@ MLN_CORE_HEADERS = [
696696
"include/mbgl/style/conversion/light.hpp",
697697
"include/mbgl/style/conversion/position.hpp",
698698
"include/mbgl/style/conversion/property_value.hpp",
699+
"include/mbgl/style/conversion/raster_dem_options.hpp",
699700
"include/mbgl/style/conversion/rotation.hpp",
700701
"include/mbgl/style/conversion/source.hpp",
701702
"include/mbgl/style/conversion/tileset.hpp",
@@ -755,6 +756,7 @@ MLN_CORE_HEADERS = [
755756
"include/mbgl/style/sources/geojson_source.hpp",
756757
"include/mbgl/style/sources/image_source.hpp",
757758
"include/mbgl/style/sources/raster_dem_source.hpp",
759+
"include/mbgl/style/sources/tile_source.hpp",
758760
"include/mbgl/style/sources/raster_source.hpp",
759761
"include/mbgl/style/sources/vector_source.hpp",
760762
"include/mbgl/style/sprite.hpp",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <mbgl/style/sources/raster_dem_source.hpp>
4+
#include <mbgl/style/conversion.hpp>
5+
6+
namespace mbgl {
7+
namespace style {
8+
namespace conversion {
9+
10+
template <>
11+
struct Converter<RasterDEMOptions> {
12+
std::optional<RasterDEMOptions> operator()(const Convertible& value, Error& error) const;
13+
};
14+
15+
} // namespace conversion
16+
} // namespace style
17+
} // namespace mbgl

include/mbgl/style/sources/raster_dem_source.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66

77
namespace mbgl {
88

9-
class AsyncRequest;
10-
119
namespace style {
1210

11+
struct RasterDEMOptions {
12+
std::optional<Tileset::DEMEncoding> encoding = std::nullopt;
13+
};
14+
1315
class RasterDEMSource : public RasterSource {
1416
public:
15-
RasterDEMSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize);
17+
RasterDEMSource(std::string id,
18+
variant<std::string, Tileset> urlOrTileset,
19+
uint16_t tileSize,
20+
std::optional<RasterDEMOptions> options = std::nullopt);
1621
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
22+
23+
protected:
24+
void setTilesetOverrides(Tileset& tileset) override;
25+
26+
private:
27+
std::optional<RasterDEMOptions> options;
1728
};
1829

1930
template <>

include/mbgl/style/sources/raster_source.hpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,21 @@
11
#pragma once
22

3-
#include <mbgl/style/source.hpp>
3+
#include <mbgl/style/sources/tile_source.hpp>
44
#include <mbgl/util/tileset.hpp>
55
#include <mbgl/util/variant.hpp>
66

77
namespace mbgl {
88

9-
class AsyncRequest;
10-
119
namespace style {
1210

13-
class RasterSource : public Source {
11+
class RasterSource : public TileSource {
1412
public:
1513
RasterSource(std::string id,
1614
variant<std::string, Tileset> urlOrTileset,
1715
uint16_t tileSize,
1816
SourceType sourceType = SourceType::Raster);
19-
~RasterSource() override;
20-
21-
const variant<std::string, Tileset>& getURLOrTileset() const;
22-
std::optional<std::string> getURL() const;
23-
24-
uint16_t getTileSize() const;
25-
26-
class Impl;
27-
const Impl& impl() const;
28-
29-
void loadDescription(FileSource&) final;
3017

3118
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
32-
33-
mapbox::base::WeakPtr<Source> makeWeakPtr() final { return weakFactory.makeWeakPtr(); }
34-
35-
protected:
36-
Mutable<Source::Impl> createMutable() const noexcept final;
37-
38-
private:
39-
const variant<std::string, Tileset> urlOrTileset;
40-
std::unique_ptr<AsyncRequest> req;
41-
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
42-
// Do not add members here, see `WeakPtrFactory`
4319
};
4420

4521
template <>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include <mbgl/style/source.hpp>
4+
#include <mbgl/util/tileset.hpp>
5+
#include <mbgl/util/variant.hpp>
6+
7+
namespace mbgl {
8+
9+
class AsyncRequest;
10+
11+
namespace style {
12+
13+
class TileSource : public Source {
14+
public:
15+
TileSource(std::string id, variant<std::string, Tileset> urlOrTileset, uint16_t tileSize, SourceType sourceType);
16+
~TileSource() override;
17+
18+
const variant<std::string, Tileset>& getURLOrTileset() const;
19+
std::optional<std::string> getURL() const;
20+
21+
uint16_t getTileSize() const;
22+
23+
class Impl;
24+
const Impl& impl() const;
25+
26+
void loadDescription(FileSource&) final;
27+
28+
mapbox::base::WeakPtr<Source> makeWeakPtr() final { return weakFactory.makeWeakPtr(); }
29+
30+
protected:
31+
Mutable<Source::Impl> createMutable() const noexcept final;
32+
virtual void setTilesetOverrides(Tileset& tileset);
33+
34+
private:
35+
const variant<std::string, Tileset> urlOrTileset;
36+
std::unique_ptr<AsyncRequest> req;
37+
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
38+
// Do not add members here, see `WeakPtrFactory`
39+
};
40+
41+
template <>
42+
inline bool Source::is<TileSource>() const {
43+
return getType() == SourceType::Raster;
44+
}
45+
46+
} // namespace style
47+
} // namespace mbgl

include/mbgl/style/sources/vector_source.hpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <mbgl/style/source.hpp>
3+
#include <mbgl/style/sources/tile_source.hpp>
44
#include <mbgl/util/tileset.hpp>
55
#include <mbgl/util/variant.hpp>
66

@@ -10,21 +10,14 @@ class AsyncRequest;
1010

1111
namespace style {
1212

13-
class VectorSource final : public Source {
13+
class VectorSource final : public TileSource {
1414
public:
1515
VectorSource(std::string id,
1616
variant<std::string, Tileset> urlOrTileset,
1717
std::optional<float> maxZoom = std::nullopt,
1818
std::optional<float> minZoom = std::nullopt);
19-
~VectorSource() final;
2019

21-
const variant<std::string, Tileset>& getURLOrTileset() const;
22-
std::optional<std::string> getURL() const;
23-
24-
class Impl;
25-
const Impl& impl() const;
26-
27-
void loadDescription(FileSource&) final;
20+
void setTilesetOverrides(Tileset& tileset) override;
2821

2922
/// @brief Gets the tile urls for this vector source.
3023
/// @return List of tile urls.
@@ -36,18 +29,9 @@ class VectorSource final : public Source {
3629

3730
bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
3831

39-
mapbox::base::WeakPtr<Source> makeWeakPtr() override { return weakFactory.makeWeakPtr(); }
40-
41-
protected:
42-
Mutable<Source::Impl> createMutable() const noexcept final;
43-
4432
private:
45-
const variant<std::string, Tileset> urlOrTileset;
46-
std::unique_ptr<AsyncRequest> req;
4733
std::optional<float> maxZoom;
4834
std::optional<float> minZoom;
49-
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
50-
// Do not add members here, see `WeakPtrFactory`
5135
};
5236

5337
template <>

src/mbgl/renderer/render_source.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ std::unique_ptr<RenderSource> RenderSource::create(const Immutable<Source::Impl>
2424
const TaggedScheduler& threadPool_) {
2525
switch (impl->type) {
2626
case SourceType::Vector:
27-
return std::make_unique<RenderVectorSource>(staticImmutableCast<VectorSource::Impl>(impl),
27+
return std::make_unique<RenderVectorSource>(staticImmutableCast<TileSource::Impl>(impl),
2828
std::move(threadPool_));
2929
case SourceType::Raster:
30-
return std::make_unique<RenderRasterSource>(staticImmutableCast<RasterSource::Impl>(impl),
30+
return std::make_unique<RenderRasterSource>(staticImmutableCast<TileSource::Impl>(impl),
3131
std::move(threadPool_));
3232
case SourceType::RasterDEM:
33-
return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<RasterSource::Impl>(impl),
33+
return std::make_unique<RenderRasterDEMSource>(staticImmutableCast<TileSource::Impl>(impl),
3434
std::move(threadPool_));
3535
case SourceType::GeoJSON:
3636
return std::make_unique<RenderGeoJSONSource>(staticImmutableCast<GeoJSONSource::Impl>(impl),

src/mbgl/renderer/sources/render_raster_dem_source.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace mbgl {
1010

1111
using namespace style;
1212

13-
RenderRasterDEMSource::RenderRasterDEMSource(Immutable<style::RasterSource::Impl> impl_,
13+
RenderRasterDEMSource::RenderRasterDEMSource(Immutable<style::TileSource::Impl> impl_,
1414
const TaggedScheduler& threadPool_)
1515
: RenderTileSetSource(std::move(impl_), threadPool_) {}
1616

17-
const style::RasterSource::Impl& RenderRasterDEMSource::impl() const {
18-
return static_cast<const style::RasterSource::Impl&>(*baseImpl);
17+
const style::TileSource::Impl& RenderRasterDEMSource::impl() const {
18+
return static_cast<const style::TileSource::Impl&>(*baseImpl);
1919
}
2020

2121
const std::optional<Tileset>& RenderRasterDEMSource::getTileset() const {

src/mbgl/renderer/sources/render_raster_dem_source.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#pragma once
22

33
#include <mbgl/renderer/sources/render_tile_source.hpp>
4-
#include <mbgl/style/sources/raster_source_impl.hpp>
4+
#include <mbgl/style/sources/tile_source_impl.hpp>
55

66
namespace mbgl {
77

88
class RenderRasterDEMSource final : public RenderTileSetSource {
99
public:
10-
explicit RenderRasterDEMSource(Immutable<style::RasterSource::Impl>, const TaggedScheduler&);
10+
explicit RenderRasterDEMSource(Immutable<style::TileSource::Impl>, const TaggedScheduler&);
1111

1212
std::unordered_map<std::string, std::vector<Feature>> queryRenderedFeatures(
1313
const ScreenLineString& geometry,
@@ -27,7 +27,7 @@ class RenderRasterDEMSource final : public RenderTileSetSource {
2727
const TileParameters&) override;
2828
const std::optional<Tileset>& getTileset() const override;
2929

30-
const style::RasterSource::Impl& impl() const;
30+
const style::TileSource::Impl& impl() const;
3131

3232
void onTileChanged(Tile&) override;
3333
};

0 commit comments

Comments
 (0)