diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-09-12 07:59:36 +0100 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-09-13 12:38:59 +0300 |
commit | 0cc062a5fd1f9ed63f688dbb802be252c04d917f (patch) | |
tree | a511062f6f0a20a2ae4400d2669bed3b392d79d6 /src/mbgl/map/map.cpp | |
parent | 4f23d0cda8facaa301532131f7d84c68cb7d3ff4 (diff) | |
download | qtlocation-mapboxgl-0cc062a5fd1f9ed63f688dbb802be252c04d917f.tar.gz |
[core] Check if style exists prior to accessing via Map functions
Diffstat (limited to 'src/mbgl/map/map.cpp')
-rw-r--r-- | src/mbgl/map/map.cpp | 78 |
1 files changed, 58 insertions, 20 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 9e18e67f3a..e7bb2bd7f4 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -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) { |