@tpzdsp/next-toolkit 1.15.1 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/map/MapComponent.tsx +8 -6
- package/src/map/MapContext.tsx +7 -0
- package/src/map/Popup.tsx +6 -35
package/package.json
CHANGED
package/src/map/MapComponent.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { memo, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { memo, useEffect, useRef, useState, type ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
import { Feature, Map, Overlay, View } from 'ol';
|
|
6
6
|
import { Attribution, ScaleLine, Zoom } from 'ol/control';
|
|
@@ -17,6 +17,7 @@ import type { PopupDirection } from '../types/map';
|
|
|
17
17
|
export type MapComponentProps = {
|
|
18
18
|
osMapsApiKey?: string;
|
|
19
19
|
basePath: string;
|
|
20
|
+
children?: ReactNode;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
const positionTransforms: Record<PopupDirection, string> = {
|
|
@@ -43,8 +44,7 @@ const arrowStyles: Record<PopupDirection, string> = {
|
|
|
43
44
|
*
|
|
44
45
|
* @return {*}
|
|
45
46
|
*/
|
|
46
|
-
const MapComponentBase = ({ osMapsApiKey, basePath }: MapComponentProps) => {
|
|
47
|
-
const [popupFeatures, setPopupFeatures] = useState<Feature[]>([]);
|
|
47
|
+
const MapComponentBase = ({ osMapsApiKey, basePath, children }: MapComponentProps) => {
|
|
48
48
|
const [popupCoordinate, setPopupCoordinate] = useState<number[] | null>(null);
|
|
49
49
|
const [popupPositionClass, setPopupPositionClass] = useState<PopupDirection>('bottom-right');
|
|
50
50
|
|
|
@@ -57,6 +57,8 @@ const MapComponentBase = ({ osMapsApiKey, basePath }: MapComponentProps) => {
|
|
|
57
57
|
mapConfig: { center, zoom },
|
|
58
58
|
setMap,
|
|
59
59
|
isDrawing,
|
|
60
|
+
popupFeatures,
|
|
61
|
+
setPopupFeatures,
|
|
60
62
|
} = useMap();
|
|
61
63
|
|
|
62
64
|
useEffect(() => {
|
|
@@ -187,12 +189,12 @@ const MapComponentBase = ({ osMapsApiKey, basePath }: MapComponentProps) => {
|
|
|
187
189
|
>
|
|
188
190
|
{popupFeatures.length > 0 ? (
|
|
189
191
|
<Popup
|
|
190
|
-
features={popupFeatures}
|
|
191
192
|
onClose={closePopup}
|
|
192
193
|
clickedCoord={popupCoordinate}
|
|
193
194
|
arrowClasses={arrowStyles[popupPositionClass]}
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
>
|
|
196
|
+
{children}
|
|
197
|
+
</Popup>
|
|
196
198
|
) : null}
|
|
197
199
|
</div>
|
|
198
200
|
</div>
|
package/src/map/MapContext.tsx
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Dispatch, RefObject, ReactNode, SetStateAction } from 'react';
|
|
4
4
|
import { createContext, useContext, useRef, useState, useMemo, useCallback } from 'react';
|
|
5
5
|
|
|
6
|
+
import { Feature } from 'ol';
|
|
6
7
|
import type { Coordinate } from 'ol/coordinate';
|
|
7
8
|
import BaseLayer from 'ol/layer/Base';
|
|
8
9
|
import Layer from 'ol/layer/Layer';
|
|
@@ -33,6 +34,8 @@ export type MapContextType = {
|
|
|
33
34
|
setSelectedLayer: Dispatch<SetStateAction<Layer | null>>;
|
|
34
35
|
isDrawing: boolean;
|
|
35
36
|
setIsDrawing: Dispatch<SetStateAction<boolean>>;
|
|
37
|
+
popupFeatures: Feature[];
|
|
38
|
+
setPopupFeatures: Dispatch<SetStateAction<Feature[]>>;
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
type MapProviderProps = {
|
|
@@ -60,6 +63,7 @@ export const MapProvider = ({ initialState = {}, children }: MapProviderProps) =
|
|
|
60
63
|
const [aoi, setAoi] = useState<Coordinate[][] | null>(null);
|
|
61
64
|
const [selectedLayer, setSelectedLayer] = useState<Layer | null>(null);
|
|
62
65
|
const [isDrawing, setIsDrawing] = useState(false);
|
|
66
|
+
const [popupFeatures, setPopupFeatures] = useState<Feature[]>([]);
|
|
63
67
|
|
|
64
68
|
const getLayers = useCallback(() => map?.getLayers().getArray(), [map]);
|
|
65
69
|
|
|
@@ -163,6 +167,8 @@ export const MapProvider = ({ initialState = {}, children }: MapProviderProps) =
|
|
|
163
167
|
setIsDrawing,
|
|
164
168
|
clearLayer,
|
|
165
169
|
resetMap,
|
|
170
|
+
popupFeatures,
|
|
171
|
+
setPopupFeatures,
|
|
166
172
|
...initialState,
|
|
167
173
|
}),
|
|
168
174
|
[
|
|
@@ -177,6 +183,7 @@ export const MapProvider = ({ initialState = {}, children }: MapProviderProps) =
|
|
|
177
183
|
isDrawing,
|
|
178
184
|
clearLayer,
|
|
179
185
|
resetMap,
|
|
186
|
+
popupFeatures,
|
|
180
187
|
initialState,
|
|
181
188
|
],
|
|
182
189
|
);
|
package/src/map/Popup.tsx
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { GoLinkExternal } from 'react-icons/go';
|
|
5
|
-
import { IoMdCloseCircle } from 'react-icons/io';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
6
4
|
|
|
7
|
-
import {
|
|
5
|
+
import { IoMdCloseCircle } from 'react-icons/io';
|
|
8
6
|
|
|
9
7
|
type PopupProps = {
|
|
10
|
-
|
|
8
|
+
children: ReactNode;
|
|
11
9
|
onClose: () => void;
|
|
12
10
|
clickedCoord: number[] | null;
|
|
13
11
|
arrowClasses: string;
|
|
14
|
-
baseUrl: string;
|
|
15
12
|
};
|
|
16
13
|
|
|
17
14
|
export const Popup = ({
|
|
18
|
-
|
|
15
|
+
children,
|
|
19
16
|
onClose,
|
|
20
17
|
clickedCoord,
|
|
21
18
|
arrowClasses = 'bottom-left',
|
|
22
|
-
baseUrl,
|
|
23
19
|
}: PopupProps) => {
|
|
24
|
-
if (!
|
|
20
|
+
if (!clickedCoord) {
|
|
25
21
|
return null;
|
|
26
22
|
}
|
|
27
23
|
|
|
@@ -40,32 +36,7 @@ export const Popup = ({
|
|
|
40
36
|
className="space-y-2 pt-4 pb-1 overflow-y-auto max-h-[300px] bg-white border border-border
|
|
41
37
|
rounded-lg divide-y divide-gray-300"
|
|
42
38
|
>
|
|
43
|
-
{
|
|
44
|
-
const name = feature.get('name');
|
|
45
|
-
const notation = feature.get('notation');
|
|
46
|
-
const libraryNotation = feature.get('libraryNotation');
|
|
47
|
-
const identifier = notation ?? name;
|
|
48
|
-
const url = libraryNotation
|
|
49
|
-
? `${baseUrl}${libraryNotation}/${identifier}`
|
|
50
|
-
: `${baseUrl}${identifier}`;
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div key={identifier}>
|
|
54
|
-
<strong>
|
|
55
|
-
<ExternalLink
|
|
56
|
-
href={url}
|
|
57
|
-
className="px-4 my-2 text-blue-500 underline flex flex-row gap-1 items-center"
|
|
58
|
-
>
|
|
59
|
-
<span>{name}</span>
|
|
60
|
-
|
|
61
|
-
<span className="flex-none w-5 h-5 flex items-center justify-center">
|
|
62
|
-
<GoLinkExternal size={20} className="cursor-pointer" />
|
|
63
|
-
</span>
|
|
64
|
-
</ExternalLink>
|
|
65
|
-
</strong>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
})}
|
|
39
|
+
{children}
|
|
69
40
|
</div>
|
|
70
41
|
|
|
71
42
|
<div
|