Skip to content
Snippets Groups Projects

Resolve "[MIN-113] Show comments on the map"

Merged Piotr Gawron requested to merge 67-min-113-show-comments-on-the-map into development
All threads resolved!
2 files
+ 66
0
Compare changes
  • Side-by-side
  • Inline
Files
2
/* eslint-disable no-magic-numbers */
import { usePointToProjection } from '@/utils/map/usePointToProjection';
import Feature from 'ol/Feature';
import { Geometry } from 'ol/geom';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { useSelector } from 'react-redux';
import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors';
import { getCommentsFeatures } from '@/components/Map/MapViewer/utils/config/commentsLayer/getCommentsFeatures';
import { useMemo } from 'react';
export const useOlMapCommentsLayer = (): VectorLayer<VectorSource<Feature<Geometry>>> => {
const pointToProjection = usePointToProjection();
const comments = useSelector(allCommentsSelectorOfCurrentMap);
const elementsFeatures = useMemo(
() =>
[
getCommentsFeatures(comments, {
pointToProjection,
}),
].flat(),
[comments, pointToProjection],
);
const vectorSource = useMemo(() => {
return new VectorSource({
features: [...elementsFeatures],
});
}, [elementsFeatures]);
const pinsLayer = useMemo(
() =>
new VectorLayer({
source: vectorSource,
}),
[vectorSource],
);
return pinsLayer;
};
Loading