@@ -2132,30 +2132,73 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2132
2132
}
2133
2133
2134
2134
switch ( options . type ) {
2135
- case 'vector' :
2136
- source = MGLVectorTileSource . alloc ( ) . initWithIdentifierConfigurationURL ( id , NSURL . URLWithString ( options . url ) ) ;
2137
- break ;
2135
+ case 'vector' : {
2136
+ if ( options . url ) {
2137
+ source = MGLVectorTileSource . alloc ( ) . initWithIdentifierConfigurationURL ( id , NSURL . URLWithString ( options . url ) ) ;
2138
+ } else {
2139
+ const sourceOptions : any = { } ;
2140
+ if ( options . minzoom !== undefined ) {
2141
+ sourceOptions [ MGLTileSourceOptionMinimumZoomLevel ] = options . minzoom ;
2142
+ }
2143
+ if ( options . maxzoom !== undefined ) {
2144
+ sourceOptions [ MGLTileSourceOptionMaximumZoomLevel ] = options . maxzoom ;
2145
+ }
2146
+ if ( options . scheme ) {
2147
+ switch ( options . scheme ) {
2148
+ case 'xyz' :
2149
+ sourceOptions [ MGLTileSourceOptionTileCoordinateSystem ] = MGLTileCoordinateSystem . XYZ ;
2150
+ break ;
2151
+ case 'tms' :
2152
+ sourceOptions [ MGLTileSourceOptionTileCoordinateSystem ] = MGLTileCoordinateSystem . TMS ;
2153
+ break ;
2154
+ default :
2155
+ throw new Error ( 'Unknown raster tile scheme.' ) ;
2156
+ }
2157
+ }
2158
+ if ( options . bounds ) {
2159
+ sourceOptions [ MGLTileSourceOptionCoordinateBounds ] = NSValue . valueWithMGLCoordinateBounds ( {
2160
+ sw : CLLocationCoordinate2DMake ( options . bounds [ 1 ] , options . bounds [ 0 ] ) ,
2161
+ ne : CLLocationCoordinate2DMake ( options . bounds [ 3 ] , options . bounds [ 2 ] ) ,
2162
+ } ) ;
2138
2163
2164
+ }
2165
+ source = MGLVectorTileSource . alloc ( ) . initWithIdentifierTileURLTemplatesOptions ( id , options . tiles , sourceOptions ) ;
2166
+ }
2167
+ break ;
2168
+ }
2139
2169
case 'geojson' :
2140
2170
if ( theMap . style . sourceWithIdentifier ( id ) ) {
2141
2171
reject ( "Remove the layer with this id first with 'removeLayer': " + id ) ;
2142
2172
return ;
2143
2173
}
2174
+ let geoJsonShape : MGLShape ;
2175
+ if ( options . data ) {
2176
+ const content : NSString = NSString . stringWithString ( JSON . stringify ( options . data ) ) ;
2177
+ const nsData : NSData = content . dataUsingEncoding ( NSUTF8StringEncoding ) ;
2178
+ geoJsonShape = MGLShape . shapeWithDataEncodingError ( nsData , NSUTF8StringEncoding ) ;
2179
+ }
2180
+
2181
+ const sourceOptions : any = { } ;
2182
+ if ( options . minzoom !== undefined ) {
2183
+ sourceOptions [ MGLShapeSourceOptionMinimumZoomLevel ] = options . minzoom ;
2184
+ }
2185
+ if ( options . maxzoom !== undefined ) {
2186
+ sourceOptions [ MGLShapeSourceOptionMaximumZoomLevel ] = options . maxzoom ;
2187
+ }
2144
2188
2145
- const content : NSString = NSString . stringWithString ( JSON . stringify ( options . data ) ) ;
2146
- const nsData : NSData = content . dataUsingEncoding ( NSUTF8StringEncoding ) ;
2147
- const geoJsonShape = MGLShape . shapeWithDataEncodingError ( nsData , NSUTF8StringEncoding ) ;
2148
-
2149
- source = MGLShapeSource . alloc ( ) . initWithIdentifierShapeOptions ( id , geoJsonShape , null ) ;
2189
+ source = MGLShapeSource . alloc ( ) . initWithIdentifierShapeOptions ( id , geoJsonShape , sourceOptions ) ;
2150
2190
2151
2191
break ;
2152
- case 'raster' :
2192
+ case 'raster' : {
2153
2193
const sourceOptions : any = {
2154
- [ MGLTileSourceOptionMinimumZoomLevel ] : options . minzoom ,
2155
- [ MGLTileSourceOptionMaximumZoomLevel ] : options . maxzoom ,
2156
- [ MGLTileSourceOptionTileSize ] : options . tileSize ,
2194
+ [ MGLTileSourceOptionTileSize ] : options . tileSize || 256 ,
2157
2195
} ;
2158
-
2196
+ if ( options . minzoom !== undefined ) {
2197
+ sourceOptions [ MGLTileSourceOptionMinimumZoomLevel ] = options . minzoom ;
2198
+ }
2199
+ if ( options . maxzoom !== undefined ) {
2200
+ sourceOptions [ MGLTileSourceOptionMaximumZoomLevel ] = options . maxzoom ;
2201
+ }
2159
2202
if ( options . scheme ) {
2160
2203
switch ( options . scheme || 'xyz' ) {
2161
2204
case 'xyz' :
@@ -2170,15 +2213,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2170
2213
}
2171
2214
2172
2215
if ( options . bounds ) {
2173
- sourceOptions [ MGLTileSourceOptionCoordinateBounds ] = {
2216
+ sourceOptions [ MGLTileSourceOptionCoordinateBounds ] = NSValue . valueWithMGLCoordinateBounds ( ( {
2174
2217
sw : CLLocationCoordinate2DMake ( options . bounds [ 1 ] , options . bounds [ 0 ] ) ,
2175
2218
ne : CLLocationCoordinate2DMake ( options . bounds [ 3 ] , options . bounds [ 2 ] ) ,
2176
- } as MGLCoordinateBounds ;
2219
+ } ) ) ;
2220
+ console . log ( 'test' , sourceOptions [ MGLTileSourceOptionCoordinateBounds ] )
2177
2221
}
2178
-
2179
2222
source = MGLRasterTileSource . alloc ( ) . initWithIdentifierTileURLTemplatesOptions ( id , options . tiles , sourceOptions ) ;
2180
2223
2181
2224
break ;
2225
+ }
2182
2226
default :
2183
2227
reject ( 'Invalid source type: ' + options [ 'type' ] ) ;
2184
2228
return ;
0 commit comments