MapKit
Carnet de route
François Pignon
Comptable au Ministère des Finances
Jeudi Confession
 Mode Thèmes iDVD activé
Infinite Loop - Cupertino
Yerba Buena Garden - San Francisco
Le Sequoia
 C’est quoi ?
Hauteur : 115,61 m
                             Périmètre(1) : 47 m
                                  Poids : 2 100 t




(1) Mesuré à 1,2 m du sol.
4 033
?
MapKit Framework
Afficher une carte
www.psdgraphics.com
MapKit Framework
MapKit Framework
+   MapKit.framework
+   CoreLocation.framework
Types de carte
MKMapTypeStandard   MKMapTypeSatellite   MKMapTypeHybrid
MKMapTypeStandard    3
MKMapTypeSatellite
MKMapTypeHybrid
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface STSViewController : UIViewController

@end
#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
Simulateur
Appareil
Simulateur


#if TARGET_IPHONE_SIMULATOR


  [_mapView setMapType:MKMapTypeHybrid];


#else


  [_mapView setMapType:3];


#endif


                                            Appareil
Se souvenir de la
dernière position
@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;
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface STSViewController : UIViewController <MKMapViewDelegate>

@end
- (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
Indiquer un
emplacement
Annotation
<MKAnnotation>
MKPointAnnotation - le mal aimé
#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
#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;
#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]
MKAnnotationView


MKPinAnnotationView
MKPinAnnotationColorRed      MKPinAnnotationColorGreen




MKPinAnnotationColorPurple
MKPinAnnotationColorRed




MKPinAnnotationColorPurple
#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
Sequoia Sempervirens       Metasequoia




Sequoiadendron Giganteum        Abattu
Sequoia Sempervirens                       Metasequoia




                       Sequoiadendron Giganteum          Abattu
CoreImage
#import <MapKit/MapKit.h>

#import "STSSharedConstants.h"

#import "STSTreeAnnotation.h"

@interface STSPinAnnotationView : MKPinAnnotationView

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

@end
- (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;
}
#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
WTF?!#
}

+ (UIImage *)imageForTreeKind:(STSTreeKind)treeKind logged:(BOOL)logged {
   UIImage *tImage=nil;

    if (logged==YES) {
        tImage=[UIImage imageNamed:@"loggedPin"];
    }
    else {
               MKPinAnnotationColorRed
        switch(treeKind) {
           case STSTreeKindSequoiadendronGiganteum:
             tImage=[UIImage imageNamed:@"sequoiadendronPin"];
             break;

            case STSTreeKindSequoiaSempervirens:
              tImage=[UIImage imageNamed:@"sempervirensPin"];
              break;
                MKPinAnnotationColorPurple
            case STSTreeKindMetasequoia:
              tImage=[UIImage imageNamed:@"metasequoiaPin"];
              break;
        }
    }

    return tImage;
}

#pragma mark -

- (id)initWithAnnotation:(STSTreeAnnotation *)annotation reuseIdentifier:(NSString
*)reuseIdentifier {
#import "STSViewController.h"
#import "STSTreeAnnotation.h"
#import "STSTreeAnnotationView.h"

#import <CoreLocation/CoreLocation.h>

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

- (void)delayedSaveVisibleMapRect;

@end

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

@implementation STSViewController

- (void)viewDidLoad
{…}

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

#pragma mark -
Délimiter une région
Overlays
MKCircle       MKPolyline       MKPolygon
MKCircleView   MKPolylineView   MKPolygonView
Données
Géographiques
www.gitesdegaule.fr/KaraMeLise/
<?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>
2.20056187,48.90881128
> awk 'NR%2==0' input output
#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
#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;
!     !
#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 */
Naviguer
Tap & Gestures
UIView ≠ UIView
#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
#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 {
#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
#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];
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "STSMapView.h"

@interface STSViewController : UIViewController <STSMapViewDelegate>

@end
#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];
Cluster
applidium.com/en/news/too_many_pins_on_your_map/
Références

WWDC sessions
 2009 : Session 118 - Embedding Maps in iPhone Applications
 2010 : Session 127 - Customizing Maps with Overlays
 2011 : Session 111 - Visualizing Information Geographically with Map Kit
 2012 : Session 300 - Getting Around With Map Kit

KML
        Régions : www.gitesdegaule.fr/KaraMeLise/
 Déparetements : git.piprime.fr Git - php/pi-google-maps-api.git/
                 tree - pi-google-maps-api/res/france/regions/
Références

Sample Code
  s.sudre.free.fr/Stuff/CocoaHeads/STSimplified-CocoaHeads.zip
www.sequoias.eu
QA
 &

Map kit light

  • 1.
  • 2.
    François Pignon Comptable auMinistère des Finances
  • 3.
    Jeudi Confession ModeThèmes iDVD activé
  • 4.
  • 5.
    Yerba Buena Garden- San Francisco
  • 6.
  • 7.
    Hauteur : 115,61 m Périmètre(1) : 47 m Poids : 2 100 t (1) Mesuré à 1,2 m du sol.
  • 12.
  • 14.
  • 15.
  • 16.
  • 20.
  • 21.
  • 22.
  • 23.
    + MapKit.framework + CoreLocation.framework
  • 25.
  • 26.
    MKMapTypeStandard MKMapTypeSatellite MKMapTypeHybrid
  • 27.
    MKMapTypeStandard 3 MKMapTypeSatellite MKMapTypeHybrid
  • 29.
    #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interfaceSTSViewController : UIViewController @end
  • 30.
    #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
  • 32.
  • 33.
  • 34.
    Simulateur #if TARGET_IPHONE_SIMULATOR [_mapView setMapType:MKMapTypeHybrid]; #else [_mapView setMapType:3]; #endif Appareil
  • 35.
    Se souvenir dela dernière position
  • 36.
    @property (nonatomic) MKCoordinateRegionregion; - (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;
  • 37.
    #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interfaceSTSViewController : UIViewController <MKMapViewDelegate> @end
  • 38.
    - (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
  • 39.
  • 40.
  • 42.
  • 43.
    #import <MapKit/MapKit.h> #import "STSSharedConstants.h" @interfaceSTSTreeAnnotation : 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
  • 44.
    #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;
  • 45.
    #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]
  • 47.
  • 48.
    MKPinAnnotationColorRed MKPinAnnotationColorGreen MKPinAnnotationColorPurple
  • 49.
  • 50.
    #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
  • 53.
    Sequoia Sempervirens Metasequoia Sequoiadendron Giganteum Abattu
  • 54.
    Sequoia Sempervirens Metasequoia Sequoiadendron Giganteum Abattu
  • 55.
  • 56.
    #import <MapKit/MapKit.h> #import "STSSharedConstants.h" #import"STSTreeAnnotation.h" @interface STSPinAnnotationView : MKPinAnnotationView - (id)initWithAnnotation:(STSTreeAnnotation *) inTreeAnnotation reuseIdentifier:(NSString *)reuseIdentifier; @end
  • 57.
    - (id)initWithAnnotation:(STSTreeAnnotation *)inTreeAnnotationreuseIdentifier:(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; }
  • 58.
    #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
  • 60.
  • 62.
    } + (UIImage *)imageForTreeKind:(STSTreeKind)treeKindlogged:(BOOL)logged { UIImage *tImage=nil; if (logged==YES) { tImage=[UIImage imageNamed:@"loggedPin"]; } else { MKPinAnnotationColorRed switch(treeKind) { case STSTreeKindSequoiadendronGiganteum: tImage=[UIImage imageNamed:@"sequoiadendronPin"]; break; case STSTreeKindSequoiaSempervirens: tImage=[UIImage imageNamed:@"sempervirensPin"]; break; MKPinAnnotationColorPurple case STSTreeKindMetasequoia: tImage=[UIImage imageNamed:@"metasequoiaPin"]; break; } } return tImage; } #pragma mark - - (id)initWithAnnotation:(STSTreeAnnotation *)annotation reuseIdentifier:(NSString *)reuseIdentifier {
  • 63.
    #import "STSViewController.h" #import "STSTreeAnnotation.h" #import"STSTreeAnnotationView.h" #import <CoreLocation/CoreLocation.h> @interface STSViewController () { MKPinAnnotationColorRed IBOutlet MKMapView *_mapView; } - (void)delayedSaveVisibleMapRect; @end MKPinAnnotationColorPurple NSString * const STSLastVisibleMapRect=@"LastVisibleMapRect"; NSString * const STSTreeAnnotationViewIdentifier=@"TreeAnnotationViewIdentifier"; @implementation STSViewController - (void)viewDidLoad {…} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {…} #pragma mark -
  • 66.
  • 69.
  • 70.
    MKCircle MKPolyline MKPolygon MKCircleView MKPolylineView MKPolygonView
  • 71.
  • 72.
  • 74.
    <?xml version="1.0" encoding="UTF-8"?> <kmlxmlns="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>
  • 75.
  • 77.
    > awk 'NR%2==0'input output
  • 78.
    #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
  • 79.
    #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; ! !
  • 80.
    #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 */
  • 84.
  • 87.
  • 88.
  • 89.
    #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
  • 90.
    #import "STSMapView.h" @implementation STSMapView @synthesizetrackingMode=_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 {
  • 91.
    #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
  • 92.
    #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];
  • 93.
    #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> #import"STSMapView.h" @interface STSViewController : UIViewController <STSMapViewDelegate> @end
  • 94.
    #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];
  • 95.
  • 96.
  • 97.
    Références WWDC sessions 2009 :Session 118 - Embedding Maps in iPhone Applications 2010 : Session 127 - Customizing Maps with Overlays 2011 : Session 111 - Visualizing Information Geographically with Map Kit 2012 : Session 300 - Getting Around With Map Kit KML Régions : www.gitesdegaule.fr/KaraMeLise/ Déparetements : git.piprime.fr Git - php/pi-google-maps-api.git/ tree - pi-google-maps-api/res/france/regions/
  • 98.
    Références Sample Code s.sudre.free.fr/Stuff/CocoaHeads/STSimplified-CocoaHeads.zip
  • 99.
  • 100.