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

feat: adds wms styling using geostyler #1771

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open

Conversation

FritzHoing
Copy link
Collaborator

This MR adds wms styling via the geostyler using the SLD_BODY.

wms-geostyler

Please note:
The geostyler has a css issue in the current version, that needs to be fixed. The canvas of the style is dislocated.

Copy link
Member

@dnlkoch dnlkoch left a comment

Choose a reason for hiding this comment

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

Thank you very much for this addition @FritzHoing!

Overall the functionality is already awesome and is working for a defined context obviously. But for the production scenarios I think we need to adjust some architectural assumptions before we can merge this:

  1. Guessing the layer's map server by its path is very prone to errors since it might not match non-default scenarios. Probably it's the easiest way to just make the style-function configurable by the layer, e.g. by introducing a property in the layer configuration like styleable (to match the existing keys like searchable or editable). A styleable layer might then be defined as layer coming from GeoServer (this is open for discussion of course) or we might add an additional config like styleConfig containing the URL where to get the default style from.
  2. Using the internal GeoServer REST interfaces to get the style is generally fine, but in default scenarios this is accessible for admin users only. Default app users won't be able to access them. An easy approach would be to introduce a new proxy interface for the style URLS in the SHOGun backend providing access to them. An alternate approach could be using the WMS GetStyles request, but I'm not sure if this is actually supported as expected by GeoServer.

But again, I really like how this is looking so far and it would be really awesome to have this included!

Comment on lines +118 to +121
export const checkIfGeoserverLayer = (layerSource: Source | undefined): boolean => {
const url = getLayerUrl(layerSource);
return url ? url.includes('/geoserver/') : false;
};
Copy link
Member

Choose a reason for hiding this comment

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

This check is quite unreliable since there a GeoServers out there that aren't served from the default path.

return false;
}
let url: string | undefined;
if (layerSource instanceof TileWMS || layerSource instanceof ImageWMS) {
Copy link
Member

Choose a reason for hiding this comment

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

Very minor, but we might want to reuse the isWmsLayer typeguard instead.

if (layerSource instanceof TileWMS || layerSource instanceof ImageWMS) {
url = layerSource instanceof TileWMS ? layerSource.getUrls()?.[0] : layerSource.getUrl();
}
return url || false;
Copy link
Member

Choose a reason for hiding this comment

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

I would assume that it's very uncommon to return false here. If no url can be found, we should just return undefined or null.

Comment on lines +108 to +110
if (!layerSource) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

This check can be omitted if we would make the input argument mandatory.

client: SHOGunAPIClient | null
): Promise<string | undefined> => {
const cleanLayerUrl = layerUrl.replace('/ows?', '');
const url = `${cleanLayerUrl}/rest/layers/${layerWorkspace}:${layerName}.json`;
Copy link
Member

Choose a reason for hiding this comment

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

This URL (and also the one used in fetchSld()) is usually accessible for users holding the role ROLE_ADMINISTRATOR in GeoServer only.

Comment on lines +88 to +91
source.updateParams({
SLD_BODY: sld,
STYLES: style.name
});
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering, but what happens if:

  • a layer has been opened in the drawer,
  • got a new style via SLD_BODY,
  • the drawer has been closed and reopened with the same layer.

What style would be shown in the styler UI? The default one or the updated one?


const {
t
} = useTranslation();

useEffect(() => {

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

@@ -293,6 +316,18 @@ export const LayerTreeContextMenu: React.FC<LayerTreeContextMenuProps> = ({
});
}

if (isGeoserverLayer) {
dropdownMenuItems.push({
label: 'Geostyler',
Copy link
Member

Choose a reason for hiding this comment

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

The label should be translatable and the current one might be confusing to users. We might want to replace it with something like Layer style.

Comment on lines +326 to +329
dropdownMenuItems.push({
label: t('LayerTreeContextMenu.layerDetails'),
key: 'layerDetails'
});
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? This will be added further down (conditionally).

Comment on lines +260 to +261
dispatch(setStylingDrawerVisibility(true));
dispatch(setStylingDrawerLayerUid(getUid(layer)));
Copy link
Member

Choose a reason for hiding this comment

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

Should we show the styler if there is no layer present?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants