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

LayerSwitcher: Add support for wms layers from the layer index #728

Merged
merged 2 commits into from
Nov 2, 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
Binary file added .swo
Binary file not shown.
Binary file added .swp
Binary file not shown.
3 changes: 2 additions & 1 deletion src/components/LayerSwitcher/AddCustomLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const LayerDataInput: React.FC<{
setLayerIndex(result);
setLayerIndexState('success');
})
.catch(() => {
.catch((err) => {
console.error(err); // eslint-disable-line no-console
setLayerIndex([]);
setLayerIndexState('error');
});
Expand Down
2 changes: 2 additions & 0 deletions src/components/LayerSwitcher/AddLayerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export const AddUserLayerButton = () => {
url,
name,
max_zoom: maxzoom,
min_zoom: minzoom,
attribution,
bbox: bboxes,
} = layer;

const newLayer: Layer = {
type: 'user',
maxzoom,
minzoom,
name,
url,
bboxes,
Expand Down
21 changes: 18 additions & 3 deletions src/components/LayerSwitcher/helpers/loadLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface LayerIndex {
*/
id: string;
bbox?: number[][];
type: 'tms';
type: 'tms' | 'wms';
/**
* A URL template for imagery tilesA URL template for imagery tiles
*/
Expand Down Expand Up @@ -156,8 +156,23 @@ export async function loadLayer() {

const boxes = coordinates?.map(getBoundingBox);

return { ...properties, bbox: boxes };
return {
...properties,
bbox: boxes,
url: properties.url
.replace('{proj}', 'EPSG:3857')
.replace('{width}', '256')
.replace('{height}', '256')
.replace('{bbox}', '{bbox-epsg-3857}'),
};
})
.filter(({ type, available_projections }) => {
if (type === 'tms') {
return true;
}
return (
type === 'wms' && (available_projections ?? []).includes('EPSG:3857')
);
})
.filter(({ type }) => type === 'tms')
.filter(({ url }) => isValidLayerUrl(url, false)) as LayerIndex[];
}
5 changes: 4 additions & 1 deletion src/components/Map/behaviour/useUpdateStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ export const useUpdateStyle = createMapEffectHook(

const osmappLayerMaxZoom = osmappLayers[key]?.maxzoom;
const userLayerMaxZoom = userLayers.find(({ url }) => url === key)?.maxzoom;

map.setMaxZoom(osmappLayerMaxZoom ?? userLayerMaxZoom ?? 24); // TODO find a way how to zoom bing further (now it stops at 19)

const osmappLayerMinZoom = osmappLayers[key]?.minzoom;
const userLayerMinZoom = userLayers.find(({ url }) => url === key)?.minzoom;
map.setMinZoom(osmappLayerMinZoom ?? userLayerMinZoom ?? 0);

const style = cloneDeep(getBaseStyle(key));
addOverlaysToStyle(map, style, overlays);
map.setStyle(style, { diff: mapLoaded });
Expand Down
1 change: 1 addition & 0 deletions src/components/utils/MapStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Layer {
Icon?: LayerIcon;
attribution?: string[]; // missing in spacer TODO refactor ugly
maxzoom?: number;
minzoom?: number;
bboxes?: number[][];
}

Expand Down
Loading