Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[core] Add minzoom to GeoJSONOptions #10074

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/mbgl/style/conversion/geojson_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ struct Converter<GeoJSONOptions> {
optional<GeoJSONOptions> operator()(const V& value, Error& error) const {
GeoJSONOptions options;

const auto minzoomValue = objectMember(value, "minzoom");
if (minzoomValue) {
if (toNumber(*minzoomValue)) {
options.minzoom = static_cast<uint8_t>(*toNumber(*minzoomValue));
} else {
error = { "GeoJSON source minzoom value must be a number" };
return {};
}
}

const auto maxzoomValue = objectMember(value, "maxzoom");
if (maxzoomValue) {
if (toNumber(*maxzoomValue)) {
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/style/sources/geojson_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace style {

struct GeoJSONOptions {
// GeoJSON-VT options
uint8_t minzoom = 0;
uint8_t maxzoom = 18;
uint16_t buffer = 128;
double tolerance = 0.375;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/sources/geojson_source_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GeoJSONSource::Impl::Impl(const Impl& other, const GeoJSON& geoJSON)
GeoJSONSource::Impl::~Impl() = default;

Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const {
return { 0, options.maxzoom };
return { options.minzoom, options.maxzoom };
}

GeoJSONData* GeoJSONSource::Impl::getData() const {
Expand Down
2 changes: 2 additions & 0 deletions test/style/conversion/geojson_options.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TEST(GeoJSONOptions, RetainsDefaults) {
GeoJSONOptions defaults;

// GeoJSON-VT
ASSERT_EQ(converted.minzoom, defaults.minzoom);
ASSERT_EQ(converted.maxzoom, defaults.maxzoom);
ASSERT_EQ(converted.buffer, defaults.buffer);
ASSERT_EQ(converted.tolerance, defaults.tolerance);
Expand Down Expand Up @@ -61,6 +62,7 @@ TEST(GeoJSONOptions, FullConversion) {
GeoJSONOptions converted = *convert<GeoJSONOptions>(raw, error);

// GeoJSON-VT
ASSERT_EQ(converted.minzoom, 0);
ASSERT_EQ(converted.maxzoom, 1);
ASSERT_EQ(converted.buffer, 2);
ASSERT_EQ(converted.tolerance, 3);
Expand Down