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/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/components/Circle.tsx
2
- import { forwardRef, useEffect as useEffect2, useImperativeHandle, useRef as useRef2 } from "react";
2
+ import { useEffect as useEffect2, useImperativeHandle, useRef as useRef2 } from "react";
3
3
 
4
4
  // src/context/MapContext.tsx
5
5
  import { createContext, useContext, useMemo } from "react";
@@ -250,9 +250,10 @@ function useMapControls() {
250
250
  }
251
251
 
252
252
  // src/components/Circle.tsx
253
- var Circle = forwardRef(function Circle2({
253
+ function Circle({
254
254
  center,
255
255
  radius,
256
+ ref,
256
257
  title,
257
258
  detail,
258
259
  popup,
@@ -267,7 +268,7 @@ var Circle = forwardRef(function Circle2({
267
268
  onClick,
268
269
  onDrag,
269
270
  onDrop
270
- }, ref) {
271
+ }) {
271
272
  const { map, isReady } = useMapContext();
272
273
  const { sphere } = useSphereContext();
273
274
  const circleRef = useRef2(null);
@@ -377,12 +378,13 @@ var Circle = forwardRef(function Circle2({
377
378
  []
378
379
  );
379
380
  return null;
380
- });
381
+ }
381
382
 
382
383
  // src/components/Dot.tsx
383
- import { forwardRef as forwardRef2, useEffect as useEffect3, useImperativeHandle as useImperativeHandle2, useRef as useRef3 } from "react";
384
- var Dot = forwardRef2(function Dot2({
384
+ import { useEffect as useEffect3, useImperativeHandle as useImperativeHandle2, useRef as useRef3 } from "react";
385
+ function Dot({
385
386
  position,
387
+ ref,
386
388
  title,
387
389
  detail,
388
390
  visibleRange,
@@ -394,7 +396,7 @@ var Dot = forwardRef2(function Dot2({
394
396
  onClick,
395
397
  onDrag,
396
398
  onDrop
397
- }, ref) {
399
+ }) {
398
400
  const { map, isReady } = useMapContext();
399
401
  const { sphere } = useSphereContext();
400
402
  const dotRef = useRef3(null);
@@ -486,7 +488,7 @@ var Dot = forwardRef2(function Dot2({
486
488
  []
487
489
  );
488
490
  return null;
489
- });
491
+ }
490
492
 
491
493
  // src/components/Layer.tsx
492
494
  import { useEffect as useEffect4, useRef as useRef4 } from "react";
@@ -622,9 +624,10 @@ function Layer({
622
624
  }
623
625
 
624
626
  // src/components/Marker.tsx
625
- import { forwardRef as forwardRef3, useEffect as useEffect5, useImperativeHandle as useImperativeHandle3, useRef as useRef5 } from "react";
626
- var Marker = forwardRef3(function Marker2({
627
+ import { useEffect as useEffect5, useImperativeHandle as useImperativeHandle3, useRef as useRef5 } from "react";
628
+ function Marker({
627
629
  position,
630
+ ref,
628
631
  icon,
629
632
  title,
630
633
  detail,
@@ -639,7 +642,7 @@ var Marker = forwardRef3(function Marker2({
639
642
  onDrop,
640
643
  onHover,
641
644
  onLeave
642
- }, ref) {
645
+ }) {
643
646
  const { map, isReady } = useMapContext();
644
647
  const { sphere } = useSphereContext();
645
648
  const markerRef = useRef5(null);
@@ -764,12 +767,13 @@ var Marker = forwardRef3(function Marker2({
764
767
  []
765
768
  );
766
769
  return null;
767
- });
770
+ }
768
771
 
769
772
  // src/components/Polygon.tsx
770
- import { forwardRef as forwardRef4, useEffect as useEffect6, useImperativeHandle as useImperativeHandle4, useRef as useRef6 } from "react";
771
- var Polygon = forwardRef4(function Polygon2({
773
+ import { useEffect as useEffect6, useImperativeHandle as useImperativeHandle4, useRef as useRef6 } from "react";
774
+ function Polygon({
772
775
  positions,
776
+ ref,
773
777
  title,
774
778
  detail,
775
779
  label,
@@ -789,7 +793,7 @@ var Polygon = forwardRef4(function Polygon2({
789
793
  onClick,
790
794
  onDrag,
791
795
  onDrop
792
- }, ref) {
796
+ }) {
793
797
  const { map, isReady } = useMapContext();
794
798
  const { sphere } = useSphereContext();
795
799
  const polygonRef = useRef6(null);
@@ -922,12 +926,117 @@ var Polygon = forwardRef4(function Polygon2({
922
926
  []
923
927
  );
924
928
  return null;
925
- });
929
+ }
926
930
 
927
931
  // src/components/Polyline.tsx
928
- import { forwardRef as forwardRef5, useEffect as useEffect7, useImperativeHandle as useImperativeHandle5, useRef as useRef7 } from "react";
929
- var Polyline = forwardRef5(
930
- function Polyline2({
932
+ import { useEffect as useEffect7, useImperativeHandle as useImperativeHandle5, useRef as useRef7 } from "react";
933
+ function Polyline({
934
+ positions,
935
+ ref,
936
+ title,
937
+ detail,
938
+ label,
939
+ labelOptions,
940
+ popup,
941
+ visibleRange,
942
+ lineWidth,
943
+ lineColor,
944
+ lineStyle,
945
+ pivot,
946
+ clickable,
947
+ draggable,
948
+ pointer,
949
+ zIndex,
950
+ onClick,
951
+ onDrag,
952
+ onDrop
953
+ }) {
954
+ const { map, isReady } = useMapContext();
955
+ const { sphere } = useSphereContext();
956
+ const polylineRef = useRef7(null);
957
+ const callbacksRef = useRef7({ onClick, onDrag, onDrop });
958
+ useEffect7(() => {
959
+ callbacksRef.current = { onClick, onDrag, onDrop };
960
+ }, [onClick, onDrag, onDrop]);
961
+ useEffect7(() => {
962
+ if (!(isReady && map && sphere) || positions.length < 2) {
963
+ return;
964
+ }
965
+ const options = {};
966
+ if (title) {
967
+ options.title = title;
968
+ }
969
+ if (detail) {
970
+ options.detail = detail;
971
+ }
972
+ if (label) {
973
+ options.label = label;
974
+ }
975
+ if (labelOptions) {
976
+ options.labelOptions = labelOptions;
977
+ }
978
+ if (popup) {
979
+ options.popup = popup;
980
+ }
981
+ if (visibleRange) {
982
+ options.visibleRange = visibleRange;
983
+ }
984
+ if (typeof lineWidth === "number") {
985
+ options.lineWidth = lineWidth;
986
+ }
987
+ if (lineColor) {
988
+ options.lineColor = lineColor;
989
+ }
990
+ if (lineStyle) {
991
+ options.lineStyle = lineStyle;
992
+ }
993
+ if (pivot) {
994
+ options.pivot = pivot;
995
+ }
996
+ if (typeof clickable === "boolean") {
997
+ options.clickable = clickable;
998
+ }
999
+ if (typeof draggable === "boolean") {
1000
+ options.draggable = draggable;
1001
+ }
1002
+ if (typeof pointer === "boolean") {
1003
+ options.pointer = pointer;
1004
+ }
1005
+ if (typeof zIndex === "number") {
1006
+ options.zIndex = zIndex;
1007
+ }
1008
+ const polyline = new sphere.Polyline(positions, options);
1009
+ polylineRef.current = polyline;
1010
+ map.Overlays.add(polyline);
1011
+ const handleOverlayClick = (data) => {
1012
+ if (data.overlay === polyline) {
1013
+ callbacksRef.current.onClick?.(polyline);
1014
+ }
1015
+ };
1016
+ const handleOverlayDrag = (overlay) => {
1017
+ if (overlay === polyline) {
1018
+ callbacksRef.current.onDrag?.(polyline);
1019
+ }
1020
+ };
1021
+ const handleOverlayDrop = (overlay) => {
1022
+ if (overlay === polyline) {
1023
+ callbacksRef.current.onDrop?.(polyline);
1024
+ }
1025
+ };
1026
+ map.Event.bind("overlayClick", handleOverlayClick);
1027
+ map.Event.bind("overlayDrag", handleOverlayDrag);
1028
+ map.Event.bind("overlayDrop", handleOverlayDrop);
1029
+ return () => {
1030
+ map.Event.unbind("overlayClick", handleOverlayClick);
1031
+ map.Event.unbind("overlayDrag", handleOverlayDrag);
1032
+ map.Event.unbind("overlayDrop", handleOverlayDrop);
1033
+ map.Overlays.remove(polyline);
1034
+ polylineRef.current = null;
1035
+ };
1036
+ }, [
1037
+ isReady,
1038
+ map,
1039
+ sphere,
931
1040
  positions,
932
1041
  title,
933
1042
  detail,
@@ -942,141 +1051,36 @@ var Polyline = forwardRef5(
942
1051
  clickable,
943
1052
  draggable,
944
1053
  pointer,
945
- zIndex,
946
- onClick,
947
- onDrag,
948
- onDrop
949
- }, ref) {
950
- const { map, isReady } = useMapContext();
951
- const { sphere } = useSphereContext();
952
- const polylineRef = useRef7(null);
953
- const callbacksRef = useRef7({ onClick, onDrag, onDrop });
954
- useEffect7(() => {
955
- callbacksRef.current = { onClick, onDrag, onDrop };
956
- }, [onClick, onDrag, onDrop]);
957
- useEffect7(() => {
958
- if (!(isReady && map && sphere) || positions.length < 2) {
959
- return;
960
- }
961
- const options = {};
962
- if (title) {
963
- options.title = title;
964
- }
965
- if (detail) {
966
- options.detail = detail;
967
- }
968
- if (label) {
969
- options.label = label;
970
- }
971
- if (labelOptions) {
972
- options.labelOptions = labelOptions;
973
- }
974
- if (popup) {
975
- options.popup = popup;
976
- }
977
- if (visibleRange) {
978
- options.visibleRange = visibleRange;
979
- }
980
- if (typeof lineWidth === "number") {
981
- options.lineWidth = lineWidth;
982
- }
983
- if (lineColor) {
984
- options.lineColor = lineColor;
985
- }
986
- if (lineStyle) {
987
- options.lineStyle = lineStyle;
988
- }
989
- if (pivot) {
990
- options.pivot = pivot;
991
- }
992
- if (typeof clickable === "boolean") {
993
- options.clickable = clickable;
994
- }
995
- if (typeof draggable === "boolean") {
996
- options.draggable = draggable;
997
- }
998
- if (typeof pointer === "boolean") {
999
- options.pointer = pointer;
1000
- }
1001
- if (typeof zIndex === "number") {
1002
- options.zIndex = zIndex;
1054
+ zIndex
1055
+ ]);
1056
+ useImperativeHandle5(
1057
+ ref,
1058
+ () => ({
1059
+ getPolyline: () => polylineRef.current,
1060
+ togglePopup: (show, location) => {
1061
+ polylineRef.current?.pop(show, location);
1062
+ },
1063
+ getPivot: () => polylineRef.current?.pivot() ?? null,
1064
+ getCentroid: () => polylineRef.current?.centroid() ?? null,
1065
+ getBound: () => polylineRef.current?.bound() ?? null,
1066
+ getLength: (language) => polylineRef.current?.size(language) ?? null,
1067
+ rotate: (angle) => {
1068
+ polylineRef.current?.rotate(angle);
1069
+ },
1070
+ updateStyle: (options) => {
1071
+ polylineRef.current?.update(options);
1003
1072
  }
1004
- const polyline = new sphere.Polyline(positions, options);
1005
- polylineRef.current = polyline;
1006
- map.Overlays.add(polyline);
1007
- const handleOverlayClick = (data) => {
1008
- if (data.overlay === polyline) {
1009
- callbacksRef.current.onClick?.(polyline);
1010
- }
1011
- };
1012
- const handleOverlayDrag = (overlay) => {
1013
- if (overlay === polyline) {
1014
- callbacksRef.current.onDrag?.(polyline);
1015
- }
1016
- };
1017
- const handleOverlayDrop = (overlay) => {
1018
- if (overlay === polyline) {
1019
- callbacksRef.current.onDrop?.(polyline);
1020
- }
1021
- };
1022
- map.Event.bind("overlayClick", handleOverlayClick);
1023
- map.Event.bind("overlayDrag", handleOverlayDrag);
1024
- map.Event.bind("overlayDrop", handleOverlayDrop);
1025
- return () => {
1026
- map.Event.unbind("overlayClick", handleOverlayClick);
1027
- map.Event.unbind("overlayDrag", handleOverlayDrag);
1028
- map.Event.unbind("overlayDrop", handleOverlayDrop);
1029
- map.Overlays.remove(polyline);
1030
- polylineRef.current = null;
1031
- };
1032
- }, [
1033
- isReady,
1034
- map,
1035
- sphere,
1036
- positions,
1037
- title,
1038
- detail,
1039
- label,
1040
- labelOptions,
1041
- popup,
1042
- visibleRange,
1043
- lineWidth,
1044
- lineColor,
1045
- lineStyle,
1046
- pivot,
1047
- clickable,
1048
- draggable,
1049
- pointer,
1050
- zIndex
1051
- ]);
1052
- useImperativeHandle5(
1053
- ref,
1054
- () => ({
1055
- getPolyline: () => polylineRef.current,
1056
- togglePopup: (show, location) => {
1057
- polylineRef.current?.pop(show, location);
1058
- },
1059
- getPivot: () => polylineRef.current?.pivot() ?? null,
1060
- getCentroid: () => polylineRef.current?.centroid() ?? null,
1061
- getBound: () => polylineRef.current?.bound() ?? null,
1062
- getLength: (language) => polylineRef.current?.size(language) ?? null,
1063
- rotate: (angle) => {
1064
- polylineRef.current?.rotate(angle);
1065
- },
1066
- updateStyle: (options) => {
1067
- polylineRef.current?.update(options);
1068
- }
1069
- }),
1070
- []
1071
- );
1072
- return null;
1073
- }
1074
- );
1073
+ }),
1074
+ []
1075
+ );
1076
+ return null;
1077
+ }
1075
1078
 
1076
1079
  // src/components/Popup.tsx
1077
- import { forwardRef as forwardRef6, useEffect as useEffect8, useImperativeHandle as useImperativeHandle6, useRef as useRef8 } from "react";
1078
- var Popup = forwardRef6(function Popup2({
1080
+ import { useEffect as useEffect8, useImperativeHandle as useImperativeHandle6, useRef as useRef8 } from "react";
1081
+ function Popup({
1079
1082
  position,
1083
+ ref,
1080
1084
  title,
1081
1085
  detail,
1082
1086
  loadDetail,
@@ -1085,7 +1089,7 @@ var Popup = forwardRef6(function Popup2({
1085
1089
  size,
1086
1090
  closable = true,
1087
1091
  onClose
1088
- }, ref) {
1092
+ }) {
1089
1093
  const { map, isReady } = useMapContext();
1090
1094
  const { sphere } = useSphereContext();
1091
1095
  const popupRef = useRef8(null);
@@ -1163,12 +1167,110 @@ var Popup = forwardRef6(function Popup2({
1163
1167
  []
1164
1168
  );
1165
1169
  return null;
1166
- });
1170
+ }
1167
1171
 
1168
1172
  // src/components/Rectangle.tsx
1169
- import { forwardRef as forwardRef7, useEffect as useEffect9, useImperativeHandle as useImperativeHandle7, useRef as useRef9 } from "react";
1170
- var Rectangle = forwardRef7(
1171
- function Rectangle2({
1173
+ import { useEffect as useEffect9, useImperativeHandle as useImperativeHandle7, useRef as useRef9 } from "react";
1174
+ function Rectangle({
1175
+ position,
1176
+ size,
1177
+ ref,
1178
+ title,
1179
+ detail,
1180
+ popup,
1181
+ visibleRange,
1182
+ lineWidth,
1183
+ lineColor,
1184
+ fillColor,
1185
+ lineStyle,
1186
+ clickable,
1187
+ draggable,
1188
+ editable,
1189
+ zIndex,
1190
+ onClick,
1191
+ onDrag,
1192
+ onDrop
1193
+ }) {
1194
+ const { map, isReady } = useMapContext();
1195
+ const { sphere } = useSphereContext();
1196
+ const rectangleRef = useRef9(null);
1197
+ const callbacksRef = useRef9({ onClick, onDrag, onDrop });
1198
+ useEffect9(() => {
1199
+ callbacksRef.current = { onClick, onDrag, onDrop };
1200
+ }, [onClick, onDrag, onDrop]);
1201
+ useEffect9(() => {
1202
+ if (!(isReady && map && sphere)) {
1203
+ return;
1204
+ }
1205
+ const options = {};
1206
+ if (title) {
1207
+ options.title = title;
1208
+ }
1209
+ if (detail) {
1210
+ options.detail = detail;
1211
+ }
1212
+ if (popup) {
1213
+ options.popup = popup;
1214
+ }
1215
+ if (visibleRange) {
1216
+ options.visibleRange = visibleRange;
1217
+ }
1218
+ if (typeof lineWidth === "number") {
1219
+ options.lineWidth = lineWidth;
1220
+ }
1221
+ if (lineColor) {
1222
+ options.lineColor = lineColor;
1223
+ }
1224
+ if (fillColor) {
1225
+ options.fillColor = fillColor;
1226
+ }
1227
+ if (lineStyle) {
1228
+ options.lineStyle = lineStyle;
1229
+ }
1230
+ if (typeof clickable === "boolean") {
1231
+ options.clickable = clickable;
1232
+ }
1233
+ if (typeof draggable === "boolean") {
1234
+ options.draggable = draggable;
1235
+ }
1236
+ if (typeof editable === "boolean") {
1237
+ options.editable = editable;
1238
+ }
1239
+ if (typeof zIndex === "number") {
1240
+ options.zIndex = zIndex;
1241
+ }
1242
+ const rectangle = new sphere.Rectangle(position, size, options);
1243
+ rectangleRef.current = rectangle;
1244
+ map.Overlays.add(rectangle);
1245
+ const handleOverlayClick = (data) => {
1246
+ if (data.overlay === rectangle) {
1247
+ callbacksRef.current.onClick?.(rectangle);
1248
+ }
1249
+ };
1250
+ const handleOverlayDrag = (overlay) => {
1251
+ if (overlay === rectangle) {
1252
+ callbacksRef.current.onDrag?.(rectangle);
1253
+ }
1254
+ };
1255
+ const handleOverlayDrop = (overlay) => {
1256
+ if (overlay === rectangle) {
1257
+ callbacksRef.current.onDrop?.(rectangle);
1258
+ }
1259
+ };
1260
+ map.Event.bind("overlayClick", handleOverlayClick);
1261
+ map.Event.bind("overlayDrag", handleOverlayDrag);
1262
+ map.Event.bind("overlayDrop", handleOverlayDrop);
1263
+ return () => {
1264
+ map.Event.unbind("overlayClick", handleOverlayClick);
1265
+ map.Event.unbind("overlayDrag", handleOverlayDrag);
1266
+ map.Event.unbind("overlayDrop", handleOverlayDrop);
1267
+ map.Overlays.remove(rectangle);
1268
+ rectangleRef.current = null;
1269
+ };
1270
+ }, [
1271
+ isReady,
1272
+ map,
1273
+ sphere,
1172
1274
  position,
1173
1275
  size,
1174
1276
  title,
@@ -1182,150 +1284,68 @@ var Rectangle = forwardRef7(
1182
1284
  clickable,
1183
1285
  draggable,
1184
1286
  editable,
1185
- zIndex,
1186
- onClick,
1187
- onDrag,
1188
- onDrop
1189
- }, ref) {
1190
- const { map, isReady } = useMapContext();
1191
- const { sphere } = useSphereContext();
1192
- const rectangleRef = useRef9(null);
1193
- const callbacksRef = useRef9({ onClick, onDrag, onDrop });
1194
- useEffect9(() => {
1195
- callbacksRef.current = { onClick, onDrag, onDrop };
1196
- }, [onClick, onDrag, onDrop]);
1197
- useEffect9(() => {
1198
- if (!(isReady && map && sphere)) {
1199
- return;
1200
- }
1201
- const options = {};
1202
- if (title) {
1203
- options.title = title;
1204
- }
1205
- if (detail) {
1206
- options.detail = detail;
1207
- }
1208
- if (popup) {
1209
- options.popup = popup;
1210
- }
1211
- if (visibleRange) {
1212
- options.visibleRange = visibleRange;
1213
- }
1214
- if (typeof lineWidth === "number") {
1215
- options.lineWidth = lineWidth;
1216
- }
1217
- if (lineColor) {
1218
- options.lineColor = lineColor;
1219
- }
1220
- if (fillColor) {
1221
- options.fillColor = fillColor;
1222
- }
1223
- if (lineStyle) {
1224
- options.lineStyle = lineStyle;
1225
- }
1226
- if (typeof clickable === "boolean") {
1227
- options.clickable = clickable;
1228
- }
1229
- if (typeof draggable === "boolean") {
1230
- options.draggable = draggable;
1231
- }
1232
- if (typeof editable === "boolean") {
1233
- options.editable = editable;
1234
- }
1235
- if (typeof zIndex === "number") {
1236
- options.zIndex = zIndex;
1287
+ zIndex
1288
+ ]);
1289
+ useImperativeHandle7(
1290
+ ref,
1291
+ () => ({
1292
+ getRectangle: () => rectangleRef.current,
1293
+ togglePopup: (show, location) => {
1294
+ rectangleRef.current?.pop(show, location);
1295
+ },
1296
+ getBound: () => rectangleRef.current?.bound() ?? null,
1297
+ getArea: (language) => rectangleRef.current?.size(language) ?? null,
1298
+ updateStyle: (options) => {
1299
+ rectangleRef.current?.update(options);
1237
1300
  }
1238
- const rectangle = new sphere.Rectangle(position, size, options);
1239
- rectangleRef.current = rectangle;
1240
- map.Overlays.add(rectangle);
1241
- const handleOverlayClick = (data) => {
1242
- if (data.overlay === rectangle) {
1243
- callbacksRef.current.onClick?.(rectangle);
1244
- }
1245
- };
1246
- const handleOverlayDrag = (overlay) => {
1247
- if (overlay === rectangle) {
1248
- callbacksRef.current.onDrag?.(rectangle);
1249
- }
1250
- };
1251
- const handleOverlayDrop = (overlay) => {
1252
- if (overlay === rectangle) {
1253
- callbacksRef.current.onDrop?.(rectangle);
1254
- }
1255
- };
1256
- map.Event.bind("overlayClick", handleOverlayClick);
1257
- map.Event.bind("overlayDrag", handleOverlayDrag);
1258
- map.Event.bind("overlayDrop", handleOverlayDrop);
1259
- return () => {
1260
- map.Event.unbind("overlayClick", handleOverlayClick);
1261
- map.Event.unbind("overlayDrag", handleOverlayDrag);
1262
- map.Event.unbind("overlayDrop", handleOverlayDrop);
1263
- map.Overlays.remove(rectangle);
1264
- rectangleRef.current = null;
1265
- };
1266
- }, [
1267
- isReady,
1268
- map,
1269
- sphere,
1270
- position,
1271
- size,
1272
- title,
1273
- detail,
1274
- popup,
1275
- visibleRange,
1276
- lineWidth,
1277
- lineColor,
1278
- fillColor,
1279
- lineStyle,
1280
- clickable,
1281
- draggable,
1282
- editable,
1283
- zIndex
1284
- ]);
1285
- useImperativeHandle7(
1286
- ref,
1287
- () => ({
1288
- getRectangle: () => rectangleRef.current,
1289
- togglePopup: (show, location) => {
1290
- rectangleRef.current?.pop(show, location);
1291
- },
1292
- getBound: () => rectangleRef.current?.bound() ?? null,
1293
- getArea: (language) => rectangleRef.current?.size(language) ?? null,
1294
- updateStyle: (options) => {
1295
- rectangleRef.current?.update(options);
1296
- }
1297
- }),
1298
- []
1299
- );
1300
- return null;
1301
- }
1302
- );
1301
+ }),
1302
+ []
1303
+ );
1304
+ return null;
1305
+ }
1303
1306
 
1304
1307
  // src/components/SphereMap.tsx
1305
1308
  import {
1306
- forwardRef as forwardRef8,
1307
1309
  useEffect as useEffect10,
1308
1310
  useImperativeHandle as useImperativeHandle8,
1309
1311
  useRef as useRef10,
1310
1312
  useState as useState2
1311
1313
  } from "react";
1312
1314
  import { jsx as jsx3 } from "react/jsx-runtime";
1313
- var SphereMap = forwardRef8(
1314
- function SphereMap2({
1315
- children,
1316
- zoom = 7,
1317
- zoomRange,
1318
- center,
1319
- language = "th",
1320
- input = true,
1321
- lastView = false,
1322
- ui,
1323
- filter,
1324
- rotate,
1325
- pitch,
1326
- className,
1327
- style,
1328
- id,
1315
+ function SphereMap({
1316
+ children,
1317
+ ref,
1318
+ zoom = 7,
1319
+ zoomRange,
1320
+ center,
1321
+ language = "th",
1322
+ input = true,
1323
+ lastView = false,
1324
+ ui,
1325
+ filter,
1326
+ rotate,
1327
+ pitch,
1328
+ className,
1329
+ style,
1330
+ id,
1331
+ onReady,
1332
+ onZoom,
1333
+ onLocation,
1334
+ onClick,
1335
+ onDoubleClick,
1336
+ onRotate,
1337
+ onPitch,
1338
+ onDrag,
1339
+ onDrop,
1340
+ onIdle,
1341
+ onMouseMove,
1342
+ onError
1343
+ }) {
1344
+ const containerRef = useRef10(null);
1345
+ const mapRef = useRef10(null);
1346
+ const [isReady, setIsReady] = useState2(false);
1347
+ const { sphere, isLoaded, registerMap, unregisterMap } = useSphereContext();
1348
+ const callbacksRef = useRef10({
1329
1349
  onReady,
1330
1350
  onZoom,
1331
1351
  onLocation,
@@ -1338,12 +1358,9 @@ var SphereMap = forwardRef8(
1338
1358
  onIdle,
1339
1359
  onMouseMove,
1340
1360
  onError
1341
- }, ref) {
1342
- const containerRef = useRef10(null);
1343
- const mapRef = useRef10(null);
1344
- const [isReady, setIsReady] = useState2(false);
1345
- const { sphere, isLoaded, registerMap, unregisterMap } = useSphereContext();
1346
- const callbacksRef = useRef10({
1361
+ });
1362
+ useEffect10(() => {
1363
+ callbacksRef.current = {
1347
1364
  onReady,
1348
1365
  onZoom,
1349
1366
  onLocation,
@@ -1356,175 +1373,158 @@ var SphereMap = forwardRef8(
1356
1373
  onIdle,
1357
1374
  onMouseMove,
1358
1375
  onError
1359
- });
1360
- useEffect10(() => {
1361
- callbacksRef.current = {
1362
- onReady,
1363
- onZoom,
1364
- onLocation,
1365
- onClick,
1366
- onDoubleClick,
1367
- onRotate,
1368
- onPitch,
1369
- onDrag,
1370
- onDrop,
1371
- onIdle,
1372
- onMouseMove,
1373
- onError
1376
+ };
1377
+ });
1378
+ const initialPropsRef = useRef10({
1379
+ zoom,
1380
+ zoomRange,
1381
+ center,
1382
+ language,
1383
+ input,
1384
+ lastView,
1385
+ ui,
1386
+ filter,
1387
+ rotate,
1388
+ pitch
1389
+ });
1390
+ useEffect10(() => {
1391
+ if (!(isLoaded && sphere && containerRef.current)) {
1392
+ return;
1393
+ }
1394
+ const initialProps = initialPropsRef.current;
1395
+ try {
1396
+ const options = {
1397
+ placeholder: containerRef.current,
1398
+ zoom: initialProps.zoom,
1399
+ language: initialProps.language,
1400
+ input: initialProps.input,
1401
+ lastView: initialProps.lastView
1374
1402
  };
1375
- });
1376
- const initialPropsRef = useRef10({
1377
- zoom,
1378
- zoomRange,
1379
- center,
1380
- language,
1381
- input,
1382
- lastView,
1383
- ui,
1384
- filter,
1385
- rotate,
1386
- pitch
1387
- });
1388
- useEffect10(() => {
1389
- if (!(isLoaded && sphere && containerRef.current)) {
1390
- return;
1391
- }
1392
- const initialProps = initialPropsRef.current;
1393
- try {
1394
- const options = {
1395
- placeholder: containerRef.current,
1396
- zoom: initialProps.zoom,
1397
- language: initialProps.language,
1398
- input: initialProps.input,
1399
- lastView: initialProps.lastView
1400
- };
1401
- if (initialProps.zoomRange) {
1402
- options.zoomRange = initialProps.zoomRange;
1403
+ if (initialProps.zoomRange) {
1404
+ options.zoomRange = initialProps.zoomRange;
1405
+ }
1406
+ if (initialProps.center) {
1407
+ options.location = initialProps.center;
1408
+ }
1409
+ if (initialProps.ui) {
1410
+ options.ui = initialProps.ui;
1411
+ }
1412
+ const map = new sphere.Map(options);
1413
+ mapRef.current = map;
1414
+ map.Event.bind("ready", () => {
1415
+ setIsReady(true);
1416
+ registerMap(map);
1417
+ if (initialProps.filter && window.sphere) {
1418
+ map.enableFilter(window.sphere.Filter[initialProps.filter]);
1403
1419
  }
1404
- if (initialProps.center) {
1405
- options.location = initialProps.center;
1420
+ if (typeof initialProps.rotate === "number") {
1421
+ map.rotate(initialProps.rotate, false);
1406
1422
  }
1407
- if (initialProps.ui) {
1408
- options.ui = initialProps.ui;
1423
+ if (typeof initialProps.pitch === "number") {
1424
+ map.pitch(initialProps.pitch);
1409
1425
  }
1410
- const map = new sphere.Map(options);
1411
- mapRef.current = map;
1412
- map.Event.bind("ready", () => {
1413
- setIsReady(true);
1414
- registerMap(map);
1415
- if (initialProps.filter && window.sphere) {
1416
- map.enableFilter(window.sphere.Filter[initialProps.filter]);
1417
- }
1418
- if (typeof initialProps.rotate === "number") {
1419
- map.rotate(initialProps.rotate, false);
1420
- }
1421
- if (typeof initialProps.pitch === "number") {
1422
- map.pitch(initialProps.pitch);
1423
- }
1424
- callbacksRef.current.onReady?.(map);
1425
- });
1426
- map.Event.bind("zoom", () => {
1427
- const currentZoom = map.zoom();
1428
- callbacksRef.current.onZoom?.(currentZoom);
1429
- });
1430
- map.Event.bind("location", () => {
1431
- const currentLocation = map.location();
1432
- callbacksRef.current.onLocation?.(currentLocation);
1433
- });
1434
- map.Event.bind("click", (location) => {
1435
- callbacksRef.current.onClick?.(location);
1436
- });
1437
- map.Event.bind("doubleClick", (location) => {
1438
- callbacksRef.current.onDoubleClick?.(location);
1439
- });
1440
- map.Event.bind("rotate", () => {
1441
- const angle = map.rotate();
1442
- callbacksRef.current.onRotate?.(angle);
1443
- });
1444
- map.Event.bind("pitch", () => {
1445
- const angle = map.pitch();
1446
- callbacksRef.current.onPitch?.(angle);
1447
- });
1448
- map.Event.bind("drag", () => {
1449
- callbacksRef.current.onDrag?.();
1450
- });
1451
- map.Event.bind("drop", () => {
1452
- callbacksRef.current.onDrop?.();
1453
- });
1454
- map.Event.bind("idle", () => {
1455
- callbacksRef.current.onIdle?.();
1456
- });
1457
- map.Event.bind("mousemove", (location) => {
1458
- callbacksRef.current.onMouseMove?.(location);
1459
- });
1460
- map.Event.bind("error", (error) => {
1461
- callbacksRef.current.onError?.(error);
1462
- });
1463
- } catch (error) {
1464
- callbacksRef.current.onError?.(
1465
- error instanceof Error ? error : new Error(String(error))
1466
- );
1467
- }
1468
- return () => {
1469
- unregisterMap();
1470
- mapRef.current = null;
1471
- setIsReady(false);
1472
- };
1473
- }, [isLoaded, sphere, registerMap, unregisterMap]);
1474
- useImperativeHandle8(
1475
- ref,
1476
- () => ({
1477
- getMap: () => mapRef.current,
1478
- setZoom: (newZoom, animate = true) => {
1479
- mapRef.current?.zoom(newZoom, animate);
1480
- },
1481
- setCenter: (location, animate = true) => {
1482
- mapRef.current?.location(location, animate);
1483
- },
1484
- setBound: (bound, options) => {
1485
- mapRef.current?.bound(bound, options);
1486
- },
1487
- goTo: (target, animate = true) => {
1488
- mapRef.current?.goTo(target, animate);
1489
- },
1490
- setRotate: (angle, animate = true) => {
1491
- mapRef.current?.rotate(angle, animate);
1492
- },
1493
- setPitch: (angle) => {
1494
- mapRef.current?.pitch(angle);
1495
- },
1496
- setFilter: (newFilter) => {
1497
- if (mapRef.current && window.sphere) {
1498
- mapRef.current.enableFilter(window.sphere.Filter[newFilter]);
1499
- }
1500
- },
1501
- resize: () => {
1502
- mapRef.current?.resize();
1503
- },
1504
- repaint: () => {
1505
- mapRef.current?.repaint();
1506
- }
1507
- }),
1508
- []
1509
- );
1510
- const containerStyle = {
1511
- width: "100%",
1512
- height: "100%",
1513
- ...style
1426
+ callbacksRef.current.onReady?.(map);
1427
+ });
1428
+ map.Event.bind("zoom", () => {
1429
+ const currentZoom = map.zoom();
1430
+ callbacksRef.current.onZoom?.(currentZoom);
1431
+ });
1432
+ map.Event.bind("location", () => {
1433
+ const currentLocation = map.location();
1434
+ callbacksRef.current.onLocation?.(currentLocation);
1435
+ });
1436
+ map.Event.bind("click", (location) => {
1437
+ callbacksRef.current.onClick?.(location);
1438
+ });
1439
+ map.Event.bind("doubleClick", (location) => {
1440
+ callbacksRef.current.onDoubleClick?.(location);
1441
+ });
1442
+ map.Event.bind("rotate", () => {
1443
+ const angle = map.rotate();
1444
+ callbacksRef.current.onRotate?.(angle);
1445
+ });
1446
+ map.Event.bind("pitch", () => {
1447
+ const angle = map.pitch();
1448
+ callbacksRef.current.onPitch?.(angle);
1449
+ });
1450
+ map.Event.bind("drag", () => {
1451
+ callbacksRef.current.onDrag?.();
1452
+ });
1453
+ map.Event.bind("drop", () => {
1454
+ callbacksRef.current.onDrop?.();
1455
+ });
1456
+ map.Event.bind("idle", () => {
1457
+ callbacksRef.current.onIdle?.();
1458
+ });
1459
+ map.Event.bind("mousemove", (location) => {
1460
+ callbacksRef.current.onMouseMove?.(location);
1461
+ });
1462
+ map.Event.bind("error", (error) => {
1463
+ callbacksRef.current.onError?.(error);
1464
+ });
1465
+ } catch (error) {
1466
+ callbacksRef.current.onError?.(
1467
+ error instanceof Error ? error : new Error(String(error))
1468
+ );
1469
+ }
1470
+ return () => {
1471
+ unregisterMap();
1472
+ mapRef.current = null;
1473
+ setIsReady(false);
1514
1474
  };
1515
- return /* @__PURE__ */ jsx3(
1516
- "div",
1517
- {
1518
- className,
1519
- id,
1520
- ref: containerRef,
1521
- style: containerStyle,
1522
- children: /* @__PURE__ */ jsx3(MapProvider, { isReady, map: mapRef.current, children: isReady && children })
1475
+ }, [isLoaded, sphere, registerMap, unregisterMap]);
1476
+ useImperativeHandle8(
1477
+ ref,
1478
+ () => ({
1479
+ getMap: () => mapRef.current,
1480
+ setZoom: (newZoom, animate = true) => {
1481
+ mapRef.current?.zoom(newZoom, animate);
1482
+ },
1483
+ setCenter: (location, animate = true) => {
1484
+ mapRef.current?.location(location, animate);
1485
+ },
1486
+ setBound: (bound, options) => {
1487
+ mapRef.current?.bound(bound, options);
1488
+ },
1489
+ goTo: (target, animate = true) => {
1490
+ mapRef.current?.goTo(target, animate);
1491
+ },
1492
+ setRotate: (angle, animate = true) => {
1493
+ mapRef.current?.rotate(angle, animate);
1494
+ },
1495
+ setPitch: (angle) => {
1496
+ mapRef.current?.pitch(angle);
1497
+ },
1498
+ setFilter: (newFilter) => {
1499
+ if (mapRef.current && window.sphere) {
1500
+ mapRef.current.enableFilter(window.sphere.Filter[newFilter]);
1501
+ }
1502
+ },
1503
+ resize: () => {
1504
+ mapRef.current?.resize();
1505
+ },
1506
+ repaint: () => {
1507
+ mapRef.current?.repaint();
1523
1508
  }
1524
- );
1525
- }
1526
- );
1527
- var SphereMap_default = SphereMap;
1509
+ }),
1510
+ []
1511
+ );
1512
+ const containerStyle = {
1513
+ width: "100%",
1514
+ height: "100%",
1515
+ ...style
1516
+ };
1517
+ return /* @__PURE__ */ jsx3(
1518
+ "div",
1519
+ {
1520
+ className,
1521
+ id,
1522
+ ref: containerRef,
1523
+ style: containerStyle,
1524
+ children: /* @__PURE__ */ jsx3(MapProvider, { isReady, map: mapRef.current, children: isReady && children })
1525
+ }
1526
+ );
1527
+ }
1528
1528
 
1529
1529
  // src/hooks/useMapEvent.ts
1530
1530
  import { useEffect as useEffect11, useRef as useRef11 } from "react";
@@ -1981,7 +1981,7 @@ export {
1981
1981
  Circle,
1982
1982
  Dot,
1983
1983
  Layer,
1984
- SphereMap_default as Map,
1984
+ SphereMap as Map,
1985
1985
  MapProvider,
1986
1986
  Marker,
1987
1987
  Polygon,