Skip to content
Open
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
6 changes: 0 additions & 6 deletions src/common/components/ol-layer/ol.helpers.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/common/components/ol-layer/ol.tile-layer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { LayerType, TileLayer, TileWMTS, TileXYZ } from '@map-colonies/react-components';
import { isWMTSProtocol, isXYZProtocol } from './ol.helpers';
import {
isWMTSProtocol,
isXYZProtocol,
} from '../../../discrete-layer/components/helpers/layersUtils';
import { LayerOptions, WMTSOptions, XYZOptions } from './layer.config.options';

interface OlTileLayerParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { ILayerImage } from '../../../../discrete-layer/models/layerImage';
import { LayerRasterRecordModelType } from '../../../../discrete-layer/models';
import { getIconStyle } from '../../../helpers/style';
import { getIconStyle, hasWFSLink } from '../../../helpers/style';
import { TypeIcon } from '../../shared/type-icon';

interface IProductTypeCellRendererParams {
Expand All @@ -18,7 +18,7 @@ export const ProductTypeRenderer: React.FC<IProductTypeCellRendererParams> = ({
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
const rasterData = data as LayerRasterRecordModelType;

if (onClick && rasterData.links?.some((link) => link.protocol === 'WFS')) {
if (onClick && hasWFSLink(rasterData as unknown as Record<string, unknown>)) {
onClick(data, !rasterData.polygonPartsShown);
}
};
Expand Down
19 changes: 11 additions & 8 deletions src/common/helpers/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { get } from 'lodash';
import { DEFAULT_ID } from '../../discrete-layer/components/layer-details/utils';
import { LayerMetadataMixedUnion, RecordStatus } from '../../discrete-layer/models';
import CONFIG from '../config';
import { LinkType } from '../models/link-type.enum';
import { isValidLayerMetadata } from './layer-url';

const STATUS = 'productStatus';
Expand All @@ -28,6 +29,14 @@ export const isPolygonPartsShown = (data: Record<string, unknown>): boolean => {
return get(data, POLYGON_PARTS_SHOWN) === true;
};

export const hasWFSLink = (data: Record<string, unknown>): boolean => {
return (
(data.links as Array<Record<string, unknown>> | undefined)?.some(
(link) => link.protocol === LinkType.WFS
) ?? false
);
};

export const isUnpublishedValue = (value: string): boolean => {
return value === RecordStatus.UNPUBLISHED;
};
Expand Down Expand Up @@ -57,20 +66,14 @@ export const getIconStyle = (
resStyle = { [colorProperty]: UNPUBLISHED_COLOR };
}
if (existPolygonParts(data) && isPolygonPartsShown(data)) {
const hasWFSLink = (data.links as Array<Record<string, unknown>>)?.some(
(link) => link.protocol === 'WFS'
);
if (hasWFSLink) {
if (hasWFSLink(data)) {
resStyle = { [colorProperty]: POLYGON_PARTS_SHOWN_COLOR };
} else {
resStyle = { opacity: 0.5 };
}
}
if (existPolygonParts(data) && !isPolygonPartsShown(data)) {
const hasWFSLink = (data.links as Array<Record<string, unknown>>)?.some(
(link) => link.protocol === 'WFS'
);
if (!hasWFSLink) {
if (!hasWFSLink(data)) {
resStyle = {
...resStyle,
opacity: 0.5,
Expand Down
17 changes: 15 additions & 2 deletions src/common/hooks/mapMenus/useHandleMapMenuTemplates.hook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useIntl } from 'react-intl';
import _ from 'lodash';
import _, { get } from 'lodash';
import { IContextMenuData } from '@map-colonies/react-components';
import {
DynamicMenuData,
Expand All @@ -20,6 +20,7 @@ import {
ContextActionsTemplates,
} from '../../actions/context.actions';
import CONFIG from '../../config';
import { hasWFSLink } from '../../helpers/style';

export const useHandleMapMenuTemplates = (
menuProperties?: IMapMenuProperties,
Expand Down Expand Up @@ -116,13 +117,25 @@ export const useHandleMapMenuTemplates = (
},
};

const layerHasWFSLink = hasWFSLink(
get(activeLayer, 'meta.layerRecord') as Record<string, unknown>
);

const generatedGroup: MenuItemsGroup = {
...groupTemplateMenuItem,
groupProps: groupProp,
title: groupProp.titleTranslationId,
items: groupTemplateMenuItem.items.map((item) => {
if (!isMenuItemGroup(item)) {
return { ...item, payloadData: activeLayer.meta as Record<string, unknown> };
const itemDisabled =
item.action.action === ContextActions.QUERY_POLYGON_PARTS
? !layerHasWFSLink
: item.disabled;
return {
...item,
disabled: itemDisabled,
payloadData: activeLayer.meta as Record<string, unknown>,
};
}

return item;
Expand Down
6 changes: 5 additions & 1 deletion src/discrete-layer/components/helpers/layersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
TileMatrixSetModelType,
} from '../../models';

export const isWMTSProtocol = (linkType?: string): boolean =>
linkType === LinkType.WMTS_LAYER || linkType === LinkType.WMTS;

export const isXYZProtocol = (linkType?: string): boolean => linkType === LinkType.XYZ_LAYER;

export const isPolygonContainedInLayer = (
polygon: Feature,
layer: LayerMetadataMixedUnion
Expand All @@ -40,7 +45,6 @@ export const findLayerLink = (layer: ILayerImage): LinkModelType | undefined =>
let wmtsLayer = layer.links?.find((link: LinkModelType) =>
[LinkType.WMTS_LAYER as string].includes(link.protocol as string)
) as LinkModelType | undefined;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (wmtsLayer === undefined) {
wmtsLayer = layer.links?.find((link: LinkModelType) =>
[LinkType.WMTS as string].includes(link.protocol as string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const ActionsContextMenu: React.FC<IActionsContextMenuProps> = observer((
<Box className="contextMenuFooter">
<Box className="heightContainer">
<Icon className="menuIcon mc-icon-Height-DTM" />
<Typography tag="p">
<Typography tag="div">
{heightsAtCoordinates.isLoadingData ? <CircularProgress /> : getHeightText()}
</Typography>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({

return (
<MenuItemWithSeparator
key={`menu_item_${menuItemOrGroup.title}_${idx}`}
separatorKeySuffix={`${idx}`}
separator={menuItemOrGroup.action.separator}
showSeparatorBefore={showSeparatorBefore}
Expand Down Expand Up @@ -196,11 +197,14 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({
})}
</TooltippedValue>
);
const groupDisabled = menuItemOrGroup.disabled ?? false;
groupToRender = (
<Submenu
key={`imageryMenuGroupItems_${menuItemOrGroup.groupProps.id}`}
dir={direction}
label={menuTitle}
disabled={groupDisabled}
style={{ pointerEvents: groupDisabled ? 'none' : 'unset' }}
onMouseOver={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
Expand All @@ -217,6 +221,7 @@ export const ContextMenu: React.FC<PropsWithChildren<IMapContextMenuData>> = ({

return (
<MenuItemWithSeparator
key={`menu_group_${menuItemOrGroup.groupProps.id}_${idx}`}
separatorKeySuffix={`${menuItemOrGroup.groupProps.id}`}
separator={menuItemOrGroup.groupProps.separator}
showSeparatorBefore={showSeparatorBefore}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export const PolygonParts: React.FC = observer(() => {
// const buildWFSUrl = (layer: ILayerImage) => {
// const token = CONFIG.ACCESS_TOKEN.TOKEN_VALUE;
// if (layer) {
// const url = layer.links?.find((link) => link.protocol === 'WFS')?.url?.split(/[?#]/)[0];
// const url = layer.links?.find((link) => link.protocol === LinkType.WFS)?.url?.split(/[?#]/)[0];
// if (!url) {
// console.log(
// `[<PolygonParts>][buildWFSUrl] Layer ${layer.productName} does not have a WFS link`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import {
XYZOptions,
} from '../../../common/components/ol-layer/layer.config.options';
import { OlTileLayer } from '../../../common/components/ol-layer/ol.tile-layer';
import { isWMTSProtocol, isXYZProtocol } from '../../../common/components/ol-layer/ol.helpers';
import {
CapabilityModelType,
LayerMetadataMixedUnion,
LayerRasterRecordModelType,
LinkModelType,
} from '../../models';
import { getLayerLink, getLinkUrlWithToken, getWMTSConfigOptions } from '../helpers/layersUtils';
import {
getLayerLink,
getLinkUrlWithToken,
getWMTSConfigOptions,
isWMTSProtocol,
isXYZProtocol,
} from '../helpers/layersUtils';
import { getOLSourceOptions } from '../helpers/olUtils';

interface OlLayerRecordTileProps {
Expand Down
1 change: 1 addition & 0 deletions src/discrete-layer/models/mapMenusManagerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface MenuItemsGroup extends CommonMenuItem {
groupProps: ContextActionGroupProps;
items: MenuItemsList;
icon?: string;
disabled?: boolean;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should be reviewed after changes in action entity structure

}


Expand Down
8 changes: 4 additions & 4 deletions src/discrete-layer/views/discrete-layer-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,10 @@ const DiscreteLayerView: React.FC = observer(() => {

const mapLegendsExtractor = useCallback(
(layers: (ILayerImage & { meta: unknown })[]): IMapLegend[] => {
const legendDocProtocol = LinkType.LEGEND_DOC;
const legendImgProtocol = LinkType.LEGEND_IMG;
const legendObjProtocol = LinkType.LEGEND;
const legendsProtocols = [legendDocProtocol, legendImgProtocol, legendObjProtocol];
const LEGEND_PDF_PROTOCOL = LinkType.LEGEND_DOC;
const LEGEND_IMG_PROTOCOL = LinkType.LEGEND_IMG;
const LEGEND_OBJ_PROTOCOL = LinkType.LEGEND;
const legendsProtocols = [LEGEND_PDF_PROTOCOL, LEGEND_IMG_PROTOCOL, LEGEND_OBJ_PROTOCOL];

return layers.reduce((legendsList, cesiumLayer): IMapLegend[] => {
if (typeof get(cesiumLayer.meta, 'layerRecord.links') !== 'undefined') {
Expand Down
Loading