Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 19 additions & 14 deletions src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export class WMSStreamlineLayer implements CustomLayerInterface {
const colormap = await fetchWMSColormap(
this.options.baseUrl,
this.options.layer,
this.options.style,
colorScaleRange,
this.signal,
this.options.transformRequest
Expand Down Expand Up @@ -320,7 +321,7 @@ export class WMSStreamlineLayer implements CustomLayerInterface {

async setStyle(style: string): Promise<void> {
this.options.style = style
await this.updateVelocityField(false)
await this.updateColorMap()
}

async setTime(time: Date): Promise<void> {
Expand Down Expand Up @@ -374,19 +375,7 @@ export class WMSStreamlineLayer implements CustomLayerInterface {
}

this.colorScaleRange = colorScaleRange

// Update colormap and velocity field for new color scale range.
const colormap = await fetchWMSColormap(
this.options.baseUrl,
this.options.layer,
colorScaleRange ?? undefined,
this.signal,
this.options.transformRequest
)
this._visualiser?.setColorMap(colormap)

// Note that we do not need a velocity update, since the TIFF response from
// the WMS server does not depend on the color scale range.
await this.updateColorMap()
}

setNumParticles(numParticles: number): void {
Expand Down Expand Up @@ -442,6 +431,22 @@ export class WMSStreamlineLayer implements CustomLayerInterface {
)
}

private async updateColorMap() {
// Update colormap and velocity field for new color scale range.
const colormap = await fetchWMSColormap(
this.options.baseUrl,
this.options.layer,
this.options.style,
this.colorScaleRange ?? undefined,
this.signal,
this.options.transformRequest
)
this._visualiser?.setColorMap(colormap)

// Note that we do not need a velocity update, since the TIFF response from
// the WMS server does not depend on the color scale range.
}

private async updateVelocityField(doResetParticles: boolean): Promise<void> {
if (!this.map) throw new Error('Not added to a map')
if (this.map.isMoving()) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/wms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class VelocityImage {
export async function fetchWMSColormap(
baseUrl: string,
layer: string,
style?: string,
colorScaleRange?: [number, number],
signal?: AbortSignal,
transformRequest?: TransformRequestFunction
Expand All @@ -57,6 +58,9 @@ export async function fetchWMSColormap(
url.searchParams.append('format', 'application/json')
url.searchParams.append('version', '1.3')
url.searchParams.append('layers', layer)
if (style) {
url.searchParams.append('style', style)
}
if (colorScaleRange) {
url.searchParams.append('colorScaleRange', `${colorScaleRange.join(',')}`)
}
Expand Down