#include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { namespace style { VectorSource::VectorSource(std::string id, variant urlOrTileset_, optional maxZoom_, optional minZoom_) : Source(makeMutable(std::move(id))), urlOrTileset(std::move(urlOrTileset_)), maxZoom(std::move(maxZoom_)), minZoom(std::move(minZoom_)) {} VectorSource::~VectorSource() = default; const VectorSource::Impl& VectorSource::impl() const { return static_cast(*baseImpl); } const variant& VectorSource::getURLOrTileset() const { return urlOrTileset; } optional VectorSource::getURL() const { if (urlOrTileset.is()) { return {}; } return urlOrTileset.get(); } void VectorSource::loadDescription(FileSource& fileSource) { if (urlOrTileset.is()) { baseImpl = makeMutable(impl(), urlOrTileset.get()); loaded = true; observer->onSourceLoaded(*this); return; } if (req) { return; } const auto& url = urlOrTileset.get(); req = fileSource.request(Resource::source(url), [this, url](const Response& res) { if (res.error) { observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message))); } else if (res.notModified) { return; } else if (res.noContent) { observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON"))); } else { conversion::Error error; optional tileset = conversion::convertJSON(*res.data, error); if (!tileset) { observer->onSourceError(*this, std::make_exception_ptr(util::StyleParseException(error.message))); return; } if (maxZoom) { tileset->zoomRange.max = *maxZoom; } if (minZoom) { tileset->zoomRange.min = *minZoom; } util::mapbox::canonicalizeTileset(*tileset, url, getType(), util::tileSize); bool changed = impl().tileset != *tileset; baseImpl = makeMutable(impl(), *tileset); loaded = true; observer->onSourceLoaded(*this); if (changed) { observer->onSourceChanged(*this); } } }); } bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const { return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind); } Mutable VectorSource::createMutable() const noexcept { return staticMutableCast(makeMutable(impl())); } } // namespace style } // namespace mbgl