summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-05-15 13:37:31 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2020-05-26 20:35:05 +0300
commitcc89ece719fcb93133d3a6f33aac9c8a12a9f4a5 (patch)
treef2c338db6d8150f16ab1656f7106598ccaf56d25 /src
parent0489a8d88abca0966b18b028ec0b5bc33180885d (diff)
downloadqtlocation-mapboxgl-cc89ece719fcb93133d3a6f33aac9c8a12a9f4a5.tar.gz
[core] Get default property API for GeoJSON and Raster DEM sources
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion/geojson_options.cpp14
-rw-r--r--src/mbgl/style/sources/geojson_source.cpp14
-rw-r--r--src/mbgl/style/sources/raster_dem_source.cpp34
3 files changed, 51 insertions, 11 deletions
diff --git a/src/mbgl/style/conversion/geojson_options.cpp b/src/mbgl/style/conversion/geojson_options.cpp
index 08553e34bb..5245cee1fa 100644
--- a/src/mbgl/style/conversion/geojson_options.cpp
+++ b/src/mbgl/style/conversion/geojson_options.cpp
@@ -154,6 +154,20 @@ optional<GeoJSONOptions> Converter<GeoJSONOptions>::operator()(const Convertible
return { std::move(options) };
}
+Value ValueFactory<GeoJSONOptions>::make(const GeoJSONOptions& options) {
+ mapbox::base::ValueObject result;
+ result["minzoom"] = options.minzoom;
+ result["maxzoom"] = options.maxzoom;
+ result["tileSize"] = options.tileSize;
+ result["buffer"] = options.buffer;
+ result["tolerance"] = options.tolerance;
+ result["lineMetrics"] = options.lineMetrics;
+ result["cluster"] = options.cluster;
+ result["clusterRadius"] = options.clusterRadius;
+ result["clusterMaxZoom"] = options.clusterMaxZoom;
+ return result;
+};
+
} // namespace conversion
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp
index f73661d820..2ac80517af 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source.cpp
@@ -1,7 +1,9 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/geojson.hpp>
+#include <mbgl/style/conversion/geojson_options.hpp>
#include <mbgl/style/conversion/json.hpp>
+#include <mbgl/style/conversion_impl.hpp>
#include <mbgl/style/layer.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
@@ -154,6 +156,18 @@ optional<conversion::Error> GeoJSONSource::setPropertyInternal(const std::string
return error;
}
+Value GeoJSONSource::getPropertyInternal(const std::string& name) const {
+ using namespace conversion;
+ if (name == "options") return makeValue(getOptions());
+ return Value();
+}
+
+Value GeoJSONSource::getPropertyDefaultValueInternal(const std::string& name) const {
+ using namespace conversion;
+ if (name == "options") return makeValue(*GeoJSONOptions::defaultOptions());
+ return Value();
+}
+
Value GeoJSONSource::serialize() const {
auto value = Source::serialize();
assert(value.getObject());
diff --git a/src/mbgl/style/sources/raster_dem_source.cpp b/src/mbgl/style/sources/raster_dem_source.cpp
index 2535772f85..95dc7d1edd 100644
--- a/src/mbgl/style/sources/raster_dem_source.cpp
+++ b/src/mbgl/style/sources/raster_dem_source.cpp
@@ -5,9 +5,15 @@
#include <mbgl/style/sources/raster_dem_source.hpp>
#include <mbgl/style/sources/raster_dem_source_impl.hpp>
#include <mbgl/tile/tile.hpp>
+#include <mbgl/util/enum.hpp>
#include <utility>
namespace mbgl {
+
+using TilesetDEMEncoding = Tileset::DEMEncoding;
+MBGL_DEFINE_ENUM(TilesetDEMEncoding,
+ {{TilesetDEMEncoding::Mapbox, "mapbox"}, {TilesetDEMEncoding::Terrarium, "terrarium"}});
+
namespace style {
RasterDEMSource::RasterDEMSource(std::string id, variant<std::string, Tileset> urlOrTileset_, uint16_t tileSize)
@@ -17,20 +23,10 @@ bool RasterDEMSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info)
return mbgl::underlying_type(TileKind::RasterDEM) == mbgl::underlying_type(info->tileKind);
}
-static std::string tilesetDEMEncodingToString(mbgl::Tileset::DEMEncoding encoding) {
- switch (encoding) {
- case mbgl::Tileset::DEMEncoding::Mapbox:
- return "mapbox";
- case mbgl::Tileset::DEMEncoding::Terrarium:
- return "terrarium";
- }
- return "terrarium";
-}
-
Value RasterDEMSource::serialize() const {
auto value = RasterSource::serialize();
if (auto* tileset = getTileset()) {
- value.getObject()->insert({"encoding", tilesetDEMEncodingToString(tileset->encoding)});
+ value.getObject()->insert({"encoding", conversion::makeValue(tileset->encoding)});
}
return value;
}
@@ -39,6 +35,22 @@ const RasterDEMSource::Impl& RasterDEMSource::impl() const {
return static_cast<const Impl&>(*baseImpl);
}
+Value RasterDEMSource::getPropertyInternal(const std::string& name) const {
+ if (name == "encoding") {
+ if (auto* tileset = getTileset()) {
+ return conversion::makeValue(tileset->encoding);
+ }
+ }
+ return NullValue();
+}
+
+Value RasterDEMSource::getPropertyDefaultValueInternal(const std::string& name) const {
+ if (name == "encoding") {
+ return conversion::makeValue(TilesetDEMEncoding::Mapbox);
+ }
+ return NullValue();
+}
+
Mutable<Source::Impl> RasterDEMSource::createMutable() const noexcept {
return staticMutableCast<Source::Impl>(makeMutable<Impl>(impl()));
}