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

[not ready] anno remove bug fix & in-app settings to flex annotations #1061

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions include/mbgl/map/annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <memory>
#include <unordered_map>
#include <unordered_set>

namespace mbgl {

Expand All @@ -29,7 +30,7 @@ class AnnotationManager : private util::noncopyable {
void setDefaultPointAnnotationSymbol(const std::string& symbol);
std::pair<std::vector<Tile::ID>, AnnotationIDs> addPointAnnotations(
const std::vector<LatLng>&, const std::vector<std::string>& symbols, const Map&);
std::vector<Tile::ID> removeAnnotations(const AnnotationIDs&);
std::vector<Tile::ID> removeAnnotations(const AnnotationIDs&, const Map&);
AnnotationIDs getAnnotationsInBounds(const LatLngBounds&, const Map&) const;
LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const;

Expand All @@ -44,8 +45,8 @@ class AnnotationManager : private util::noncopyable {
private:
mutable std::mutex mtx;
std::string defaultPointAnnotationSymbol;
std::map<uint32_t, std::unique_ptr<Annotation>> annotations;
std::map<Tile::ID, std::pair<AnnotationIDs, std::unique_ptr<LiveTile>>> annotationTiles;
std::unordered_map<uint32_t, std::unique_ptr<Annotation>> annotations;
std::unordered_map<Tile::ID, std::pair<std::unordered_set<uint32_t>, std::unique_ptr<LiveTile>>, Tile::ID::Hash> tiles;
uint32_t nextID_ = 0;
};

Expand Down
7 changes: 7 additions & 0 deletions include/mbgl/map/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <forward_list>
#include <iosfwd>
#include <string>
#include <functional>

namespace mbgl {

Expand Down Expand Up @@ -44,6 +45,12 @@ class Tile : private util::noncopyable {
return ((std::pow(2, z) * y + x) * 32) + z;
}

struct Hash {
std::size_t operator()(ID const& i) const {
return std::hash<uint64_t>()(i.to_uint64());
}
};

inline bool operator==(const ID& rhs) const {
return w == rhs.w && z == rhs.z && x == rhs.x && y == rhs.y;
}
Expand Down
12 changes: 12 additions & 0 deletions ios/app/MBXAnnotation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

#import <mbgl/ios/MGLAnnotation.h>

@interface MBXAnnotation : NSObject <MGLAnnotation>

+ (instancetype)annotationWithLocation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

- (instancetype)initWithLocation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

@end
30 changes: 30 additions & 0 deletions ios/app/MBXAnnotation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#import "MBXAnnotation.h"

@interface MBXAnnotation ()

@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic) NSString *title;
@property (nonatomic) NSString *subtitle;

@end

@implementation MBXAnnotation

+ (instancetype)annotationWithLocation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle
{
return [[self alloc] initWithLocation:coordinate title:title subtitle:subtitle];
}

- (instancetype)initWithLocation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle
{
if (self = [super init])
{
_coordinate = coordinate;
_title = title;
_subtitle = subtitle;
}

return self;
}

@end
72 changes: 71 additions & 1 deletion ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#import <CoreLocation/CoreLocation.h>

#import "MBXAnnotation.h"

static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue:0.670 alpha:1.000];

static NSArray *const kStyleNames = @[
Expand Down Expand Up @@ -134,7 +136,14 @@ - (void)showSettings
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Reset North", @"Reset Position", @"Toggle Debug", nil];
otherButtonTitles:@"Reset North",
@"Reset Position",
@"Toggle Debug",
@"Add 100 Points",
@"Add 1,000 Points",
@"Add 10,000 Points",
@"Remove Points",
nil];

[sheet showFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}
Expand All @@ -153,6 +162,67 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
{
[self.mapView toggleDebug];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 3)
{
[self parseFeaturesAddingCount:100];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 4)
{
[self parseFeaturesAddingCount:1000];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 5)
{
[self parseFeaturesAddingCount:10000];
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 6)
{
[self.mapView removeAnnotations:self.mapView.annotations];
}
}

- (void)parseFeaturesAddingCount:(NSUInteger)featuresCount
{
[self.mapView removeAnnotations:self.mapView.annotations];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
NSData *featuresData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"features" ofType:@"geojson"]];

id features = [NSJSONSerialization JSONObjectWithData:featuresData
options:0
error:nil];

if ([features isKindOfClass:[NSDictionary class]])
{
NSMutableArray *annotations = [NSMutableArray array];

for (NSDictionary *feature in features[@"features"])
{
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake([feature[@"geometry"][@"coordinates"][1] doubleValue],
[feature[@"geometry"][@"coordinates"][0] doubleValue]);
NSString *title = feature[@"properties"][@"NAME"];

MBXAnnotation *annotation = [MBXAnnotation annotationWithLocation:coordinate
title:title
subtitle:nil];

[annotations addObject:annotation];

if (annotations.count == featuresCount) break;
}

dispatch_async(dispatch_get_main_queue(), ^
{
[self.mapView addAnnotations:annotations];

[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(38.904722, -77.016389)
zoomLevel:10
animated:NO];

[self.mapView setDirection:0];
});
}
});
}

- (void)cycleStyles
Expand Down
Loading