[core] Check if style exists prior to accessing via Map functions
This commit is contained in:
@@ -761,26 +761,40 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
|
||||
#pragma mark - Style API
|
||||
|
||||
style::Source* Map::getSource(const std::string& sourceID) {
|
||||
impl->styleMutated = true;
|
||||
return impl->style ? impl->style->getSource(sourceID) : nullptr;
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
return impl->style->getSource(sourceID);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Map::addSource(std::unique_ptr<style::Source> source) {
|
||||
impl->styleMutated = true;
|
||||
impl->style->addSource(std::move(source));
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
impl->style->addSource(std::move(source));
|
||||
}
|
||||
}
|
||||
|
||||
void Map::removeSource(const std::string& sourceID) {
|
||||
impl->styleMutated = true;
|
||||
impl->style->removeSource(sourceID);
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
impl->style->removeSource(sourceID);
|
||||
}
|
||||
}
|
||||
|
||||
style::Layer* Map::getLayer(const std::string& layerID) {
|
||||
impl->styleMutated = true;
|
||||
return impl->style ? impl->style->getLayer(layerID) : nullptr;
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
return impl->style->getLayer(layerID);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& before) {
|
||||
if (!impl->style) {
|
||||
return;
|
||||
}
|
||||
|
||||
impl->styleMutated = true;
|
||||
impl->view.activate();
|
||||
|
||||
@@ -792,6 +806,10 @@ void Map::addLayer(std::unique_ptr<Layer> layer, const optional<std::string>& be
|
||||
}
|
||||
|
||||
void Map::removeLayer(const std::string& id) {
|
||||
if (!impl->style) {
|
||||
return;
|
||||
}
|
||||
|
||||
impl->styleMutated = true;
|
||||
impl->view.activate();
|
||||
|
||||
@@ -805,23 +823,38 @@ void Map::removeLayer(const std::string& id) {
|
||||
#pragma mark - Defaults
|
||||
|
||||
std::string Map::getStyleName() const {
|
||||
return impl->style->getName();
|
||||
if (impl->style) {
|
||||
return impl->style->getName();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
LatLng Map::getDefaultLatLng() const {
|
||||
return impl->style->getDefaultLatLng();
|
||||
if (impl->style) {
|
||||
return impl->style->getDefaultLatLng();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
double Map::getDefaultZoom() const {
|
||||
return impl->style->getDefaultZoom();
|
||||
if (impl->style) {
|
||||
return impl->style->getDefaultZoom();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
double Map::getDefaultBearing() const {
|
||||
return impl->style->getDefaultBearing();
|
||||
if (impl->style) {
|
||||
return impl->style->getDefaultBearing();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
double Map::getDefaultPitch() const {
|
||||
return impl->style->getDefaultPitch();
|
||||
if (impl->style) {
|
||||
return impl->style->getDefaultPitch();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#pragma mark - Toggles
|
||||
@@ -860,32 +893,37 @@ MapDebugOptions Map::getDebug() const {
|
||||
}
|
||||
|
||||
bool Map::isFullyLoaded() const {
|
||||
return impl->style->isLoaded();
|
||||
return impl->style ? impl->style->isLoaded() : false;
|
||||
}
|
||||
|
||||
void Map::addClass(const std::string& className, const TransitionOptions& properties) {
|
||||
if (impl->style->addClass(className, properties)) {
|
||||
if (impl->style && impl->style->addClass(className, properties)) {
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::removeClass(const std::string& className, const TransitionOptions& properties) {
|
||||
if (impl->style->removeClass(className, properties)) {
|
||||
if (impl->style && impl->style->removeClass(className, properties)) {
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setClasses(const std::vector<std::string>& classNames, const TransitionOptions& properties) {
|
||||
impl->style->setClasses(classNames, properties);
|
||||
update(Update::Classes);
|
||||
if (impl->style) {
|
||||
impl->style->setClasses(classNames, properties);
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
bool Map::hasClass(const std::string& className) const {
|
||||
return impl->style->hasClass(className);
|
||||
return impl->style ? impl->style->hasClass(className) : false;
|
||||
}
|
||||
|
||||
std::vector<std::string> Map::getClasses() const {
|
||||
return impl->style->getClasses();
|
||||
if (impl->style) {
|
||||
return impl->style->getClasses();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Map::setSourceTileCacheSize(size_t size) {
|
||||
|
||||
Reference in New Issue
Block a user