Merge pull request #1133 from mapbox/metrics-less-magic-strings

more metrics magic strings removals
This commit is contained in:
Justin R. Miller
2015-03-27 00:14:27 -07:00
4 changed files with 65 additions and 53 deletions

View File

@@ -1,16 +1,24 @@
#import <Foundation/Foundation.h>
extern NSString *const MGLEventMapLoad;
extern NSString *const MGLEventMapTap;
extern NSString *const MGLEventMapSingleTap;
extern NSString *const MGLEventMapDoubleTap;
extern NSString *const MGLEventMapTwoFingerSingleTap;
extern NSString *const MGLEventMapQuickZoom;
extern NSString *const MGLEventMapPanStart;
extern NSString *const MGLEventMapPanEnd;
extern NSString *const MGLEventMapPinchStart;
extern NSString *const MGLEventMapRotateStart;
extern NSString *const MGLEventMapLocation;
extern NSString *const MGLEventTypeMapLoad;
extern NSString *const MGLEventTypeMapTap;
extern NSString *const MGLEventTypeMapDragEnd;
extern NSString *const MGLEventTypeLocation;
extern NSString *const MGLEventKeyLatitude;
extern NSString *const MGLEventKeyLongitude;
extern NSString *const MGLEventKeyZoomLevel;
extern NSString *const MGLEventKeyPushEnabled;
extern NSString *const MGLEventKeyEmailEnabled;
extern NSString *const MGLEventKeyGestureID;
extern NSString *const MGLEventGestureSingleTap;
extern NSString *const MGLEventGestureDoubleTap;
extern NSString *const MGLEventGestureTwoFingerSingleTap;
extern NSString *const MGLEventGestureQuickZoom;
extern NSString *const MGLEventGesturePanStart;
extern NSString *const MGLEventGesturePinchStart;
extern NSString *const MGLEventGestureRotateStart;
@interface MGLMapboxEvents : NSObject

View File

@@ -355,12 +355,12 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
const mbgl::LatLng latLng = mbglMap->getLatLng();
const double zoom = mbglMap->getZoom();
[MGLMapboxEvents pushEvent:MGLEventMapLoad withAttributes:@{
@"lat": @(latLng.latitude),
@"lng": @(latLng.longitude),
@"zoom": @(zoom),
@"enabled.push": @([MGLMapboxEvents checkPushEnabled]),
@"enabled.email": [MGLMapboxEvents checkEmailEnabled]
[MGLMapboxEvents pushEvent:MGLEventTypeMapLoad withAttributes:@{
MGLEventKeyLatitude: @(latLng.latitude),
MGLEventKeyLongitude: @(latLng.longitude),
MGLEventKeyZoomLevel: @(zoom),
MGLEventKeyPushEnabled: @([MGLMapboxEvents checkPushEnabled]),
MGLEventKeyEmailEnabled: [MGLMapboxEvents checkEmailEnabled]
}];
return YES;
@@ -586,7 +586,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handlePanGesture:(UIPanGestureRecognizer *)pan
{
[self trackGestureEvent:MGLEventMapPanStart forRecognizer:pan];
[self trackGestureEvent:MGLEventGesturePanStart forRecognizer:pan];
if ( ! self.isScrollEnabled) return;
@@ -653,17 +653,17 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
CLLocationCoordinate2D panCoordinate = [self convertPoint:pointInView toCoordinateFromView:pan.view];
double zoom = [self zoomLevel];
[MGLMapboxEvents pushEvent:MGLEventMapPanEnd withAttributes:@{
@"lat": @(panCoordinate.latitude),
@"lng": @(panCoordinate.longitude),
@"zoom": @(zoom)
[MGLMapboxEvents pushEvent:MGLEventTypeMapDragEnd withAttributes:@{
MGLEventKeyLatitude: @(panCoordinate.latitude),
MGLEventKeyLongitude: @(panCoordinate.longitude),
MGLEventKeyZoomLevel: @(zoom)
}];
}
}
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch
{
[self trackGestureEvent:MGLEventMapPinchStart forRecognizer:pinch];
[self trackGestureEvent:MGLEventGesturePinchStart forRecognizer:pinch];
if ( ! self.isZoomEnabled) return;
@@ -701,7 +701,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate
{
[self trackGestureEvent:MGLEventMapRotateStart forRecognizer:rotate];
[self trackGestureEvent:MGLEventGestureRotateStart forRecognizer:rotate];
if ( ! self.isRotateEnabled) return;
@@ -743,7 +743,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handleSingleTapGesture:(UITapGestureRecognizer *)singleTap
{
[self trackGestureEvent:MGLEventMapSingleTap forRecognizer:singleTap];
[self trackGestureEvent:MGLEventGestureSingleTap forRecognizer:singleTap];
CGPoint tapPoint = [singleTap locationInView:self];
@@ -866,7 +866,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap
{
[self trackGestureEvent:MGLEventMapDoubleTap forRecognizer:doubleTap];
[self trackGestureEvent:MGLEventGestureDoubleTap forRecognizer:doubleTap];
if ( ! self.isZoomEnabled) return;
@@ -897,7 +897,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap
{
[self trackGestureEvent:MGLEventMapTwoFingerSingleTap forRecognizer:twoFingerTap];
[self trackGestureEvent:MGLEventGestureTwoFingerSingleTap forRecognizer:twoFingerTap];
if ( ! self.isZoomEnabled) return;
@@ -930,7 +930,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom
{
[self trackGestureEvent:MGLEventMapQuickZoom forRecognizer:quickZoom];
[self trackGestureEvent:MGLEventGestureQuickZoom forRecognizer:quickZoom];
if ( ! self.isZoomEnabled) return;
@@ -984,11 +984,11 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
CLLocationCoordinate2D gestureCoordinate = [self convertPoint:pointInView toCoordinateFromView:recognizer.view];
double zoom = [self zoomLevel];
[MGLMapboxEvents pushEvent:MGLEventMapTap withAttributes:@{
@"lat": @(gestureCoordinate.latitude),
@"lng": @(gestureCoordinate.longitude),
@"zoom": @(zoom),
@"gesture": gestureID
[MGLMapboxEvents pushEvent:MGLEventTypeMapTap withAttributes:@{
MGLEventKeyLatitude: @(gestureCoordinate.latitude),
MGLEventKeyLongitude: @(gestureCoordinate.longitude),
MGLEventKeyZoomLevel: @(zoom),
MGLEventKeyGestureID: gestureID
}];
}

View File

@@ -12,17 +12,25 @@
static NSString *const MGLMapboxEventsUserAgent = @"MapboxEventsiOS/1.0";
static NSString *const MGLMapboxEventsAPIBase = @"https://api.tiles.mapbox.com";
NSString *const MGLEventMapLoad = @"map.load";
NSString *const MGLEventMapTap = @"map.click";
NSString *const MGLEventMapSingleTap = @"SingleTap";
NSString *const MGLEventMapDoubleTap = @"DoubleTap";
NSString *const MGLEventMapTwoFingerSingleTap = @"TwoFingerTap";
NSString *const MGLEventMapQuickZoom = @"QuickZoom";
NSString *const MGLEventMapPanStart = @"Pan";
NSString *const MGLEventMapPanEnd = @"map.dragend";
NSString *const MGLEventMapPinchStart = @"Pinch";
NSString *const MGLEventMapRotateStart = @"Rotation";
NSString *const MGLEventMapLocation = @"Location";
NSString *const MGLEventTypeMapLoad = @"map.load";
NSString *const MGLEventTypeMapTap = @"map.click";
NSString *const MGLEventTypeMapDragEnd = @"map.dragend";
NSString *const MGLEventTypeLocation = @"Location";
NSString *const MGLEventKeyLatitude = @"lat";
NSString *const MGLEventKeyLongitude = @"lng";
NSString *const MGLEventKeyZoomLevel = @"zoom";
NSString *const MGLEventKeyPushEnabled = @"enabled.push";
NSString *const MGLEventKeyEmailEnabled = @"enabled.email";
NSString *const MGLEventKeyGestureID = @"gesture";
NSString *const MGLEventGestureSingleTap = @"SingleTap";
NSString *const MGLEventGestureDoubleTap = @"DoubleTap";
NSString *const MGLEventGestureTwoFingerSingleTap = @"TwoFingerTap";
NSString *const MGLEventGestureQuickZoom = @"QuickZoom";
NSString *const MGLEventGesturePanStart = @"Pan";
NSString *const MGLEventGesturePinchStart = @"Pinch";
NSString *const MGLEventGestureRotateStart = @"Rotation";
//
// Threadsafety conventions:
@@ -233,7 +241,7 @@ NSString *const MGLEventMapLocation = @"Location";
if (!event) return;
NSMutableDictionary *evt = [[NSMutableDictionary alloc] init];
NSMutableDictionary *evt = [[NSMutableDictionary alloc] initWithDictionary:attributeDictionary];
// mapbox-events stock attributes
[evt setObject:event forKey:@"event"];
[evt setObject:@(1) forKey:@"version"];
@@ -252,11 +260,7 @@ NSString *const MGLEventMapLocation = @"Location";
[evt setValue:[weakSelf getCurrentCellularNetworkConnectionType] forKey:@"cellularNetworkType"];
[evt setValue:[weakSelf getWifiNetworkName] forKey:@"wifi"];
[evt setValue:@([weakSelf getContentSizeScale]) forKey:@"accessibilityFontScale"];
for (NSString *key in [attributeDictionary allKeys]) {
[evt setObject:[attributeDictionary valueForKey:key] forKey:key];
}
// Make Immutable Version
NSDictionary *finalEvent = [NSDictionary dictionaryWithDictionary:evt];

View File

@@ -43,9 +43,9 @@
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// Iterate through locations to pass all data
for (CLLocation *loc in locations) {
[MGLMapboxEvents pushEvent:MGLEventMapLocation withAttributes:@{
@"lat": @(loc.coordinate.latitude),
@"lng": @(loc.coordinate.longitude)
[MGLMapboxEvents pushEvent:MGLEventTypeLocation withAttributes:@{
MGLEventKeyLatitude: @(loc.coordinate.latitude),
MGLEventKeyLongitude: @(loc.coordinate.longitude)
}];
}
}