[core] Virtualize Source::createTile
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/annotation/annotation_source.hpp>
|
||||
#include <mbgl/annotation/annotation_manager.hpp>
|
||||
#include <mbgl/annotation/annotation_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -7,4 +8,9 @@ AnnotationSource::AnnotationSource()
|
||||
: Source(SourceType::Annotations, AnnotationManager::SourceID, "", util::tileSize, std::make_unique<Tileset>()) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Tile> AnnotationSource::createTile(const OverscaledTileID& tileID,
|
||||
const style::UpdateParameters& parameters) {
|
||||
return std::make_unique<AnnotationTile>(tileID, id, parameters);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,6 +7,9 @@ namespace mbgl {
|
||||
class AnnotationSource : public style::Source {
|
||||
public:
|
||||
AnnotationSource();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const style::UpdateParameters&) final;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
#include <mbgl/util/tile_cover.hpp>
|
||||
#include <mbgl/util/enum.hpp>
|
||||
|
||||
#include <mbgl/tile/raster_tile.hpp>
|
||||
#include <mbgl/tile/geojson_tile.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
#include <mbgl/annotation/annotation_tile.hpp>
|
||||
#include <mbgl/style/parser.hpp>
|
||||
#include <mbgl/gl/debugging.hpp>
|
||||
|
||||
@@ -184,23 +180,6 @@ const std::map<UnwrappedTileID, RenderTile>& Source::getRenderTiles() const {
|
||||
return renderTiles;
|
||||
}
|
||||
|
||||
std::unique_ptr<Tile> Source::createTile(const OverscaledTileID& overscaledTileID,
|
||||
const UpdateParameters& parameters) {
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
if (type == SourceType::Raster) {
|
||||
return std::make_unique<RasterTile>(overscaledTileID, parameters, *tileset);
|
||||
} else if (type == SourceType::Vector) {
|
||||
return std::make_unique<VectorTile>(overscaledTileID, id, parameters, *tileset);
|
||||
} else if (type == SourceType::Annotations) {
|
||||
return std::make_unique<AnnotationTile>(overscaledTileID, id, parameters);
|
||||
} else if (type == SourceType::GeoJSON) {
|
||||
return std::make_unique<GeoJSONTile>(overscaledTileID, id, parameters, geojsonvt.get());
|
||||
} else {
|
||||
Log::Warning(Event::Style, "Source type '%s' is not implemented", Enum<SourceType>::toString(type));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
|
||||
auto it = tiles.find(overscaledTileID);
|
||||
if (it != tiles.end()) {
|
||||
|
||||
@@ -93,12 +93,10 @@ private:
|
||||
void onTileError(Tile&, std::exception_ptr) override;
|
||||
void onNeedsRepaint() override;
|
||||
|
||||
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<const Tileset> tileset;
|
||||
virtual std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) = 0;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<const Tileset> tileset;
|
||||
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt;
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/style/sources/geojson_source.hpp>
|
||||
#include <mbgl/tile/geojson_tile.hpp>
|
||||
|
||||
#include <mapbox/geojsonvt.hpp>
|
||||
|
||||
@@ -14,5 +15,10 @@ GeoJSONSource::GeoJSONSource(std::string id_,
|
||||
geojsonvt = std::move(geojsonvt_);
|
||||
}
|
||||
|
||||
std::unique_ptr<Tile> GeoJSONSource::createTile(const OverscaledTileID& tileID,
|
||||
const UpdateParameters& parameters) {
|
||||
return std::make_unique<GeoJSONTile>(tileID, id, parameters, geojsonvt.get());
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
uint16_t tileSize,
|
||||
std::unique_ptr<Tileset>&&,
|
||||
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>&&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/style/sources/raster_source.hpp>
|
||||
#include <mbgl/tile/raster_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -10,5 +11,10 @@ RasterSource::RasterSource(std::string id_,
|
||||
: Source(SourceType::Raster, std::move(id_), std::move(url_), tileSize_, std::move(tileset_)) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Tile> RasterSource::createTile(const OverscaledTileID& tileID,
|
||||
const UpdateParameters& parameters) {
|
||||
return std::make_unique<RasterTile>(tileID, parameters, *tileset);
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,6 +11,9 @@ public:
|
||||
std::string url,
|
||||
uint16_t tileSize,
|
||||
std::unique_ptr<Tileset>&&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <mbgl/style/sources/vector_source.hpp>
|
||||
#include <mbgl/tile/vector_tile.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -9,5 +10,10 @@ VectorSource::VectorSource(std::string id_,
|
||||
: Source(SourceType::Vector, std::move(id_), std::move(url_), util::tileSize, std::move(tileset_)) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Tile> VectorSource::createTile(const OverscaledTileID& tileID,
|
||||
const UpdateParameters& parameters) {
|
||||
return std::make_unique<VectorTile>(tileID, id, parameters, *tileset);
|
||||
}
|
||||
|
||||
} // namespace style
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -10,6 +10,9 @@ public:
|
||||
VectorSource(std::string id,
|
||||
std::string url,
|
||||
std::unique_ptr<Tileset>&&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
|
||||
};
|
||||
|
||||
} // namespace style
|
||||
|
||||
@@ -20,6 +20,8 @@ RasterTile::RasterTile(const OverscaledTileID& id_,
|
||||
loader(*this, id_, parameters, tileset) {
|
||||
}
|
||||
|
||||
RasterTile::~RasterTile() = default;
|
||||
|
||||
void RasterTile::setError(std::exception_ptr err) {
|
||||
observer->onTileError(*this, err);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
RasterTile(const OverscaledTileID&,
|
||||
const style::UpdateParameters&,
|
||||
const Tileset&);
|
||||
~RasterTile() final;
|
||||
|
||||
void setNecessity(Necessity) final;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
const OverscaledTileID&,
|
||||
const style::UpdateParameters&,
|
||||
const Tileset&);
|
||||
~TileLoader();
|
||||
|
||||
using Necessity = Resource::Necessity;
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ TileLoader<T>::TileLoader(T& tile_,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TileLoader<T>::~TileLoader() = default;
|
||||
|
||||
template <typename T>
|
||||
void TileLoader<T>::loadOptional() {
|
||||
assert(!request);
|
||||
|
||||
Reference in New Issue
Block a user