Style::Style(const std::string& data, const std::string&, uv_loop_t* loop, Environment& env) : glyphStore(std::make_unique<GlyphStore>(loop, env)), glyphAtlas(std::make_unique<GlyphAtlas>(1024, 1024)), spriteAtlas(std::make_unique<SpriteAtlas>(512, 512)), lineAtlas(std::make_unique<LineAtlas>(512, 512)), mtx(std::make_unique<uv::rwlock>()), workers(4) { rapidjson::Document doc; doc.Parse<0>((const char *const)data.c_str()); if (doc.HasParseError()) { Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", doc.GetErrorOffset(), doc.GetParseError()); return; } StyleParser parser; parser.parse(doc); sources = parser.getSources(); layers = parser.getLayers(); spriteURL = parser.getSprite(); glyphStore->setURL(parser.getGlyphURL()); for (const auto& source : sources) { source->setObserver(this); source->load(); } glyphStore->setObserver(this); }
void Style::loadJSON(const uint8_t *const data) { uv::writelock lock(mtx); rapidjson::Document doc; doc.Parse<0>((const char *const)data); if (doc.HasParseError()) { Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", doc.GetErrorOffset(), doc.GetParseError()); return; } StyleParser parser; parser.parse(doc); sources = parser.getSources(); layers = parser.getLayers(); sprite_url = parser.getSprite(); glyph_url = parser.getGlyphURL(); }