Skip to content
Snippets Groups Projects
Commit f024928e authored by Adrian Orłów's avatar Adrian Orłów
Browse files

feat: add partial bio entities events

parent 3e02c760
No related branches found
No related tags found
Loading
Pipeline #86809 passed
Showing
with 91 additions and 9 deletions
...@@ -201,6 +201,34 @@ To listen for specific events, plugins can use the `addListener` method in `even ...@@ -201,6 +201,34 @@ To listen for specific events, plugins can use the `addListener` method in `even
} }
``` ```
- onPinIconClick - triggered when someone clicks on a pin icon; the element to which the pin is attached is passed as an argument. Example argument:
```javascript
{
"id": 40072,
}
```
```javascript
{
"id": "b0a478ad-7e7a-47f5-8130-e96cbeaa0cfe", // marker pin
}
```
- onSurfaceOverlayClick - triggered when someone clicks on a overlay surface; the element to which the pin is attached is passed as an argument. Example argument:
```javascript
{
"id": 18,
}
```
```javascript
{
"id": "a3a5305f-acfa-47ff-bf77-a26d017c6eb3", // surface marker overlay
}
```
- onSubmapOpen - triggered when submap opens; the submap identifier is passed as an argument. Example argument: - onSubmapOpen - triggered when submap opens; the submap identifier is passed as an argument. Example argument:
``` ```
......
import Polygon, { fromExtent } from 'ol/geom/Polygon';
import Feature from 'ol/Feature'; import Feature from 'ol/Feature';
import Polygon, { fromExtent } from 'ol/geom/Polygon';
export const createFeatureFromExtent = ([xMin, yMin, xMax, yMax]: number[]): Feature<Polygon> => export const createFeatureFromExtent = ([xMin, yMin, xMax, yMax]: number[]): Feature<Polygon> =>
new Feature({ geometry: fromExtent([xMin, yMin, xMax, yMax]) }); new Feature({ geometry: fromExtent([xMin, yMin, xMax, yMax]), type: 'surface' });
...@@ -15,8 +15,11 @@ export const getPinFeature = ( ...@@ -15,8 +15,11 @@ export const getPinFeature = (
y: y + (height || ZERO) / HALF, y: y + (height || ZERO) / HALF,
}; };
return new Feature({ const feature = new Feature({
geometry: new Point(pointToProjection(point)), geometry: new Point(pointToProjection(point)),
name: id, id,
type: 'pin',
}); });
return feature;
}; };
...@@ -22,7 +22,7 @@ export const useOlMapLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig[ ...@@ -22,7 +22,7 @@ export const useOlMapLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig[
return; return;
} }
mapInstance.setLayers([tileLayer, reactionsLayer, pinsLayer, overlaysLayer]); mapInstance.setLayers([tileLayer, reactionsLayer, overlaysLayer, pinsLayer]);
}, [reactionsLayer, tileLayer, pinsLayer, mapInstance, overlaysLayer]); }, [reactionsLayer, tileLayer, pinsLayer, mapInstance, overlaysLayer]);
return [tileLayer, pinsLayer, reactionsLayer, overlaysLayer]; return [tileLayer, pinsLayer, reactionsLayer, overlaysLayer];
......
import { FeatureLike } from 'ol/Feature';
interface UseMapFeatureClickResult {
handleFeatureClick(feature: FeatureLike): void;
}
export const useMapFeatureClick = (): UseMapFeatureClickResult => {
const handleFeatureClick = (feature: FeatureLike): void => {
console.log(feature.get('type'));
};
return {
handleFeatureClick,
};
};
import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common';
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 { MapInstance } from '@/types/map';
import { MapBrowserEvent } from 'ol'; import { MapBrowserEvent } from 'ol';
import { getSearchResults } from './getSearchResults'; import { getSearchResults } from './getSearchResults';
import { handleDataReset } from './handleDataReset'; import { handleDataReset } from './handleDataReset';
...@@ -9,7 +10,7 @@ import { handleSearchResultAction } from './handleSearchResultAction'; ...@@ -9,7 +10,7 @@ import { handleSearchResultAction } from './handleSearchResultAction';
/* prettier-ignore */ /* prettier-ignore */
export const onMapSingleClick = export const onMapSingleClick =
(mapSize: MapSize, modelId: number, dispatch: AppDispatch) => (mapSize: MapSize, modelId: number, dispatch: AppDispatch) =>
async ({ coordinate }: MapBrowserEvent<UIEvent>): Promise<void> => { async ({ coordinate }: Pick<MapBrowserEvent<UIEvent>, 'coordinate'>, mapInstance: MapInstance): Promise<void> => {
// side-effect below is to prevent complications with data update - old data may conflict with new data // side-effect below is to prevent complications with data update - old data may conflict with new data
// so we need to reset all the data before updating // so we need to reset all the data before updating
dispatch(handleDataReset); dispatch(handleDataReset);
......
...@@ -10,6 +10,7 @@ import { Pixel } from 'ol/pixel'; ...@@ -10,6 +10,7 @@ import { Pixel } from 'ol/pixel';
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useDebouncedCallback } from 'use-debounce'; import { useDebouncedCallback } from 'use-debounce';
import { useMapFeatureClick } from './mapFeatureClick/useMapFeatureClick';
import { onMapRightClick } from './mapRightClick/onMapRightClick'; import { onMapRightClick } from './mapRightClick/onMapRightClick';
import { onMapSingleClick } from './mapSingleClick/onMapSingleClick'; import { onMapSingleClick } from './mapSingleClick/onMapSingleClick';
import { onMapPositionChange } from './onMapPositionChange'; import { onMapPositionChange } from './onMapPositionChange';
...@@ -23,6 +24,7 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) ...@@ -23,6 +24,7 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput)
const mapSize = useSelector(mapDataSizeSelector); const mapSize = useSelector(mapDataSizeSelector);
const modelId = useSelector(currentModelIdSelector); const modelId = useSelector(currentModelIdSelector);
const mapLastZoomValue = useSelector(mapDataLastZoomValue); const mapLastZoomValue = useSelector(mapDataLastZoomValue);
const { handleFeatureClick } = useMapFeatureClick();
const coordinate = useRef<Coordinate>([]); const coordinate = useRef<Coordinate>([]);
const pixel = useRef<Pixel>([]); const pixel = useRef<Pixel>([]);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
...@@ -58,7 +60,22 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput) ...@@ -58,7 +60,22 @@ export const useOlMapListeners = ({ view, mapInstance }: UseOlMapListenersInput)
return; return;
} }
const key = mapInstance.on('singleclick', handleMapSingleClick); const key = mapInstance.on('click', e => {
mapInstance.forEachFeatureAtPixel(e.pixel, handleFeatureClick);
});
// eslint-disable-next-line consistent-return
return () => unByKey(key);
}, [mapInstance, handleFeatureClick]);
useEffect(() => {
if (!mapInstance) {
return;
}
const key = mapInstance.on('singleclick', ({ coordinate: ciird }) =>
handleMapSingleClick({ coordinate }, mapInstance),
);
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
return () => unByKey(key); return () => unByKey(key);
......
...@@ -14,6 +14,8 @@ const PLUGINS_EVENTS = { ...@@ -14,6 +14,8 @@ const PLUGINS_EVENTS = {
onZoomChanged: 'onZoomChanged', onZoomChanged: 'onZoomChanged',
onCenterChanged: 'onCenterChanged', onCenterChanged: 'onCenterChanged',
onBioEntityClick: 'onBioEntityClick', onBioEntityClick: 'onBioEntityClick',
onPinIconClick: 'onPinIconClick',
onSurfaceOverlayClick: 'onSurfaceOverlayClick',
}, },
search: { search: {
onSearch: 'onSearch', onSearch: 'onSearch',
......
...@@ -4,6 +4,8 @@ import { ALLOWED_PLUGINS_EVENTS, LISTENER_NOT_FOUND } from './pluginsEventBus.co ...@@ -4,6 +4,8 @@ import { ALLOWED_PLUGINS_EVENTS, LISTENER_NOT_FOUND } from './pluginsEventBus.co
import type { import type {
CenteredCoordinates, CenteredCoordinates,
ClickedBioEntity, ClickedBioEntity,
ClickedPinIcon,
ClickedSurfaceOverlay,
Events, Events,
EventsData, EventsData,
PluginsEventBusType, PluginsEventBusType,
...@@ -21,6 +23,8 @@ export function dispatchEvent(type: 'onSubmapClose', submapId: number): void; ...@@ -21,6 +23,8 @@ export function dispatchEvent(type: 'onSubmapClose', submapId: number): void;
export function dispatchEvent(type: 'onZoomChanged', data: ZoomChanged): void; export function dispatchEvent(type: 'onZoomChanged', data: ZoomChanged): void;
export function dispatchEvent(type: 'onCenterChanged', data: CenteredCoordinates): void; export function dispatchEvent(type: 'onCenterChanged', data: CenteredCoordinates): void;
export function dispatchEvent(type: 'onBioEntityClick', data: ClickedBioEntity): void; export function dispatchEvent(type: 'onBioEntityClick', data: ClickedBioEntity): void;
export function dispatchEvent(type: 'onPinIconClick', data: ClickedPinIcon): void;
export function dispatchEvent(type: 'onSurfaceOverlayClick', data: ClickedSurfaceOverlay): void;
export function dispatchEvent(type: 'onSearch', data: SearchData): void; export function dispatchEvent(type: 'onSearch', data: SearchData): void;
export function dispatchEvent(type: Events, data: EventsData): void { export function dispatchEvent(type: Events, data: EventsData): void {
if (!ALLOWED_PLUGINS_EVENTS.includes(type)) throw new Error(`Invalid event type: ${type}`); if (!ALLOWED_PLUGINS_EVENTS.includes(type)) throw new Error(`Invalid event type: ${type}`);
......
...@@ -6,13 +6,15 @@ export type OverlayEvents = ...@@ -6,13 +6,15 @@ export type OverlayEvents =
| 'onAddDataOverlay' | 'onAddDataOverlay'
| 'onRemoveDataOverlay' | 'onRemoveDataOverlay'
| 'onShowOverlay' | 'onShowOverlay'
| 'onHideOverlay'; | 'onHideOverlay'
| 'onSurfaceOverlayClick';
export type SubmapEvents = export type SubmapEvents =
| 'onSubmapOpen' | 'onSubmapOpen'
| 'onSubmapClose' | 'onSubmapClose'
| 'onZoomChanged' | 'onZoomChanged'
| 'onCenterChanged' | 'onCenterChanged'
| 'onBioEntityClick'; | 'onBioEntityClick'
| 'onPinIconClick';
export type SearchEvents = 'onSearch'; export type SearchEvents = 'onSearch';
export type Events = OverlayEvents | BackgroundEvents | SubmapEvents | SearchEvents; export type Events = OverlayEvents | BackgroundEvents | SubmapEvents | SearchEvents;
...@@ -34,6 +36,14 @@ export type ClickedBioEntity = { ...@@ -34,6 +36,14 @@ export type ClickedBioEntity = {
modelId: number; modelId: number;
}; };
export type ClickedPinIcon = {
id: number | string;
};
export type ClickedSurfaceOverlay = {
id: number | string;
};
export type SearchDataBioEntity = { export type SearchDataBioEntity = {
type: 'bioEntity'; type: 'bioEntity';
searchValues: string[]; searchValues: string[];
...@@ -61,6 +71,8 @@ export type EventsData = ...@@ -61,6 +71,8 @@ export type EventsData =
| ZoomChanged | ZoomChanged
| CenteredCoordinates | CenteredCoordinates
| ClickedBioEntity | ClickedBioEntity
| ClickedPinIcon
| ClickedSurfaceOverlay
| SearchData; | SearchData;
export type PluginsEventBusType = { export type PluginsEventBusType = {
......
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