Esempio n. 1
0
/**
 * Find a loaded parent of the given tile.
 *
 * @param id The tile ID that we should find children for.
 * @param minCoveringZoom The minimum zoom level of parents to look for.
 * @param retain An object that we add the found tiles to.
 *
 * @return boolean Whether a parent was found.
 */
bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::forward_list<Tile::ID>& retain) {
    for (int32_t z = id.z - 1; z >= minCoveringZoom; --z) {
        const Tile::ID parent_id = id.parent(z);
        const TileData::State state = hasTile(parent_id);
        if (state == TileData::State::parsed) {
            retain.emplace_front(parent_id);
            return true;
        }
    }
    return false;
}
Esempio n. 2
0
std::forward_list<mbgl::Tile::ID> Source::covering_tiles(const TransformState &state, int32_t clamped_zoom, const box& points) {
    int32_t dim = std::pow(2, clamped_zoom);
    std::forward_list<mbgl::Tile::ID> tiles;
    bool is_raster = (info.type == SourceType::Raster);
    double search_zoom = getZoom(state);

    auto scanLine = [&tiles, clamped_zoom, is_raster, search_zoom](int32_t x0, int32_t x1, int32_t y, int32_t ymax) {
        int32_t x;
        if (y >= 0 && y <= ymax) {
            for (x = x0; x < x1; x++) {
                if (is_raster) {
                    Tile::ID id = Tile::ID(clamped_zoom, x, y);
                    auto ids = id.children(search_zoom);
                    for (const Tile::ID& child_id : ids) {
                        tiles.emplace_front(child_id.z, child_id.x, child_id.y);
                    }
                } else {
                    tiles.emplace_front(clamped_zoom, x, y);
                }
            }
        }
    };

    // Divide the screen up in two triangles and scan each of them:
    // \---+
    // | \ |
    // +---\.
    _scanTriangle(points.tl, points.tr, points.br, 0, dim, scanLine);
    _scanTriangle(points.br, points.bl, points.tl, 0, dim, scanLine);

    const vec2<double>& center = points.center;
    tiles.sort([&center](const Tile::ID& a, const Tile::ID& b) {
        // Sorts by distance from the box center
        return std::fabs(a.x - center.x) + std::fabs(a.y - center.y) <
        std::fabs(b.x - center.x) + std::fabs(b.y - center.y);
    });

    tiles.unique();

    return tiles;
}
Esempio n. 3
0
TileData::State Source::addTile(Map& map, uv::worker& worker,
                                util::ptr<Style> style,
                                GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
                                SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite,
                                FileSource& fileSource, Texturepool& texturepool,
                                const Tile::ID& id,
                                std::function<void ()> callback) {
    const TileData::State state = hasTile(id);

    if (state != TileData::State::invalid) {
        return state;
    }

    auto pos = tiles.emplace(id, std::make_unique<Tile>(id));
    Tile& new_tile = *pos.first->second;

    // We couldn't find the tile in the list. Create a new one.
    // Try to find the associated TileData object.
    const Tile::ID normalized_id = id.normalized();

    auto it = tile_data.find(normalized_id);
    if (it != tile_data.end()) {
        // Create a shared_ptr handle. Note that this might be empty!
        new_tile.data = it->second.lock();
    }

    if (new_tile.data && new_tile.data->state == TileData::State::obsolete) {
        // Do not consider the tile if it's already obsolete.
        new_tile.data.reset();
    }

    if (!new_tile.data) {
        // If we don't find working tile data, we're just going to load it.
        if (info.type == SourceType::Vector) {
            new_tile.data = std::make_shared<VectorTileData>(normalized_id, map.getMaxZoom(), style,
                                                             glyphAtlas, glyphStore,
                                                             spriteAtlas, sprite,
                                                             texturepool, info);
        } else if (info.type == SourceType::Raster) {
            new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturepool, info);
        } else {
            throw std::runtime_error("source type not implemented");
        }

        new_tile.data->request(worker, fileSource, map.getState().getPixelRatio(), callback);
        tile_data.emplace(new_tile.data->id, new_tile.data);
    }

    return new_tile.data->state;
}
Esempio n. 4
0
/**
 * Recursively find children of the given tile that are already loaded.
 *
 * @param id The tile ID that we should find children for.
 * @param maxCoveringZoom The maximum zoom level of children to look for.
 * @param retain An object that we add the found tiles to.
 *
 * @return boolean Whether the children found completely cover the tile.
 */
bool Source::findLoadedChildren(const Tile::ID& id, int32_t maxCoveringZoom, std::forward_list<Tile::ID>& retain) {
    bool complete = true;
    int32_t z = id.z;
    auto ids = id.children(z + 1);
    for (const Tile::ID& child_id : ids) {
        const TileData::State state = hasTile(child_id);
        if (state == TileData::State::parsed) {
            retain.emplace_front(child_id);
        } else {
            complete = false;
            if (z < maxCoveringZoom) {
                // Go further down the hierarchy to find more unloaded children.
                findLoadedChildren(child_id, maxCoveringZoom, retain);
            }
        }
    }
    return complete;
}
Esempio n. 5
0
TileData::State Source::addTile(Map &map, const Tile::ID& id) {
    const TileData::State state = hasTile(id);

    if (state != TileData::State::invalid) {
        return state;
    }

    auto pos = tiles.emplace(id, std::make_unique<Tile>(id));
    Tile& new_tile = *pos.first->second;

    // We couldn't find the tile in the list. Create a new one.
    // Try to find the associated TileData object.
    const Tile::ID normalized_id = id.normalized();

    auto it = tile_data.find(normalized_id);
    if (it != tile_data.end()) {
        // Create a shared_ptr handle. Note that this might be empty!
        new_tile.data = it->second.lock();
    }

    if (new_tile.data && new_tile.data->state == TileData::State::obsolete) {
        // Do not consider the tile if it's already obsolete.
        new_tile.data.reset();
    }

    if (!new_tile.data) {
        // If we don't find working tile data, we're just going to load it.
        if (info.type == SourceType::Vector) {
            new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, info);
        } else if (info.type == SourceType::Raster) {
            new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, info);
        } else if (info.type == SourceType::GeoJSON) {
            new_tile.data = std::make_shared<GeoJSONTileData>(normalized_id, map, info);
        } else {
            throw std::runtime_error("source type not implemented");
        }

        new_tile.data->request();
        tile_data.emplace(new_tile.data->id, new_tile.data);
    }

    return new_tile.data->state;
}