void parse(const char* name, const JSValue& layer) {
        mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; });

        std::string transitionName = { name };
        transitionName += "-transition";

        for (auto it = layer.MemberBegin(); it != layer.MemberEnd(); ++it) {
            const std::string paintName { it->name.GetString(), it->name.GetStringLength() };
            if (paintName.compare(0, 5, "paint") != 0)
                continue;

            bool isClass = paintName.compare(0, 6, "paint.") == 0;
            if (isClass && paintName.length() <= 6)
                continue;

            ClassID classID = isClass ? ClassDictionary::Get().lookup(paintName.substr(6)) : ClassID::Default;

            if (it->value.HasMember(name)) {
                if (auto v = parseProperty<T>(name, it->value[name])) {
                    values.emplace(classID, v);
                }
            }

            if (it->value.HasMember(transitionName.c_str())) {
                if (auto v = parseTransitionOptions(name, it->value[transitionName.c_str()])) {
                    transitions.emplace(classID, *v);
                }
            }
        }
    }
Beispiel #2
0
void Parser::parseSources(const JSValue& value) {
    if (!value.IsObject()) {
        Log::Warning(Event::ParseStyle, "sources must be an object");
        return;
    }

    for (auto it = value.MemberBegin(); it != value.MemberEnd(); ++it) {
        std::string id = *conversion::toString(it->name);

        conversion::Result<std::unique_ptr<Source>> source
            = conversion::convert<std::unique_ptr<Source>>(it->value, id);
        if (!source) {
            Log::Warning(Event::ParseStyle, source.error().message);
            continue;
        }

        sourcesMap.emplace(id, (*source).get());
        sources.emplace_back(std::move(*source));
    }
}