platform-osx now vends a real NSView subclass, MGLMapView, that is readily embedded inside a Cocoa application for OS X. MGLMapView is backed by an NSOpenGLLayer for optimal performance and integration with other layer-backed views. It supports keyboard shortcuts and several gestures and hosts attribution, zooming, and rotation controls as subviews. osxapp is now a bona fide Cocoa application that embeds MGLMapView inside a XIB. osxapp has preferences and a share button for tight integration with custom styles. Enabling asynchronous rendering would be more consistent with iOS but increases CPU usage so much, even when idle, that it isn’t worth any performance gain. The bigger issue is that VAOs aren’t being used. make xpackage creates a static library similar to the one created by make ipackage. make clean cleans additional places where build output ends up. The OS X minimum deployment target has been increased from 10.9 to 10.10. osxapp’s window has a full size content view, which requires 10.10. Lightweight generics require iOS 9+ and OS X 10.11 regardless, because it was only in that release that Foundation collection classes started adopting lightweight generics. Shuffled files around and refactored annotations so that iOS and OS X share a good chunk of the annotations code, which now takes advantage of polymorphism. MGLMapView can now display annotations but cannot yet select them. In osxapp, a long press drops a pin, and so does the map view’s context menu. Annotations have NSPopovers as callouts, and their view controllers can be customized. Annotation image alignment rects are respected for hit testing purposes and for positioning the callout anchor. Callouts in osxapp demonstrate the use of bindings to keep callouts in sync with underlying model objects.
96 lines
3.9 KiB
Objective-C
96 lines
3.9 KiB
Objective-C
#import <Foundation/Foundation.h>
|
|
#import <CoreLocation/CoreLocation.h>
|
|
#import <CoreGraphics/CGBase.h>
|
|
|
|
#import "MGLTypes.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
/** Defines the area spanned by an MGLCoordinateBounds. */
|
|
typedef struct {
|
|
CLLocationDegrees latitudeDelta;
|
|
CLLocationDegrees longitudeDelta;
|
|
} MGLCoordinateSpan;
|
|
|
|
/** Creates a new MGLCoordinateSpan from the given latitudinal and longitudinal deltas. */
|
|
NS_INLINE MGLCoordinateSpan MGLCoordinateSpanMake(CLLocationDegrees latitudeDelta, CLLocationDegrees longitudeDelta) {
|
|
MGLCoordinateSpan span;
|
|
span.latitudeDelta = latitudeDelta;
|
|
span.longitudeDelta = longitudeDelta;
|
|
return span;
|
|
}
|
|
|
|
/** Returns `YES` if the two coordinate spans represent the same latitudinal change and the same longitudinal change. */
|
|
NS_INLINE BOOL MGLCoordinateSpanEqualToCoordinateSpan(MGLCoordinateSpan span1, MGLCoordinateSpan span2) {
|
|
return (span1.latitudeDelta == span2.latitudeDelta &&
|
|
span1.longitudeDelta == span2.longitudeDelta);
|
|
}
|
|
|
|
/** An area of zero width and zero height. */
|
|
extern const MGLCoordinateSpan MGLCoordinateSpanZero;
|
|
|
|
/** A rectangular area as measured on a two-dimensional map projection. */
|
|
typedef struct {
|
|
CLLocationCoordinate2D sw;
|
|
CLLocationCoordinate2D ne;
|
|
} MGLCoordinateBounds;
|
|
|
|
/** Creates a new MGLCoordinateBounds structure from the given southwest and northeast coordinates. */
|
|
NS_INLINE MGLCoordinateBounds MGLCoordinateBoundsMake(CLLocationCoordinate2D sw, CLLocationCoordinate2D ne) {
|
|
MGLCoordinateBounds bounds;
|
|
bounds.sw = sw;
|
|
bounds.ne = ne;
|
|
return bounds;
|
|
}
|
|
|
|
/** Returns `YES` if the two coordinate bounds are equal to each other. */
|
|
NS_INLINE BOOL MGLCoordinateBoundsEqualToCoordinateBounds(MGLCoordinateBounds bounds1, MGLCoordinateBounds bounds2) {
|
|
return (bounds1.sw.latitude == bounds2.sw.latitude &&
|
|
bounds1.sw.longitude == bounds2.sw.longitude &&
|
|
bounds1.ne.latitude == bounds2.ne.latitude &&
|
|
bounds1.ne.longitude == bounds2.ne.longitude);
|
|
}
|
|
|
|
/** Returns the area spanned by the coordinate bounds. */
|
|
NS_INLINE MGLCoordinateSpan MGLCoordinateBoundsGetCoordinateSpan(MGLCoordinateBounds bounds) {
|
|
return MGLCoordinateSpanMake(bounds.ne.latitude - bounds.sw.latitude,
|
|
bounds.ne.longitude - bounds.sw.longitude);
|
|
}
|
|
|
|
/** Returns a coordinate bounds with southwest and northeast coordinates that are offset from those of the source bounds. */
|
|
NS_INLINE MGLCoordinateBounds MGLCoordinateBoundsOffset(MGLCoordinateBounds bounds, MGLCoordinateSpan offset) {
|
|
MGLCoordinateBounds offsetBounds = bounds;
|
|
offsetBounds.sw.latitude += offset.latitudeDelta;
|
|
offsetBounds.sw.longitude += offset.longitudeDelta;
|
|
offsetBounds.ne.latitude += offset.latitudeDelta;
|
|
offsetBounds.ne.longitude += offset.longitudeDelta;
|
|
return offsetBounds;
|
|
}
|
|
|
|
/** Returns `YES` if the coordinate bounds covers no area.
|
|
*
|
|
* Note that a bounds may be empty but have a non-zero coordinate span (e.g., when its northeast point lies due north of its southwest point). */
|
|
NS_INLINE BOOL MGLCoordinateBoundsIsEmpty(MGLCoordinateBounds bounds) {
|
|
MGLCoordinateSpan span = MGLCoordinateBoundsGetCoordinateSpan(bounds);
|
|
return span.latitudeDelta == 0 || span.longitudeDelta == 0;
|
|
}
|
|
|
|
/** Returns a formatted string for the given coordinate bounds. */
|
|
NS_INLINE NSString *MGLStringFromCoordinateBounds(MGLCoordinateBounds bounds) {
|
|
return [NSString stringWithFormat:@"{{%.1f, %.1f}, {%.1f, %.1f}}",
|
|
bounds.sw.latitude, bounds.sw.longitude,
|
|
bounds.ne.latitude, bounds.ne.longitude];
|
|
}
|
|
|
|
/** Returns radians, converted from degrees. */
|
|
NS_INLINE CGFloat MGLRadiansFromDegrees(CLLocationDegrees degrees) {
|
|
return (CGFloat)(degrees * M_PI) / 180;
|
|
}
|
|
|
|
/** Returns degrees, converted from radians. */
|
|
NS_INLINE CLLocationDegrees MGLDegreesFromRadians(CGFloat radians) {
|
|
return radians * 180 / M_PI;
|
|
}
|
|
|
|
NS_ASSUME_NONNULL_END
|