diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/map/backend.hpp | 7 | ||||
-rw-r--r-- | include/mbgl/map/map.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/map/map_observer.hpp | 42 | ||||
-rw-r--r-- | include/mbgl/style/layers/custom_layer.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/style/source.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/util/enum.hpp | 38 | ||||
-rw-r--r-- | include/mbgl/util/exception.hpp | 15 |
7 files changed, 83 insertions, 28 deletions
diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp index 4a43921c0b..cd756abe43 100644 --- a/include/mbgl/map/backend.hpp +++ b/include/mbgl/map/backend.hpp @@ -1,6 +1,6 @@ #pragma once -#include <mbgl/map/change.hpp> +#include <mbgl/map/map_observer.hpp> #include <memory> @@ -12,7 +12,7 @@ class Context; class BackendScope; -class Backend { +class Backend : public MapObserver { public: Backend(); virtual ~Backend(); @@ -24,9 +24,6 @@ public: // in the near future. (Not called for Map::renderStill() mode.) virtual void invalidate() = 0; - // Notifies a watcher of map x/y/scale/rotation changes. - virtual void notifyMapChange(MapChange change); - protected: // Called when the backend's GL context needs to be made active or inactive. These are called, // as a matched pair, in four situations: diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 02e14bea4e..79fcd34d9b 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -2,6 +2,7 @@ #include <mbgl/util/optional.hpp> #include <mbgl/util/chrono.hpp> +#include <mbgl/map/map_observer.hpp> #include <mbgl/map/mode.hpp> #include <mbgl/util/geo.hpp> #include <mbgl/util/feature.hpp> diff --git a/include/mbgl/map/map_observer.hpp b/include/mbgl/map/map_observer.hpp new file mode 100644 index 0000000000..4fefb79121 --- /dev/null +++ b/include/mbgl/map/map_observer.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include <mbgl/style/source.hpp> + +#include <cstdint> +#include <exception> +#include <string> + +namespace mbgl { + +class MapObserver { +public: + static MapObserver& nullObserver() { + static MapObserver mapObserver; + return mapObserver; + } + + enum class CameraChangeMode : uint32_t { + Immediate, + Animated + }; + + enum class RenderMode : uint32_t { + Partial, + Full + }; + + virtual void onCameraWillChange(CameraChangeMode) {} + virtual void onCameraIsChanging() {} + virtual void onCameraDidChange(CameraChangeMode) {} + virtual void onWillStartLoadingMap() {} + virtual void onDidFinishLoadingMap() {} + virtual void onDidFailLoadingMap(std::exception_ptr) {} + virtual void onWillStartRenderingFrame() {} + virtual void onDidFinishRenderingFrame(RenderMode) {} + virtual void onWillStartRenderingMap() {} + virtual void onDidFinishRenderingMap(RenderMode) {} + virtual void onDidFinishLoadingStyle() {} + virtual void onSourceChanged(style::Source&) {} +}; + +} // namespace mbgl diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 6bde087820..edc8d43f89 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -65,9 +65,7 @@ public: }; template <> -inline bool Layer::is<CustomLayer>() const { - return type == Type::Custom; -} +bool Layer::is<CustomLayer>() const; } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index 0901bb1954..0e6e32b112 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -3,6 +3,7 @@ #include <mbgl/util/feature.hpp> #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/optional.hpp> +#include <mbgl/util/range.hpp> #include <mbgl/style/types.hpp> #include <mbgl/style/query.hpp> @@ -55,7 +56,8 @@ public: std::unique_ptr<Source> copy(const std::string& id) const; optional<std::string> getAttribution() const; - + optional<Range<uint8_t>> getZoomRange() const; + std::vector<Feature> querySourceFeatures(const SourceQueryOptions& options = {}); // Private implementation diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp index 48ffda463e..369ca86bfd 100644 --- a/include/mbgl/util/enum.hpp +++ b/include/mbgl/util/enum.hpp @@ -11,26 +11,26 @@ namespace mbgl { template <typename T> class Enum { public: - using Value = std::pair<const T, const char *>; - - static const char * toString(T t) { - auto it = std::find_if(begin, end, [&] (const auto& v) { return t == v.first; }); - assert(it != end); return it->second; - } - - static optional<T> toEnum(const std::string& s) { - auto it = std::find_if(begin, end, [&] (const auto& v) { return s == v.second; }); - return it == end ? optional<T>() : it->first; - } - -private: - static const Value* begin; - static const Value* end; + static const char * toString(T); + static optional<T> toEnum(const std::string&); }; -#define MBGL_DEFINE_ENUM(type, strings...) \ -const constexpr Enum<type>::Value type##_names[] = strings; \ -template <> const Enum<type>::Value* Enum<type>::begin = std::begin(type##_names); \ -template <> const Enum<type>::Value* Enum<type>::end = std::end(type##_names) +#define MBGL_DEFINE_ENUM(T, values...) \ + \ +static const constexpr std::pair<const T, const char *> T##_names[] = values; \ + \ +template <> \ +const char * Enum<T>::toString(T t) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&] (const auto& v) { return t == v.first; }); \ + assert(it != std::end(T##_names)); return it->second; \ +} \ + \ +template <> \ +optional<T> Enum<T>::toEnum(const std::string& s) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&] (const auto& v) { return s == v.second; }); \ + return it == std::end(T##_names) ? optional<T>() : it->first; \ +} } // namespace mbgl diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp index 46de8528c7..a9804e96c5 100644 --- a/include/mbgl/util/exception.hpp +++ b/include/mbgl/util/exception.hpp @@ -20,5 +20,20 @@ struct MisuseException : Exception { MisuseException(const std::string &msg) : Exception(msg) {} }; +struct StyleParseException : Exception { + StyleParseException(const char *msg) : Exception(msg) {} + StyleParseException(const std::string &msg) : Exception(msg) {} +}; + +struct StyleLoadException : Exception { + StyleLoadException(const char *msg) : Exception(msg) {} + StyleLoadException(const std::string &msg) : Exception(msg) {} +}; + +struct NotFoundException : Exception { + NotFoundException(const char *msg) : Exception(msg) {} + NotFoundException(const std::string &msg) : Exception(msg) {} +}; + } // namespace util } // namespace mbgl |