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

feat: add map action buttons

parent bebaa973
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!99feat: Add map action buttons (without zoom to pin group)
Pipeline #84166 passed
import { searchedBioEntitesSelectorOfCurrentMap } from '@/redux/bioEntity/bioEntity.selectors';
import { usePointToProjection } from '@/utils/map/usePointToProjection';
import { boundingExtent } from 'ol/extent';
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { MapInstance } from '../MapViewer.types';
interface Props {
mapInstance: MapInstance;
}
export const useSetBoundingExtent = ({ mapInstance }: Props): void => {
const contentBioEntites = useSelector(searchedBioEntitesSelectorOfCurrentMap);
const pointToProjection = usePointToProjection();
useEffect(() => {
if (!mapInstance || contentBioEntites.length === 0 || true) {
return;
}
const [allX, allY] = [contentBioEntites.map(e => e.x), contentBioEntites.map(e => e.y)];
const [minX, maxX] = [Math.min(...allX), Math.max(...allX)];
const [minY, maxY] = [Math.min(...allY), Math.max(...allY)];
console.log([
[minX, maxY],
[maxX, minY],
]);
const ext = boundingExtent([
pointToProjection({ x: minX, y: maxY }),
pointToProjection({ x: maxX, y: minY }),
]);
mapInstance.getView().fit(ext, {
size: mapInstance.getSize(),
});
}, [mapInstance, contentBioEntites, pointToProjection]);
};
...@@ -3,14 +3,15 @@ import { searchedBioEntitesSelectorOfCurrentMap } from '@/redux/bioEntity/bioEnt ...@@ -3,14 +3,15 @@ import { searchedBioEntitesSelectorOfCurrentMap } from '@/redux/bioEntity/bioEnt
import { searchedChemicalsBioEntitesOfCurrentMapSelector } from '@/redux/chemicals/chemicals.selectors'; import { searchedChemicalsBioEntitesOfCurrentMapSelector } from '@/redux/chemicals/chemicals.selectors';
import { searchedDrugsBioEntitesOfCurrentMapSelector } from '@/redux/drugs/drugs.selectors'; import { searchedDrugsBioEntitesOfCurrentMapSelector } from '@/redux/drugs/drugs.selectors';
import { usePointToProjection } from '@/utils/map/usePointToProjection'; import { usePointToProjection } from '@/utils/map/usePointToProjection';
import BaseLayer from 'ol/layer/Base'; import Feature from 'ol/Feature';
import { Geometry } from 'ol/geom';
import VectorLayer from 'ol/layer/Vector'; import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector'; import VectorSource from 'ol/source/Vector';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { getBioEntitiesFeatures } from './getBioEntitiesFeatures'; import { getBioEntitiesFeatures } from './getBioEntitiesFeatures';
export const useOlMapPinsLayer = (): BaseLayer => { export const useOlMapPinsLayer = (): VectorLayer<VectorSource<Feature<Geometry>>> => {
const pointToProjection = usePointToProjection(); const pointToProjection = usePointToProjection();
const contentBioEntites = useSelector(searchedBioEntitesSelectorOfCurrentMap); const contentBioEntites = useSelector(searchedBioEntitesSelectorOfCurrentMap);
const chemicalsBioEntities = useSelector(searchedChemicalsBioEntitesOfCurrentMapSelector); const chemicalsBioEntities = useSelector(searchedChemicalsBioEntitesOfCurrentMapSelector);
......
...@@ -30,11 +30,17 @@ export const useOlMapLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig[ ...@@ -30,11 +30,17 @@ export const useOlMapLayers = ({ mapInstance }: UseOlMapLayersInput): MapConfig[
}, [reactionsLayer, tileLayer, pinsLayer, mapInstance, overlaysLayer]); }, [reactionsLayer, tileLayer, pinsLayer, mapInstance, overlaysLayer]);
useEffect(() => { useEffect(() => {
/* TODO: remove when poc not needed */
if (!mapInstance || contentBioEntites.length === 0) { if (!mapInstance || contentBioEntites.length === 0) {
return; return;
} }
const extent = pinsLayer.getSource().getExtent(); const source = pinsLayer.getSource();
if (source === null) {
return;
}
const extent = source.getExtent();
mapInstance.getView().fit(extent, { mapInstance.getView().fit(extent, {
size: mapInstance.getSize(), size: mapInstance.getSize(),
maxZoom, maxZoom,
......
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