Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/three/plugins/images/ImageOverlayPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class ImageOverlay {
color: number | Color;
opacity: number;
frame?: Matrix4 | null;
proxyUrl?: string;
fetchOptions?: any;

}

Expand Down Expand Up @@ -72,7 +74,6 @@ export class WMSTilesOverlay extends ImageOverlay {
levels?: number,
transparent?: boolean,
contentBoundingBox?: [ number, number, number, number ],

color: number | Color,
opacity: number,
frame?: Matrix4 | null,
Expand Down
19 changes: 16 additions & 3 deletions src/three/plugins/images/ImageOverlayPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,8 @@ export class ImageOverlayPlugin {
_initOverlay( overlay ) {

const { tiles } = this;
overlay.imageSource.fetchOptions = tiles.fetchOptions;
overlay.imageSource.fetchOptions = overlay.fetchOptions;

if ( ! overlay.isInitialized ) {

overlay.imageSource.fetchData = ( ...args ) => tiles
Expand Down Expand Up @@ -1407,8 +1408,12 @@ class ImageOverlay {
opacity = 1,
color = 0xffffff,
frame = null,
fetchOptions = {},
preprocessURL = null,
} = options;
this.imageSource = null;
this.fetchOptions = fetchOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the options on imageSource are really the ones being used here it may make most sense to add getters / setters for those options instead of storing them multiple places:

get fetchOptions() { return this.imageSource.fetchOptions; }
set fetchOptions( v ) { this.imageSource.fetchOptions = v; }

Copy link
Contributor Author

@SoftwareMechanic SoftwareMechanic Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but in order to make fetchOptions still usable as a parameter in the constructor from the client (and so for usage in R3F) I had to set the imageSource fetchOptions in the WMSTilesOverlay using the options, otherwise I can't set from ImageOverlay the fetch Options before the imageSource is defined.

export class WMSTilesOverlay extends ImageOverlay {

	constructor( options = {} ) {

		super( options );
		
		this.imageSource = new WMSImageSource( options );

		if (options.fetchOptions) {

			this.imageSource.fetchOptions = options.fetchOptions;

		}

		this.imageSource.fetchData = ( ...args ) => this.fetch( ...args );

	}
... rest of the code


if this the way to go I would consider implementing the same logic for all other overlays

this.preprocessURL = preprocessURL;
this.opacity = opacity;
this.color = new Color( color );
this.frame = frame !== null ? frame.clone() : null;
Expand All @@ -1428,9 +1433,17 @@ class ImageOverlay {

}

fetch( ...args ) {
// Apply proxy prefix and merge options
fetch( url, options = {} ) {

if ( this.preprocessURL ) {

url = this.preprocessURL( url );

}

return fetch( ...args );
const finalOptions = { ...this.fetchOptions, ...options };
return fetch( url, finalOptions );

}

Expand Down
9 changes: 8 additions & 1 deletion src/three/plugins/images/sources/WMSImageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export class WMSImageSource extends TiledImageSource {
REQUEST: 'GetMap',
VERSION: version,
LAYERS: layer,
STYLES: styles,
[ crsParam ]: crs,
BBOX: bboxParam.join( ',' ),
WIDTH: tileDimension,
Expand All @@ -149,6 +148,14 @@ export class WMSImageSource extends TiledImageSource {
TRANSPARENT: transparent ? 'TRUE' : 'FALSE',
} );

// Only add STYLES if it's defined (not null or undefined)
// This is a WMS-specific parameter, and giving it an unexpected value can lead to errors
if ( styles !== null && styles !== undefined ) {

params.set( 'STYLES', styles );

}

return new URL( '?' + params.toString(), this.url ).toString();

}
Expand Down
Loading