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

Fix encodeWmsLayerState #28

Merged
merged 5 commits into from
Mar 21, 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
16 changes: 16 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {
} from '@geoblocks/mapfishprint';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
import ImageWMS from 'ol/source/ImageWMS.js';
import VectorLayer from 'ol/layer/Vector.js';
import VectorSource from 'ol/source/Vector.js';
import {Circle, Fill, Stroke, Style, Text} from 'ol/style.js';
import Feature from './ol/Feature.js';
import {Polygon, LineString, Point} from 'ol/geom.js';
import {getPrintExtent} from './lib/utils.js';
import ImageLayer from 'ol/layer/Image.js';

const MFP_URL = 'https://geomapfish-demo-2-8.camptocamp.com/printproxy';
const layout = '1 A4 portrait'; // better take from MFP
Expand Down Expand Up @@ -77,13 +79,27 @@ features[1].setStyle(getStyleFn('rgba(0,0,0,0.4)'));
// Features 0 and 1 use dedicated style. Feature 2 uses layer style.
vectorLayer.getSource().addFeatures(features);

const wmsLayer = new ImageLayer({
source: new ImageWMS({
url: 'https://wms.geo.admin.ch/',
params: {
LAYERS: 'ch.astra.wanderland-sperrungen_umleitungen',
FORMAT: 'image/png',
CRS: 'EPSG:4326',
TRANSPARENT: true,
},
crossOrigin: 'anonymous',
}),
});

const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM(),
}),
vectorLayer,
wmsLayer,
],
view: new View({
center: [796612, 5836960],
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"doc": "typedoc --name 'Mapfish Print geoblock' --includeVersion --emit docs --excludeExternals --entryPointStrategy expand ./src"
},
"optionalDependencies": {
"@geoblocks/print": "0.7"
"@geoblocks/print": "0.7.8"
},
"peerDependencies": {
"ol": "7 || 8 || 9"
},
"devDependencies": {
"@geoblocks/print": "0.7.7",
"@geoblocks/print": "0.7.8",
"@geoblocks/recast-utils": "0.1.0",
"@types/geojson": "7946.0.14",
"@typescript-eslint/eslint-plugin": "7.3.1",
Expand Down
8 changes: 4 additions & 4 deletions src/MFPEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default class MFPBaseEncoder {
encodeImageWmsLayerState(layerState: State, customizer: BaseCustomizer) {
const layer = layerState.layer;
const source = layer.getSource() as ImageWMSSource;
console.assert(layer instanceof ImageWMSSource);
console.assert(source instanceof ImageWMSSource);
const url = source.getUrl();
if (url !== undefined) {
return this.encodeWmsLayerState(layerState, url, source.getParams(), customizer);
Expand All @@ -185,8 +185,8 @@ export default class MFPBaseEncoder {
return {
name: layer.get('name'),
baseURL: url,
imageFormat: 'image/png',
layers: [''],
imageFormat: params.FORMAT,
layers: params.LAYERS.split(','),
customParams: {},
serverType: 'mapserver',
type: 'wms',
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class MFPBaseEncoder {
const layer = layerState.layer;
console.assert(layer instanceof TileLayer);
const source = layer.getSource() as TileWMSSource;
console.assert(layer instanceof TileWMSSource);
console.assert(source instanceof TileWMSSource);
const urls = source.getUrls();
console.assert(!!urls);
return this.encodeWmsLayerState(layerState, urls[0], source.getParams(), customizer);
Expand Down
Loading