Authored by Justin R. Miller

fixes #115: add SSL support

@@ -69,6 +69,15 @@ typedef enum : NSUInteger { @@ -69,6 +69,15 @@ typedef enum : NSUInteger {
69 * @return An initialized MapBox tile source. */ 69 * @return An initialized MapBox tile source. */
70 - (id)initWithMapID:(NSString *)mapID; 70 - (id)initWithMapID:(NSString *)mapID;
71 71
  72 +/** Initialize a tile source using the MapBox map ID, optionally enabling SSL.
  73 +*
  74 +* This method requires a network connection in order to download the TileJSON used to define the tile source.
  75 +*
  76 +* @param mapID The MapBox map ID string, typically in the format `<username>.map-<random characters>`.
  77 +* @param enableSSL Whether to use SSL-enabled HTTPS connections for map tiles and other related data. Defaults to `NO`. At some point in the future, this will default to `YES`.
  78 +* @return An initialized MapBox tile source. */
  79 +- (id)initWithMapID:(NSString *)mapID enablingSSL:(BOOL)enableSSL;
  80 +
72 /** Initialize a tile source with either a remote or local TileJSON structure. 81 /** Initialize a tile source with either a remote or local TileJSON structure.
73 * 82 *
74 * Passing a remote URL requires a network connection. If offline functionality is desired, you should cache the TileJSON locally at a prior date, then pass a file path URL to this method. 83 * Passing a remote URL requires a network connection. If offline functionality is desired, you should cache the TileJSON locally at a prior date, then pass a file path URL to this method.
@@ -93,6 +102,16 @@ typedef enum : NSUInteger { @@ -93,6 +102,16 @@ typedef enum : NSUInteger {
93 * @return An initialized MapBox tile source. */ 102 * @return An initialized MapBox tile source. */
94 - (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView; 103 - (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView;
95 104
  105 +/** For TileJSON 2.1.0+ layers, initialize a tile source and automatically find and add annotations from [simplestyle](http://mapbox.com/developers/simplestyle/) data, optionally enabling SSL.
  106 +*
  107 +* This method requires a network connection in order to download the TileJSON used to define the tile source.
  108 +*
  109 +* @param mapID The MapBox map ID string, typically in the format `<username>.map-<random characters>`.
  110 +* @param mapView A map view on which to display the annotations.
  111 +* @param enableSSL Whether to use SSL-enabled HTTPS connections for map tiles and other related data. Defaults to `NO`. At some point in the future, this will default to `YES`.
  112 +* @return An initialized MapBox tile source. */
  113 +- (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView enablingSSL:(BOOL)enableSSL;
  114 +
96 /** For TileJSON 2.1.0+ layers, initialize a tile source and automatically find and add annotations from [simplestyle](http://mapbox.com/developers/simplestyle/) data. 115 /** For TileJSON 2.1.0+ layers, initialize a tile source and automatically find and add annotations from [simplestyle](http://mapbox.com/developers/simplestyle/) data.
97 * @param tileJSON A string containing TileJSON. 116 * @param tileJSON A string containing TileJSON.
98 * @param mapView A map view on which to display the annotations. 117 * @param mapView A map view on which to display the annotations.
@@ -61,7 +61,12 @@ @@ -61,7 +61,12 @@
61 61
62 - (id)initWithMapID:(NSString *)mapID 62 - (id)initWithMapID:(NSString *)mapID
63 { 63 {
64 - return [self initWithMapID:mapID enablingDataOnMapView:nil]; 64 + return [self initWithMapID:mapID enablingSSL:NO];
  65 +}
  66 +
  67 +- (id)initWithMapID:(NSString *)mapID enablingSSL:(BOOL)enableSSL
  68 +{
  69 + return [self initWithMapID:mapID enablingDataOnMapView:nil enablingSSL:enableSSL];
65 } 70 }
66 71
67 - (id)initWithTileJSON:(NSString *)tileJSON 72 - (id)initWithTileJSON:(NSString *)tileJSON
@@ -161,7 +166,12 @@ @@ -161,7 +166,12 @@
161 166
162 - (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView 167 - (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView
163 { 168 {
164 - NSString *referenceURLString = [NSString stringWithFormat:@"http://a.tiles.mapbox.com/v3/%@.json", mapID]; 169 + return [self initWithMapID:mapID enablingDataOnMapView:mapView enablingSSL:NO];
  170 +}
  171 +
  172 +- (id)initWithMapID:(NSString *)mapID enablingDataOnMapView:(RMMapView *)mapView enablingSSL:(BOOL)enableSSL
  173 +{
  174 + NSString *referenceURLString = [NSString stringWithFormat:@"http%@://api.tiles.mapbox.com/v3/%@.json%@", (enableSSL ? @"s" : @""), mapID, (enableSSL ? @"?secure" : @"")];
165 175
166 return [self initWithReferenceURL:[NSURL URLWithString:referenceURLString] enablingDataOnMapView:mapView]; 176 return [self initWithReferenceURL:[NSURL URLWithString:referenceURLString] enablingDataOnMapView:mapView];
167 } 177 }
@@ -175,7 +185,9 @@ @@ -175,7 +185,9 @@
175 185
176 - (NSURL *)tileJSONURL 186 - (NSURL *)tileJSONURL
177 { 187 {
178 - return [NSURL URLWithString:[NSString stringWithFormat:@"http://a.tiles.mapbox.com/v3/%@.json", [self.infoDictionary objectForKey:@"id"]]]; 188 + BOOL useSSL = [[[self.infoDictionary objectForKey:@"tiles"] objectAtIndex:0] hasPrefix:@"https"];
  189 +
  190 + return [NSURL URLWithString:[NSString stringWithFormat:@"http%@://api.tiles.mapbox.com/v3/%@.json%@", (useSSL ? @"s" : @""), [self.infoDictionary objectForKey:@"id"], (useSSL ? @"?secure" : @"")]];
179 } 191 }
180 192
181 - (NSURL *)URLForTile:(RMTile)tile 193 - (NSURL *)URLForTile:(RMTile)tile