Skip to content

Instantly share code, notes, and snippets.

@1ec5
Created July 14, 2016 17:40
Show Gist options
  • Save 1ec5/fcd98632654a75ccc52999f1dd3e04c3 to your computer and use it in GitHub Desktop.
Save 1ec5/fcd98632654a75ccc52999f1dd3e04c3 to your computer and use it in GitHub Desktop.
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 6158a9a..0af52af 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -30,6 +30,18 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
@implementation MBXCustomCalloutAnnotation
@end
+@interface MBXArrowFillPolyline : MGLPolyline
+@end
+
+@implementation MBXArrowFillPolyline
+@end
+
+@interface MBXArrowStrokePolyline : MBXArrowFillPolyline
+@end
+
+@implementation MBXArrowStrokePolyline
+@end
+
@interface MBXViewController () <UIActionSheetDelegate, MGLMapViewDelegate>
@property (nonatomic) IBOutlet MGLMapView *mapView;
@@ -144,6 +156,45 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
{
self.mapView.debugMask = (MGLMapDebugMaskOptions)uncheckedDebugMask;
}
+
+ [self.mapView removeAnnotations:self.mapView.annotations];
+
+ NSMutableArray *polylines = [NSMutableArray array];
+
+ CLLocationCoordinate2D shaftStrokeCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334451505193513, -122.03718376209449),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ };
+ [polylines addObject:[MBXArrowStrokePolyline polylineWithCoordinates:shaftStrokeCoordinates count:sizeof(shaftStrokeCoordinates) / sizeof(shaftStrokeCoordinates[0])]];
+
+ CLLocationCoordinate2D headStrokeCoordinates[] = {
+ CLLocationCoordinate2DMake(37.334299255838424, -122.03713417268618),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334608510903742, -122.03717225433464),
+ };
+ [polylines addObject:[MBXArrowStrokePolyline polylineWithCoordinates:headStrokeCoordinates count:sizeof(headStrokeCoordinates) / sizeof(headStrokeCoordinates[0])]];
+
+ CLLocationCoordinate2D leftHookCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.33444955877281, -122.03720876453863),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334314689204085, -122.03711822429648),
+ };
+ [polylines addObject:[MBXArrowFillPolyline polylineWithCoordinates:leftHookCoordinates count:sizeof(leftHookCoordinates) / sizeof(leftHookCoordinates[0])]];
+
+ CLLocationCoordinate2D rightHookCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.33444955877281, -122.03720876453863),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334595830177712, -122.03715284391136),
+ };
+ [polylines addObject:[MBXArrowFillPolyline polylineWithCoordinates:rightHookCoordinates count:sizeof(rightHookCoordinates) / sizeof(rightHookCoordinates[0])]];
+
+ [self.mapView addAnnotations:polylines];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
@@ -610,19 +661,21 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
return YES;
}
-- (CGFloat)mapView:(__unused MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation
-{
- return ([annotation isKindOfClass:[MGLPolygon class]] ? 0.5 : 1.0);
-}
-
-- (UIColor *)mapView:(__unused MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation
-{
- return ([annotation isKindOfClass:[MGLPolyline class]] ? [UIColor purpleColor] : [UIColor blackColor]);
+- (CGFloat)mapView:(MGLMapView *)mapView lineWidthForPolylineAnnotation:(MGLPolyline *)annotation {
+ if ([annotation isKindOfClass:[MBXArrowStrokePolyline class]]) {
+ return 10;
+ }
+ return 8;
}
-- (UIColor *)mapView:(__unused MGLMapView *)mapView fillColorForPolygonAnnotation:(__unused MGLPolygon *)annotation
-{
- return (annotation.pointCount > 3 ? [UIColor greenColor] : [UIColor redColor]);
+- (UIColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation {
+ if ([annotation isKindOfClass:[MBXArrowStrokePolyline class]]) {
+ return mapView.tintColor;
+ }
+ if ([annotation isKindOfClass:[MBXArrowFillPolyline class]]) {
+ return [UIColor whiteColor];
+ }
+ return nil;
}
- (void)mapView:(__unused MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(__unused BOOL)animated
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index f30b832..64871f3 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -46,6 +46,18 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
return flattenedShapes;
}
+@interface MBXArrowFillPolyline : MGLPolyline
+@end
+
+@implementation MBXArrowFillPolyline
+@end
+
+@interface MBXArrowStrokePolyline : MBXArrowFillPolyline
+@end
+
+@implementation MBXArrowStrokePolyline
+@end
+
@interface MapDocument () <NSWindowDelegate, NSSharingServicePickerDelegate, NSMenuDelegate, MGLMapViewDelegate>
@property (weak) IBOutlet NSMenu *mapViewContextMenu;
@@ -256,6 +268,45 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
NSValue *coordinateValue = [NSValue valueWithMGLCoordinate:self.mapView.centerCoordinate];
self.displayName = [[NSValueTransformer valueTransformerForName:@"LocationCoordinate2DTransformer"]
transformedValue:coordinateValue];
+
+ [self.mapView removeAnnotations:self.mapView.annotations];
+
+ NSMutableArray *polylines = [NSMutableArray array];
+
+ CLLocationCoordinate2D shaftStrokeCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334451505193513, -122.03718376209449),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ };
+ [polylines addObject:[MBXArrowStrokePolyline polylineWithCoordinates:shaftStrokeCoordinates count:sizeof(shaftStrokeCoordinates) / sizeof(shaftStrokeCoordinates[0])]];
+
+ CLLocationCoordinate2D headStrokeCoordinates[] = {
+ CLLocationCoordinate2DMake(37.334299255838424, -122.03713417268618),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334608510903742, -122.03717225433464),
+ };
+ [polylines addObject:[MBXArrowStrokePolyline polylineWithCoordinates:headStrokeCoordinates count:sizeof(headStrokeCoordinates) / sizeof(headStrokeCoordinates[0])]];
+
+ CLLocationCoordinate2D leftHookCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.33444955877281, -122.03720876453863),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334314689204085, -122.03711822429648),
+ };
+ [polylines addObject:[MBXArrowFillPolyline polylineWithCoordinates:leftHookCoordinates count:sizeof(leftHookCoordinates) / sizeof(leftHookCoordinates[0])]];
+
+ CLLocationCoordinate2D rightHookCoordinates[] = {
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.33444955877281, -122.03720876453863),
+ CLLocationCoordinate2DMake(37.33443009427657, -122.03745878890875),
+ CLLocationCoordinate2DMake(37.334469022742951, -122.0369587400389),
+ CLLocationCoordinate2DMake(37.334595830177712, -122.03715284391136),
+ };
+ [polylines addObject:[MBXArrowFillPolyline polylineWithCoordinates:rightHookCoordinates count:sizeof(rightHookCoordinates) / sizeof(rightHookCoordinates[0])]];
+
+ [self.mapView addAnnotations:polylines];
}
#pragma mark Debug methods
@@ -781,8 +832,21 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
}
}
-- (CGFloat)mapView:(MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation {
- return 0.8;
+- (CGFloat)mapView:(MGLMapView *)mapView lineWidthForPolylineAnnotation:(MGLPolyline *)annotation {
+ if ([annotation isKindOfClass:[MBXArrowStrokePolyline class]]) {
+ return 10;
+ }
+ return 8;
+}
+
+- (NSColor *)mapView:(MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation {
+ if ([annotation isKindOfClass:[MBXArrowStrokePolyline class]]) {
+ return [NSColor selectedMenuItemColor];
+ }
+ if ([annotation isKindOfClass:[MBXArrowFillPolyline class]]) {
+ return [NSColor whiteColor];
+ }
+ return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment