Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WMS custom params and WMS customizer entry point #30

Merged
merged 1 commit into from
Apr 24, 2024
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
12 changes: 10 additions & 2 deletions src/BaseCustomizer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {Geometry} from 'ol/geom.js';
import type {State} from 'ol/layer/Layer.js';
import type {WMTS} from 'ol/source.js';
import type {WMTS, TileWMS} from 'ol/source.js';
import type {Image, Stroke} from 'ol/style.js';
import type {MFPSymbolizerLine, MFPSymbolizerPoint, MFPWmtsLayer} from './types';
import type {MFPWmsLayer, MFPSymbolizerLine, MFPSymbolizerPoint, MFPWmtsLayer} from './types';
import type {Feature as GeoJSONFeature} from 'geojson';

/**
Expand Down Expand Up @@ -80,4 +80,12 @@ export default class BaseCustomizer {
wmtsLayer(layerState: State, wmtsLayer: MFPWmtsLayer, source: WMTS) {}
// FIXME: does it really makes sense?
// Why isn't it done on an extended BaseEncoder instead?

/**
* Can be used to manipulate a converted WMS layer
* @param layerState
* @param wmsLayer
* @param source
*/
wmsLayer(layerState: State, wmsLayer: MFPWmsLayer, source: TileWMS) {}
}
13 changes: 10 additions & 3 deletions src/MFPEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,23 @@ export default class MFPBaseEncoder {
*/
encodeWmsLayerState(layerState: State, url: string, params: any, customizer: BaseCustomizer): MFPWmsLayer {
const layer = layerState.layer;
// Pass all WMS params, but not the one standard one that are handled by mapfishprint
const customParams: any = {...params};
['SERVICE', 'REQUEST', 'FORMAT', 'LAYERS', 'VERSION', 'STYLES'].forEach(
(p: string) => delete customParams[p],
);
return {
name: layer.get('name'),
baseURL: url,
imageFormat: params.FORMAT,
layers: params.LAYERS.split(','),
customParams: {},
customParams,
serverType: 'mapserver',
type: 'wms',
opacity: layer.getOpacity(),
version: params.VERSION,
useNativeAngle: true,
styles: [''],
styles: params.STYLES?.split(',') ?? [''],
};
}

Expand Down Expand Up @@ -235,7 +240,9 @@ export default class MFPBaseEncoder {
console.assert(source instanceof TileWMSSource);
const urls = source.getUrls();
console.assert(!!urls);
return this.encodeWmsLayerState(layerState, urls[0], source.getParams(), customizer);
const wmsLayer = this.encodeWmsLayerState(layerState, urls[0], source.getParams(), customizer);
customizer.wmsLayer(layerState, wmsLayer, source);
return wmsLayer;
}

/**
Expand Down
Loading