Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Example for MGLImageSource (#120)
Browse files Browse the repository at this point in the history
* bumped podfile

* added objective-c

* Added some comments

* Improved comments

* Moved example within list

* Edited Podfile

* addressed @captainbarbosa's feedback

Fix rebase/merge mistakes.

Added resizing for map view
  • Loading branch information
jmkiley authored and friedbunny committed Nov 17, 2017
1 parent fe0a76a commit 6d601ac
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
1F1F84771E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1F84761E53A3B700332CC3 /* BlockingGesturesDelegateExample.swift */; };
3E085B801EC526C500163C99 /* ExtrusionsExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */; };
3E085B831EC526E500163C99 /* ExtrusionsExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E085B821EC526E500163C99 /* ExtrusionsExample.m */; };
3E22EF4F1F87F10C00605203 /* ImageSourceExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E22EF4E1F87F10C00605203 /* ImageSourceExample.swift */; };
3E22EF521F8821F800605203 /* ImageSourceExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E22EF511F8821F800605203 /* ImageSourceExample.m */; };
3E3BFAD91E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3BFAD81E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift */; };
3E3BFADC1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E3BFADB1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m */; };
3E3FB66B1F05888E004512C6 /* LightExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3FB66A1F05888E004512C6 /* LightExample.swift */; };
3E3FB66E1F0588B3004512C6 /* LightExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E3FB66D1F0588B3004512C6 /* LightExample.m */; };
3E3FB6711F058A18004512C6 /* PointHotspotExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E3FB66F1F0589AD004512C6 /* PointHotspotExample.m */; };
3E52ACD31EE8D8AF0056242C /* LiveDataExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E52ACD21EE8D8AF0056242C /* LiveDataExample.m */; };
3E52ACD51EE8D94A0056242C /* LiveDataExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E52ACD41EE8D94A0056242C /* LiveDataExample.swift */; };
3E4574ED1FA3D8F1000C8CF1 /* radar.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3E4574EC1FA3D8F1000C8CF1 /* radar.gif */; };
3EBCD7161DC28240001E342F /* AnnotationViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBCD7021DC28240001E342F /* AnnotationViewExample.swift */; };
3EBCD7171DC28240001E342F /* CalloutDelegateUsageExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBCD7031DC28240001E342F /* CalloutDelegateUsageExample.swift */; };
3EBCD7181DC28240001E342F /* CameraAnimationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBCD7041DC28240001E342F /* CameraAnimationExample.swift */; };
Expand Down Expand Up @@ -190,6 +193,9 @@
3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExtrusionsExample.swift; sourceTree = "<group>"; };
3E085B811EC526E500163C99 /* ExtrusionsExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtrusionsExample.h; sourceTree = "<group>"; };
3E085B821EC526E500163C99 /* ExtrusionsExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExtrusionsExample.m; sourceTree = "<group>"; };
3E22EF4E1F87F10C00605203 /* ImageSourceExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSourceExample.swift; sourceTree = "<group>"; };
3E22EF501F8821F800605203 /* ImageSourceExample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageSourceExample.h; sourceTree = "<group>"; };
3E22EF511F8821F800605203 /* ImageSourceExample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ImageSourceExample.m; sourceTree = "<group>"; };
3E3BFAD81E81D7A300D0BEA1 /* DDSLayerSelectionExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DDSLayerSelectionExample.swift; sourceTree = "<group>"; };
3E3BFADA1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DDSLayerSelectionExample.h; sourceTree = "<group>"; };
3E3BFADB1E81D7BB00D0BEA1 /* DDSLayerSelectionExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DDSLayerSelectionExample.m; sourceTree = "<group>"; };
Expand All @@ -200,6 +206,7 @@
3E52ACD11EE8D8AF0056242C /* LiveDataExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LiveDataExample.h; sourceTree = "<group>"; };
3E52ACD21EE8D8AF0056242C /* LiveDataExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LiveDataExample.m; sourceTree = "<group>"; };
3E52ACD41EE8D94A0056242C /* LiveDataExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiveDataExample.swift; sourceTree = "<group>"; };
3E4574EC1FA3D8F1000C8CF1 /* radar.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = radar.gif; sourceTree = "<group>"; };
3EBCD7021DC28240001E342F /* AnnotationViewExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnnotationViewExample.swift; sourceTree = "<group>"; };
3EBCD7031DC28240001E342F /* CalloutDelegateUsageExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalloutDelegateUsageExample.swift; sourceTree = "<group>"; };
3EBCD7041DC28240001E342F /* CameraAnimationExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraAnimationExample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -444,6 +451,7 @@
9682470E1C5BF12700494AB8 /* DrawingAMarkerExample.m */,
9682471F1C5C1C0400494AB8 /* DrawingAPolygonExample.m */,
3E085B821EC526E500163C99 /* ExtrusionsExample.m */,
3E22EF511F8821F800605203 /* ImageSourceExample.m */,
3E3FB66D1F0588B3004512C6 /* LightExample.m */,
3E3FB66F1F0589AD004512C6 /* PointHotspotExample.m */,
055ABCC01EFB139C0063BACA /* FillPatternExample.m */,
Expand Down Expand Up @@ -491,6 +499,7 @@
3EBCD7101DC28240001E342F /* DrawingAPolygonExample.swift */,
3E085B7F1EC526C500163C99 /* ExtrusionsExample.swift */,
055ABCC21EFB14AE0063BACA /* FillPatternExample.swift */,
3E22EF4E1F87F10C00605203 /* ImageSourceExample.swift */,
3E3FB66A1F05888E004512C6 /* LightExample.swift */,
3E52ACD41EE8D94A0056242C /* LiveDataExample.swift */,
3EBCD7111DC28240001E342F /* OfflinePackExample.swift */,
Expand Down Expand Up @@ -593,6 +602,7 @@
9682471B1C5C123B00494AB8 /* Files */ = {
isa = PBXGroup;
children = (
3E4574EC1FA3D8F1000C8CF1 /* radar.gif */,
3EC92DB61E78C431001D0503 /* metro-line.geojson */,
9682471C1C5C123B00494AB8 /* example.geojson */,
64BBDAEF1DF22D9600BB705D /* third_party_vector_style.json */,
Expand Down Expand Up @@ -628,6 +638,7 @@
9682470D1C5BF12700494AB8 /* DrawingAMarkerExample.h */,
9682471E1C5C1C0400494AB8 /* DrawingAPolygonExample.h */,
3E085B811EC526E500163C99 /* ExtrusionsExample.h */,
3E22EF501F8821F800605203 /* ImageSourceExample.h */,
3E3FB66C1F0588B3004512C6 /* LightExample.h */,
055ABCBF1EFB139C0063BACA /* FillPatternExample.h */,
3E52ACD11EE8D8AF0056242C /* LiveDataExample.h */,
Expand Down Expand Up @@ -810,7 +821,7 @@
0503373D1F7199DF007309B0 = {
CreatedOnToolsVersion = 8.3.3;
DevelopmentTeam = GJZR2MEM28;
LastSwiftMigration = 0900;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
05DB802B1F75A4AD00F73326 = {
Expand Down Expand Up @@ -881,6 +892,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3E4574ED1FA3D8F1000C8CF1 /* radar.gif in Resources */,
DDF9432B1E5DEACC00545D0F /* ports.geojson in Resources */,
3EC92DB71E78C431001D0503 /* metro-line.geojson in Resources */,
9619629F1C581700002D3DAB /* LaunchScreen.storyboard in Resources */,
Expand Down Expand Up @@ -1221,6 +1233,7 @@
64CF97171DF2251500C3C27B /* SourceCustomRasterExample.m in Sources */,
3EBCD7271DC28240001E342F /* SatelliteStyleExample.swift in Sources */,
96115A681CAD4E1C000963B8 /* OfflinePackExample.m in Sources */,
3E22EF521F8821F800605203 /* ImageSourceExample.m in Sources */,
3EBCD71C1DC28240001E342F /* CustomCalloutViewExample.swift in Sources */,
DDF943291E5DE63300545D0F /* ClusteringExample.m in Sources */,
3EBCD7171DC28240001E342F /* CalloutDelegateUsageExample.swift in Sources */,
Expand All @@ -1231,6 +1244,7 @@
DD5939E41E6639BA0009BEB2 /* ClusteringExample.swift in Sources */,
9682471A1C5C115000494AB8 /* DrawingAGeoJSONLineExample.m in Sources */,
64CF970C1DF224C500C3C27B /* SourceCustomVectorExample.m in Sources */,
3E22EF4F1F87F10C00605203 /* ImageSourceExample.swift in Sources */,
969E7FDD1D25C31700663F84 /* UserTrackingModesExample.m in Sources */,
646B62A41DEF7115000AA523 /* RuntimeAddLineExample.m in Sources */,
3E3FB66E1F0588B3004512C6 /* LightExample.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Examples/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern NSString *const MBXExampleDrawingACustomMarker;
extern NSString *const MBXExampleDrawingAMarker;
extern NSString *const MBXExampleDrawingAPolygon;
extern NSString *const MBXExample3DExtrusions;
extern NSString *const MBXExampleImageSource;
extern NSString *const MBXExampleLight;
extern NSString *const MBXExampleFillPattern;
extern NSString *const MBXExampleLiveData;
Expand Down
1 change: 1 addition & 0 deletions Examples/Examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ + (NSArray *)list {
MBXExampleDrawingAPolygon,
MBXExample3DExtrusions,
MBXExampleFillPattern,
MBXExampleImageSource,
MBXExampleLight,
MBXExampleLiveData,
MBXExampleOfflinePack,
Expand Down
Binary file added Examples/Files/radar.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Examples/ObjectiveC/ImageSourceExample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ImageSourceExample.h
// Examples
//
// Created by Jordan Kiley on 10/6/17.
// Copyright © 2017 Mapbox. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ImageSourceExample : UIViewController

@end
49 changes: 49 additions & 0 deletions Examples/ObjectiveC/ImageSourceExample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

#import "ImageSourceExample.h"
@import Mapbox;

NSString *const MBXExampleImageSource = @"ImageSourceExample";

@interface ImageSourceExample () <MGLMapViewDelegate>

@end

@implementation ImageSourceExample

- (void)viewDidLoad {
[super viewDidLoad];

MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds styleURL:[MGLStyle darkStyleURL]];
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(43.457, -75.789) zoomLevel:4 animated:NO];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

// Set the map view‘s delegate property.
mapView.delegate = self;
[self.view addSubview:mapView];
}

- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {

// Set the coordinate bounds for the raster image.
MGLCoordinateQuad coordinates = MGLCoordinateQuadMake(
CLLocationCoordinate2DMake(46.437, -80.425),
CLLocationCoordinate2DMake(37.936, -80.425),
CLLocationCoordinate2DMake(37.936, -71.516),
CLLocationCoordinate2DMake(46.437, -71.516));

// Create a MGLImageSource, which can be used to add georeferenced raster images to a map.
NSString *radarImage = [[NSBundle mainBundle] pathForResource:@"radar" ofType:@"gif"];
MGLImageSource *source = [[MGLImageSource alloc] initWithIdentifier:@"radar" coordinateQuad:coordinates URL:[NSURL URLWithString:radarImage]];
[style addSource:source];

MGLRasterStyleLayer *radarLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"radar-layer" source:source];

for (MGLStyleLayer *layer in style.layers.reverseObjectEnumerator) {
if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) {
[style insertLayer:radarLayer aboveLayer:layer];
break;
}
}
}

@end
46 changes: 46 additions & 0 deletions Examples/Swift/ImageSourceExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import Mapbox

@objc(ImageSourceExample_Swift)

class ImageSourceExample: UIViewController, MGLMapViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

let mapView = MGLMapView(frame: view.bounds, styleURL: MGLStyle.darkStyleURL())
mapView.setCenter(CLLocationCoordinate2D(latitude: 43.457, longitude: -75.789), zoomLevel: 4, animated: false)
mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth]

// Set the map view‘s delegate property.
mapView.delegate = self
view.addSubview(mapView)
}

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {

// Set the coordinate bounds for the raster image.
let coordinates = MGLCoordinateQuad(
topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425),
bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425),
bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516),
topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516))

// Create a MGLImageSource, which can be used to add georeferenced raster images to a map.
if let radarImage = Bundle.main.path(forResource: "radar", ofType: "gif") {
let source = MGLImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: radarImage)!)
style.addSource(source)

// Create a raster layer from the MGLImageSource.
let radarLayer = MGLRasterStyleLayer(identifier: "radar-layer", source: source)

// Insert the image below the map's symbol layers.
for layer in style.layers.reversed() {
if !layer.isKind(of: MGLSymbolStyleLayer.self) {
style.insertLayer(radarLayer, above: layer)
break
}
}
}
}
}
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ platform :ios, '8.0'
use_frameworks!

def shared_pods
#pod 'Mapbox-iOS-SDK', '~> 3.6.3'
pod 'Mapbox-iOS-SDK-symbols', :podspec => 'https://raw.githubusercontent.com/mapbox/mapbox-gl-native/ios-v3.7.0-beta.3/platform/ios/Mapbox-iOS-SDK-symbols.podspec'
end

Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Mapbox-iOS-SDK-symbols: 1b4cda6613f81b627069375e62995916c10b2cc4

PODFILE CHECKSUM: fb0ec44ad116be9cb78667a37c3a164901306ef4
PODFILE CHECKSUM: 0a3a8209cacf878970544d73c1f634136688ba2d

COCOAPODS: 1.2.1

0 comments on commit 6d601ac

Please sign in to comment.