Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
create LiveTile* objects on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Jun 10, 2015
1 parent b9809c6 commit bddbdbb
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 283 deletions.
82 changes: 82 additions & 0 deletions src/mbgl/annotation/point_annotation_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <mbgl/annotation/point_annotation_layer.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wshadow"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#endif
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wdeprecated-register"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/box.hpp>
#include <boost/geometry/index/rtree.hpp>
#pragma GCC diagnostic pop

namespace bg = boost::geometry;

// Make Boost Geometry aware of our LatLng type
BOOST_GEOMETRY_REGISTER_POINT_2D(mbgl::LatLng, double, bg::cs::cartesian, longitude, latitude)
BOOST_GEOMETRY_REGISTER_BOX(mbgl::LatLngBounds, mbgl::LatLng, sw, ne)

// Tell Boost Geometry how to access a std::shared_ptr<mbgl::PointAnnotation> object.
namespace boost {
namespace geometry {
namespace index {

template <>
struct indexable<std::shared_ptr<const mbgl::Annotation>> {
using result_type = const mbgl::LatLng&;
inline const mbgl::LatLng& operator()(const std::shared_ptr<const mbgl::Annotation>& v) const {
return v->point;
}
};

} // end namespace index
} // end namespace geometry
} // end namespace boost

namespace mbgl {

class PointAnnotationLayer::Tree {
public:
using Value = std::shared_ptr<const Annotation>;
bg::index::rtree<Value, bg::index::rstar<16, 4>> data;
};

PointAnnotationLayer::PointAnnotationLayer() : tree(std::make_unique<Tree>()) {
}

PointAnnotationLayer::~PointAnnotationLayer() = default;

void PointAnnotationLayer::add(const std::shared_ptr<const Annotation>& point) {
tree->data.insert(point);
}

void PointAnnotationLayer::add(const std::vector<std::shared_ptr<const Annotation>>& points) {
tree->data.insert(points);
}

void PointAnnotationLayer::remove(const std::shared_ptr<const Annotation>& point) {
tree->data.remove(point);
}

void PointAnnotationLayer::remove(const std::vector<std::shared_ptr<const Annotation>>& points) {
tree->data.remove(points);
}

std::vector<std::shared_ptr<const Annotation>> PointAnnotationLayer::getInBounds(const LatLngBounds& bounds) const {
std::vector<std::shared_ptr<const Annotation>> result;
tree->data.query(bg::index::intersects(bounds), std::back_inserter(result));
return result;
}

} // end namespace mbgl
37 changes: 37 additions & 0 deletions src/mbgl/annotation/point_annotation_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef MBGL_ANNOTATION_POINT_ANNOTATION_LAYER
#define MBGL_ANNOTATION_POINT_ANNOTATION_LAYER

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/map/annotation.hpp>
#include <mbgl/map/tile.hpp>

#include <string>
#include <vector>

namespace mbgl {

// Stores a tree of AnnotationPoints. Creates Bucket objects for a particular tile ID.
class PointAnnotationLayer : private util::noncopyable {
class Tree;

public:
PointAnnotationLayer();
~PointAnnotationLayer();

void add(const std::shared_ptr<const Annotation>&);
void add(const std::vector<std::shared_ptr<const Annotation>>&);

void remove(const std::shared_ptr<const Annotation>&);
void remove(const std::vector<std::shared_ptr<const Annotation>>&);

std::vector<std::shared_ptr<const Annotation>> getInBounds(const LatLngBounds&) const;

private:

const std::unique_ptr<Tree> tree;
};

} // end namespace mbgl

#endif
Loading

0 comments on commit bddbdbb

Please sign in to comment.