Пример #1
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;
}
Пример #2
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;
}