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,9 +12,18 @@ import type {
|
|
|
12
12
|
SphereRectangle,
|
|
13
13
|
} from "../types";
|
|
14
14
|
|
|
15
|
+
export interface RectangleRef {
|
|
16
|
+
getRectangle(): SphereRectangle | null;
|
|
17
|
+
togglePopup(show?: boolean, location?: Location): void;
|
|
18
|
+
getBound(): Bound | null;
|
|
19
|
+
getArea(language?: string): number | string | null;
|
|
20
|
+
updateStyle(options: Partial<GeometryOptions>): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
export interface RectangleProps {
|
|
16
24
|
position: Location;
|
|
17
25
|
size: Size | Location;
|
|
26
|
+
ref?: Ref<RectangleRef>;
|
|
18
27
|
title?: string;
|
|
19
28
|
detail?: string;
|
|
20
29
|
popup?: PopupOptions;
|
|
@@ -32,163 +41,149 @@ export interface RectangleProps {
|
|
|
32
41
|
onDrop?: (rectangle: SphereRectangle) => void;
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
export
|
|
36
|
-
|
|
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
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
44
|
+
export function Rectangle({
|
|
45
|
+
position,
|
|
46
|
+
size,
|
|
47
|
+
ref,
|
|
48
|
+
title,
|
|
49
|
+
detail,
|
|
50
|
+
popup,
|
|
51
|
+
visibleRange,
|
|
52
|
+
lineWidth,
|
|
53
|
+
lineColor,
|
|
54
|
+
fillColor,
|
|
55
|
+
lineStyle,
|
|
56
|
+
clickable,
|
|
57
|
+
draggable,
|
|
58
|
+
editable,
|
|
59
|
+
zIndex,
|
|
60
|
+
onClick,
|
|
61
|
+
onDrag,
|
|
62
|
+
onDrop,
|
|
63
|
+
}: RectangleProps) {
|
|
64
|
+
const { map, isReady } = useMapContext();
|
|
65
|
+
const { sphere } = useSphereContext();
|
|
66
|
+
const rectangleRef = useRef<SphereRectangle | null>(null);
|
|
67
|
+
const callbacksRef = useRef({ onClick, onDrag, onDrop });
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
callbacksRef.current = { onClick, onDrag, onDrop };
|
|
71
|
+
}, [onClick, onDrag, onDrop]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!(isReady && map && sphere)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const options: GeometryOptions = {};
|
|
79
|
+
|
|
80
|
+
if (title) {
|
|
81
|
+
options.title = title;
|
|
82
|
+
}
|
|
83
|
+
if (detail) {
|
|
84
|
+
options.detail = detail;
|
|
85
|
+
}
|
|
86
|
+
if (popup) {
|
|
87
|
+
options.popup = popup;
|
|
88
|
+
}
|
|
89
|
+
if (visibleRange) {
|
|
90
|
+
options.visibleRange = visibleRange;
|
|
91
|
+
}
|
|
92
|
+
if (typeof lineWidth === "number") {
|
|
93
|
+
options.lineWidth = lineWidth;
|
|
94
|
+
}
|
|
95
|
+
if (lineColor) {
|
|
96
|
+
options.lineColor = lineColor;
|
|
97
|
+
}
|
|
98
|
+
if (fillColor) {
|
|
99
|
+
options.fillColor = fillColor;
|
|
100
|
+
}
|
|
101
|
+
if (lineStyle) {
|
|
102
|
+
options.lineStyle = lineStyle;
|
|
103
|
+
}
|
|
104
|
+
if (typeof clickable === "boolean") {
|
|
105
|
+
options.clickable = clickable;
|
|
106
|
+
}
|
|
107
|
+
if (typeof draggable === "boolean") {
|
|
108
|
+
options.draggable = draggable;
|
|
109
|
+
}
|
|
110
|
+
if (typeof editable === "boolean") {
|
|
111
|
+
options.editable = editable;
|
|
112
|
+
}
|
|
113
|
+
if (typeof zIndex === "number") {
|
|
114
|
+
options.zIndex = zIndex;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const rectangle = new sphere.Rectangle(position, size, options);
|
|
118
|
+
rectangleRef.current = rectangle;
|
|
119
|
+
|
|
120
|
+
map.Overlays.add(rectangle);
|
|
121
|
+
|
|
122
|
+
const handleOverlayClick = (data: { overlay: SphereRectangle }) => {
|
|
123
|
+
if (data.overlay === rectangle) {
|
|
124
|
+
callbacksRef.current.onClick?.(rectangle);
|
|
78
125
|
}
|
|
126
|
+
};
|
|
79
127
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
options.title = title;
|
|
84
|
-
}
|
|
85
|
-
if (detail) {
|
|
86
|
-
options.detail = detail;
|
|
87
|
-
}
|
|
88
|
-
if (popup) {
|
|
89
|
-
options.popup = popup;
|
|
90
|
-
}
|
|
91
|
-
if (visibleRange) {
|
|
92
|
-
options.visibleRange = visibleRange;
|
|
93
|
-
}
|
|
94
|
-
if (typeof lineWidth === "number") {
|
|
95
|
-
options.lineWidth = lineWidth;
|
|
96
|
-
}
|
|
97
|
-
if (lineColor) {
|
|
98
|
-
options.lineColor = lineColor;
|
|
99
|
-
}
|
|
100
|
-
if (fillColor) {
|
|
101
|
-
options.fillColor = fillColor;
|
|
102
|
-
}
|
|
103
|
-
if (lineStyle) {
|
|
104
|
-
options.lineStyle = lineStyle;
|
|
105
|
-
}
|
|
106
|
-
if (typeof clickable === "boolean") {
|
|
107
|
-
options.clickable = clickable;
|
|
108
|
-
}
|
|
109
|
-
if (typeof draggable === "boolean") {
|
|
110
|
-
options.draggable = draggable;
|
|
111
|
-
}
|
|
112
|
-
if (typeof editable === "boolean") {
|
|
113
|
-
options.editable = editable;
|
|
114
|
-
}
|
|
115
|
-
if (typeof zIndex === "number") {
|
|
116
|
-
options.zIndex = zIndex;
|
|
128
|
+
const handleOverlayDrag = (overlay: SphereRectangle) => {
|
|
129
|
+
if (overlay === rectangle) {
|
|
130
|
+
callbacksRef.current.onDrag?.(rectangle);
|
|
117
131
|
}
|
|
132
|
+
};
|
|
118
133
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
getRectangle: () => rectangleRef.current,
|
|
177
|
-
togglePopup: (show?: boolean, location?: Location) => {
|
|
178
|
-
rectangleRef.current?.pop(show, location);
|
|
179
|
-
},
|
|
180
|
-
getBound: () => rectangleRef.current?.bound() ?? null,
|
|
181
|
-
getArea: (language?: string) =>
|
|
182
|
-
rectangleRef.current?.size(language) ?? null,
|
|
183
|
-
updateStyle: (options: Partial<GeometryOptions>) => {
|
|
184
|
-
rectangleRef.current?.update(options);
|
|
185
|
-
},
|
|
186
|
-
}),
|
|
187
|
-
[]
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
export default Rectangle;
|
|
134
|
+
const handleOverlayDrop = (overlay: SphereRectangle) => {
|
|
135
|
+
if (overlay === rectangle) {
|
|
136
|
+
callbacksRef.current.onDrop?.(rectangle);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
map.Event.bind("overlayClick", handleOverlayClick);
|
|
141
|
+
map.Event.bind("overlayDrag", handleOverlayDrag);
|
|
142
|
+
map.Event.bind("overlayDrop", handleOverlayDrop);
|
|
143
|
+
|
|
144
|
+
return () => {
|
|
145
|
+
map.Event.unbind("overlayClick", handleOverlayClick);
|
|
146
|
+
map.Event.unbind("overlayDrag", handleOverlayDrag);
|
|
147
|
+
map.Event.unbind("overlayDrop", handleOverlayDrop);
|
|
148
|
+
map.Overlays.remove(rectangle);
|
|
149
|
+
rectangleRef.current = null;
|
|
150
|
+
};
|
|
151
|
+
}, [
|
|
152
|
+
isReady,
|
|
153
|
+
map,
|
|
154
|
+
sphere,
|
|
155
|
+
position,
|
|
156
|
+
size,
|
|
157
|
+
title,
|
|
158
|
+
detail,
|
|
159
|
+
popup,
|
|
160
|
+
visibleRange,
|
|
161
|
+
lineWidth,
|
|
162
|
+
lineColor,
|
|
163
|
+
fillColor,
|
|
164
|
+
lineStyle,
|
|
165
|
+
clickable,
|
|
166
|
+
draggable,
|
|
167
|
+
editable,
|
|
168
|
+
zIndex,
|
|
169
|
+
]);
|
|
170
|
+
|
|
171
|
+
useImperativeHandle(
|
|
172
|
+
ref,
|
|
173
|
+
() => ({
|
|
174
|
+
getRectangle: () => rectangleRef.current,
|
|
175
|
+
togglePopup: (show?: boolean, location?: Location) => {
|
|
176
|
+
rectangleRef.current?.pop(show, location);
|
|
177
|
+
},
|
|
178
|
+
getBound: () => rectangleRef.current?.bound() ?? null,
|
|
179
|
+
getArea: (language?: string) =>
|
|
180
|
+
rectangleRef.current?.size(language) ?? null,
|
|
181
|
+
updateStyle: (options: Partial<GeometryOptions>) => {
|
|
182
|
+
rectangleRef.current?.update(options);
|
|
183
|
+
},
|
|
184
|
+
}),
|
|
185
|
+
[]
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
return null;
|
|
189
|
+
}
|