Skip to content

Commit

Permalink
Add ios documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Lensing committed Apr 10, 2017
1 parent ad3040c commit 6baa00c
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 9 deletions.
23 changes: 22 additions & 1 deletion docs/basic-functions.md
@@ -1 +1,22 @@
# Position, rotation, and zoom
# Position, rotation, zoom, and tilt

When the map style finishes loading, your `OnStyleLoaded` closure will be executed and you can begin to manipulate the map. Set the position, rotation, zoom, and tilt as follows:

```swift
import Foundation
import TangramMap

class PositionExampleViewController: MZMapViewController {

override func viewDidLoad() {
super.viewDidLoad()
_ = try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.position = TGGeoPointMake(-73.9903, 40.74433)
self.rotation = 0
self.zoom = 17
self.tilt = 0
}
}

}
```
95 changes: 95 additions & 0 deletions docs/features.md
Expand Up @@ -3,8 +3,103 @@
The iOS SDK offers ways to add various feature overlays to a map as markers (points), polygons, and polylines.

## Markers
There are three different marker classes: `PointMarker`, `SystemPointMarker`, and `SelectableSystemPointMarker`. Use `PointMarker` for markers with either a custom background color or image. Use `SystemPointMarker` for items such as a current location indicator, route location arrow, or dropped pin. If you would like selectable system markers, use `SelectableSystemPointMarker` for search and route start & end pins. Add the marker to the map by calling `MZMapViewController#addMarker(GenericMarker)`.

```swift
import Foundation
import TangramMap

class FeatureExampleViewController: MZMapViewController {

override func viewDidLoad() {
super.viewDidLoad()
_ = try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.position = TGGeoPointMake(-73.9908, 40.73711)
self.zoom = 14
self.addMarkers()
}
}

fileprivate func addMarkers() {
let pointMarker = PointMarker.init(size: CGSize(width: 30, height: 30))
pointMarker.icon = UIImage.init(named: "logo")
pointMarker.backgroundColor = UIColor.purple
pointMarker.point = TGGeoPointMake(-73.9903, 40.74433)
self.addMarker(pointMarker);

let systemMarker = SystemPointMarker.init(markerType: .currentLocation)
systemMarker.point = TGGeoPointMake(-73.984770, 40.734807)
self.addMarker(systemMarker);

let selectableSystemMarker = SelectableSystemPointMarker.init(markerType: .searchPin)
selectableSystemMarker.point = TGGeoPointMake(-73.998674, 40.732172)
self.addMarker(selectableSystemMarker);
}
}
```

## Polygons
To add a polygon to the map, create a `TGGeoPolygon` and add points to it. Then create a `PolygonMarker`, set its polygon to be the one you created above and call `MZMapViewController#addMarker(PolygonMarker)`.

```swift
import Foundation
import TangramMap

class FeatureExampleViewController: MZMapViewController {

override func viewDidLoad() {
super.viewDidLoad()
_ = try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.position = TGGeoPointMake(-73.9908, 40.73711)
self.zoom = 14
self.addPolygon()
}
}

fileprivate func addPolygon() {
let polygon = TGGeoPolygon.init()
polygon.startPath(TGGeoPointMake(-73.9903, 40.74433))
polygon.add(TGGeoPointMake(-73.984770, 40.734807))
polygon.add(TGGeoPointMake(-73.998674, 40.732172))
polygon.add(TGGeoPointMake(-73.996142, 40.741050))
let marker = PolygonMarker.init()
marker.polygon = polygon
marker.backgroundColor = UIColor.green
self.addMarker(marker)
}

}
```

## Polylines
To add a polyline to the map, create a `TGGeoPolyline` and add points to it. Then create a `PolylineMarker`, set its polyline to be the one you created above and call `MZMapViewController#addMarker(PolylineMarker)`.

```swift
import Foundation
import TangramMap

class FeatureExampleViewController: MZMapViewController {

override func viewDidLoad() {
super.viewDidLoad()
_ = try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.position = TGGeoPointMake(-73.9908, 40.73711)
self.zoom = 14
self.addPolyline()
}
}

fileprivate func addPolyline() {
let polyline = TGGeoPolyline.init()
polyline.add(TGGeoPointMake(-73.9903, 40.74433))
polyline.add(TGGeoPointMake(-73.984770, 40.734807))
polyline.add(TGGeoPointMake(-73.998674, 40.732172))
polyline.add(TGGeoPointMake(-73.996142, 40.741050))
let marker = PolylineMarker.init()
marker.polyline = polyline
marker.backgroundColor = UIColor.blue
self.addMarker(marker)
}

}
```
81 changes: 81 additions & 0 deletions docs/gesture-responders.md
@@ -1 +1,82 @@
# Gesture Responders

The map supports taps, double taps, shoves, scales, rotations, pans, and long presses. To receive information about when these events occur, create a responder.

```swift
import Foundation
import UIKit

class GestureExampleViewController: MZMapViewController, MapSingleTapGestureDelegate, MapDoubleTapGestureDelegate, MapLongPressGestureDelegate, MapPanGestureDelegate, MapPinchGestureDelegate, MapRotateGestureDelegate, MapShoveGestureDelegate {

override func viewDidLoad() {
super.viewDidLoad()

try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.setupDelegates()
}
}

//MARK: Private
private func setupDelegates() {
self.singleTapGestureDelegate = self
self.doubleTapGestureDelegate = self
self.longPressGestureDelegate = self
self.panDelegate = self
self.pinchDelegate = self
self.rotateDelegate = self
self.shoveDelegate = self
}

private func logGesture(_ gesture: String) {
print("Gesture: \(gesture)")
}

//MARK: MapSingleTapGestureDelegate
func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, shouldRecognizeSingleTapGesture location: CGPoint) -> Bool {
return true
}


func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, didRecognizeSingleTapGesture location: CGPoint) {
logGesture("Single tap")
}

//MARK: MapDoubleTapGestureDelegate
func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, shouldRecognizeDoubleTapGesture location: CGPoint) -> Bool {
return true
}

func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, didRecognizeDoubleTapGesture location: CGPoint) {
logGesture("Double tap")
}

//MARK: MapLongPressGestureDelegate
func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, shouldRecognizeLongPressGesture location: CGPoint) -> Bool {
return true
}

func mapController(_ controller: MZMapViewController, recognizer: UIGestureRecognizer, didRecognizeLongPressGesture location: CGPoint) {
logGesture("Long press")
}

//MARK: MapPanGestureDelegate
func mapController(_ controller: MZMapViewController, didPanMap displacement: CGPoint) {
logGesture("Pan")
}

//MARK: MapPinchGestureDelegate
func mapController(_ controller: MZMapViewController, didPinchMap location: CGPoint) {
logGesture("Pinch")
}

//MARK: MapRotateGestureDelegate
func mapController(_ controller: MZMapViewController, didRotateMap location: CGPoint) {
logGesture("Rotate")
}

//MARK: MapShoveGestureDelegate
func mapController(_ controller: MZMapViewController, didShoveMap displacement: CGPoint) {
logGesture("Shove")
}
}
```
12 changes: 7 additions & 5 deletions docs/getting-started.md
Expand Up @@ -11,15 +11,17 @@ MapzenManager.sharedManager.apiKey = "[YOUR_MAPZEN_API_KEY]"
Adding a Mapzen map to your storyboard is as easy as:

1. Drag a GLKitViewController onto your storyboard canvas
2. Create a subclass file named, for example: `MapVC` and set it's super class to be `MapViewController`
3. Back, in the storyboard, change the GLKitViewController's subclass to be `MapVC`
2. Create a subclass file named, for example: `DemoMapViewController` and set it's super class to be `MZMapViewController`
3. Back, in the storyboard, change the GLKitViewController's subclass to be `DemoMapViewController`

## 3. Initialize the map
Override `viewDidLoad()` in `MapVC`'s implementation and instruct it to load a scene file like so:
Override `viewDidLoad()` in `DemoMapViewController`'s implementation and instruct it to load a map style like so:
```swift
let _ = try? loadScene("scene.yaml")
_ = try? loadStyleAsync(.bubbleWrap) { (style) in
// the map is now ready for interaction
}
```
This will load the default scene file [Bubble Wrap])(https://github.com/tangrams/bubble-wrap) that's packaged with the SDK
This will load the house style [Bubble Wrap])(https://github.com/tangrams/bubble-wrap) that's packaged with the SDK


Your map is now ready to use.
Expand Down
16 changes: 16 additions & 0 deletions docs/location-services.md
@@ -0,0 +1,16 @@
# Location Services
It is extremely easy to show the user's current location on the map. Simply call `MZMapViewController#showCurrentLocation(true)` to display an icon on the map. The iOS SDK also supports visually tracking and centering on the user's current location. To display a button to enable this behavior, call `MZMapViewController#showFindMeButon(true)`.

```swift
class LocationExampleViewController: MZMapViewController {

override func viewDidLoad() {
super.viewDidLoad()

try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
_ = self.showCurrentLocation(true)
_ = self.showFindMeButon(true)
}
}
}
```
2 changes: 1 addition & 1 deletion docs/places.md
@@ -1,3 +1,3 @@
# Mapzen Places

Coming soon!
We will be building this feature soon. Track its progress [here](https://github.com/mapzen/ios/issues). Feel free to create issues or submit pull requests, we welcome outside contributions!
35 changes: 34 additions & 1 deletion docs/search.md
@@ -1,12 +1,45 @@
# Search

## Getting Started
Be sure to sign up for an API key as described [here](https://mapzen.com/documentation/ios/getting-started/). After you have a key configured in your app, use the main entry point, `MapzenSearch`, for executing search-related queries.

## Search
Find a place by searching for an address or name.

```swift
private func search() {
let config = SearchConfig.init(searchText: "pizza") { (response) in
// display result
}
_ = MapzenSearch.sharedInstance.search(config)
}
```

## Autocomplete
Get real-time result suggestions without having to type the whole location.
Get real-time result suggestions with autocomplete.

```swift
private func autocomplete() {
let point = GeoPoint.init(latitude: 40.74433, longitude: -73.9903)
let config = AutocompleteConfig.init(searchText: "pizza", focusPoint: point) { (response) in
// display result
}
_ = MapzenSearch.sharedInstance.autocompleteQuery(config)
}
```

## Reverse
Find what is located at a certain coordinate location.

```swift
private func reverseGeo() {
let point = GeoPoint.init(latitude: 40.74433, longitude: -73.9903)
let config = ReverseConfig.init(point: point) { (response) in
// display result
}
_ = MapzenSearch.sharedInstance.reverseGeocode(config)
}
```

## Place
Get rich details about a place.
68 changes: 68 additions & 0 deletions docs/styles.md
@@ -1 +1,69 @@
# Switching Styles
The map’s style can be configured with `MZMapViewController#loadStyleAsync`. We recommend using the asynchronous method which takes an `OnStyleLoaded` closure however, the style can also be updated synchronously.

```swift
import UIKit
import TangramMap
class StyleExampleViewController: MZMapViewController {

private var styleLoaded = false

lazy var activityIndicator : UIActivityIndicatorView = {
let indicator = UIActivityIndicatorView.init(activityIndicatorStyle: .whiteLarge)
indicator.color = .black
indicator.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(indicator)

let xConstraint = indicator.centerXAnchor.constraint(equalTo: self.view.centerXAnchor)
let yConstraint = indicator.centerYAnchor.constraint(equalTo: self.view.centerYAnchor)
NSLayoutConstraint.activate([xConstraint, yConstraint])

return indicator
}()

override func viewDidLoad() {
super.viewDidLoad()

setupSwitchStyleBtn()
try? loadStyleAsync(.bubbleWrap) { [unowned self] (style) in
self.styleLoaded = true
}
}

//MARK: Private
private func setupSwitchStyleBtn() {
let btn = UIBarButtonItem.init(title: "Map Style", style: .plain, target: self, action: #selector(showStyleActionSheet))
self.navigationItem.rightBarButtonItem = btn
}

@objc private func showStyleActionSheet() {
let actionSheet = UIAlertController.init(title: "Map Style", message: "Choose a map style", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction.init(title: "Bubble Wrap", style: .default, handler: { [unowned self] (action) in
self.indicateLoadStyle(style: .bubbleWrap)
}))
actionSheet.addAction(UIAlertAction.init(title: "Cinnabar", style: .default, handler: { [unowned self] (action) in
self.indicateLoadStyle(style: .cinnabar)
}))
actionSheet.addAction(UIAlertAction.init(title: "Refill", style: .default, handler: { [unowned self] (action) in
self.indicateLoadStyle(style: .refill)
}))
actionSheet.addAction(UIAlertAction.init(title: "Walkabout", style: .default, handler: { [unowned self] (action) in
self.indicateLoadStyle(style: .walkabout)
}))
actionSheet.addAction(UIAlertAction.init(title: "Zinc", style: .default, handler: { [unowned self] (action) in
self.indicateLoadStyle(style: .zinc)
}))
actionSheet.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: { [unowned self] (action) in
self.dismiss(animated: true, completion: nil)
}))
self.navigationController?.present(actionSheet, animated: true, completion: nil)
}

private func indicateLoadStyle(style: MapStyle) {
activityIndicator.startAnimating()
try? loadStyleAsync(style, onStyleLoaded: { [unowned self] (style) in
self.activityIndicator.stopAnimating()
})
}
}
```
15 changes: 14 additions & 1 deletion docs/turn-by-turn.md
@@ -1,7 +1,20 @@
# Turn-by-Turn

## Getting Started
Be sure to sign up for an API key as described [here](https://mapzen.com/documentation/ios/getting-started/). After you have a key configured in your app, use the main entry point, `RoutingController`, for executing turn-by-turn queries.

## Fetch Route
To fetch a route you need to give the router a list of locations and a costing model at minimum. The first and last locations must be "break" points. To configure costing options see the turn-by-turn [costing options documentation](https://mapzen.com/documentation/mobility/turn-by-turn/api-reference/#costing-options) for available parameters. And, to configure directions options such as the units, see the [directions options documentation](https://mapzen.com/documentation/mobility/turn-by-turn/api-reference/#directions-options).

## Track User's Progress Along Route
```swift
let router = try? RoutingController.controller()
let locations = [
OTRRoutingPoint.init(coordinate: OTRGeoPoint.init(latitude: 40.74433, longitude: -73.9903), type: .break),
OTRRoutingPoint.init(coordinate: OTRGeoPoint.init(latitude: 40.734807, longitude: -73.984770), type: .through),
OTRRoutingPoint.init(coordinate: OTRGeoPoint.init(latitude: 40.732172, longitude: -73.998674), type: .through),
OTRRoutingPoint.init(coordinate: OTRGeoPoint.init(latitude: 40.741050, longitude: -73.996142), type: .break)
]
_ = router?.requestRoute(withLocations: locations, costingModel: .auto, costingOption: nil, directionsOptions: nil) { (result, asd, error) in
//
}
```

0 comments on commit 6baa00c

Please sign in to comment.