Example #1
0
void Style::update(MapData& data,
                   const TransformState& transform,
                   TexturePool& texturePool) {
    const float pixelRatio = transform.getPixelRatio();
    if (!sprite || !sprite->hasPixelRatio(pixelRatio)) {
        sprite = std::make_unique<Sprite>(spriteURL, pixelRatio);
        sprite->setObserver(this);

        spriteAtlas->resize(pixelRatio);
        spriteAtlas->setSprite(sprite);
    }

    bool allTilesUpdated = true;
    for (const auto& source : sources) {
        if (!source->update(data, transform, *this, *glyphAtlas, *glyphStore,
                       *spriteAtlas, sprite, texturePool, shouldReparsePartialTiles)) {
            allTilesUpdated = false;
        }
    }

    // We can only stop updating "partial" tiles when all of them
    // were notified of the arrival of the new resources.
    if (allTilesUpdated) {
        shouldReparsePartialTiles = false;
    }
}
Example #2
0
void Map::prepare() {
    view.make_active();

    // Update transform transitions.
    animationTime = util::now();
    if (transform.needsTransition()) {
        transform.updateTransitions(animationTime);
    }

    const TransformState oldState = state;
    state = transform.currentState();

    bool pixelRatioChanged = oldState.getPixelRatio() != state.getPixelRatio();
    bool dimensionsChanged = oldState.getFramebufferWidth() != state.getFramebufferWidth() ||
                             oldState.getFramebufferHeight() != state.getFramebufferHeight();

    if (pixelRatioChanged) {
        style->sprite = std::make_shared<Sprite>(*this, state.getPixelRatio());
        style->sprite->load(kSpriteURL);

        spriteAtlas->resize(state.getPixelRatio());
    }

    if (pixelRatioChanged || dimensionsChanged) {
        painter.clearFramebuffers();
    }

    style->cascade(state.getNormalizedZoom());

    // Update style transitions.
    animationTime = util::now();
    if (style->needsTransition()) {
        style->updateTransitions(animationTime);
        update();
    }

    // Allow the sprite atlas to potentially pull new sprite images if needed.
    if (style->sprite && style->sprite->isLoaded()) {
        spriteAtlas->update(*style->sprite);
    }

    updateTiles();
}
void ResourceLoader::update(MapData& data,
                            const TransformState& transform,
                            GlyphAtlas& glyphAtlas,
                            GlyphStore& glyphStore,
                            SpriteAtlas& spriteAtlas,
                            TexturePool& texturePool) {
    if (!style_) {
        return;
    }

    const float pixelRatio = transform.getPixelRatio();
    if (!sprite_ || !sprite_->hasPixelRatio(pixelRatio)) {
        sprite_ = util::make_unique<Sprite>(style_->getSpriteURL(), pixelRatio);
        sprite_->setObserver(this);

        spriteAtlas.resize(pixelRatio);
        spriteAtlas.setSprite(sprite_);
    }

    for (const auto& source : style_->sources) {
        source->update(
            data, transform, *style_, glyphAtlas, glyphStore, spriteAtlas, sprite_, texturePool);
    }
}
Example #4
0
double Source::getZoom(const TransformState& state) const {
    double offset = std::log(util::tileSize / info.tile_size) / std::log(2);
    offset += (state.getPixelRatio() > 1.0 ? 1 :0);
    return state.getZoom() + offset;
}