From 4328e6fd0d973c0a0bc2800f4c67fdbfcae342c9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 15 Jan 2016 11:16:00 -0800 Subject: [PATCH] [core] tileSize is a source property, not a TileJSON property --- src/mbgl/annotation/annotation_manager.cpp | 2 +- src/mbgl/map/source.cpp | 4 +++- src/mbgl/map/source.hpp | 2 ++ src/mbgl/map/source_info.hpp | 1 - src/mbgl/style/style_parser.cpp | 18 +++++++++++++++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 4884ae446..4e395e063 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -112,7 +112,7 @@ std::unique_ptr AnnotationManager::getTile(const TileID& tileID) void AnnotationManager::updateStyle(Style& style) { // Create annotation source, point layer, and point bucket if (!style.getSource(SourceID)) { - std::unique_ptr source = std::make_unique(SourceType::Annotations, SourceID, "", std::make_unique(), nullptr); + std::unique_ptr source = std::make_unique(SourceType::Annotations, SourceID, "", util::tileSize, std::make_unique(), nullptr); source->enabled = true; style.addSource(std::move(source)); diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index e34ba0748..4253a6065 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -43,11 +43,13 @@ namespace mbgl { Source::Source(SourceType type_, const std::string& id_, const std::string& url_, + uint16_t tileSize_, std::unique_ptr&& info_, std::unique_ptr&& geojsonvt_) : type(type_), id(id_), url(url_), + tileSize(tileSize_), info(std::move(info_)), geojsonvt(std::move(geojsonvt_)) { } @@ -306,7 +308,7 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter } double Source::getZoom(const TransformState& state) const { - double offset = std::log(util::tileSize / info->tile_size) / std::log(2); + double offset = std::log(util::tileSize / tileSize) / std::log(2); return state.getZoom() + offset; } diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index ade2317cc..9e9b6b66a 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -42,6 +42,7 @@ public: Source(SourceType, const std::string& id, const std::string& url, + uint16_t tileSize, std::unique_ptr&&, std::unique_ptr&&); ~Source(); @@ -73,6 +74,7 @@ public: const SourceType type; const std::string id; const std::string url; + uint16_t tileSize = util::tileSize; bool enabled = false; private: diff --git a/src/mbgl/map/source_info.hpp b/src/mbgl/map/source_info.hpp index 0f0ee1cad..01d01b60a 100644 --- a/src/mbgl/map/source_info.hpp +++ b/src/mbgl/map/source_info.hpp @@ -16,7 +16,6 @@ class TileID; class SourceInfo { public: std::vector tiles; - uint16_t tile_size = util::tileSize; uint16_t min_zoom = 0; uint16_t max_zoom = 22; std::string attribution; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 88d644f51..4c1fe593f 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -156,12 +156,25 @@ void StyleParser::parseSources(const JSValue& value) { // parameters are specified inline. std::string url; + uint16_t tileSize = util::tileSize; + std::unique_ptr info; std::unique_ptr geojsonvt; switch (type) { - case SourceType::Vector: case SourceType::Raster: + if (sourceVal.HasMember("tileSize")) { + const JSValue& tileSizeVal = sourceVal["tileSize"]; + if (tileSizeVal.IsNumber() && tileSizeVal.GetUint64() <= std::numeric_limits::max()) { + tileSize = tileSizeVal.GetUint64(); + } else { + Log::Error(Event::ParseStyle, "invalid tileSize"); + continue; + } + } + // Fall through. Vector sources are forbidden from having a tileSize. + + case SourceType::Vector: if (sourceVal.HasMember("url")) { const JSValue& urlVal = sourceVal["url"]; if (urlVal.IsString()) { @@ -208,7 +221,7 @@ void StyleParser::parseSources(const JSValue& value) { } const std::string id { nameVal.GetString(), nameVal.GetStringLength() }; - std::unique_ptr source = std::make_unique(type, id, url, std::move(info), std::move(geojsonvt)); + std::unique_ptr source = std::make_unique(type, id, url, tileSize, std::move(info), std::move(geojsonvt)); sourcesMap.emplace(id, source.get()); sources.emplace_back(std::move(source)); @@ -231,7 +244,6 @@ std::unique_ptr StyleParser::parseGeoJSON(const JS std::unique_ptr StyleParser::parseTileJSON(const JSValue& value) { auto info = std::make_unique(); parseTileJSONMember(value, info->tiles, "tiles"); - parseTileJSONMember(value, info->tile_size, "tileSize"); parseTileJSONMember(value, info->min_zoom, "minzoom"); parseTileJSONMember(value, info->max_zoom, "maxzoom"); parseTileJSONMember(value, info->attribution, "attribution");