MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
feature.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <mbgl/util/string.hpp>
4 
5 #include <mapbox/compatibility/value.hpp>
6 
7 #include <optional>
8 
9 namespace mbgl {
10 
13 using PropertyMap = mapbox::base::ValueObject;
14 using FeatureIdentifier = mapbox::feature::identifier;
15 using GeoJSONFeature = mapbox::feature::feature<double>;
16 using FeatureState = mapbox::base::ValueObject;
17 using FeatureStates = std::unordered_map<std::string, FeatureState>; // <featureID, FeatureState>
18 using LayerFeatureStates = std::unordered_map<std::string, FeatureStates>; // <sourceLayer, FeatureStates>
19 
20 class Feature : public GeoJSONFeature {
21 public:
25 
26  using GeometryType = mapbox::geometry::geometry<double>;
27 
28  Feature() = default;
30  Feature(const GeometryType& geom_) : GeoJSONFeature(geom_) {}
31  Feature(GeometryType&& geom_) : GeoJSONFeature(std::move(geom_)) {}
32 };
33 
34 template <class T>
35 std::optional<T> numericValue(const Value& value) {
36  return value.match([](uint64_t t) { return std::optional<T>(static_cast<T>(t)); },
37  [](int64_t t) { return std::optional<T>(static_cast<T>(t)); },
38  [](double t) { return std::optional<T>(static_cast<T>(t)); },
39  [](const auto&) { return std::optional<T>(); });
40 }
41 
42 inline std::optional<std::string> featureIDtoString(const FeatureIdentifier& id) {
43  if (id.is<NullValue>()) {
44  return std::nullopt;
45  }
46 
47  return id.match(
48  [](const std::string& value_) { return value_; }, [](uint64_t value_) { return util::toString(value_); },
49  [](int64_t value_) { return util::toString(value_); }, [](double value_) { return util::toString(value_); },
50 [](const auto&) -> std::optional<std::string> { return std::nullopt; });
51 }
52 
53 } // namespace mbgl
std::string source
Definition: feature.hpp:22
PropertyMap state
Definition: feature.hpp:24
Feature(GeometryType &&geom_)
Definition: feature.hpp:31
Feature(const GeoJSONFeature &f)
Definition: feature.hpp:29
Feature()=default
Feature(const GeometryType &geom_)
Definition: feature.hpp:30
std::string sourceLayer
Definition: feature.hpp:23
mapbox::geometry::geometry< double > GeometryType
Definition: feature.hpp:26
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
std::string toString(const CanonicalTileID &)
Definition: actor.hpp:15
mapbox::feature::identifier FeatureIdentifier
Definition: feature.hpp:14
mapbox::base::NullValue NullValue
Definition: feature.hpp:12
std::unordered_map< std::string, FeatureStates > LayerFeatureStates
Definition: feature.hpp:18
mapbox::base::Value Value
Definition: feature.hpp:11
std::unordered_map< std::string, FeatureState > FeatureStates
Definition: feature.hpp:17
mapbox::base::ValueObject FeatureState
Definition: feature.hpp:16
mapbox::base::ValueObject PropertyMap
Definition: feature.hpp:13
mapbox::feature::feature< double > GeoJSONFeature
Definition: feature.hpp:15
std::optional< T > numericValue(const Value &value)
Definition: feature.hpp:35
std::optional< std::string > featureIDtoString(const FeatureIdentifier &id)
Definition: feature.hpp:42
Definition: tile_id.hpp:256