MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
geojson_source.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <mbgl/style/source.hpp>
5 #include <mbgl/tile/tile_id.hpp>
7 #include <mbgl/util/geojson.hpp>
8 
9 #include <map>
10 #include <memory>
11 #include <utility>
12 
13 namespace mbgl {
14 
15 class AsyncRequest;
16 class Scheduler;
17 namespace style {
18 
20  // GeoJSON-VT options
21  uint8_t minzoom = 0;
22  uint8_t maxzoom = 18;
24  uint16_t buffer = 128;
25  double tolerance = 0.375;
26  bool lineMetrics = false;
27 
28  // Supercluster options
29  bool cluster = false;
30  uint16_t clusterRadius = 50;
31  uint8_t clusterMaxZoom = 17;
32  using ClusterExpression = std::pair<std::shared_ptr<mbgl::style::expression::Expression>,
33  std::shared_ptr<mbgl::style::expression::Expression>>;
34  using ClusterProperties = std::map<std::string, ClusterExpression>;
36 
38 };
39 class GeoJSONData {
40 public:
41  using TileFeatures = mapbox::feature::feature_collection<int16_t>;
42  using Features = mapbox::feature::feature_collection<double>;
43  static std::shared_ptr<GeoJSONData> create(const GeoJSON&,
45  std::shared_ptr<Scheduler> scheduler = nullptr);
46 
47  virtual ~GeoJSONData() = default;
48  virtual void getTile(const CanonicalTileID&, const std::function<void(TileFeatures)>&) = 0;
49 
50  // SuperclusterData
51  virtual Features getChildren(std::uint32_t) = 0;
52  virtual Features getLeaves(std::uint32_t, std::uint32_t limit, std::uint32_t offset) = 0;
53  virtual std::uint8_t getClusterExpansionZoom(std::uint32_t) = 0;
54 
55  virtual std::shared_ptr<Scheduler> getScheduler() { return nullptr; }
56 };
57 
58 class GeoJSONSource final : public Source {
59 public:
61  ~GeoJSONSource() final;
62 
63  void setURL(const std::string& url);
64  void setGeoJSON(const GeoJSON&);
65  void setGeoJSONData(std::shared_ptr<GeoJSONData>);
66 
67  std::optional<std::string> getURL() const;
68  const GeoJSONOptions& getOptions() const;
69 
70  class Impl;
71  const Impl& impl() const;
72 
74 
75  bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const override;
76 
77  mapbox::base::WeakPtr<Source> makeWeakPtr() override {
78  return weakFactory.makeWeakPtr();
79  }
80 
81 protected:
82  Mutable<Source::Impl> createMutable() const noexcept final;
83 
84 private:
85  std::optional<std::string> url;
86  std::unique_ptr<AsyncRequest> req;
87  std::shared_ptr<Scheduler> threadPool;
88  mapbox::base::WeakPtrFactory<Source> weakFactory {this};
89 };
90 
91 template <>
92 inline bool Source::is<GeoJSONSource>() const {
93  return getType() == SourceType::GeoJSON;
94 }
95 
96 } // namespace style
97 } // namespace mbgl
virtual Features getLeaves(std::uint32_t, std::uint32_t limit, std::uint32_t offset)=0
mapbox::feature::feature_collection< int16_t > TileFeatures
virtual Features getChildren(std::uint32_t)=0
virtual std::uint8_t getClusterExpansionZoom(std::uint32_t)=0
mapbox::feature::feature_collection< double > Features
virtual void getTile(const CanonicalTileID &, const std::function< void(TileFeatures)> &)=0
virtual ~GeoJSONData()=default
virtual std::shared_ptr< Scheduler > getScheduler()
static std::shared_ptr< GeoJSONData > create(const GeoJSON &, const Immutable< GeoJSONOptions > &=GeoJSONOptions::defaultOptions(), std::shared_ptr< Scheduler > scheduler=nullptr)
void setGeoJSON(const GeoJSON &)
void loadDescription(FileSource &) final
std::optional< std::string > getURL() const
const Impl & impl() const
void setGeoJSONData(std::shared_ptr< GeoJSONData >)
void setURL(const std::string &url)
mapbox::base::WeakPtr< Source > makeWeakPtr() override
Mutable< Source::Impl > createMutable() const noexcept final
const GeoJSONOptions & getOptions() const
bool supportsLayerType(const mbgl::style::LayerTypeInfo *) const override
GeoJSONSource(std::string id, Immutable< GeoJSONOptions >=GeoJSONOptions::defaultOptions())
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
constexpr uint16_t tileSize_I
Definition: constants.hpp:14
Definition: actor.hpp:15
mapbox::geojson::geojson GeoJSON
Definition: geojson.hpp:8
Definition: tile_id.hpp:256
std::pair< std::shared_ptr< mbgl::style::expression::Expression >, std::shared_ptr< mbgl::style::expression::Expression > > ClusterExpression
ClusterProperties clusterProperties
static Immutable< GeoJSONOptions > defaultOptions()
std::map< std::string, ClusterExpression > ClusterProperties