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

feat(vector-map): skip handle click on elements with negative zIndex

parent 127a25cb
No related branches found
No related tags found
1 merge request!318fix(vector-map): correct handle click event on glyph element
Pipeline #98378 passed
...@@ -51,7 +51,11 @@ describe('onMapLeftClick', () => { ...@@ -51,7 +51,11 @@ describe('onMapLeftClick', () => {
it('dispatches updateLastClick and resets data if no feature at pixel', async () => { it('dispatches updateLastClick and resets data if no feature at pixel', async () => {
const dispatch = jest.fn(); const dispatch = jest.fn();
jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => {
callback(new Feature({}), null as unknown as Layer, null as unknown as SimpleGeometry); callback(
new Feature({ zIndex: 1 }),
null as unknown as Layer,
null as unknown as SimpleGeometry,
);
}); });
await onMapLeftClick( await onMapLeftClick(
mapSize, mapSize,
...@@ -74,7 +78,7 @@ describe('onMapLeftClick', () => { ...@@ -74,7 +78,7 @@ describe('onMapLeftClick', () => {
const dispatch = jest.fn(() => ({ const dispatch = jest.fn(() => ({
unwrap: jest.fn().mockResolvedValue(mockBioEntities), unwrap: jest.fn().mockResolvedValue(mockBioEntities),
})); }));
const feature = new Feature({ id: 1, type: FEATURE_TYPE.ALIAS }); const feature = new Feature({ id: 1, type: FEATURE_TYPE.ALIAS, zIndex: 1 });
jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => {
callback(feature, null as unknown as Layer, null as unknown as SimpleGeometry); callback(feature, null as unknown as Layer, null as unknown as SimpleGeometry);
}); });
...@@ -98,7 +102,7 @@ describe('onMapLeftClick', () => { ...@@ -98,7 +102,7 @@ describe('onMapLeftClick', () => {
const dispatch = jest.fn(() => ({ const dispatch = jest.fn(() => ({
unwrap: jest.fn().mockResolvedValue(mockBioEntities), unwrap: jest.fn().mockResolvedValue(mockBioEntities),
})); }));
const feature = new Feature({ id: 1, type: FEATURE_TYPE.REACTION }); const feature = new Feature({ id: 1, type: FEATURE_TYPE.REACTION, zIndex: 1 });
jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => { jest.spyOn(mapInstance, 'forEachFeatureAtPixel').mockImplementation((_, callback) => {
callback(feature, null as unknown as Layer, null as unknown as SimpleGeometry); callback(feature, null as unknown as Layer, null as unknown as SimpleGeometry);
}); });
......
/* eslint-disable no-magic-numbers */
import { MapSize } from '@/redux/map/map.types'; import { MapSize } from '@/redux/map/map.types';
import { AppDispatch } from '@/redux/store'; import { AppDispatch } from '@/redux/store';
import { Map, MapBrowserEvent } from 'ol'; import { Map, MapBrowserEvent } from 'ol';
...@@ -26,13 +27,12 @@ export const onMapLeftClick = ...@@ -26,13 +27,12 @@ export const onMapLeftClick =
let featureAtPixel: FeatureLike | undefined; let featureAtPixel: FeatureLike | undefined;
mapInstance.forEachFeatureAtPixel(pixel, (feature, ) => { mapInstance.forEachFeatureAtPixel(pixel, (feature, ) => {
if(feature.get('id') && [...Object.values(FEATURE_TYPE)].includes(feature.get('type'))) { if(feature.get('id') && [...Object.values(FEATURE_TYPE)].includes(feature.get('type')) && feature.get('zIndex') >= 0) {
featureAtPixel = feature; featureAtPixel = feature;
return true; return true;
} }
return false; return false;
}, {hitTolerance: 10}); }, {hitTolerance: 10});
if(!featureAtPixel) { if(!featureAtPixel) {
if (isResultDrawerOpen) { if (isResultDrawerOpen) {
dispatch(closeDrawer()); dispatch(closeDrawer());
......
/* eslint-disable no-magic-numbers */
import { MapSize } from '@/redux/map/map.types'; import { MapSize } from '@/redux/map/map.types';
import { AppDispatch } from '@/redux/store'; import { AppDispatch } from '@/redux/store';
import { Feature, Map, MapBrowserEvent } from 'ol'; import { Feature, Map, MapBrowserEvent } from 'ol';
...@@ -30,7 +31,11 @@ export const onMapRightClick = ...@@ -30,7 +31,11 @@ export const onMapRightClick =
const source = layer.getSource(); const source = layer.getSource();
if (source instanceof VectorSource) { if (source instanceof VectorSource) {
foundFeature = source.getClosestFeatureToCoordinate(coordinate, (feature) => { foundFeature = source.getClosestFeatureToCoordinate(coordinate, (feature) => {
return [FEATURE_TYPE.ALIAS, FEATURE_TYPE.REACTION, FEATURE_TYPE.GLYPH].includes(feature.get('type')); return [
FEATURE_TYPE.ALIAS,
FEATURE_TYPE.REACTION,
FEATURE_TYPE.GLYPH
].includes(feature.get('type')) && feature.get('zIndex') >= 0;
}); });
} }
} }
......
...@@ -178,6 +178,7 @@ export default abstract class BaseMultiPolygon { ...@@ -178,6 +178,7 @@ export default abstract class BaseMultiPolygon {
}, },
id: this.id, id: this.id,
type: this.type, type: this.type,
zIndex: this.zIndex,
}); });
this.feature.setStyle(this.getStyle.bind(this)); this.feature.setStyle(this.getStyle.bind(this));
......
...@@ -92,6 +92,7 @@ export default class Glyph { ...@@ -92,6 +92,7 @@ export default class Glyph {
geometry: polygon, geometry: polygon,
id: elementId, id: elementId,
type: FEATURE_TYPE.GLYPH, type: FEATURE_TYPE.GLYPH,
zIndex,
getImageScale: (resolution: number): number => { getImageScale: (resolution: number): number => {
if (mapInstance) { if (mapInstance) {
return mapInstance.getView().getMinResolution() / resolution; return mapInstance.getView().getMinResolution() / resolution;
......
...@@ -60,6 +60,7 @@ export default function getArrowFeature({ ...@@ -60,6 +60,7 @@ export default function getArrowFeature({
const arrowFeature = new Feature({ const arrowFeature = new Feature({
geometry: new MultiPolygon(arrowPolygons), geometry: new MultiPolygon(arrowPolygons),
style: arrowStyles, style: arrowStyles,
zIndex,
}); });
arrowFeature.setStyle(arrowStyles); arrowFeature.setStyle(arrowStyles);
return arrowFeature; return arrowFeature;
......
...@@ -213,6 +213,7 @@ export default class Reaction { ...@@ -213,6 +213,7 @@ export default class Reaction {
id: this.id, id: this.id,
type: FEATURE_TYPE.REACTION, type: FEATURE_TYPE.REACTION,
elementType: REACTION_ELEMENT_TYPES.LINE, elementType: REACTION_ELEMENT_TYPES.LINE,
zIndex: this.zIndex,
}); });
lineFeature.setStyle(this.getStyle.bind(this)); lineFeature.setStyle(this.getStyle.bind(this));
...@@ -262,6 +263,7 @@ export default class Reaction { ...@@ -262,6 +263,7 @@ export default class Reaction {
id: this.id, id: this.id,
type: FEATURE_TYPE.REACTION, type: FEATURE_TYPE.REACTION,
elementType: REACTION_ELEMENT_TYPES.SQUARE, elementType: REACTION_ELEMENT_TYPES.SQUARE,
zIndex: this.zIndex,
}); });
squareFeature.setStyle(this.getStyle.bind(this)); squareFeature.setStyle(this.getStyle.bind(this));
return squareFeature; return squareFeature;
...@@ -318,6 +320,7 @@ export default class Reaction { ...@@ -318,6 +320,7 @@ export default class Reaction {
type: FEATURE_TYPE.REACTION, type: FEATURE_TYPE.REACTION,
elementType: REACTION_ELEMENT_TYPES.OPERATOR, elementType: REACTION_ELEMENT_TYPES.OPERATOR,
fontSize: 10, fontSize: 10,
zIndex: this.zIndex,
}); });
circleFeature.setStyle(this.getStyle.bind(this)); circleFeature.setStyle(this.getStyle.bind(this));
return circleFeature; return circleFeature;
......
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