iOS 11 includes amazing new drag and drop features that allow developers to give users new ways to move media between applications. We’ve been experimenting at Mapbox with how drag and drop can work with maps, and are excited to show a demo of how you can use it too.
Here’s a sample project containing all of the Swift code needed to get a basic drag activity running with a Mapbox map. Don’t forget to add your access token in the Info.plist! Note: This code only runs on a pre-release version of Xcode 9, and can only be run on a device using a pre-release of iOS 11. The code in this demo may become outdated as these features are still in beta.
The static image of the map, called a Snapshot, is created by passing in size and style options that are taken from the map view of the interactive map. This allows the static snapshot to retain the same size and custom style implemented in the interactive map.
The drop activity (UIDropInteraction) consumes the drag items - in this case, a UIImage returned by the image property of the Snapshot.
Open the demo application and run it on an iPad or simulator running iOS 11. This demo application will be the source application for the drag activity. Set up a destination for the drag activity by enabling Split View with another application that accepts images as media input (such as the messages or notes application). This will be the application that you drop our static map into. Once Split View is set up, you can now press and hold on the interactive map, and a new static snapshot of the map will be created, which you can then drag into the destination application.