[ios, macos] Add selection support to MGLMultiPoint annotations. (#9984)

* [ios, macos] Add selection support to MGLMultiPoint annotations.

* [ios, macos] Update changelogs.
This commit is contained in:
Fabian Guerra Soto
2017-10-18 15:18:54 -04:00
committed by GitHub
parent 24fc48982a
commit b7b8baef9d
12 changed files with 167 additions and 66 deletions

View File

@@ -18,6 +18,7 @@ using namespace style;
const std::string AnnotationManager::SourceID = "com.mapbox.annotations";
const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points";
const std::string AnnotationManager::ShapeLayerID = "com.mapbox.annotations.shape.";
AnnotationManager::AnnotationManager(Style& style_)
: style(style_) {

View File

@@ -46,6 +46,7 @@ public:
static const std::string SourceID;
static const std::string PointLayerID;
static const std::string ShapeLayerID;
private:
void add(const AnnotationID&, const SymbolAnnotation&, const uint8_t);

View File

@@ -1,5 +1,6 @@
#include <mbgl/annotation/shape_annotation_impl.hpp>
#include <mbgl/annotation/annotation_tile.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/math/wrap.hpp>
#include <mbgl/math/clamp.hpp>
@@ -15,7 +16,7 @@ namespace geojsonvt = mapbox::geojsonvt;
ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_, const uint8_t maxZoom_)
: id(id_),
maxZoom(maxZoom_),
layerID("com.mapbox.annotations.shape." + util::toString(id)) {
layerID(AnnotationManager::ShapeLayerID + util::toString(id)) {
}
void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, AnnotationTileData& data) {

View File

@@ -57,6 +57,21 @@ AnnotationIDs Renderer::queryPointAnnotations(const ScreenBox& box) const {
RenderedQueryOptions options;
options.layerIDs = {{ AnnotationManager::PointLayerID }};
auto features = queryRenderedFeatures(box, options);
return getAnnotationIDs(features);
}
AnnotationIDs Renderer::queryShapeAnnotations(const ScreenBox& box) const {
auto features = impl->queryShapeAnnotations({
box.min,
{box.max.x, box.min.y},
box.max,
{box.min.x, box.max.y},
box.min
});
return getAnnotationIDs(features);
}
AnnotationIDs Renderer::getAnnotationIDs(const std::vector<Feature>& features) const {
std::set<AnnotationID> set;
for (auto &feature : features) {
assert(feature.id);

View File

@@ -629,6 +629,10 @@ std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin
}
}
return queryRenderedFeatures(geometry, options, layers);
}
std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options, const std::vector<const RenderLayer*>& layers) const {
std::unordered_set<std::string> sourceIDs;
for (const RenderLayer* layer : layers) {
sourceIDs.emplace(layer->baseImpl->source);
@@ -663,6 +667,21 @@ std::vector<Feature> Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin
return result;
}
std::vector<Feature> Renderer::Impl::queryShapeAnnotations(const ScreenLineString& geometry) const {
std::vector<const RenderLayer*> shapeAnnotationLayers;
RenderedQueryOptions options;
for (const auto& layerImpl : *layerImpls) {
if (std::mismatch(layerImpl->id.begin(), layerImpl->id.end(),
AnnotationManager::ShapeLayerID.begin(), AnnotationManager::ShapeLayerID.end()).second == AnnotationManager::ShapeLayerID.end()) {
if (const RenderLayer* layer = getRenderLayer(layerImpl->id)) {
shapeAnnotationLayers.emplace_back(layer);
}
}
}
return queryRenderedFeatures(geometry, options, shapeAnnotationLayers);
}
std::vector<Feature> Renderer::Impl::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) const {
const RenderSource* source = getRenderSource(sourceID);
if (!source) return {};

View File

@@ -49,6 +49,7 @@ public:
std::vector<Feature> queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&) const;
std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions&) const;
std::vector<Feature> queryShapeAnnotations(const ScreenLineString&) const;
void onLowMemory();
void dumDebugLogs();
@@ -61,6 +62,8 @@ private:
RenderLayer* getRenderLayer(const std::string& id);
const RenderLayer* getRenderLayer(const std::string& id) const;
std::vector<Feature> queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&, const std::vector<const RenderLayer*>&) const;
// GlyphManagerObserver implementation.
void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override;