#include #include #include #include #include #include #include namespace mbgl { namespace style { GeoJSONSource::GeoJSONSource(const std::string& id, const GeoJSONOptions& options) : Source(makeMutable(std::move(id), options)), stateChanges(makeMutable>()) { } GeoJSONSource::~GeoJSONSource() = default; const GeoJSONSource::Impl& GeoJSONSource::impl() const { return static_cast(*baseImpl); } void GeoJSONSource::setURL(const std::string& url_) { url = std::move(url_); // Signal that the source description needs a reload if (loaded || req) { loaded = false; req.reset(); observer->onSourceDescriptionChanged(*this); } } void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) { req.reset(); baseImpl = makeMutable(impl(), geoJSON); observer->onSourceChanged(*this); } void GeoJSONSource::setFeatureState(const FeatureIdentifier& featureId, const std::string& key, const mbgl::Value& value) { if ( featureId.valid() && !key.empty()) { stateChanges->emplace_back(FeatureStateChange::ChangeType::Insert, featureId, key, value); // observer->onSourceChanged(*this); } } Immutable> GeoJSONSource::collectFeatureStates() { Immutable> immutable(std::move(stateChanges)); stateChanges = makeMutable>(); printf("!)!)! Collecting feature state!@$!@$\n"); return immutable; } optional GeoJSONSource::getURL() const { return url; } void GeoJSONSource::loadDescription(FileSource& fileSource) { if (!url) { loaded = true; return; } if (req) { return; } req = fileSource.request(Resource::source(*url), [this](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 GeoJSON"))); } else { conversion::Error error; optional geoJSON = conversion::convertJSON(*res.data, error); if (!geoJSON) { Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s", error.message.c_str()); // Create an empty GeoJSON VT object to make sure we're not infinitely waiting for // tiles to load. baseImpl = makeMutable(impl(), GeoJSON{ FeatureCollection{} }); } else { baseImpl = makeMutable(impl(), *geoJSON); } loaded = true; observer->onSourceLoaded(*this); } }); } } // namespace style } // namespace mbgl