gistda-sphere-react 1.0.0 → 1.0.1
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/README.md +0 -2
- package/dist/index.d.mts +79 -71
- package/dist/index.d.ts +79 -71
- package/dist/index.js +452 -451
- package/dist/index.mjs +459 -459
- package/package.json +7 -7
- package/src/components/Circle.tsx +32 -35
- package/src/components/Dot.tsx +24 -27
- package/src/components/Marker.tsx +28 -31
- package/src/components/Polygon.tsx +38 -41
- package/src/components/Polyline.tsx +168 -173
- package/src/components/Popup.tsx +23 -26
- package/src/components/Rectangle.tsx +152 -157
- package/src/components/SphereMap.tsx +237 -242
- package/src/components/index.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Ref, useEffect, useImperativeHandle, useRef } from "react";
|
|
2
2
|
import { useMapContext } from "../context/MapContext";
|
|
3
3
|
import { useSphereContext } from "../context/SphereContext";
|
|
4
4
|
import type {
|
|
@@ -12,8 +12,20 @@ import type {
|
|
|
12
12
|
SpherePolyline,
|
|
13
13
|
} from "../types";
|
|
14
14
|
|
|
15
|
+
export interface PolylineRef {
|
|
16
|
+
getPolyline(): SpherePolyline | null;
|
|
17
|
+
togglePopup(show?: boolean, location?: Location): void;
|
|
18
|
+
getPivot(): Location | null;
|
|
19
|
+
getCentroid(): Location | null;
|
|
20
|
+
getBound(): Bound | null;
|
|
21
|
+
getLength(language?: string): number | string | null;
|
|
22
|
+
rotate(angle: number): void;
|
|
23
|
+
updateStyle(options: Partial<GeometryOptions>): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
export interface PolylineProps {
|
|
16
27
|
positions: Location[];
|
|
28
|
+
ref?: Ref<PolylineRef>;
|
|
17
29
|
title?: string;
|
|
18
30
|
detail?: string;
|
|
19
31
|
label?: string;
|
|
@@ -33,179 +45,162 @@ export interface PolylineProps {
|
|
|
33
45
|
onDrop?: (polyline: SpherePolyline) => void;
|
|
34
46
|
}
|
|
35
47
|
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
export function Polyline({
|
|
49
|
+
positions,
|
|
50
|
+
ref,
|
|
51
|
+
title,
|
|
52
|
+
detail,
|
|
53
|
+
label,
|
|
54
|
+
labelOptions,
|
|
55
|
+
popup,
|
|
56
|
+
visibleRange,
|
|
57
|
+
lineWidth,
|
|
58
|
+
lineColor,
|
|
59
|
+
lineStyle,
|
|
60
|
+
pivot,
|
|
61
|
+
clickable,
|
|
62
|
+
draggable,
|
|
63
|
+
pointer,
|
|
64
|
+
zIndex,
|
|
65
|
+
onClick,
|
|
66
|
+
onDrag,
|
|
67
|
+
onDrop,
|
|
68
|
+
}: PolylineProps) {
|
|
69
|
+
const { map, isReady } = useMapContext();
|
|
70
|
+
const { sphere } = useSphereContext();
|
|
71
|
+
const polylineRef = useRef<SpherePolyline | null>(null);
|
|
72
|
+
const callbacksRef = useRef({ onClick, onDrag, onDrop });
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
callbacksRef.current = { onClick, onDrag, onDrop };
|
|
76
|
+
}, [onClick, onDrag, onDrop]);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!(isReady && map && sphere) || positions.length < 2) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const options: GeometryOptions = {};
|
|
84
|
+
|
|
85
|
+
if (title) {
|
|
86
|
+
options.title = title;
|
|
87
|
+
}
|
|
88
|
+
if (detail) {
|
|
89
|
+
options.detail = detail;
|
|
90
|
+
}
|
|
91
|
+
if (label) {
|
|
92
|
+
options.label = label;
|
|
93
|
+
}
|
|
94
|
+
if (labelOptions) {
|
|
95
|
+
options.labelOptions = labelOptions;
|
|
96
|
+
}
|
|
97
|
+
if (popup) {
|
|
98
|
+
options.popup = popup;
|
|
99
|
+
}
|
|
100
|
+
if (visibleRange) {
|
|
101
|
+
options.visibleRange = visibleRange;
|
|
102
|
+
}
|
|
103
|
+
if (typeof lineWidth === "number") {
|
|
104
|
+
options.lineWidth = lineWidth;
|
|
105
|
+
}
|
|
106
|
+
if (lineColor) {
|
|
107
|
+
options.lineColor = lineColor;
|
|
108
|
+
}
|
|
109
|
+
if (lineStyle) {
|
|
110
|
+
options.lineStyle = lineStyle;
|
|
111
|
+
}
|
|
112
|
+
if (pivot) {
|
|
113
|
+
options.pivot = pivot;
|
|
114
|
+
}
|
|
115
|
+
if (typeof clickable === "boolean") {
|
|
116
|
+
options.clickable = clickable;
|
|
117
|
+
}
|
|
118
|
+
if (typeof draggable === "boolean") {
|
|
119
|
+
options.draggable = draggable;
|
|
120
|
+
}
|
|
121
|
+
if (typeof pointer === "boolean") {
|
|
122
|
+
options.pointer = pointer;
|
|
123
|
+
}
|
|
124
|
+
if (typeof zIndex === "number") {
|
|
125
|
+
options.zIndex = zIndex;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const polyline = new sphere.Polyline(positions, options);
|
|
129
|
+
polylineRef.current = polyline;
|
|
130
|
+
|
|
131
|
+
map.Overlays.add(polyline);
|
|
132
|
+
|
|
133
|
+
const handleOverlayClick = (data: { overlay: SpherePolyline }) => {
|
|
134
|
+
if (data.overlay === polyline) {
|
|
135
|
+
callbacksRef.current.onClick?.(polyline);
|
|
83
136
|
}
|
|
137
|
+
};
|
|
84
138
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
options.title = title;
|
|
89
|
-
}
|
|
90
|
-
if (detail) {
|
|
91
|
-
options.detail = detail;
|
|
92
|
-
}
|
|
93
|
-
if (label) {
|
|
94
|
-
options.label = label;
|
|
95
|
-
}
|
|
96
|
-
if (labelOptions) {
|
|
97
|
-
options.labelOptions = labelOptions;
|
|
98
|
-
}
|
|
99
|
-
if (popup) {
|
|
100
|
-
options.popup = popup;
|
|
101
|
-
}
|
|
102
|
-
if (visibleRange) {
|
|
103
|
-
options.visibleRange = visibleRange;
|
|
104
|
-
}
|
|
105
|
-
if (typeof lineWidth === "number") {
|
|
106
|
-
options.lineWidth = lineWidth;
|
|
107
|
-
}
|
|
108
|
-
if (lineColor) {
|
|
109
|
-
options.lineColor = lineColor;
|
|
110
|
-
}
|
|
111
|
-
if (lineStyle) {
|
|
112
|
-
options.lineStyle = lineStyle;
|
|
113
|
-
}
|
|
114
|
-
if (pivot) {
|
|
115
|
-
options.pivot = pivot;
|
|
116
|
-
}
|
|
117
|
-
if (typeof clickable === "boolean") {
|
|
118
|
-
options.clickable = clickable;
|
|
119
|
-
}
|
|
120
|
-
if (typeof draggable === "boolean") {
|
|
121
|
-
options.draggable = draggable;
|
|
122
|
-
}
|
|
123
|
-
if (typeof pointer === "boolean") {
|
|
124
|
-
options.pointer = pointer;
|
|
125
|
-
}
|
|
126
|
-
if (typeof zIndex === "number") {
|
|
127
|
-
options.zIndex = zIndex;
|
|
139
|
+
const handleOverlayDrag = (overlay: SpherePolyline) => {
|
|
140
|
+
if (overlay === polyline) {
|
|
141
|
+
callbacksRef.current.onDrag?.(polyline);
|
|
128
142
|
}
|
|
143
|
+
};
|
|
129
144
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
getPivot: () => polylineRef.current?.pivot() ?? null,
|
|
193
|
-
getCentroid: () => polylineRef.current?.centroid() ?? null,
|
|
194
|
-
getBound: () => polylineRef.current?.bound() ?? null,
|
|
195
|
-
getLength: (language?: string) =>
|
|
196
|
-
polylineRef.current?.size(language) ?? null,
|
|
197
|
-
rotate: (angle: number) => {
|
|
198
|
-
polylineRef.current?.rotate(angle);
|
|
199
|
-
},
|
|
200
|
-
updateStyle: (options: Partial<GeometryOptions>) => {
|
|
201
|
-
polylineRef.current?.update(options);
|
|
202
|
-
},
|
|
203
|
-
}),
|
|
204
|
-
[]
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
export default Polyline;
|
|
145
|
+
const handleOverlayDrop = (overlay: SpherePolyline) => {
|
|
146
|
+
if (overlay === polyline) {
|
|
147
|
+
callbacksRef.current.onDrop?.(polyline);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
map.Event.bind("overlayClick", handleOverlayClick);
|
|
152
|
+
map.Event.bind("overlayDrag", handleOverlayDrag);
|
|
153
|
+
map.Event.bind("overlayDrop", handleOverlayDrop);
|
|
154
|
+
|
|
155
|
+
return () => {
|
|
156
|
+
map.Event.unbind("overlayClick", handleOverlayClick);
|
|
157
|
+
map.Event.unbind("overlayDrag", handleOverlayDrag);
|
|
158
|
+
map.Event.unbind("overlayDrop", handleOverlayDrop);
|
|
159
|
+
map.Overlays.remove(polyline);
|
|
160
|
+
polylineRef.current = null;
|
|
161
|
+
};
|
|
162
|
+
}, [
|
|
163
|
+
isReady,
|
|
164
|
+
map,
|
|
165
|
+
sphere,
|
|
166
|
+
positions,
|
|
167
|
+
title,
|
|
168
|
+
detail,
|
|
169
|
+
label,
|
|
170
|
+
labelOptions,
|
|
171
|
+
popup,
|
|
172
|
+
visibleRange,
|
|
173
|
+
lineWidth,
|
|
174
|
+
lineColor,
|
|
175
|
+
lineStyle,
|
|
176
|
+
pivot,
|
|
177
|
+
clickable,
|
|
178
|
+
draggable,
|
|
179
|
+
pointer,
|
|
180
|
+
zIndex,
|
|
181
|
+
]);
|
|
182
|
+
|
|
183
|
+
useImperativeHandle(
|
|
184
|
+
ref,
|
|
185
|
+
() => ({
|
|
186
|
+
getPolyline: () => polylineRef.current,
|
|
187
|
+
togglePopup: (show?: boolean, location?: Location) => {
|
|
188
|
+
polylineRef.current?.pop(show, location);
|
|
189
|
+
},
|
|
190
|
+
getPivot: () => polylineRef.current?.pivot() ?? null,
|
|
191
|
+
getCentroid: () => polylineRef.current?.centroid() ?? null,
|
|
192
|
+
getBound: () => polylineRef.current?.bound() ?? null,
|
|
193
|
+
getLength: (language?: string) =>
|
|
194
|
+
polylineRef.current?.size(language) ?? null,
|
|
195
|
+
rotate: (angle: number) => {
|
|
196
|
+
polylineRef.current?.rotate(angle);
|
|
197
|
+
},
|
|
198
|
+
updateStyle: (options: Partial<GeometryOptions>) => {
|
|
199
|
+
polylineRef.current?.update(options);
|
|
200
|
+
},
|
|
201
|
+
}),
|
|
202
|
+
[]
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
return null;
|
|
206
|
+
}
|
package/src/components/Popup.tsx
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Ref, useEffect, useImperativeHandle, useRef } from "react";
|
|
2
2
|
import { useMapContext } from "../context/MapContext";
|
|
3
3
|
import { useSphereContext } from "../context/SphereContext";
|
|
4
4
|
import type { Location, PopupOptions, Size, SpherePopup } from "../types";
|
|
5
5
|
|
|
6
|
+
export interface PopupRef {
|
|
7
|
+
getPopup(): SpherePopup | null;
|
|
8
|
+
setPosition(location: Location): void;
|
|
9
|
+
setTitle(title: string): void;
|
|
10
|
+
setDetail(detail: string): void;
|
|
11
|
+
getElement(): HTMLElement | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
export interface PopupProps {
|
|
7
15
|
position: Location;
|
|
16
|
+
ref?: Ref<PopupRef>;
|
|
8
17
|
title?: string;
|
|
9
18
|
detail?: string;
|
|
10
19
|
loadDetail?: (element: HTMLElement) => void;
|
|
@@ -15,28 +24,18 @@ export interface PopupProps {
|
|
|
15
24
|
onClose?: (popup: SpherePopup) => void;
|
|
16
25
|
}
|
|
17
26
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
detail,
|
|
31
|
-
loadDetail,
|
|
32
|
-
html,
|
|
33
|
-
loadHtml,
|
|
34
|
-
size,
|
|
35
|
-
closable = true,
|
|
36
|
-
onClose,
|
|
37
|
-
},
|
|
38
|
-
ref
|
|
39
|
-
) {
|
|
27
|
+
export function Popup({
|
|
28
|
+
position,
|
|
29
|
+
ref,
|
|
30
|
+
title,
|
|
31
|
+
detail,
|
|
32
|
+
loadDetail,
|
|
33
|
+
html,
|
|
34
|
+
loadHtml,
|
|
35
|
+
size,
|
|
36
|
+
closable = true,
|
|
37
|
+
onClose,
|
|
38
|
+
}: PopupProps) {
|
|
40
39
|
const { map, isReady } = useMapContext();
|
|
41
40
|
const { sphere } = useSphereContext();
|
|
42
41
|
const popupRef = useRef<SpherePopup | null>(null);
|
|
@@ -125,6 +124,4 @@ export const Popup = forwardRef<PopupRef, PopupProps>(function Popup(
|
|
|
125
124
|
);
|
|
126
125
|
|
|
127
126
|
return null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export default Popup;
|
|
127
|
+
}
|