@@ -335,20 +335,28 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
335335 this . mask_strategy = options . mask_strategy ;
336336 } ,
337337
338- getProjDef : function ( proj : number | string ) {
338+ getProjectionString : function ( proj : number | string ) {
339339 if ( isUTM ( proj ) ) return getProjString ( proj ) ;
340340 if ( typeof proj === "number" ) proj = "EPSG:" + proj ;
341341 if ( proj in this . proj4 . defs ) return proj ;
342342 if ( "EPSG:" + proj in this . proj4 . defs ) return "EPSG:" + proj ;
343343 throw new Error ( "[georaster-layer-for-leaflet] unsupported projection:" + proj ) ;
344344 } ,
345345
346- getProjector : function ( _from : number | string , _to : number | string ) {
346+ getProjector : function ( _from : number | string , _to : number | string = "EPSG:4326" ) {
347+ if ( _from === null || _from === undefined ) {
348+ if ( new Set ( this . georasters . map ( ( georaster : any ) => georaster . projection ) ) . size !== 1 ) {
349+ throw new Error ( "[georaster-layer-for-leaflet] getProjector called without a _from and georasters don't all have the same projection" ) ;
350+ } else {
351+ _from = this . georasters [ 0 ] . projection ;
352+ }
353+ }
354+
347355 if ( ! this . isSupportedProjection ( _from ) ) {
348356 throw Error ( "[georaster-layer-for-leaflet] unsupported projection: " + _from ) ;
349357 }
350358 if ( ! this . isSupportedProjection ( _to ) ) throw Error ( "[georaster-layer-for-leaflet] unsupported projection: " + _to ) ;
351- return this . proj4 ( this . getProjDef ( _from ) , this . getProjDef ( _to ) ) ;
359+ return this . proj4 ( this . getProjectionString ( _from ) , this . getProjectionString ( _to ) ) ;
352360 } ,
353361
354362 createTile : function ( coords : Coords , done : DoneCallback ) {
@@ -566,7 +574,14 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
566574 // const defaultCanvasWidth = Math.max(256, this.resolution || 256);
567575 // const widthOfCanvasPixelInMapCRS = extentOfTileInMapCRS.width / defaultCanvasHeight;
568576 // const heightOfCanvasPixelInMapCRS = extentOfTileInMapCRS.height / defaultCanvasWidth;
569- if ( debugLevel >= 3 ) log ( { heightOfScreenPixelInMapCRS, widthOfScreenPixelInMapCRS } ) ;
577+ if ( debugLevel >= 3 )
578+ console . log (
579+ `[georaster-layer-for-leaflet] [${ cacheKey } ] heightOfScreenPixelInMapCRS: ${ heightOfScreenPixelInMapCRS } `
580+ ) ;
581+ if ( debugLevel >= 3 )
582+ console . log (
583+ `[georaster-layer-for-leaflet] [${ cacheKey } ] widthOfScreenPixelInMapCRS: ${ widthOfScreenPixelInMapCRS } `
584+ ) ;
570585
571586 // even if we aren't doing the more advanced sample alignment above
572587 // we should still factor in the resolution when determing the resolution of the sampled rasters
@@ -579,10 +594,13 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
579594 resolution * ( extentOfInnerTileInMapCRS . height / extentOfTileInMapCRS . height )
580595 ) ;
581596
582- const skew = map_crs_code === ( "EPSG:" + this . georasters [ 0 ] . projection ) ? [ 0 , 0 ] : measureSkew (
583- [ this . georasters [ 0 ] . xmin , this . georasters [ 0 ] . ymin , this . georasters [ 0 ] . xmax , this . georasters [ 0 ] . ymax ] ,
584- this . getProjector ( this . georasters [ 0 ] . projection , map_crs_code ) . forward
585- ) ;
597+ const skew =
598+ map_crs_code === "EPSG:" + this . georasters [ 0 ] . projection
599+ ? [ 0 , 0 ]
600+ : measureSkew (
601+ [ this . georasters [ 0 ] . xmin , this . georasters [ 0 ] . ymin , this . georasters [ 0 ] . xmax , this . georasters [ 0 ] . ymax ] ,
602+ this . getProjector ( this . georasters [ 0 ] . projection , map_crs_code ) . forward
603+ ) ;
586604 if ( debugLevel >= 2 ) console . log ( `[georaster-layer-for-leaflet] [${ cacheKey } ] skew:` , skew ) ;
587605
588606 if (
@@ -978,7 +996,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
978996 theoretical_max,
979997 expr,
980998 turbo : this . options . turbo ?? false ,
981- skip_no_data_strategy : "any" // don't bother trying to render pixels with no data values
999+ skip_no_data_strategy : "any" , // don't bother trying to render pixels with no data values
1000+ before_warp : ( options : any ) => {
1001+ // provide backwards compatability
1002+ this . getColor = ( pixel : number [ ] ) => options . expr ( { pixel } ) ;
1003+ }
9821004 } ) ;
9831005 tile . style . visibility = "visible" ;
9841006 } catch ( e : any ) {
@@ -1146,6 +1168,11 @@ const GeoRasterLayer: (new (options: GeoRasterLayerOptions) => any) & typeof L.C
11461168 return false ;
11471169 } ,
11481170
1171+ // provided for backwards compatability
1172+ getColor : function ( values : number [ ] ) : string | undefined {
1173+ throw new Error ( "[georaster-layer-for-leaflet] please call getColor after creating at least one tile" ) ;
1174+ } ,
1175+
11491176 /**
11501177 * Redraws the active map tiles updating the pixel values using the supplie callback
11511178 */
0 commit comments