diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-01-13 11:53:33 +0100 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-01-13 13:04:59 -0800 |
commit | f00a6a997b5c019e1628ec0b10f77f4ed442624f (patch) | |
tree | 5d4746a774902769d3e613be069761965021f5ef /src | |
parent | 62973f9e5a2be037f582e111248e06f623f2374e (diff) | |
download | qtlocation-mapboxgl-f00a6a997b5c019e1628ec0b10f77f4ed442624f.tar.gz |
[core] move invariant SourceType from SourceInfo to Source
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 29 | ||||
-rw-r--r-- | src/mbgl/map/source.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/source_info.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/style/style_parser.cpp | 12 |
5 files changed, 22 insertions, 26 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 6538cb8e9e..9a966827c9 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -112,8 +112,7 @@ std::unique_ptr<AnnotationTile> 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> source = std::make_unique<Source>(); - source->info.type = SourceType::Annotations; + std::unique_ptr<Source> source = std::make_unique<Source>(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 e8dc704923..eb2f853d5b 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -117,7 +117,7 @@ void parse(const JSValue& value, std::array<float, N>& 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<RasterTileData>(normalized_id, parameters.texturePool, parameters.worker); @@ -323,14 +323,14 @@ TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& p } else { std::unique_ptr<GeometryTileMonitor> monitor; - if (info.type == SourceType::Vector) { + if (type == SourceType::Vector) { monitor = std::make_unique<VectorTileMonitor>(normalized_id, info.tiles.at(0)); - } else if (info.type == SourceType::Annotations) { + } else if (type == SourceType::Annotations) { monitor = std::make_unique<AnnotationTileMonitor>(normalized_id, parameters.data); - } else if (info.type == SourceType::GeoJSON) { + } else if (type == SourceType::GeoJSON) { monitor = std::make_unique<GeoJSONTileMonitor>(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<TileID> 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<TileID> retain_data; - util::erase_if(tiles, [&retain, &retain_data, &tileCache, &type](std::pair<const TileID, std::unique_ptr<Tile>> &pair) { + util::erase_if(tiles, [this, &retain, &retain_data, &tileCache](std::pair<const TileID, std::unique_ptr<Tile>> &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 8f6620d52d..d5166ef448 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 0a72380d63..c279374399 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<std::string> tiles; uint16_t tile_size = util::tileSize; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 6521d1339f..4c3061dcb4 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> source = std::make_unique<Source>(); - - 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> source = std::make_unique<Source>(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()); |