-
Notifications
You must be signed in to change notification settings - Fork 1.3k
OS X SDK and revamped OS X demo application #3135
Conversation
Great start — this app is already pretty damn nice. Noticed that |
It's an excellent starting point! Thanks for your work @1ec5 ! |
MGLMapView is now layer-backed via NSOpenGLLayer, addressing the crash-on-close, eliminating CPU usage when idle, and enabling Cocoa controls like the toolbar to appear above the map view: The map view stays visible while resizing, too. However, animation performance is suffering, probably due in part to:
|
glfw is still used by linuxapp, which is ironically built as part of the xproj workspace. |
As part of this PR, I’ve taken a fresh look at a lot of the iOS SDK’s MGLMapView code, with an eye towards modularity. The annotation classes are now responsible for styling themselves, and the annotation management and selection code is a lot simpler now that IDs are mapped to annotations rather than the other way around. (That approach is also required for #1496.) Where necessary for code sharing, I’ve updated the iOS SDK, but I’ll need to backport more sweeping changes in a separate PR. I’m particularly pleased with how callouts turned out. On iOS, MGLMapView acts as a middleman between SMCalloutView and MGLMapViewDelegate. On OS X, MGLMapView gets out of the way, allowing MGLMapViewDelegate to supply any NSViewController (such as one instantiated from a nib); MGLMapView wraps it in an NSPopover for display. The default view controller uses bindings to keep everything tidy: The callout respects the annotation image’s alignment rect, solving #1504 and #2151. (Although it would be more natural for MGLAnnotationImage to know its |
Thanks @1ec5 for rewriting OSX app using Cocoa.
|
@mb12, thanks for trying out this branch! Those errors should be fixed now. They’re specific to Xcode 6.x (which doesn’t support lightweight generics) and crept in because I’ve been developing in Xcode 7.0 or 7.1 lately. |
Not sure how I triggered this, but I got stuck in a mode where I can't pan the map anymore with click + drag. Trackpad panning still works though. How can I rotate the map? In the GLFW version, I could right-click and drag to rotate the map. Here's a small list of things that we should also add to the app:
|
This was working originally when I used an NSOpenGLView (similar to what GLFW used from glfw/glfw@81bcefe to glfw/glfw@8f0fd7e), but now that I’m using an NSOpenGLLayer, the extensions aren’t being initialized correctly. Given that we have to explicitly activate the context on the Map thread, I suspect that
Hold down Option while dragging the cursor up and down. I haven’t bothered to implement the compass-inclinometer control that Maps.app has. |
Fixed in 66066bd. @kkaefer, regarding VAOs, |
Might be because it seems deprecated in the OpenGL spec. Quick search turned up that you should use |
|
On OS X Yosemite (10.10.1), its crashing with the following error. 2015-11-30 10:58:26.053 Mapbox GL[23588:454865] -[NSSegmentedControl setTrackingMode:]: unrecognized selector sent to instance 0x608000181380 This is the specific assignment in commonInit that's causing the problem. If I comment it out it launches and runs successfully. Without this mode, the zoom button stays blue even after the mouse click.
|
Ah, thanks. I was afraid I'd use a 10.11-only API; I don't have a Yosemite machine handy to test with. Edit: In fact, it was introduced in 10.10.3, so kudos for having a great OS version for testing with. 😄 |
Thanks @1ec5 for fixing this. I've just verified it on Yosemite 10.10.. The look and feel and callouts are very close to native Apple Maps on Mac. |
Stripping the framework means you can’t debug the framework.
Shared MGLMapCamera between iOS and OS X. Unfortunately -camera and -setCamera: implementations need to be copy-pasted for now.
Also fixed an issue where removing a selected annotation failed to deselect it.
appledoc can’t understand conditional compilation. This is the best we can do until we move to Jazzy.
Copied some pixel-reading code from HeadlessView.
Corrected the path to the build output. Also added a missing inline comment.
- Change all smart quotes to dumb quotes to workaround SourceKitten bug. - Port changes from OS X (#3135)
- Change all smart quotes to dumb quotes to workaround SourceKitten bug. - Port changes from OS X (#3135)
- Change all smart quotes to dumb quotes to workaround SourceKitten bug. - Port changes from OS X (#3135)
- Change all smart quotes to dumb quotes to workaround SourceKitten bug. - Port changes from OS X (#3135)
This PR replaces the minimal, glfw-based OS X support in this project with a proper SDK that mirrors (and in many places shares code with) the Mapbox iOS SDK.
make xproj
now creates an Xcode project with a framework target and a rewritten osxapp application target. The vestigial static library target is immediately repackaged as a bone fide dynamic framework (#828) – not the kind of faux framework that framework.sh creates for iOS. (In the future, we can cut out the intermediate static library step.)make xpackage
simply builds the project thatmake xproj
creates.Inside the SDK is almost all the same functionality as you’d find in the iOS SDK: MGLMapView has support for gestures, animations, annotations, callouts, etc. It lacks support for the user dot, user location tracking, or telemetry. However, the optimized framework weighs in at only 5 MB compared to 290 MB for the iOS SDK. It’s also easier to install: you just plop Mapbox.framework into your application’s Xcode project, set the access token in Info.plist, and add the MGLMapView to MainMenu.xib or Main.storyboard.
osxapp is now a typical Cocoa application that links against Mapbox.framework and allows you to view any GL style in an MGLMapView. osxapp no longer depends on glfw. Go to Help ‣ Mapbox GL Help for an explanation of the various gestures that are supported.
Both SDKs share almost all of the model object classes and most geometry conversion code – basically anything that doesn’t touch AppKit or UIKit. They have separate implementations of view classes, annotation images (because I didn’t want to confuse appledoc with conditional compilation; see #3203), gesture recognition (because the Mac has different standard gestures), and callouts (because NSPopover is such an elegant solution to the problem).
The biggest architectural difference between the two SDKs, other than the use of a framework, is that the OS X version of MGLMapView holds a mapping from numeric “annotation tags” to annotation context objects that contain the annotations themselves (#3159). This optimizes nearly every operation involving annotations. It allowed me to fix longstanding bugs and performance bottlenecks such as #1504 right off the bat and implement some nifty Mac-only features like annotation tooltips, custom cursors, and proper hit testing for annotations. (A doughnut-shaped annotation can only be selected by clicking the dough, not the transparent hole in the middle.)
The goal of this PR is to ensure that when we say we target OS X (as we do in the readme), we do so in a way that others can reuse outside of the Mapbox GL project. Hopefully the way I’ve architected this port will keep it going with minimal maintenance cost. Even if it requires slightly more attention than the glfw-based demo application, I think it’ll be much easier for Mac developers to contribute to the new framework and osxapp. We don’t have to think about releasing official builds of the OS X SDK right now; I don’t think it’s too onerous to expect developers to clone the repository and run
make xpackage
. Plus, osxapp is now an enjoyable little application to debug with.This PR covers a massive list of features:
Fixes #8, #3043.
/cc @incanus @kkaefer @friedbunny