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: adds checks for missing properties #1104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
55 changes: 46 additions & 9 deletions src/util/AppContextUtil/Shogun2AppContextUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import OlTileGrid from 'ol/tilegrid/TileGrid';
import OlLayer from 'ol/layer/Base';
import OlLayerGroup from 'ol/layer/Group';
import {get as getProjection, transformExtent, transform} from 'ol/proj';
import { getWidth } from 'ol/extent';
import { getTopLeft, getWidth } from 'ol/extent';

import * as moment from 'moment';

Expand Down Expand Up @@ -186,23 +186,60 @@ class Shogun2AppContextUtil extends BaseAppContextUtil implements AppContextUtil
legendUrl
} = layer.appearance;

const wmtsTileGrid = new OlTileGridWMTS({
origin: layer.source.tileGrid.origin,
resolutions: layer.source.tileGrid.resolutions,
matrixIds: layer.source.tileGrid.matrixIds
});
let projection;
let wmtsTileGrid;
let style;

if (layer.source.projection) {
projection = layer.source.projection;
} else {
projection = getProjection('EPSG:3857');
};

if (layer.source.tileGrid.origin &&
layer.source.tileGrid.resolutions &&
layer.source.tileGrid.matrixIds) {
wmtsTileGrid = new OlTileGridWMTS({
origin: layer.source.tileGrid.origin,
resolutions: layer.source.tileGrid.resolutions,
matrixIds: layer.source.tileGrid.matrixIds
});
} else {

const projectionExtent = projection.getExtent();
const size = getWidth(projectionExtent) / 256;
const resolutions = new Array(19);
Copy link
Member

Choose a reason for hiding this comment

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

You assume that always 19 Matrix levels are available in tile grid definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got this part from the OpenLayers Examples but you are right, the array could always be different!

const matrixIds = new Array(19);
for (let z = 0; z < 19; ++z) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (let z = 0; z < 19; ++z) {
for (let z = 0; z < 19; z++) {

You need to increment after the statements in the loop are made, don't you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in that particular case it does not really matter, both variants seem to work.

resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = z;
}

wmtsTileGrid = new OlTileGridWMTS({
origin: getTopLeft(projectionExtent),
resolutions: resolutions,
matrixIds: matrixIds,
});
};

if (layer.source.style) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor: You could also write

const style = layer?.source?.style ?? 'default'

instead of the if-else block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that looks way more clean thank you!

style = layer.source.style;
} else {
style = 'default';
}

const wmtsSource = new OlSourceWMTS({
projection: layer.source.projection,
urls: [
layer.source.url
],
layer: layer.source.layerNames,
format: layer.source.format,
matrixSet: layer.source.tileMatrixSet,
attributions: [attribution],
matrixSet: layer.source.matrixSet,
projection: projection,
tileGrid: wmtsTileGrid,
style: layer.source.style,
style: style,
wrapX: true,
requestEncoding: layer.source.requestEncoding
});

Expand Down