Skip to content

Commit

Permalink
Add demo app
Browse files Browse the repository at this point in the history
Fix file paths, remove unused storybaord vc

Address feedback

Fix file name

whyyy
  • Loading branch information
captainbarbosa committed Aug 9, 2019
1 parent 6d7e44e commit 9edcb29
Show file tree
Hide file tree
Showing 33 changed files with 1,435 additions and 154 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "camera-icon-image.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "dots.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "flag-icon-image.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "squares.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "star-icon-image.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "stars.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "stripes.pdf",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Map View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="MapViewController" customModule="annotationapp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import UIKit
import Mapbox
import MapboxAnnotationsExtension

class MapViewController: UIViewController {

var mapView: MGLMapView!

var circleAnnotationController: MGLCircleAnnotationController!
var circleAnnotation: MGLCircleStyleAnnotation!

var symbolAnnotationController: MGLSymbolAnnotationController!
var symbolAnnotation: MGLSymbolStyleAnnotation!

var lineAnnotationController: MGLLineAnnotationController!
var lineAnnotation: MGLLineStyleAnnotation!

var polygonAnnotationController: MGLPolygonAnnotationController!
var polygonAnnotation: MGLPolygonStyleAnnotation!

override func viewDidLoad() {
super.viewDidLoad()

mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.streetsStyleURL)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.setCenter(CLLocationCoordinate2D(latitude: -42, longitude: -187.5), zoomLevel: 4, animated: false)
mapView.delegate = self
view.addSubview(mapView)

let singleTap = UITapGestureRecognizer(target: self, action: #selector(handleMapTap(sender:)))
mapView.addGestureRecognizer(singleTap)
}

@objc func handleMapTap(sender: UITapGestureRecognizer) {
let coordinate = mapView.convert(sender.location(in: mapView), toCoordinateFrom: mapView)
print(coordinate)
}

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
self.loadStyleImages(for: style)
self.addCircleStyleAnnotation()
self.addSymbolStyleAnnotation()
self.addLineStyleAnnotation()
self.addPolygonStyleAnnotation()
}

// MARK: Style annotation setup

func loadStyleImages(for style: MGLStyle) {
style.setImage(UIImage(named: "star-icon-image")!, forName: "star-icon-image")
style.setImage(UIImage(named: "camera-icon-image")!, forName: "camera-icon-image")
style.setImage(UIImage(named: "flag-icon-image")!, forName: "flag-icon-image")

style.setImage(UIImage(named: "squares")!, forName: "Squares")
style.setImage(UIImage(named: "dots")!, forName: "Dots")
style.setImage(UIImage(named: "stripes")!, forName: "Stripes")
}

func addCircleStyleAnnotation() {
circleAnnotationController = MGLCircleAnnotationController(mapView: mapView)
circleAnnotationController.delegate = self
circleAnnotationController.annotationsInteractionEnabled = true
let circleCoordinate = CLLocationCoordinate2D(latitude: -45, longitude: -183)
circleAnnotation = MGLCircleStyleAnnotation(center: circleCoordinate)
circleAnnotation.title = "circle"
circleAnnotation.circleColor = UIColor.red
circleAnnotation.circleRadius = 20.0
circleAnnotation.circleOpacity = 0.8
circleAnnotationController.addStyleAnnotation(circleAnnotation)
}

func addSymbolStyleAnnotation() {
symbolAnnotationController = MGLSymbolAnnotationController(mapView: mapView)
symbolAnnotationController.delegate = self
symbolAnnotationController.annotationsInteractionEnabled = true
let symbolCoordinate = CLLocationCoordinate2D(latitude: -34, longitude: -187)
symbolAnnotation = MGLSymbolStyleAnnotation(coordinate: symbolCoordinate)
symbolAnnotation.title = "symbol"
symbolAnnotation.text = "Label"
symbolAnnotation.textFontSize = 36.0
symbolAnnotation.iconImageName = "camera-icon-image"
symbolAnnotation.textOffset = CGVector(dx: 0.0, dy: -1.0)

symbolAnnotation.textHaloWidth = 2.0
symbolAnnotation.textHaloBlur = 2.0
symbolAnnotation.textHaloColor = UIColor.red

symbolAnnotationController.addStyleAnnotation(symbolAnnotation)
}

func addLineStyleAnnotation() {

let lineCoordinates = [
CLLocationCoordinate2D(latitude: -46.392, longitude: 168.303),
CLLocationCoordinate2D(latitude: -45.047, longitude: 168.670),
CLLocationCoordinate2D(latitude: -43.544, longitude: 172.631),
CLLocationCoordinate2D(latitude: -41.273, longitude: 173.283),
CLLocationCoordinate2D(latitude: -41.299, longitude: 174.779),
CLLocationCoordinate2D(latitude: -36.877, longitude: 174.755)
]

lineAnnotationController = MGLLineAnnotationController(mapView: mapView)
lineAnnotationController.delegate = self
lineAnnotationController.annotationsInteractionEnabled = true
lineAnnotation = MGLLineStyleAnnotation(coordinates: lineCoordinates, count: UInt(lineCoordinates.count))
lineAnnotation.title = "line"
lineAnnotation.lineWidth = 5.0
lineAnnotation.lineColor = .blue
lineAnnotationController.addStyleAnnotation(lineAnnotation)
}

func addPolygonStyleAnnotation() {

let polygonCoordinates = [
CLLocationCoordinate2D(latitude: -40.21, longitude: 166.15),
CLLocationCoordinate2D(latitude: -40.21, longitude: 171.07),
CLLocationCoordinate2D(latitude: -36.17, longitude: 171.07),
CLLocationCoordinate2D(latitude: -36.17, longitude: 166.15),
CLLocationCoordinate2D(latitude: -40.21, longitude: 166.15)
]

polygonAnnotationController = MGLPolygonAnnotationController(mapView: mapView)
polygonAnnotationController.delegate = self
polygonAnnotationController.annotationsInteractionEnabled = true
polygonAnnotation = MGLPolygonStyleAnnotation(coordinates: polygonCoordinates, count: UInt(polygonCoordinates.count))
polygonAnnotation.title = "polygon"
polygonAnnotation.fillColor = UIColor.yellow.withAlphaComponent(0.4)
polygonAnnotation.fillOutlineColor = .black
polygonAnnotationController.addStyleAnnotation(polygonAnnotation)
}
}

extension MapViewController: MGLMapViewDelegate {
// This is required in order to hide the default Maps SDK pin
func mapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? {
return MGLAnnotationView(frame: CGRect(x: 0, y: 0, width: 10, height: 10))
}
}

extension MapViewController: MGLAnnotationControllerDelegate {
func annotationController(_ annotationController: MGLAnnotationController, didSelect styleAnnotation: MGLStyleAnnotation) {
let settingsViewController = SettingsViewController(for: styleAnnotation)
settingsViewController.delegate = self
let customTransitioningDelegate = PresentationControllerDelegate()
settingsViewController.transitioningDelegate = customTransitioningDelegate
settingsViewController.modalPresentationStyle = .custom
self.present(settingsViewController, animated: true, completion: nil)
}

func annotationController(_ annotationController: MGLAnnotationController, didDeselect styleAnnotation: MGLStyleAnnotation) {
// This isn't an optional method so we have to do something here.
// Ref: https://github.com/mapbox/map-extensions-ios/issues/44
print("Deselected style annotation")
}
}

extension MapViewController: AnnotationStyleSettingsDelegate {
func didUpdateStyleAnnotation(with updatedAnnotation: MGLStyleAnnotation) {
if updatedAnnotation is MGLCircleStyleAnnotation {
circleAnnotationController.updateStyleAnnotation(updatedAnnotation)
}

if updatedAnnotation is MGLSymbolStyleAnnotation {
symbolAnnotationController.updateStyleAnnotation(updatedAnnotation)
}

if updatedAnnotation is MGLLineStyleAnnotation {
lineAnnotationController.updateStyleAnnotation(updatedAnnotation)
}

if updatedAnnotation is MGLPolygonStyleAnnotation {
polygonAnnotationController.updateStyleAnnotation(updatedAnnotation)
}
}
}
Loading

0 comments on commit 9edcb29

Please sign in to comment.