@@ -2132,30 +2132,73 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
21322132 }
21332133
21342134 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+ } ) ;
21382163
2164+ }
2165+ source = MGLVectorTileSource . alloc ( ) . initWithIdentifierTileURLTemplatesOptions ( id , options . tiles , sourceOptions ) ;
2166+ }
2167+ break ;
2168+ }
21392169 case 'geojson' :
21402170 if ( theMap . style . sourceWithIdentifier ( id ) ) {
21412171 reject ( "Remove the layer with this id first with 'removeLayer': " + id ) ;
21422172 return ;
21432173 }
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+ }
21442188
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 ) ;
21502190
21512191 break ;
2152- case 'raster' :
2192+ case 'raster' : {
21532193 const sourceOptions : any = {
2154- [ MGLTileSourceOptionMinimumZoomLevel ] : options . minzoom ,
2155- [ MGLTileSourceOptionMaximumZoomLevel ] : options . maxzoom ,
2156- [ MGLTileSourceOptionTileSize ] : options . tileSize ,
2194+ [ MGLTileSourceOptionTileSize ] : options . tileSize || 256 ,
21572195 } ;
2158-
2196+ if ( options . minzoom !== undefined ) {
2197+ sourceOptions [ MGLTileSourceOptionMinimumZoomLevel ] = options . minzoom ;
2198+ }
2199+ if ( options . maxzoom !== undefined ) {
2200+ sourceOptions [ MGLTileSourceOptionMaximumZoomLevel ] = options . maxzoom ;
2201+ }
21592202 if ( options . scheme ) {
21602203 switch ( options . scheme || 'xyz' ) {
21612204 case 'xyz' :
@@ -2170,15 +2213,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
21702213 }
21712214
21722215 if ( options . bounds ) {
2173- sourceOptions [ MGLTileSourceOptionCoordinateBounds ] = {
2216+ sourceOptions [ MGLTileSourceOptionCoordinateBounds ] = NSValue . valueWithMGLCoordinateBounds ( ( {
21742217 sw : CLLocationCoordinate2DMake ( options . bounds [ 1 ] , options . bounds [ 0 ] ) ,
21752218 ne : CLLocationCoordinate2DMake ( options . bounds [ 3 ] , options . bounds [ 2 ] ) ,
2176- } as MGLCoordinateBounds ;
2219+ } ) ) ;
2220+ console . log ( 'test' , sourceOptions [ MGLTileSourceOptionCoordinateBounds ] )
21772221 }
2178-
21792222 source = MGLRasterTileSource . alloc ( ) . initWithIdentifierTileURLTemplatesOptions ( id , options . tiles , sourceOptions ) ;
21802223
21812224 break ;
2225+ }
21822226 default :
21832227 reject ( 'Invalid source type: ' + options [ 'type' ] ) ;
21842228 return ;
0 commit comments