100
MapKit Carnet de route

Map kit light

Embed Size (px)

Citation preview

Page 1: Map kit light

MapKitCarnet de route

Page 2: Map kit light

François PignonComptable au Ministère des Finances

Page 3: Map kit light

Jeudi ConfessionMode Thèmes iDVD activé

Page 4: Map kit light

Infinite Loop - Cupertino

Page 5: Map kit light

Yerba Buena Garden - San Francisco

Page 6: Map kit light

Le SequoiaC’est quoi ?

Page 7: Map kit light

Hauteur :Périmètre(1) :

Poids :

115,61 m47 m

2 100 t

(1) Mesuré à 1,2 m du sol.

Page 8: Map kit light
Page 9: Map kit light
Page 10: Map kit light
Page 11: Map kit light
Page 12: Map kit light

4 033

Page 13: Map kit light
Page 14: Map kit light

?

Page 15: Map kit light

MapKit Framework

Page 16: Map kit light

Afficher une carte

Page 17: Map kit light
Page 18: Map kit light
Page 19: Map kit light
Page 21: Map kit light

MapKit Framework

Page 22: Map kit light

MapKit Framework

Page 23: Map kit light

MapKit.frameworkCoreLocation.framework

++

Page 24: Map kit light
Page 25: Map kit light

Types de carte

Page 26: Map kit light

MKMapTypeStandard MKMapTypeSatellite MKMapTypeHybrid

Page 27: Map kit light

MKMapTypeStandardMKMapTypeSatelliteMKMapTypeHybrid

3

Page 28: Map kit light
Page 29: Map kit light

#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>

@interface STSViewController : UIViewController

@end

Page 30: Map kit light

#import "STSViewController.h"

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

@end

@implementation STSViewController

- (void)viewDidLoad { [super viewDidLoad]; [_mapView setMapType:3];}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES;}

@end

Page 31: Map kit light
Page 32: Map kit light

Simulateur

Page 33: Map kit light

Appareil

Page 34: Map kit light

Appareil

Simulateur

#if TARGET_IPHONE_SIMULATOR

[_mapView setMapType:MKMapTypeHybrid];

#else

[_mapView setMapType:3];

#endif

Page 35: Map kit light

Se souvenir de la dernière position

Page 36: Map kit light

@property (nonatomic) MKCoordinateRegion region;- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated;

@property (nonatomic) MKMapRect visibleMapRect;- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate;

@protocol MKMapViewDelegate <NSObject>@optional

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;

Page 37: Map kit light

#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>

@interface STSViewController : UIViewController <MKMapViewDelegate>

@end

Page 38: Map kit light

#import "STSViewController.h"

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";

@implementation STSViewController

- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */ NSString *tString=[[NSUserDefaults standardUserDefaults] objectForKey:STSLastVisibleMapRect]; if (tString!=nil) { NSArray *tComponents=[tString componentsSeparatedByString:@"|"]; if ([tComponents count]==4) { MKMapRect tVisibleMapRect=MKMapRectMake([[tComponents objectAtIndex:0] doubleValue], [[tComponents objectAtIndex:1] doubleValue], [[tComponents objectAtIndex:2] doubleValue], [[tComponents objectAtIndex:3] doubleValue]); [_mapView setVisibleMapRect:tVisibleMapRect]; } }}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…}

#pragma mark -

- (void)delayedSaveVisibleMapRect { MKMapRect tVisibleMapRect=_mapView.visibleMapRect; NSString *tString=[NSString stringWithFormat:@"%g|%g|%g|%g",tVisibleMapRect.origin.x, tVisibleMapRect.origin.y, tVisibleMapRect.size.width, tVisibleMapRect.size.height]; [[NSUserDefaults standardUserDefaults] setObject:tString forKey:STSLastVisibleMapRect];}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(delayedSaveVisibleMapRect) object:nil]; [self performSelector:@selector(delayedSaveVisibleMapRect) withObject:nil afterDelay:1.0];}

@end

Page 39: Map kit light

Indiquer un emplacement

Page 40: Map kit light

Annotation

Page 41: Map kit light
Page 42: Map kit light

<MKAnnotation>MKPointAnnotation - le mal aimé

Page 43: Map kit light

#import <MapKit/MapKit.h>

#import "STSSharedConstants.h"

@interface STSTreeAnnotation : NSObject <MKAnnotation>

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) STSTreeKind treeKind;@property (nonatomic, readonly,getter=isTreeLogged) BOOL logged;

+ (id)treeAnnotationWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged;- (id)initWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged;

@end

Page 44: Map kit light

#import "STSTreeAnnotation.h"

@interface STSTreeAnnotation (){! CLLocationCoordinate2D _coordinate;! STSTreeKind _treeKind;! BOOL _logged;}

@end

@implementation STSTreeAnnotation

@synthesize coordinate=_coordinate,treeKind=_treeKind,logged=_logged;

+ (id) treeAnnotationWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged {! return [[[STSTreeAnnotation alloc] initWithCoordinate:inCoordinate treeKind:inKind logged:inLogged] autorelease];}

- (id) initWithCoordinate:(CLLocationCoordinate2D)inCoordinate treeKind:(STSTreeKind)inKind logged:(BOOL)inLogged {! self=[super init];!! if (self!=nil) {! ! _coordinate=inCoordinate;! ! _treeKind=inKind;! ! _logged=inLogged;! }!! return self;}

@end

Page 45: Map kit light

#import "STSViewController.h"#import "STSTreeAnnotation.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";

@implementation STSViewController

- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */ NSString *tString=[[NSUserDefaults standardUserDefaults] objectForKey:STSLastVisibleMapRect]; if (tString!=nil) {…} /* Show Annotations */ NSDictionary *tDictionary=[NSDictionary dictionaryWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"Paris" withExtension:@"plist"]]; if (tDictionary!=nil) { NSMutableArray *tAnnotationsArray=[NSMutableArray array]; NSArray *tCitiesArray=[tDictionary objectForKey:STDataCitiesListKey]; for(NSDictionary *tCityDictionary in tCitiesArray) { NSArray *tAddressesArray=[tCityDictionary objectForKey:STDataCityPlacesListKey]; for (NSDictionary *tAddressDictionary in tAddressesArray) { NSArray *tTreesArray=[tAddressDictionary objectForKey:STDataPlaceTreesListKey]; for (NSDictionary *tTreeDictionary in tTreesArray) { NSNumber *tKindNumber=[tTreeDictionary objectForKey:STDataTreeKindKey]; NSNumber *tLoggedNumber=[tTreeDictionary objectForKey:@"Logged"]; NSDictionary *tPositionDictionary=[tTreeDictionary objectForKey:STDataTreeCoordinateKey]; if (tPositionDictionary!=nil) { NSNumber *tLatitudeNumber=[tPositionDictionary objectForKey:STDataTreeCoordinateLatitudeKey]; NSNumber *tLongitudeNumber=[tPositionDictionary objectForKey:STDataTreeCoordinateLongitudeKey]; STSTreeAnnotation *tTreeAnnotation=[STSTreeAnnotation treeAnnotationWithCoordinate:CLLocationCoordinate2DMake([tLatitudeNumber doubleValue], [tLongitudeNumber doubleValue]) treeKind:[tKindNumber unsignedIntegerValue] logged:[tLoggedNumber boolValue]]; if (tTreeAnnotation!=nil) [tAnnotationsArray addObject:tTreeAnnotation]; } } } } if ([tAnnotationsArray count]>0) [_mapView addAnnotations:tAnnotationsArray]; }}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…}

#pragma mark -

- (void)delayedSaveVisibleMapRect{…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {…}

@end

Page 46: Map kit light
Page 47: Map kit light

MKPinAnnotationView

MKAnnotationView

Page 48: Map kit light

MKPinAnnotationColorRed MKPinAnnotationColorGreen

MKPinAnnotationColorPurple

Page 49: Map kit light

MKPinAnnotationColorRed

MKPinAnnotationColorPurple

Page 50: Map kit light

#import "STSViewController.h"#import "STSTreeAnnotation.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationIdentifier=@"STSTreeAnnotationIdentifier";

@implementation STSViewController

- (void)viewDidLoad{…}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…}

#pragma mark -

- (void)delayedSaveVisibleMapRect{…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{…}

- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *tPinAnnotationView=(MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:STSTreeAnnotationIdentifier]; if (tPinAnnotationView==nil) { tPinAnnotationView=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STSTreeAnnotationIdentifier] autorelease]; if (tPinAnnotationView!=nil) [tPinAnnotationView setPinColor:MKPinAnnotationColorGreen]; } else { tPinAnnotationView.annotation=annotation; } return tPinAnnotationView;}

@end

Page 51: Map kit light
Page 52: Map kit light
Page 53: Map kit light

Sequoiadendron Giganteum

Sequoia Sempervirens Metasequoia

Abattu

Page 54: Map kit light

Sequoiadendron Giganteum

Sequoia Sempervirens Metasequoia

Abattu

Page 55: Map kit light

CoreImage

Page 56: Map kit light

#import <MapKit/MapKit.h>

#import "STSSharedConstants.h"

#import "STSTreeAnnotation.h"

@interface STSPinAnnotationView : MKPinAnnotationView

- (id)initWithAnnotation:(STSTreeAnnotation *) inTreeAnnotation reuseIdentifier:(NSString *)reuseIdentifier;

@end

Page 57: Map kit light

#import "STSPinAnnotationView.h"#import <CoreImage/CoreImage.h>

@interface STSPinAnnotationView (){ BOOL _cachedHighlighted;}

+ (UIImage *)imageFromCIImage:(CIImage *)inCIImage scale:(CGFloat)inScale orientation:(UIImageOrientation)inOrientation;

@end

@implementation STSPinAnnotationView

+ (UIImage *)imageFromCIImage:(CIImage *)inCIImage scale:(CGFloat)inScale orientation:(UIImageOrientation)inOrientation { UIImage *tImage=nil; CIContext *tContext = [CIContext contextWithOptions:nil]; CGImageRef tImageRef = [tContext createCGImage:inCIImage fromRect:inCIImage.extent]; if (tImageRef!=NULL) { tImage = [UIImage imageWithCGImage:tImageRef scale:inScale orientation:inOrientation]; CGImageRelease(tImageRef); } return tImage;}

#pragma mark -

- (id)initWithAnnotation:(STSTreeAnnotation *)inTreeAnnotation reuseIdentifier:(NSString *)reuseIdentifier { self=[super initWithAnnotation:inTreeAnnotation reuseIdentifier:reuseIdentifier]; if (self!=nil) { if ([inTreeAnnotation isTreeLogged]==YES) { self.pinColor=MKPinAnnotationColorRed; } else { switch([inTreeAnnotation treeKind]) { case STSTreeKindSequoiadendronGiganteum: self.pinColor=MKPinAnnotationColorGreen; break; case STSTreeKindSequoiaSempervirens: self.pinColor=MKPinAnnotationColorPurple; break; case STSTreeKindMetasequoia: self.pinColor=MKPinAnnotationColorGreen; break; } } [super setImage:[self image]]; } return self;}

#pragma mark -

- (UIImage *)image { UIImage *tImage=[super image]; STSTreeKind tTreeKind=[(STSTreeAnnotation *)self.annotation treeKind]; if (tTreeKind!=STSTreeKindSequoiadendronGiganteum || [(STSTreeAnnotation *)self.annotation isTreeLogged]==YES) { CIImage *tCIImage=tImage.CIImage; if (tCIImage==nil) { CGImageRef tImageRef=tImage.CGImage; if (tImageRef!=nil) tCIImage=[CIImage imageWithCGImage:tImageRef]; } if (tCIImage!=nil) { CIImage *tCIImageOutput; CIFilter *tFilter=nil; if ([(STSTreeAnnotation *)self.annotation isTreeLogged]==YES) { static CIFilter *sCoreImageImageMinimumComponentFilter=nil; if (sCoreImageImageMinimumComponentFilter==nil) sCoreImageImageMinimumComponentFilter=[[CIFilter filterWithName:@"CIMinimumComponent"] copy]; tFilter=sCoreImageImageMinimumComponentFilter; } else { static CIFilter *sCoreImageImageHueAdjustFilter=nil; if (sCoreImageImageHueAdjustFilter==nil) sCoreImageImageHueAdjustFilter=[[CIFilter filterWithName:@"CIHueAdjust"] copy]; tFilter=sCoreImageImageHueAdjustFilter; switch(tTreeKind) { case STSTreeKindSequoiaSempervirens: [tFilter setValue:[NSNumber numberWithFloat:(-167/180.0)*3.14] forKey:@"inputAngle"]; break; case STSTreeKindMetasequoia: [tFilter setValue:[NSNumber numberWithFloat:(-38/180.0)*3.14] forKey:@"inputAngle"]; break; default: return tImage; } } [tFilter setValue:tCIImage forKey:kCIInputImageKey]; tCIImageOutput=[tFilter valueForKey:kCIOutputImageKey]; tImage=[STSPinAnnotationView imageFromCIImage:tCIImageOutput scale:tImage.scale orientation:tImage.imageOrientation]; } } return tImage;}

- (void)setHighlighted:(BOOL)highlighted { BOOL tOldHighlighted=_cachedHighlighted; [super setHighlighted:highlighted]; if (tOldHighlighted!=highlighted) [self setImage:[self image]]; _cachedHighlighted=highlighted;}

@end

Page 58: Map kit light

#import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSPinAnnotationView.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationSequoiadendronIdentifier=@"TreeAnnotationSequoiadendronIdentifier";NSString * const STSTreeAnnotationSempervirensIdentifier=@"TreeAnnotationSempervirensIdentifier";NSString * const STSTreeAnnotationMetasequoiaIdentifier=@"TreeAnnotationMetasequoiaIdentifier";

@implementation STSViewController

- (void)viewDidLoad {…}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…}

#pragma mark -

- (void)delayedSaveVisibleMapRect {…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {…}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(STSTreeAnnotation *)annotation { NSString * tIdentifier=nil; switch([annotation treeKind]) { case STSTreeKindSequoiadendronGiganteum: tIdentifier=STSTreeAnnotationSequoiadendronIdentifier; break; case STSTreeKindSequoiaSempervirens: tIdentifier=STSTreeAnnotationSempervirensIdentifier; break; case STSTreeKindMetasequoia: tIdentifier=STSTreeAnnotationMetasequoiaIdentifier; break; } STSPinAnnotationView *tPinAnnotationView=(STSPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:tIdentifier]; if (tPinAnnotationView==nil) tPinAnnotationView=[[[STSPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:tIdentifier] autorelease]; else tPinAnnotationView.annotation=annotation; return tPinAnnotationView;}

@end

Page 59: Map kit light
Page 60: Map kit light

WTF?!#

Page 61: Map kit light
Page 62: Map kit light

MKPinAnnotationColorRed

MKPinAnnotationColorPurple

#import "STSTreeAnnotationView.h"

#define CENTER_OFFSET_X 14.0#define CENTER_OFFSET_Y -15.0

@interface STSTreeAnnotationView ()

+ (UIImage *)imageForTreeKind:(STSTreeKind)treeKind logged:(BOOL)logged;

+ (UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color; /* From StackOverflow */

@end

@implementation STSTreeAnnotationView

+ (UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color { UIGraphicsBeginImageContext(image.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGRect area = CGRectMake(0, 0, image.size.width, image.size.height); CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -area.size.height); CGContextSaveGState(context); CGContextClipToMask(context, area, image.CGImage); [color set]; CGContextFillRect(context, area); CGContextRestoreGState(context); CGContextSetBlendMode(context, kCGBlendModeMultiply); CGContextDrawImage(context, area, image.CGImage); UIImage *colorizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return colorizedImage;}

+ (UIImage *)imageForTreeKind:(STSTreeKind)treeKind logged:(BOOL)logged { UIImage *tImage=nil; if (logged==YES) { tImage=[UIImage imageNamed:@"loggedPin"]; } else { switch(treeKind) { case STSTreeKindSequoiadendronGiganteum: tImage=[UIImage imageNamed:@"sequoiadendronPin"]; break; case STSTreeKindSequoiaSempervirens: tImage=[UIImage imageNamed:@"sempervirensPin"]; break; case STSTreeKindMetasequoia: tImage=[UIImage imageNamed:@"metasequoiaPin"]; break; } } return tImage;}

#pragma mark -

- (id)initWithAnnotation:(STSTreeAnnotation *)annotation reuseIdentifier:(NSString *)reuseIdentifier { self=[super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; if (self!=nil) { [self setImage:[STSTreeAnnotationView imageForTreeKind:[annotation treeKind] logged:[annotation isTreeLogged]]]; self.centerOffset=CGPointMake(CENTER_OFFSET_X,CENTER_OFFSET_Y); } return self;}

- (void) setHighlighted:(BOOL)highlighted { if (highlighted!=self.isHighlighted) { [super setHighlighted:highlighted]; UIImage *tImage=[STSTreeAnnotationView imageForTreeKind:[(STSTreeAnnotation *)self.annotation treeKind] logged:[(STSTreeAnnotation *)self.annotation isTreeLogged]]; if (highlighted==YES) tImage=[STSTreeAnnotationView colorizeImage:tImage withColor:[UIColor grayColor]]; [self setImage:tImage]; self.centerOffset=CGPointMake(CENTER_OFFSET_X,CENTER_OFFSET_Y); }}

- (void) setSelected:(BOOL)selected { if (selected!=self.isSelected) { [super setSelected:selected]; UIImage *tImage=[STSTreeAnnotationView imageForTreeKind:[(STSTreeAnnotation *)self.annotation treeKind] logged:[(STSTreeAnnotation *)self.annotation isTreeLogged]]; if (selected==YES) tImage=[STSTreeAnnotationView colorizeImage:tImage withColor:[UIColor grayColor]]; [self setImage:tImage]; self.centerOffset=CGPointMake(CENTER_OFFSET_X,CENTER_OFFSET_Y); }}

@end

Page 63: Map kit light

MKPinAnnotationColorRed

MKPinAnnotationColorPurple

#import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSTreeAnnotationView.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){ IBOutlet MKMapView *_mapView;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier";

@implementation STSViewController

- (void)viewDidLoad{…}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…}

#pragma mark -

- (void)delayedSaveVisibleMapRect{…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {…}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(STSTreeAnnotation *)annotation { STSTreeAnnotationView *tAnnotationView=(STSTreeAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:STSTreeAnnotationViewIdentifier]; if (tAnnotationView==nil) tAnnotationView=[[[STSTreeAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:STSTreeAnnotationViewIdentifier] autorelease]; else tAnnotationView.annotation=annotation; return tAnnotationView;}

@end

Page 64: Map kit light
Page 65: Map kit light
Page 66: Map kit light

Délimiter une région

Page 67: Map kit light
Page 68: Map kit light
Page 69: Map kit light

Overlays

Page 70: Map kit light

MKCircleMKCircleView

MKPolylineMKPolylineView

MKPolygonMKPolygonView

Page 71: Map kit light

Données Géographiques

Page 73: Map kit light
Page 74: Map kit light

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.2"><Document>

<name><![CDATA[Val-d'Oise (95)]]></name><Style id="gitesdegaule.fr">

<LineStyle><color>cc2d3939</color><width>3</width>

</LineStyle><PolyStyle>

<color>804d4def</color></PolyStyle>

</Style><Placemark id="val-doise">

<name><![CDATA[Val-d'Oise (95)]]></name><styleUrl>#gitesdegaule.fr</styleUrl><Polygon>

<outerBoundaryIs><LinearRing>

<tessellate>1</tessellate><coordinates>

2.20056187,48.90881128,250</coordinates>

</LinearRing></outerBoundaryIs>

</Polygon></Placemark>

</Document></kml>

Page 75: Map kit light

2.20056187,48.90881128

Page 76: Map kit light
Page 77: Map kit light

> awk 'NR%2==0' input output

Page 78: Map kit light

#import <MapKit/MapKit.h>

@interface STSPolygonWrapper : NSObject <MKOverlay>

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) MKMapRect boundingMapRect;@property (nonatomic, retain) MKPolygon *polygon;

+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL;- (id)initWithContentsOfURL:(NSURL *)inURL;

- (BOOL)intersectsMapRect:(MKMapRect)inMapRect;

@end

Page 79: Map kit light

#import "STSPolygonWrapper.h"

@interface STSPolygonWrapper (){! MKPolygon * _polygon;}

@end

@implementation STSPolygonWrapper

@synthesize polygon=_polygon;

+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL {! STSPolygonWrapper *tPolygonWrapper=nil;!! if (inURL!=nil) tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:inURL];!! return [tPolygonWrapper autorelease];}

- (id)initWithContentsOfURL:(NSURL *)inURL {! self=[super init];!! if (self!=nil) {! ! NSString *tRawCoordinates;! !! ! // Polygon! !! ! tRawCoordinates=[NSString stringWithContentsOfURL:inURL encoding:NSUTF8StringEncoding error:NULL];! !! ! if (tRawCoordinates!=nil) {! ! ! NSArray *tCoordinatesArray;! ! ! NSUInteger tCoordinatesCount;! ! !! ! ! tCoordinatesArray=[tRawCoordinates componentsSeparatedByString:@"\n"];! ! !! ! ! tCoordinatesCount=[tCoordinatesArray count];! ! !! ! ! if (tCoordinatesCount>1) {! ! ! ! CLLocationCoordinate2D *tLocationsArray;! ! ! ! NSUInteger tIndex=0;! ! ! !! ! ! ! tLocationsArray=(CLLocationCoordinate2D *) malloc(tCoordinatesCount*sizeof(CLLocationCoordinate2D));! ! ! !! ! ! ! if (tLocationsArray!=NULL) {! ! ! ! ! for(NSString *tCoordinatesString in tCoordinatesArray) {! ! ! ! ! ! NSArray *tCoordinatesCouple;! ! ! ! ! !! ! ! ! ! ! tCoordinatesCouple=[tCoordinatesString componentsSeparatedByString:@","];! ! ! ! ! !! ! ! ! ! ! if (tCoordinatesCouple!=nil) {! ! ! ! ! ! ! tLocationsArray[tIndex].longitude=[[tCoordinatesCouple objectAtIndex:0] doubleValue];! ! ! ! ! ! ! tLocationsArray[tIndex].latitude=[[tCoordinatesCouple objectAtIndex:1] doubleValue];! ! ! ! ! ! !! ! ! ! ! ! ! tIndex++;! ! ! ! ! ! }! ! ! ! ! }! ! ! ! }! ! ! !! ! ! ! if (tIndex>1) self.polygon=[MKPolygon polygonWithCoordinates:tLocationsArray count:tIndex];! ! ! !! ! ! ! free(tLocationsArray);! ! ! }! ! }! }!! return self;}

- (void)dealloc {! [_polygon release];!! [super dealloc];}

#pragma mark -

- (CLLocationCoordinate2D)coordinate {! return self.polygon.coordinate;}

- (MKMapRect)boundingMapRect {! return self.polygon.boundingMapRect;}

#pragma mark -

- (BOOL)intersectsMapRect:(MKMapRect)inMapRect {! return [self.polygon intersectsMapRect:inMapRect];}

@end

Page 80: Map kit light

#import "STSViewController.h"#import "STSTreeAnnotation.h"#import "STSTreeAnnotationView.h"#import "STSPolygonWrapper.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){…}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier";

@implementation STSViewController

- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */ NSString *tString=[[NSUserDefaults standardUserDefaults] objectForKey:STSLastVisibleMapRect]; if (tString!=nil) {…} /* Show Annotations */ NSDictionary *tDictionary=[NSDictionary dictionaryWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"Paris" withExtension:@"plist"]]; if (tDictionary!=nil) {…} /* Add overlay */ _polygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"75" withExtension:@"coord"]];

[_mapView addOverlays:[NSArray arrayWithObject:_polygonWrapper]];}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{…}

#pragma mark -

- (void)delayedSaveVisibleMapRect{…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {…}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(STSTreeAnnotation *)annotation{…}

- (MKOverlayView *) mapView:(MKMapView *)mv viewForOverlay:(id <MKOverlay>)inOverlay {! MKPolygonView *tPolygonView=nil; MKPolygon *tPolygon=_polygonWrapper.polygon;!! if (tPolygon!=nil) {! ! MKPolygon *tContourPolygon; CLLocationCoordinate2D tSquare[4]={{36,-10},{36,14},{57,14},{57,-10}}; tContourPolygon=[MKPolygon polygonWithCoordinates:tSquare count:4 interiorPolygons:[NSArray arrayWithObject:tPolygon]]; tPolygonView=[[MKPolygonView alloc] initWithPolygon:tContourPolygon]; tPolygonView.lineWidth=1; tPolygonView.fillColor=[UIColor colorWithWhite:0.0 alpha:0.15]; tPolygonView.strokeColor=[UIColor colorWithWhite:0.5 alpha:1.0];! }!! return [tPolygonView autorelease];}

@end

Page 81: Map kit light
Page 82: Map kit light
Page 83: Map kit light
Page 84: Map kit light

Naviguer

Page 85: Map kit light
Page 86: Map kit light
Page 87: Map kit light

Tap & Gestures

Page 88: Map kit light

UIView ≠ UIView

Page 89: Map kit light

#import <MapKit/MapKit.h>

#define STSMAPVIEW_TRACKING_MODE_NORMAL! 0#define STSMAPVIEW_TRACKING_MODE_SPECIAL! 1

@interface STSMapView : MKMapView{! NSInteger _trackingMode;! NSArray *_cachedOriginalRecognizers;}

@property (nonatomic) NSInteger trackingMode;

@end

@protocol STSMapViewDelegate <MKMapViewDelegate>

- (void) mapView:(STSMapView *)inMapView handleZoomInRequestAtPoint:(CGPoint)inPoint;- (void) mapView:(STSMapView *)inMapView handleZoomOutRequestAtPoint:(CGPoint)inPoint;

@end

Page 90: Map kit light

#import "STSMapView.h"

@implementation STSMapView

@synthesize trackingMode=_trackingMode;

- (void) dealloc {! [_cachedOriginalRecognizers release];!! [super dealloc];}

#pragma mark -

- (void) setTrackingMode:(NSInteger)inMode {! if (_trackingMode!=inMode) {! ! if (inMode==STSMAPVIEW_TRACKING_MODE_NORMAL) {! ! ! self.zoomEnabled=YES; self.scrollEnabled=YES; if (_cachedOriginalRecognizers!=nil) {! ! ! ! self.gestureRecognizers=_cachedOriginalRecognizers;! ! ! !! ! ! ! [_cachedOriginalRecognizers release];! ! ! !! ! ! ! _cachedOriginalRecognizers=nil;! ! ! }! ! }! ! else {! ! ! UITapGestureRecognizer * tOneFingerDoubleTapRecognizer;! ! ! UITapGestureRecognizer * tTwoFingerSingleTapRecognizer;! ! !! ! ! // Save the original recognizers! ! !! ! ! _cachedOriginalRecognizers=[self.gestureRecognizers retain];! ! ! self.zoomEnabled=NO; self.scrollEnabled=NO; self.gestureRecognizers=nil;! ! !! ! ! tOneFingerDoubleTapRecognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleOneFingerDoubleTapFrom:)];! ! !! ! ! if (tOneFingerDoubleTapRecognizer!=nil) { tOneFingerDoubleTapRecognizer.numberOfTouchesRequired=1; tOneFingerDoubleTapRecognizer.numberOfTapsRequired=2;! ! ! ! [self addGestureRecognizer:tOneFingerDoubleTapRecognizer];! ! ! [tOneFingerDoubleTapRecognizer release];! ! ! }! ! !! ! ! tTwoFingerSingleTapRecognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerSingleTapFrom:)];! ! !! ! ! if (tTwoFingerSingleTapRecognizer!=nil) { tTwoFingerSingleTapRecognizer.numberOfTouchesRequired=2; tTwoFingerSingleTapRecognizer.numberOfTapsRequired=1; [self addGestureRecognizer:tTwoFingerSingleTapRecognizer];! ! ! ! [tTwoFingerSingleTapRecognizer release];! ! ! }! ! }! !! ! _trackingMode=inMode;! }}

- (void) handleOneFingerDoubleTapFrom:(UIGestureRecognizer *)inGestureRecognizer {! [(id <STSMapViewDelegate>)self.delegate mapView:self handleZoomInRequestAtPoint:[inGestureRecognizer locationInView:self]];}

- (void) handleTwoFingerSingleTapFrom:(UIGestureRecognizer *)inGestureRecognizer {! [(id <STSMapViewDelegate>)self.delegate mapView:self handleZoomOutRequestAtPoint:[inGestureRecognizer locationInView:self]];}

@end

Page 91: Map kit light

#import <MapKit/MapKit.h>

@interface STSPolygonWrapper : NSObject <MKOverlay>

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, readonly) MKMapRect boundingMapRect;@property (nonatomic) BOOL contours;@property (nonatomic, retain) MKPolygon * polygon;@property (nonatomic, retain) NSString * label;

+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL label:(NSString *)inLabel;- (id)initWithContentsOfURL:(NSURL *) inURL label:(NSString *)inLabel;

- (BOOL)containsPoint:(CLLocationCoordinate2D)inCoordinate;- (BOOL)intersectsMapRect:(MKMapRect)inMapRect;

@end

Page 92: Map kit light

#import "STSPolygonWrapper.h"

@interface STSPolygonWrapper (){! MKPolygon * _polygon;! CGMutablePathRef _pathRef;! BOOL _contours; NSString * _label;}

@end

@implementation STSPolygonWrapper

@synthesize polygon=_polygon,contours=_contours,label=_label;

+ (STSPolygonWrapper *)polygonWrapperWithContentsOfURL:(NSURL *)inURL label:(NSString *)inLabel {! STSPolygonWrapper * tPolygonWrapper=nil;!! if (inURL!=nil) tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:inURL label:inLabel];!! return [tPolygonWrapper autorelease];}

- (id)initWithContentsOfURL:(NSURL *)inURL label:(NSString *)inLabel {! self=[super init];!! if (self!=nil) {! ! NSString * tRawCoordinates;! ! self.label=inLabel; ! ! // Polygon and Path! !! ! tRawCoordinates=[NSString stringWithContentsOfURL:inURL encoding:NSUTF8StringEncoding error:NULL];! !! ! if (tRawCoordinates!=nil) {! ! ! NSArray * tCoordinatesArray=[tRawCoordinates componentsSeparatedByString:@"\n"];! ! ! NSUInteger tCoordinatesCount=[tCoordinatesArray count];! ! !! ! ! if (tCoordinatesCount>1) {! ! ! ! CLLocationCoordinate2D * tLocationsArray=(CLLocationCoordinate2D *) malloc(tCoordinatesCount*sizeof(CLLocationCoordinate2D));! ! ! ! NSUInteger tIndex=0;! ! ! !! ! ! ! if (tLocationsArray!=NULL) {! ! ! ! ! for(NSString * tCoordinatesString in tCoordinatesArray) {! ! ! ! ! ! NSArray * tCoordinatesCouple=[tCoordinatesString componentsSeparatedByString:@","];! ! ! ! ! !! ! ! ! ! ! if (tCoordinatesCouple!=nil) {! ! ! ! ! ! ! tLocationsArray[tIndex].longitude=[[tCoordinatesCouple objectAtIndex:0] doubleValue];! ! ! ! ! ! ! tLocationsArray[tIndex].latitude=[[tCoordinatesCouple objectAtIndex:1] doubleValue];! ! ! ! ! ! !! ! ! ! ! ! ! tIndex++;! ! ! ! ! ! }! ! ! ! ! }! ! ! ! }! ! ! !! ! ! ! if (tIndex>1) {! ! ! ! ! self.polygon=[MKPolygon polygonWithCoordinates:tLocationsArray count:tIndex];! ! ! ! !! ! ! ! ! _pathRef=CGPathCreateMutable();! ! ! ! !! ! ! ! ! if (_pathRef!=NULL) {! ! ! ! ! ! NSUInteger i;! ! ! ! ! !! ! ! ! !!CGPathMoveToPoint(_pathRef,NULL,tLocationsArray[0].longitude,tLocationsArray[0].latitude);! ! ! ! ! !! ! ! ! ! ! for(i=1;i<tIndex;i+=2) CGPathAddLineToPoint(_pathRef,NULL,tLocationsArray[i].longitude,tLocationsArray[i].latitude);! ! ! ! ! !! ! ! ! ! ! CGPathCloseSubpath(_pathRef);! ! ! ! ! }! ! ! ! }! ! ! !! ! ! ! free(tLocationsArray);! ! ! }! ! }! }!! return self;}

- (void) dealloc {! [_polygon release];!! CGPathRelease(_pathRef);!! [super dealloc];}

#pragma mark -

- (CLLocationCoordinate2D)coordinate {…}

- (MKMapRect)boundingMapRect {…}

#pragma mark -

- (BOOL)containsPoint:(CLLocationCoordinate2D)inCoordinate {! if (_pathRef!=NULL) {! ! CGPoint tPoint;! !! ! tPoint.x=inCoordinate.longitude;! ! tPoint.y=inCoordinate.latitude;! !! ! return (CGPathContainsPoint(_pathRef,NULL, tPoint, false)==true);! }!! return NO;}

#pragma mark -

- (BOOL)intersectsMapRect:(MKMapRect)inMapRect {…}

@end

Page 93: Map kit light

#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>#import "STSMapView.h"

@interface STSViewController : UIViewController <STSMapViewDelegate>

@end

Page 94: Map kit light

#import "STSViewController.h"#import "STSPolygonWrapper.h"

#import <CoreLocation/CoreLocation.h>

@interface STSViewController (){ IBOutlet STSMapView *_mapView; NSMutableArray *_overlays; STSPolygonWrapper *_overlay;}

- (void)delayedSaveVisibleMapRect;

@end

NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect";

@implementation STSViewController

- (void)viewDidLoad { [super viewDidLoad]; /* Set Map Type to Terrain */ [_mapView setMapType:3]; /* Restore (approximately) the visible map rect */ NSString *tString=[[NSUserDefaults standardUserDefaults] objectForKey:STSLastVisibleMapRect]; if (tString!=nil) {…} /* Set the Map mode */ [_mapView setTrackingMode:STSMAPVIEW_TRACKING_MODE_SPECIAL]; /* Add overlays */ _overlays=[[NSMutableArray alloc] initWithCapacity:10]; STSPolygonWrapper * tPolygonWrapper; tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"idf" withExtension:@"coord"] label:@""]; tPolygonWrapper.contours=YES; [_overlays addObject:tPolygonWrapper]; [tPolygonWrapper release]; NSArray * tArray=[NSArray arrayWithObjects:@"75",@"77",@"78",@"91",@"92",@"93",@"94",@"95",nil]; for(NSString * tLabel in tArray) { tPolygonWrapper=[[STSPolygonWrapper alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:tLabel withExtension:@"coord"] label:tLabel]; [_overlays addObject:tPolygonWrapper]; [tPolygonWrapper release]; } [_mapView addOverlays:_overlays];}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{…}

#pragma mark -

- (void)delayedSaveVisibleMapRect{…}

#pragma mark - MKMapView delegate

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{…}

- (MKOverlayView *)mapView:(MKMapView *)inMapView viewForOverlay:(id <MKOverlay>)inOverlay{! STSPolygonWrapper * tPolygonWrapper;! MKPolygon * tPolygon;! MKPolygonView * tPolygonView=nil;!! tPolygonWrapper=(STSPolygonWrapper *) inOverlay;!! tPolygon=tPolygonWrapper.polygon;!! if (tPolygon!=nil) {! ! if (tPolygonWrapper.contours==NO) {! ! ! tPolygonView=[[MKPolygonView alloc] initWithPolygon:tPolygon];! ! !! ! ! tPolygonView.lineWidth=3;! ! ! tPolygonView.strokeColor=[UIColor whiteColor];! ! }! ! else {! ! ! MKPolygon * tContourPolygon;! ! ! CLLocationCoordinate2D tSquare[4]={{36,-10},{36,14},{57,14},{57,-10}};! ! !! ! ! tContourPolygon=[MKPolygon polygonWithCoordinates:tSquare count:4 interiorPolygons:[NSArray arrayWithObject:tPolygon]];! ! !! ! ! tPolygonView=[[MKPolygonView alloc] initWithPolygon:tContourPolygon];! ! !! ! ! tPolygonView.lineWidth=1;! ! ! tPolygonView.fillColor=[UIColor colorWithWhite:0.0 alpha:0.15];! ! ! tPolygonView.strokeColor=[UIColor colorWithWhite:0.5 alpha:1.0];! ! } ! }!! return [tPolygonView autorelease];}

#pragma mark -

- (void)mapView:(STSMapView *)inMapView handleZoomInRequestAtPoint:(CGPoint)inPoint {! if (_overlay!=nil) return; if (_overlays!=nil) { NSString * tOverlayLabel=nil; CLLocationCoordinate2D tCoordinate; tCoordinate=[_mapView convertPoint:inPoint toCoordinateFromView:_mapView]; for(STSPolygonWrapper * tPolygonWrapper in _overlays) { if ([tPolygonWrapper contours]==NO && [tPolygonWrapper containsPoint:tCoordinate]==YES) { tOverlayLabel=tPolygonWrapper.label; break; } } if (tOverlayLabel!=nil) { [_mapView removeOverlays:_overlays]; _overlay=[[STSPolygonWrapper alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:tOverlayLabel withExtension:@"coord"] label:tOverlayLabel]; _overlay.contours=YES; [_mapView addOverlay:_overlay]; }! }}

- (void)mapView:(STSMapView *)inMapView handleZoomOutRequestAtPoint:(CGPoint)inPoint{ if (_overlay==nil) return; [_mapView removeOverlay:_overlay]; [_overlay release]; _overlay=nil; [_mapView addOverlays:_overlays];}

@end

Page 95: Map kit light

Cluster

Page 97: Map kit light

Références

WWDC sessions

2009 : Session 118 - Embedding Maps in iPhone Applications2010 : Session 127 - Customizing Maps with Overlays2011 : Session 111 - Visualizing Information Geographically with Map Kit2012 : Session 300 - Getting Around With Map Kit

KML

Régions :Déparetements :

www.gitesdegaule.fr/KaraMeLise/git.piprime.fr Git - php/pi-google-maps-api.git/tree - pi-google-maps-api/res/france/regions/

Page 98: Map kit light

Références

Sample Code

s.sudre.free.fr/Stuff/CocoaHeads/STSimplified-CocoaHeads.zip

Page 100: Map kit light

Q A&