예제 #1
0
    void SetUp() override {
        LOG("SETUP");
        if (scene) {  return; }

        auto sceneRelPath = setResourceRoot(sceneFile);
        auto sceneString = stringFromFile(sceneRelPath.c_str(), PathType::resource);

        YAML::Node sceneNode;

        try { sceneNode = YAML::Load(sceneString); }
        catch (YAML::ParserException e) {
            LOGE("Parsing scene config '%s'", e.what());
            return;
        }
        scene = std::make_unique<Scene>();
        SceneLoader::loadScene(sceneNode, *scene);
        styleContext.initFunctions(*scene);
        styleContext.setGlobalZoom(10);

        const char* path = "tile.mvt";

        std::ifstream resource(path, std::ifstream::ate | std::ifstream::binary);
        if(!resource.is_open()) {
            LOGE("Failed to read file at path: %s", path.c_str());
            return;
        }

        size_t _size = resource.tellg();
        resource.seekg(std::ifstream::beg);

        rawTileData.resize(_size);

        resource.read(&rawTileData[0], _size);
        resource.close();

        LOG("Initialized TileData");

        Tile tile({0,0,0}, s_projection);

        if (!scene->dataSources().empty()) {
            source = scene->dataSources()[0];
            auto task = source->createTask(tile.getID());
            auto& t = dynamic_cast<DownloadTileTask&>(*task);
            t.rawTileData = std::make_shared<std::vector<char>>();
            std::swap(*t.rawTileData, rawTileData);

            tileData = source->parse(*task, s_projection);
        }

        LOG("Ready");
    }
예제 #2
0
void Tile::build(StyleContext& _ctx, const Scene& _scene, const TileData& _data,
                 const DataSource& _source) {

    // Initialize m_geometry
    initGeometry(_scene.styles().size());

    const auto& layers = _scene.layers();

    _ctx.setGlobalZoom(m_id.s);

    for (auto& style : _scene.styles()) {
        style->onBeginBuildTile(*this);
    }

    DrawRuleMergeSet ruleSet;

    for (const auto& datalayer : layers) {

        if (datalayer.source() != _source.name()) {
            continue;
        }

        for (const auto& collection : _data.layers) {

            if (!collection.name.empty()) {
                const auto& dlc = datalayer.collections();
                bool layerContainsCollection =
                    std::find(dlc.begin(), dlc.end(), collection.name) != dlc.end();

                if (!layerContainsCollection) {
                    continue;
                }
            }

            for (const auto& feat : collection.features) {
                ruleSet.apply(feat, _scene, datalayer, _ctx, *this);
            }
        }
    }

    for (auto& style : _scene.styles()) {
        style->onEndBuildTile(*this);
    }

    for (auto& geometry : m_geometry) {
        if (geometry) {
            geometry->compileVertexBuffer();
        }
    }
}
예제 #3
0
    void loadScene(const char* sceneFile) {
        auto sceneRelPath = setResourceRoot(sceneFile);
        auto sceneString = stringFromFile(sceneRelPath.c_str(), PathType::resource);

        YAML::Node sceneNode;

        try { sceneNode = YAML::Load(sceneString); }
        catch (YAML::ParserException e) {
            LOGE("Parsing scene config '%s'", e.what());
            return;
        }
        scene = std::make_unique<Scene>();
        SceneLoader::loadScene(sceneNode, *scene);
        styleContext.initFunctions(*scene);
        styleContext.setGlobalZoom(0);

        source = scene->dataSources()[0];
    }