Skip to content
Snippets Groups Projects

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

Merged Miłosz Grocholewski requested to merge fix/MIN-112-hiding-context-menu into development
2 files
+ 54
29
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -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);
}
}
};
};
Loading