[core] Add virtual Source::getZoomRange()

This commit is contained in:
John Firebaugh
2016-06-13 15:00:57 -07:00
parent 6eab895bc0
commit 755cc80edf
8 changed files with 22 additions and 4 deletions

View File

@@ -8,6 +8,10 @@ AnnotationSource::AnnotationSource()
: Source(SourceType::Annotations, AnnotationManager::SourceID, "", util::tileSize, std::make_unique<Tileset>()) {
}
Range<uint8_t> AnnotationSource::getZoomRange() {
return { 0, 22 };
}
void AnnotationSource::load(FileSource&) {
loaded = true;
}

View File

@@ -11,6 +11,7 @@ public:
void load(FileSource&) final;
private:
Range<uint8_t> getZoomRange() final;
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const style::UpdateParameters&) final;
};

View File

@@ -100,13 +100,15 @@ bool Source::update(const UpdateParameters& parameters) {
return allTilesUpdated;
}
const Range<uint8_t> zoomRange = getZoomRange();
// Determine the overzooming/underzooming amounts and required tiles.
int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize);
int32_t dataTileZoom = overscaledZoom;
std::vector<UnwrappedTileID> idealTiles;
if (overscaledZoom >= tileset->zoomRange.min) {
int32_t idealZoom = std::min<int32_t>(tileset->zoomRange.max, overscaledZoom);
if (overscaledZoom >= zoomRange.min) {
int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom);
// Make sure we're not reparsing overzoomed raster tiles.
if (type == SourceType::Raster) {
@@ -150,7 +152,7 @@ bool Source::update(const UpdateParameters& parameters) {
renderTiles.clear();
algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn,
idealTiles, tileset->zoomRange, dataTileZoom);
idealTiles, zoomRange, dataTileZoom);
if (type != SourceType::Raster && type != SourceType::Annotations && cache.getSize() == 0) {
size_t conservativeCacheSize =

View File

@@ -85,6 +85,7 @@ private:
void onTileError(Tile&, std::exception_ptr) override;
void onNeedsRepaint() override;
virtual Range<uint8_t> getZoomRange() = 0;
virtual std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) = 0;
protected:

View File

@@ -53,7 +53,6 @@ std::unique_ptr<GeoJSONSource> GeoJSONSource::parse(const std::string& id,
} else if (dataVal.IsObject()) {
// We need to parse dataVal as a GeoJSON object
geojsonvt = parseGeoJSON(dataVal);
tileset->zoomRange.max = geojsonvt->options.maxZoom;
} else {
Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object");
return nullptr;
@@ -72,6 +71,10 @@ GeoJSONSource::GeoJSONSource(std::string id_,
GeoJSONSource::~GeoJSONSource() = default;
Range<uint8_t> GeoJSONSource::getZoomRange() {
return { 0, geojsonvt->options.maxZoom };
}
void GeoJSONSource::load(FileSource& fileSource) {
if (url.empty()) {
// If the URL is empty, the GeoJSON was specified inline in the stylesheet.

View File

@@ -30,6 +30,7 @@ public:
void load(FileSource&) final;
private:
Range<uint8_t> getZoomRange() final;
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> geojsonvt;

View File

@@ -16,6 +16,10 @@ TileSource::TileSource(SourceType type_,
TileSource::~TileSource() = default;
Range<uint8_t> TileSource::getZoomRange() {
return tileset->zoomRange;
}
void TileSource::load(FileSource& fileSource) {
if (url.empty()) {
// If the URL is empty, the TileJSON was specified inline in the stylesheet.

View File

@@ -24,6 +24,8 @@ public:
void load(FileSource&) final;
private:
Range<uint8_t> getZoomRange() final;
std::unique_ptr<AsyncRequest> req;
};