Skip to content

Commit d862442

Browse files
authored
fix WmsLoader catalogue demo (#247)
1 parent b337ac8 commit d862442

File tree

3 files changed

+68
-43
lines changed

3 files changed

+68
-43
lines changed

packages/react-maplibre/src/components/MlWmsLoader/MlWmsLoader.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface MlWmsLoaderStoryProps {
2424
url: string;
2525
}
2626
const Template: any = (props: MlWmsLoaderStoryProps) => {
27-
const [url, setUrl] = useState(props.url || 'https://magosm.magellium.com/geoserver/wms');
27+
const [url, setUrl] = useState(props.url || 'https://img.nj.gov/imagerywms/Infrared1995');
2828
const [demoMode, setDemoMode] = useState(false);
2929
const [guide, setGuide] = useState(false);
3030
const [openSidebar, setOpenSidebar] = useState(true);
@@ -100,6 +100,7 @@ const Template: any = (props: MlWmsLoaderStoryProps) => {
100100
url={url}
101101
onConfigChange={(config) => console.log(config)}
102102
zoomToExtent={true}
103+
layerId="WMS-layer"
103104
featureInfoActive={featureInfoActive}
104105
setFeatureInfoActive={setFeatureInfoActive}
105106
/>

packages/react-maplibre/src/components/MlWmsLoader/MlWmsLoader.tsx

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ListItem from '@mui/material/ListItem';
1010
import ListItemText from '@mui/material/ListItemText';
1111
import IconButton from '@mui/material/IconButton';
1212
import { LngLat, MapMouseEvent } from 'maplibre-gl';
13-
import { Layer2, Layer3 } from 'wms-capabilities';
1413
import useMap from '../../hooks/useMap';
1514
import { Box, Checkbox, ListItemIcon, Snackbar } from '@mui/material';
1615
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
@@ -66,7 +65,7 @@ export interface MlWmsLoaderProps {
6665
/**
6766
* WMS URL
6867
*/
69-
url: string;
68+
url?: string;
7069
/**
7170
* Id of the target MapLibre instance in mapContext
7271
*/
@@ -124,19 +123,64 @@ export interface MlWmsLoaderProps {
124123
sortable?: boolean;
125124
}
126125

126+
export interface WmsLayer {
127+
Name?: string;
128+
Title?: string;
129+
Abstract?: string;
130+
KeywordList?: string[];
131+
CRS?: string | string[];
132+
SRS?: string | string[];
133+
EX_GeographicBoundingBox?: number[];
134+
LatLonBoundingBox?: number[];
135+
BoundingBox?: any[];
136+
Dimension?: any;
137+
Attribution?: { Title: string; OnlineResource?: string; LogoURL?: any };
138+
AuthorityURL?: any[];
139+
Identifier?: any[];
140+
MetadataURL?: any[];
141+
DataURL?: any[];
142+
FeatureListURL?: any[];
143+
Style?: any[];
144+
MinScaleDenominator?: number;
145+
MaxScaleDenominator?: number;
146+
Layer?: WmsLayer[];
147+
queryable?: boolean;
148+
opaque?: boolean;
149+
noSubsets?: boolean;
150+
fixedWidth?: number;
151+
fixedHeight?: number;
152+
}
153+
127154
export type LayerType = {
128155
visible: boolean;
129156
Name: string;
130157
Attribution?: { Title: string };
131-
} & Omit<Layer2, 'Layer' | 'CRS'> &
132-
Partial<Pick<Layer2, 'Layer'>>;
158+
} & Omit<WmsLayer, 'Layer' | 'CRS'> &
159+
Partial<Pick<WmsLayer, 'Layer'>>;
160+
161+
const defaultProps = {
162+
mapId: undefined,
163+
url: '',
164+
urlParameters: {
165+
SERVICE: 'WMS',
166+
VERSION: '1.3.0',
167+
REQUEST: 'GetCapabilities',
168+
},
169+
wmsUrlParameters: {
170+
TRANSPARENT: 'TRUE',
171+
},
172+
featureInfoEnabled: true,
173+
zoomToExtent: false,
174+
showDeleteButton: false,
175+
};
133176
/**
134177
* Loads a WMS getCapabilities xml document and adds a MlWmsLayer component for each layer that is
135178
* offered by the WMS.
136179
*
137180
* @component
138181
*/
139182
const MlWmsLoader = (props: MlWmsLoaderProps) => {
183+
props = { ...defaultProps, ...props };
140184
const {
141185
capabilities: _capabilities,
142186
error,
@@ -146,6 +190,7 @@ const MlWmsLoader = (props: MlWmsLoaderProps) => {
146190
}: useWmsReturnType = useWms({
147191
urlParameters: props.urlParameters,
148192
});
193+
149194
const [open, setOpen] = useState(props?.config?.open || false);
150195
const [visible, setVisible] = useState<boolean>(props?.config?.visible || true);
151196
const [showDeletionConfirmationDialog, setShowDeletionConfirmationDialog] = useState(false);
@@ -259,8 +304,8 @@ const MlWmsLoader = (props: MlWmsLoaderProps) => {
259304
let _gfiUrl: string | undefined = getFeatureInfoUrl;
260305
let _gfiUrlParts;
261306
if (_gfiUrl?.indexOf?.('?') !== -1) {
262-
_gfiUrlParts = props.url.split('?');
263-
_gfiUrl = _gfiUrlParts[0];
307+
_gfiUrlParts = props?.url?.split('?') || props?.config?.wmsUrl?.split('?');
308+
_gfiUrl = _gfiUrlParts?.[0];
264309
}
265310
const _urlParamsFromUrl = new URLSearchParams(_gfiUrlParts?.[1]);
266311

@@ -317,6 +362,8 @@ const MlWmsLoader = (props: MlWmsLoaderProps) => {
317362
useEffect(() => {
318363
if (!capabilities?.Service) return;
319364

365+
let _LatLonBoundingBox: Array<number> = [];
366+
320367
if (
321368
capabilities?.Capability?.Layer?.CRS?.indexOf?.('EPSG:3857') === -1 &&
322369
capabilities?.Capability?.Layer?.CRS?.indexOf?.('CRS:84') === -1
@@ -329,38 +376,34 @@ const MlWmsLoader = (props: MlWmsLoaderProps) => {
329376
'MlWmsLoader (' + capabilities.Service.Title + '): WGS 84/Pseudo-Mercator supported'
330377
);
331378

332-
let _LatLonBoundingBox: Array<number> = [];
333-
334379
// collect queriable Layer2 layers
335380
let _layers: LayerType[] = capabilities?.Capability?.Layer?.Layer.filter(
336-
(el) => !el.Layer?.length
337-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
338-
// @ts-expect-error
339-
).map((layer: Layer2 & { Name: string }, idx: number) => {
381+
(el: WmsLayer) => !el.Layer?.length
382+
).map((layer: WmsLayer, idx: number) => {
340383
if (idx === 0) {
341-
_LatLonBoundingBox = layer.EX_GeographicBoundingBox;
384+
_LatLonBoundingBox = layer.EX_GeographicBoundingBox || layer?.LatLonBoundingBox || [];
342385
}
343386
return {
344387
visible: capabilities?.Capability?.Layer?.Layer?.length > 2 ? idx > 1 : true,
345388
Attribution: { Title: '' },
346389
// eslint-disable-next-line @typescript-eslint/no-unused-vars
347390
...(({ CRS, ..._layer }) => _layer)(layer),
348-
};
391+
} as LayerType;
349392
});
350393

351394
// collect queriable Layer3 layers
352-
capabilities?.Capability?.Layer?.Layer.forEach((el) => {
353-
const tmpLayers = el?.Layer?.filter((el) => el.CRS.length).map(
354-
(layer: Layer3, idx: number) => {
395+
capabilities?.Capability?.Layer?.Layer.forEach((el: WmsLayer) => {
396+
const tmpLayers = el?.Layer?.filter((el) => el.CRS?.length).map(
397+
(layer: WmsLayer, idx: number) => {
355398
if (idx === 0) {
356-
_LatLonBoundingBox = layer.EX_GeographicBoundingBox;
399+
_LatLonBoundingBox = layer.EX_GeographicBoundingBox || layer?.LatLonBoundingBox || [];
357400
}
358401
return {
359402
visible: false,
360403
Attribution: { Title: '' },
361404
// eslint-disable-next-line @typescript-eslint/no-unused-vars
362405
...(({ CRS, ..._layer }) => _layer)(layer),
363-
};
406+
} as LayerType;
364407
}
365408
);
366409

@@ -542,24 +585,5 @@ const MlWmsLoader = (props: MlWmsLoaderProps) => {
542585
</>
543586
);
544587
};
545-
//<p key="description" style={{ fontSize: '.7em' }}>
546-
// {capabilities?.Capability?.Layer?.['Abstract']}
547-
//</p>
548-
549-
MlWmsLoader.defaultProps = {
550-
mapId: undefined,
551-
url: '',
552-
urlParameters: {
553-
SERVICE: 'WMS',
554-
VERSION: '1.3.0',
555-
REQUEST: 'GetCapabilities',
556-
},
557-
wmsUrlParameters: {
558-
TRANSPARENT: 'TRUE',
559-
},
560-
featureInfoEnabled: true,
561-
zoomToExtent: false,
562-
showDeleteButton: false,
563-
};
564588

565589
export default MlWmsLoader;

packages/react-maplibre/src/components/MlWmsLoader/utils/WMSLinks.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ const wmsServices = [
4848
id: '1',
4949
title: 'HistOSM',
5050
description: 'Historic objects stored in the OpenStreetMap database',
51-
link: 'https://maps.heigit.org/histosm/wms',
51+
link: 'https://maps.heigit.org/histosm/wms/',
5252
},
5353
{
5454
id: '2',
55-
title: 'MagOSM',
55+
title: 'New Jersey Infrared 1995',
5656
description:
57-
'MagOSM is a project of the company Magellium which offers services related to thematic data from OpenStreetMap. Currently these services are provided at the scale of metropolitan France. The data of the different services are updated daily.',
58-
link: 'https://magosm.magellium.com/geoserver/wms',
57+
'This service was created to provide convenient internet access to 1995 - 1997 New Jersey orthophotos in false color infrared.',
58+
link: 'https://img.nj.gov/imagerywms/Infrared1995',
5959
},
6060
{
6161
id: '3',

0 commit comments

Comments
 (0)