diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 6538cb8e9..9a966827c 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -112,8 +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(); - source->info.type = SourceType::Annotations; + std::unique_ptr source = std::make_unique(SourceType::Annotations); source->info.source_id = SourceID; source->enabled = true; style.addSource(std::move(source)); diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index e8dc70492..eb2f853d5 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -117,7 +117,7 @@ void parse(const JSValue& value, std::array& target, const char* name) } // end namespace -Source::Source() {} +Source::Source(SourceType type_) : type(type_) {} Source::~Source() = default; @@ -172,17 +172,17 @@ void Source::load() { return; } - if (info.type == SourceType::Vector || info.type == SourceType::Raster) { + if (type == SourceType::Vector || type == SourceType::Raster) { parseTileJSON(d); // TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with. - if (info.type == SourceType::Raster && util::mapbox::isMapboxURL(info.url)) { + if (type == SourceType::Raster && util::mapbox::isMapboxURL(info.url)) { // We need to insert {ratio} into raster source URLs that are loaded from mapbox:// // TileJSONs. std::transform(info.tiles.begin(), info.tiles.end(), info.tiles.begin(), util::mapbox::normalizeRasterTileURL); } - } else if (info.type == SourceType::GeoJSON) { + } else if (type == SourceType::GeoJSON) { parseGeoJSON(d); } @@ -313,7 +313,7 @@ TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& p auto callback = std::bind(&Source::tileLoadingCompleteCallback, this, normalized_id, parameters.transformState, parameters.debugOptions & MapDebugOptions::Collision); // If we don't find working tile data, we're just going to load it. - if (info.type == SourceType::Raster) { + if (type == SourceType::Raster) { auto tileData = std::make_shared(normalized_id, parameters.texturePool, parameters.worker); @@ -323,14 +323,14 @@ TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& p } else { std::unique_ptr monitor; - if (info.type == SourceType::Vector) { + if (type == SourceType::Vector) { monitor = std::make_unique(normalized_id, info.tiles.at(0)); - } else if (info.type == SourceType::Annotations) { + } else if (type == SourceType::Annotations) { monitor = std::make_unique(normalized_id, parameters.data); - } else if (info.type == SourceType::GeoJSON) { + } else if (type == SourceType::GeoJSON) { monitor = std::make_unique(geojsonvt.get(), normalized_id); } else { - Log::Warning(Event::Style, "Source type '%s' is not implemented", SourceTypeClass(info.type).c_str()); + Log::Warning(Event::Style, "Source type '%s' is not implemented", SourceTypeClass(type).c_str()); return TileData::State::invalid; } @@ -357,7 +357,7 @@ double Source::getZoom(const TransformState& state) const { int32_t Source::coveringZoomLevel(const TransformState& state) const { double zoom = getZoom(state); - if (info.type == SourceType::Raster || info.type == SourceType::Video) { + if (type == SourceType::Raster || type == SourceType::Video) { zoom = ::round(zoom); } else { zoom = std::floor(zoom); @@ -370,8 +370,8 @@ std::forward_list Source::coveringTiles(const TransformState& state) con auto actualZ = z; const bool reparseOverscaled = - info.type == SourceType::Vector || - info.type == SourceType::Annotations; + type == SourceType::Vector || + type == SourceType::Annotations; if (z < info.min_zoom) return {{}}; if (z > info.max_zoom) z = info.max_zoom; @@ -496,7 +496,7 @@ bool Source::update(const StyleUpdateParameters& parameters) { } } - if (info.type != SourceType::Raster && cache.getSize() == 0) { + if (type != SourceType::Raster && cache.getSize() == 0) { size_t conservativeCacheSize = ((float)parameters.transformState.getWidth() / util::tileSize) * ((float)parameters.transformState.getHeight() / util::tileSize) * (parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) * @@ -505,12 +505,11 @@ bool Source::update(const StyleUpdateParameters& parameters) { } auto& tileCache = cache; - auto& type = info.type; // Remove tiles that we definitely don't need, i.e. tiles that are not on // the required list. std::set retain_data; - util::erase_if(tiles, [&retain, &retain_data, &tileCache, &type](std::pair> &pair) { + util::erase_if(tiles, [this, &retain, &retain_data, &tileCache](std::pair> &pair) { Tile &tile = *pair.second; bool obsolete = std::find(retain.begin(), retain.end(), tile.id) == retain.end(); if (!obsolete) { diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 8f6620d52..d5166ef44 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -39,7 +39,7 @@ public: virtual void onTileError(Source&, const TileID&, std::exception_ptr) {}; }; - Source(); + Source(SourceType); ~Source(); void parseTileJSON(const JSValue&); @@ -69,6 +69,7 @@ public: void setObserver(Observer* observer); void dumpDebugLogs() const; + const SourceType type; SourceInfo info; bool enabled = false; diff --git a/src/mbgl/map/source_info.hpp b/src/mbgl/map/source_info.hpp index 0a72380d6..c27937439 100644 --- a/src/mbgl/map/source_info.hpp +++ b/src/mbgl/map/source_info.hpp @@ -15,7 +15,6 @@ class TileID; class SourceInfo { public: - SourceType type = SourceType::Vector; std::string url; std::vector tiles; uint16_t tile_size = util::tileSize; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 6521d1339..4c3061dcb 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -56,10 +56,6 @@ void StyleParser::parseSources(const JSValue& value) { const JSValue& nameVal = itr->name; const JSValue& sourceVal = itr->value; - std::unique_ptr source = std::make_unique(); - - source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() }; - if (!sourceVal.HasMember("type")) { Log::Warning(Event::ParseStyle, "source must have a type"); continue; @@ -71,9 +67,11 @@ void StyleParser::parseSources(const JSValue& value) { continue; } - source->info.type = SourceTypeClass({ typeVal.GetString(), typeVal.GetStringLength() }); + const auto type = SourceTypeClass({ typeVal.GetString(), typeVal.GetStringLength() }); + std::unique_ptr source = std::make_unique(type); + source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() }; - switch (source->info.type) { + switch (type) { case SourceType::Vector: if (!parseVectorSource(*source, sourceVal)) { continue; @@ -90,7 +88,7 @@ void StyleParser::parseSources(const JSValue& value) { } break; default: - Log::Warning(Event::ParseStyle, "source type %s is not supported", SourceTypeClass(source->info.type).c_str()); + Log::Warning(Event::ParseStyle, "source type %s is not supported", type.c_str()); } sourcesMap.emplace(source->info.source_id, source.get());