Skip to content
Snippets Groups Projects
Commit c01c8825 authored by Miłosz Grocholewski's avatar Miłosz Grocholewski
Browse files

Merge branch 'fix/MIN-112-hiding-context-menu' into 'development'

fix(vector-map): add hiding context menu after clicking on the map

Closes MIN-112

See merge request !328
parents f30af620 a6baa7a0
No related branches found
No related tags found
1 merge request!328fix(vector-map): add hiding context menu after clicking on the map
Pipeline #98680 passed
...@@ -16,32 +16,65 @@ import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapS ...@@ -16,32 +16,65 @@ import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapS
import { FEATURE_TYPE } from '@/constants/features'; import { FEATURE_TYPE } from '@/constants/features';
import { clickHandleReaction } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction'; import { clickHandleReaction } from '@/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction';
function isFeatureFilledCompartment(feature: FeatureLike): boolean {
return feature.get('type') === FEATURE_TYPE.COMPARTMENT && feature.get('filled');
}
function isFeatureNotCompartment(feature: FeatureLike): boolean {
return (
[...Object.values(FEATURE_TYPE)].includes(feature.get('type')) &&
feature.get('type') !== FEATURE_TYPE.COMPARTMENT
);
}
/* prettier-ignore */ /* prettier-ignore */
export const onMapLeftClick = export const onMapLeftClick =
(mapSize: MapSize, modelId: number, dispatch: AppDispatch, isResultDrawerOpen: boolean, comments: Comment[], modelElements: Array<ModelElement>, reactions: Array<NewReaction>) => (
async ({ coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>, mapInstance: Map): Promise<void> => { mapSize: MapSize,
modelId: number,
dispatch: AppDispatch,
isResultDrawerOpen: boolean,
comments: Comment[],
modelElements: Array<ModelElement>,
reactions: Array<NewReaction>,
) =>
async (
{ coordinate, pixel }: Pick<MapBrowserEvent<UIEvent>, 'coordinate' | 'pixel'>,
mapInstance: Map,
): Promise<void> => {
const [lng, lat] = toLonLat(coordinate); const [lng, lat] = toLonLat(coordinate);
const point = latLngToPoint([lat, lng], mapSize); const point = latLngToPoint([lat, lng], mapSize);
dispatch(updateLastClick({ coordinates: point, modelId })); dispatch(updateLastClick({ coordinates: point, modelId }));
let featureAtPixel: FeatureLike | undefined; let featureAtPixel: FeatureLike | undefined;
mapInstance.forEachFeatureAtPixel(pixel, (feature, ) => { mapInstance.forEachFeatureAtPixel(
if( pixel,
feature.get('id') && feature => {
( const featureZIndex = feature.get('zIndex');
feature.get('type') === FEATURE_TYPE.COMPARTMENT && feature.get('filled') || if (
[...Object.values(FEATURE_TYPE)].includes(feature.get('type')) && feature.get('type') !== FEATURE_TYPE.COMPARTMENT (isFeatureFilledCompartment(feature) || isFeatureNotCompartment(feature)) &&
) (featureZIndex === undefined || featureZIndex >= 0) &&
&& feature.get('zIndex') >= 0 !feature.get('hidden')
&& !feature.get('hidden') ) {
) { featureAtPixel = feature;
featureAtPixel = feature; return true;
return true; }
return false;
},
{ hitTolerance: 10 },
);
if (featureAtPixel) {
const { shouldBlockCoordSearch } = handleFeaturesClick([featureAtPixel], dispatch, comments);
if (shouldBlockCoordSearch) {
return;
} }
return false; }
}, {hitTolerance: 10});
if(!featureAtPixel) { dispatch(handleDataReset);
if (!featureAtPixel) {
if (isResultDrawerOpen) { if (isResultDrawerOpen) {
dispatch(closeDrawer()); dispatch(closeDrawer());
} }
...@@ -51,19 +84,11 @@ export const onMapLeftClick = ...@@ -51,19 +84,11 @@ export const onMapLeftClick =
return; return;
} }
const { shouldBlockCoordSearch } = handleFeaturesClick([featureAtPixel], dispatch, comments);
if (shouldBlockCoordSearch) {
return;
}
dispatch(handleDataReset);
const type = featureAtPixel.get('type'); const type = featureAtPixel.get('type');
const id = featureAtPixel.get('id'); const id = featureAtPixel.get('id');
if([FEATURE_TYPE.ALIAS, FEATURE_TYPE.GLYPH, FEATURE_TYPE.COMPARTMENT].includes(type)) { if ([FEATURE_TYPE.ALIAS, FEATURE_TYPE.GLYPH, FEATURE_TYPE.COMPARTMENT].includes(type)) {
await leftClickHandleAlias(dispatch)(featureAtPixel, modelId); await leftClickHandleAlias(dispatch)(featureAtPixel, modelId);
} else if (type === FEATURE_TYPE.REACTION) { } else if (type === FEATURE_TYPE.REACTION) {
clickHandleReaction(dispatch)(modelElements, reactions, id, modelId); clickHandleReaction(dispatch)(modelElements, reactions, id, modelId);
} }
}; };
...@@ -23,6 +23,8 @@ export const onMapRightClick = ...@@ -23,6 +23,8 @@ export const onMapRightClick =
const [lng, lat] = toLonLat(coordinate); const [lng, lat] = toLonLat(coordinate);
const point = latLngToPoint([lat, lng], mapSize); const point = latLngToPoint([lat, lng], mapSize);
dispatch(updateLastRightClick({ coordinates: point, modelId })); dispatch(updateLastRightClick({ coordinates: point, modelId }));
dispatch(handleDataReset);
dispatch(openContextMenu(pixel));
let foundFeature: Feature | undefined; let foundFeature: Feature | undefined;
mapInstance.getAllLayers().forEach(layer => { mapInstance.getAllLayers().forEach(layer => {
...@@ -47,8 +49,6 @@ export const onMapRightClick = ...@@ -47,8 +49,6 @@ export const onMapRightClick =
if(!foundFeature) { if(!foundFeature) {
return; return;
} }
dispatch(handleDataReset);
dispatch(openContextMenu(pixel));
const type = foundFeature.get('type'); const type = foundFeature.get('type');
const id = foundFeature.get('id'); const id = foundFeature.get('id');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment