[ios, osx] Feature querying; complex geometry classes
Added methods to MGLMapView that return the rendered features at a visible point or within a visible rectangle on the map, optionally restricted to a set of layers, plus voluminous documentation. Added several new geometry classes corresponding to distinct geometry types supported by geometry.hpp. Added parallel “feature” classes to represent these geometries along with tags (IDs) and attributes (properties) from the source. Grouped classes in the Foundation and SDK groups by theme. In iosapp, dropped pins’ callout views now display the name of the topmost named feature at that point. In osxapp, a long press on the map highlights the features under the cursor. Dropping a pin via the menu or context menu item shows the usual dropped pin, but the pin’s title is now the name of a feature under the cursor, if available, rather than “Dropped Pin”. Fixes the iOS/OS X side of #352.
This commit is contained in:
committed by
Minh Nguyễn
parent
c9520713ca
commit
c6683ee1d3
@@ -26,6 +26,7 @@
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
|
||||
#import "Mapbox.h"
|
||||
#import "MGLFeature_Private.h"
|
||||
#import "MGLGeometry_Private.h"
|
||||
#import "MGLMultiPoint_Private.h"
|
||||
#import "MGLOfflineStorage_Private.h"
|
||||
@@ -2814,6 +2815,22 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
[(MGLMultiPoint *)annotation addShapeAnnotationObjectToCollection:shapes withDelegate:self];
|
||||
[userShapes addObject:annotation];
|
||||
}
|
||||
else if ([annotation isKindOfClass:[MGLMultiPolyline class]])
|
||||
{
|
||||
// TODO: Add real support for these types down in mbgl instead of breaking the annotation apart.
|
||||
NS_ARRAY_OF(MGLPolyline *) *polylines = [(MGLMultiPolyline *)annotation polylines];
|
||||
[self addAnnotations:polylines];
|
||||
}
|
||||
else if ([annotation isKindOfClass:[MGLMultiPolygon class]])
|
||||
{
|
||||
NS_ARRAY_OF(MGLPolygon *) *polygons = [(MGLMultiPolygon *)annotation polygons];
|
||||
[self addAnnotations:polygons];
|
||||
}
|
||||
else if ([annotation isKindOfClass:[MGLShapeCollection class]])
|
||||
{
|
||||
NS_ARRAY_OF(MGLShape <MGLAnnotation> *) *shapes = [(MGLShapeCollection *)annotation shapes];
|
||||
[self addAnnotations:shapes];
|
||||
}
|
||||
else
|
||||
{
|
||||
MGLAnnotationView *annotationView;
|
||||
@@ -4184,6 +4201,57 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Data
|
||||
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point
|
||||
{
|
||||
return [self visibleFeaturesAtPoint:point inStyleLayersWithIdentifiers:nil];
|
||||
}
|
||||
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesAtPoint:(CGPoint)point inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers
|
||||
{
|
||||
mbgl::ScreenCoordinate screenCoordinate = { point.x, point.y };
|
||||
|
||||
mbgl::optional<std::vector<std::string>> optionalLayerIDs;
|
||||
if (styleLayerIdentifiers)
|
||||
{
|
||||
__block std::vector<std::string> layerIDs;
|
||||
layerIDs.reserve(styleLayerIdentifiers.count);
|
||||
[styleLayerIdentifiers enumerateObjectsUsingBlock:^(NSString * _Nonnull identifier, BOOL * _Nonnull stop)
|
||||
{
|
||||
layerIDs.push_back(identifier.UTF8String);
|
||||
}];
|
||||
optionalLayerIDs = layerIDs;
|
||||
}
|
||||
|
||||
std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenCoordinate, optionalLayerIDs);
|
||||
return MGLFeaturesFromMBGLFeatures(features);
|
||||
}
|
||||
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect {
|
||||
return [self visibleFeaturesInRect:rect inStyleLayersWithIdentifiers:nil];
|
||||
}
|
||||
|
||||
- (NS_ARRAY_OF(id <MGLFeature>) *)visibleFeaturesInRect:(CGRect)rect inStyleLayersWithIdentifiers:(NS_SET_OF(NSString *) *)styleLayerIdentifiers {
|
||||
mbgl::ScreenBox screenBox = {
|
||||
{ CGRectGetMinX(rect), CGRectGetMinY(rect) },
|
||||
{ CGRectGetMaxX(rect), CGRectGetMaxY(rect) },
|
||||
};
|
||||
|
||||
mbgl::optional<std::vector<std::string>> optionalLayerIDs;
|
||||
if (styleLayerIdentifiers) {
|
||||
__block std::vector<std::string> layerIDs;
|
||||
layerIDs.reserve(styleLayerIdentifiers.count);
|
||||
[styleLayerIdentifiers enumerateObjectsUsingBlock:^(NSString * _Nonnull identifier, BOOL * _Nonnull stop) {
|
||||
layerIDs.push_back(identifier.UTF8String);
|
||||
}];
|
||||
optionalLayerIDs = layerIDs;
|
||||
}
|
||||
|
||||
std::vector<mbgl::Feature> features = _mbglMap->queryRenderedFeatures(screenBox, optionalLayerIDs);
|
||||
return MGLFeaturesFromMBGLFeatures(features);
|
||||
}
|
||||
|
||||
#pragma mark - Utility -
|
||||
|
||||
- (void)animateWithDelay:(NSTimeInterval)delay animations:(void (^)(void))animations
|
||||
|
||||
Reference in New Issue
Block a user