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.js CHANGED
@@ -23,7 +23,7 @@ __export(index_exports, {
23
23
  Circle: () => Circle,
24
24
  Dot: () => Dot,
25
25
  Layer: () => Layer,
26
- Map: () => SphereMap_default,
26
+ Map: () => SphereMap,
27
27
  MapProvider: () => MapProvider,
28
28
  Marker: () => Marker,
29
29
  Polygon: () => Polygon,
@@ -299,9 +299,10 @@ function useMapControls() {
299
299
  }
300
300
 
301
301
  // src/components/Circle.tsx
302
- var Circle = (0, import_react3.forwardRef)(function Circle2({
302
+ function Circle({
303
303
  center,
304
304
  radius,
305
+ ref,
305
306
  title,
306
307
  detail,
307
308
  popup,
@@ -316,7 +317,7 @@ var Circle = (0, import_react3.forwardRef)(function Circle2({
316
317
  onClick,
317
318
  onDrag,
318
319
  onDrop
319
- }, ref) {
320
+ }) {
320
321
  const { map, isReady } = useMapContext();
321
322
  const { sphere } = useSphereContext();
322
323
  const circleRef = (0, import_react3.useRef)(null);
@@ -426,12 +427,13 @@ var Circle = (0, import_react3.forwardRef)(function Circle2({
426
427
  []
427
428
  );
428
429
  return null;
429
- });
430
+ }
430
431
 
431
432
  // src/components/Dot.tsx
432
433
  var import_react4 = require("react");
433
- var Dot = (0, import_react4.forwardRef)(function Dot2({
434
+ function Dot({
434
435
  position,
436
+ ref,
435
437
  title,
436
438
  detail,
437
439
  visibleRange,
@@ -443,7 +445,7 @@ var Dot = (0, import_react4.forwardRef)(function Dot2({
443
445
  onClick,
444
446
  onDrag,
445
447
  onDrop
446
- }, ref) {
448
+ }) {
447
449
  const { map, isReady } = useMapContext();
448
450
  const { sphere } = useSphereContext();
449
451
  const dotRef = (0, import_react4.useRef)(null);
@@ -535,7 +537,7 @@ var Dot = (0, import_react4.forwardRef)(function Dot2({
535
537
  []
536
538
  );
537
539
  return null;
538
- });
540
+ }
539
541
 
540
542
  // src/components/Layer.tsx
541
543
  var import_react5 = require("react");
@@ -672,8 +674,9 @@ function Layer({
672
674
 
673
675
  // src/components/Marker.tsx
674
676
  var import_react6 = require("react");
675
- var Marker = (0, import_react6.forwardRef)(function Marker2({
677
+ function Marker({
676
678
  position,
679
+ ref,
677
680
  icon,
678
681
  title,
679
682
  detail,
@@ -688,7 +691,7 @@ var Marker = (0, import_react6.forwardRef)(function Marker2({
688
691
  onDrop,
689
692
  onHover,
690
693
  onLeave
691
- }, ref) {
694
+ }) {
692
695
  const { map, isReady } = useMapContext();
693
696
  const { sphere } = useSphereContext();
694
697
  const markerRef = (0, import_react6.useRef)(null);
@@ -813,12 +816,13 @@ var Marker = (0, import_react6.forwardRef)(function Marker2({
813
816
  []
814
817
  );
815
818
  return null;
816
- });
819
+ }
817
820
 
818
821
  // src/components/Polygon.tsx
819
822
  var import_react7 = require("react");
820
- var Polygon = (0, import_react7.forwardRef)(function Polygon2({
823
+ function Polygon({
821
824
  positions,
825
+ ref,
822
826
  title,
823
827
  detail,
824
828
  label,
@@ -838,7 +842,7 @@ var Polygon = (0, import_react7.forwardRef)(function Polygon2({
838
842
  onClick,
839
843
  onDrag,
840
844
  onDrop
841
- }, ref) {
845
+ }) {
842
846
  const { map, isReady } = useMapContext();
843
847
  const { sphere } = useSphereContext();
844
848
  const polygonRef = (0, import_react7.useRef)(null);
@@ -971,12 +975,117 @@ var Polygon = (0, import_react7.forwardRef)(function Polygon2({
971
975
  []
972
976
  );
973
977
  return null;
974
- });
978
+ }
975
979
 
976
980
  // src/components/Polyline.tsx
977
981
  var import_react8 = require("react");
978
- var Polyline = (0, import_react8.forwardRef)(
979
- function Polyline2({
982
+ function Polyline({
983
+ positions,
984
+ ref,
985
+ title,
986
+ detail,
987
+ label,
988
+ labelOptions,
989
+ popup,
990
+ visibleRange,
991
+ lineWidth,
992
+ lineColor,
993
+ lineStyle,
994
+ pivot,
995
+ clickable,
996
+ draggable,
997
+ pointer,
998
+ zIndex,
999
+ onClick,
1000
+ onDrag,
1001
+ onDrop
1002
+ }) {
1003
+ const { map, isReady } = useMapContext();
1004
+ const { sphere } = useSphereContext();
1005
+ const polylineRef = (0, import_react8.useRef)(null);
1006
+ const callbacksRef = (0, import_react8.useRef)({ onClick, onDrag, onDrop });
1007
+ (0, import_react8.useEffect)(() => {
1008
+ callbacksRef.current = { onClick, onDrag, onDrop };
1009
+ }, [onClick, onDrag, onDrop]);
1010
+ (0, import_react8.useEffect)(() => {
1011
+ if (!(isReady && map && sphere) || positions.length < 2) {
1012
+ return;
1013
+ }
1014
+ const options = {};
1015
+ if (title) {
1016
+ options.title = title;
1017
+ }
1018
+ if (detail) {
1019
+ options.detail = detail;
1020
+ }
1021
+ if (label) {
1022
+ options.label = label;
1023
+ }
1024
+ if (labelOptions) {
1025
+ options.labelOptions = labelOptions;
1026
+ }
1027
+ if (popup) {
1028
+ options.popup = popup;
1029
+ }
1030
+ if (visibleRange) {
1031
+ options.visibleRange = visibleRange;
1032
+ }
1033
+ if (typeof lineWidth === "number") {
1034
+ options.lineWidth = lineWidth;
1035
+ }
1036
+ if (lineColor) {
1037
+ options.lineColor = lineColor;
1038
+ }
1039
+ if (lineStyle) {
1040
+ options.lineStyle = lineStyle;
1041
+ }
1042
+ if (pivot) {
1043
+ options.pivot = pivot;
1044
+ }
1045
+ if (typeof clickable === "boolean") {
1046
+ options.clickable = clickable;
1047
+ }
1048
+ if (typeof draggable === "boolean") {
1049
+ options.draggable = draggable;
1050
+ }
1051
+ if (typeof pointer === "boolean") {
1052
+ options.pointer = pointer;
1053
+ }
1054
+ if (typeof zIndex === "number") {
1055
+ options.zIndex = zIndex;
1056
+ }
1057
+ const polyline = new sphere.Polyline(positions, options);
1058
+ polylineRef.current = polyline;
1059
+ map.Overlays.add(polyline);
1060
+ const handleOverlayClick = (data) => {
1061
+ if (data.overlay === polyline) {
1062
+ callbacksRef.current.onClick?.(polyline);
1063
+ }
1064
+ };
1065
+ const handleOverlayDrag = (overlay) => {
1066
+ if (overlay === polyline) {
1067
+ callbacksRef.current.onDrag?.(polyline);
1068
+ }
1069
+ };
1070
+ const handleOverlayDrop = (overlay) => {
1071
+ if (overlay === polyline) {
1072
+ callbacksRef.current.onDrop?.(polyline);
1073
+ }
1074
+ };
1075
+ map.Event.bind("overlayClick", handleOverlayClick);
1076
+ map.Event.bind("overlayDrag", handleOverlayDrag);
1077
+ map.Event.bind("overlayDrop", handleOverlayDrop);
1078
+ return () => {
1079
+ map.Event.unbind("overlayClick", handleOverlayClick);
1080
+ map.Event.unbind("overlayDrag", handleOverlayDrag);
1081
+ map.Event.unbind("overlayDrop", handleOverlayDrop);
1082
+ map.Overlays.remove(polyline);
1083
+ polylineRef.current = null;
1084
+ };
1085
+ }, [
1086
+ isReady,
1087
+ map,
1088
+ sphere,
980
1089
  positions,
981
1090
  title,
982
1091
  detail,
@@ -991,141 +1100,36 @@ var Polyline = (0, import_react8.forwardRef)(
991
1100
  clickable,
992
1101
  draggable,
993
1102
  pointer,
994
- zIndex,
995
- onClick,
996
- onDrag,
997
- onDrop
998
- }, ref) {
999
- const { map, isReady } = useMapContext();
1000
- const { sphere } = useSphereContext();
1001
- const polylineRef = (0, import_react8.useRef)(null);
1002
- const callbacksRef = (0, import_react8.useRef)({ onClick, onDrag, onDrop });
1003
- (0, import_react8.useEffect)(() => {
1004
- callbacksRef.current = { onClick, onDrag, onDrop };
1005
- }, [onClick, onDrag, onDrop]);
1006
- (0, import_react8.useEffect)(() => {
1007
- if (!(isReady && map && sphere) || positions.length < 2) {
1008
- return;
1009
- }
1010
- const options = {};
1011
- if (title) {
1012
- options.title = title;
1013
- }
1014
- if (detail) {
1015
- options.detail = detail;
1016
- }
1017
- if (label) {
1018
- options.label = label;
1019
- }
1020
- if (labelOptions) {
1021
- options.labelOptions = labelOptions;
1022
- }
1023
- if (popup) {
1024
- options.popup = popup;
1025
- }
1026
- if (visibleRange) {
1027
- options.visibleRange = visibleRange;
1028
- }
1029
- if (typeof lineWidth === "number") {
1030
- options.lineWidth = lineWidth;
1031
- }
1032
- if (lineColor) {
1033
- options.lineColor = lineColor;
1034
- }
1035
- if (lineStyle) {
1036
- options.lineStyle = lineStyle;
1037
- }
1038
- if (pivot) {
1039
- options.pivot = pivot;
1040
- }
1041
- if (typeof clickable === "boolean") {
1042
- options.clickable = clickable;
1043
- }
1044
- if (typeof draggable === "boolean") {
1045
- options.draggable = draggable;
1046
- }
1047
- if (typeof pointer === "boolean") {
1048
- options.pointer = pointer;
1049
- }
1050
- if (typeof zIndex === "number") {
1051
- options.zIndex = zIndex;
1103
+ zIndex
1104
+ ]);
1105
+ (0, import_react8.useImperativeHandle)(
1106
+ ref,
1107
+ () => ({
1108
+ getPolyline: () => polylineRef.current,
1109
+ togglePopup: (show, location) => {
1110
+ polylineRef.current?.pop(show, location);
1111
+ },
1112
+ getPivot: () => polylineRef.current?.pivot() ?? null,
1113
+ getCentroid: () => polylineRef.current?.centroid() ?? null,
1114
+ getBound: () => polylineRef.current?.bound() ?? null,
1115
+ getLength: (language) => polylineRef.current?.size(language) ?? null,
1116
+ rotate: (angle) => {
1117
+ polylineRef.current?.rotate(angle);
1118
+ },
1119
+ updateStyle: (options) => {
1120
+ polylineRef.current?.update(options);
1052
1121
  }
1053
- const polyline = new sphere.Polyline(positions, options);
1054
- polylineRef.current = polyline;
1055
- map.Overlays.add(polyline);
1056
- const handleOverlayClick = (data) => {
1057
- if (data.overlay === polyline) {
1058
- callbacksRef.current.onClick?.(polyline);
1059
- }
1060
- };
1061
- const handleOverlayDrag = (overlay) => {
1062
- if (overlay === polyline) {
1063
- callbacksRef.current.onDrag?.(polyline);
1064
- }
1065
- };
1066
- const handleOverlayDrop = (overlay) => {
1067
- if (overlay === polyline) {
1068
- callbacksRef.current.onDrop?.(polyline);
1069
- }
1070
- };
1071
- map.Event.bind("overlayClick", handleOverlayClick);
1072
- map.Event.bind("overlayDrag", handleOverlayDrag);
1073
- map.Event.bind("overlayDrop", handleOverlayDrop);
1074
- return () => {
1075
- map.Event.unbind("overlayClick", handleOverlayClick);
1076
- map.Event.unbind("overlayDrag", handleOverlayDrag);
1077
- map.Event.unbind("overlayDrop", handleOverlayDrop);
1078
- map.Overlays.remove(polyline);
1079
- polylineRef.current = null;
1080
- };
1081
- }, [
1082
- isReady,
1083
- map,
1084
- sphere,
1085
- positions,
1086
- title,
1087
- detail,
1088
- label,
1089
- labelOptions,
1090
- popup,
1091
- visibleRange,
1092
- lineWidth,
1093
- lineColor,
1094
- lineStyle,
1095
- pivot,
1096
- clickable,
1097
- draggable,
1098
- pointer,
1099
- zIndex
1100
- ]);
1101
- (0, import_react8.useImperativeHandle)(
1102
- ref,
1103
- () => ({
1104
- getPolyline: () => polylineRef.current,
1105
- togglePopup: (show, location) => {
1106
- polylineRef.current?.pop(show, location);
1107
- },
1108
- getPivot: () => polylineRef.current?.pivot() ?? null,
1109
- getCentroid: () => polylineRef.current?.centroid() ?? null,
1110
- getBound: () => polylineRef.current?.bound() ?? null,
1111
- getLength: (language) => polylineRef.current?.size(language) ?? null,
1112
- rotate: (angle) => {
1113
- polylineRef.current?.rotate(angle);
1114
- },
1115
- updateStyle: (options) => {
1116
- polylineRef.current?.update(options);
1117
- }
1118
- }),
1119
- []
1120
- );
1121
- return null;
1122
- }
1123
- );
1122
+ }),
1123
+ []
1124
+ );
1125
+ return null;
1126
+ }
1124
1127
 
1125
1128
  // src/components/Popup.tsx
1126
1129
  var import_react9 = require("react");
1127
- var Popup = (0, import_react9.forwardRef)(function Popup2({
1130
+ function Popup({
1128
1131
  position,
1132
+ ref,
1129
1133
  title,
1130
1134
  detail,
1131
1135
  loadDetail,
@@ -1134,7 +1138,7 @@ var Popup = (0, import_react9.forwardRef)(function Popup2({
1134
1138
  size,
1135
1139
  closable = true,
1136
1140
  onClose
1137
- }, ref) {
1141
+ }) {
1138
1142
  const { map, isReady } = useMapContext();
1139
1143
  const { sphere } = useSphereContext();
1140
1144
  const popupRef = (0, import_react9.useRef)(null);
@@ -1212,12 +1216,110 @@ var Popup = (0, import_react9.forwardRef)(function Popup2({
1212
1216
  []
1213
1217
  );
1214
1218
  return null;
1215
- });
1219
+ }
1216
1220
 
1217
1221
  // src/components/Rectangle.tsx
1218
1222
  var import_react10 = require("react");
1219
- var Rectangle = (0, import_react10.forwardRef)(
1220
- function Rectangle2({
1223
+ function Rectangle({
1224
+ position,
1225
+ size,
1226
+ ref,
1227
+ title,
1228
+ detail,
1229
+ popup,
1230
+ visibleRange,
1231
+ lineWidth,
1232
+ lineColor,
1233
+ fillColor,
1234
+ lineStyle,
1235
+ clickable,
1236
+ draggable,
1237
+ editable,
1238
+ zIndex,
1239
+ onClick,
1240
+ onDrag,
1241
+ onDrop
1242
+ }) {
1243
+ const { map, isReady } = useMapContext();
1244
+ const { sphere } = useSphereContext();
1245
+ const rectangleRef = (0, import_react10.useRef)(null);
1246
+ const callbacksRef = (0, import_react10.useRef)({ onClick, onDrag, onDrop });
1247
+ (0, import_react10.useEffect)(() => {
1248
+ callbacksRef.current = { onClick, onDrag, onDrop };
1249
+ }, [onClick, onDrag, onDrop]);
1250
+ (0, import_react10.useEffect)(() => {
1251
+ if (!(isReady && map && sphere)) {
1252
+ return;
1253
+ }
1254
+ const options = {};
1255
+ if (title) {
1256
+ options.title = title;
1257
+ }
1258
+ if (detail) {
1259
+ options.detail = detail;
1260
+ }
1261
+ if (popup) {
1262
+ options.popup = popup;
1263
+ }
1264
+ if (visibleRange) {
1265
+ options.visibleRange = visibleRange;
1266
+ }
1267
+ if (typeof lineWidth === "number") {
1268
+ options.lineWidth = lineWidth;
1269
+ }
1270
+ if (lineColor) {
1271
+ options.lineColor = lineColor;
1272
+ }
1273
+ if (fillColor) {
1274
+ options.fillColor = fillColor;
1275
+ }
1276
+ if (lineStyle) {
1277
+ options.lineStyle = lineStyle;
1278
+ }
1279
+ if (typeof clickable === "boolean") {
1280
+ options.clickable = clickable;
1281
+ }
1282
+ if (typeof draggable === "boolean") {
1283
+ options.draggable = draggable;
1284
+ }
1285
+ if (typeof editable === "boolean") {
1286
+ options.editable = editable;
1287
+ }
1288
+ if (typeof zIndex === "number") {
1289
+ options.zIndex = zIndex;
1290
+ }
1291
+ const rectangle = new sphere.Rectangle(position, size, options);
1292
+ rectangleRef.current = rectangle;
1293
+ map.Overlays.add(rectangle);
1294
+ const handleOverlayClick = (data) => {
1295
+ if (data.overlay === rectangle) {
1296
+ callbacksRef.current.onClick?.(rectangle);
1297
+ }
1298
+ };
1299
+ const handleOverlayDrag = (overlay) => {
1300
+ if (overlay === rectangle) {
1301
+ callbacksRef.current.onDrag?.(rectangle);
1302
+ }
1303
+ };
1304
+ const handleOverlayDrop = (overlay) => {
1305
+ if (overlay === rectangle) {
1306
+ callbacksRef.current.onDrop?.(rectangle);
1307
+ }
1308
+ };
1309
+ map.Event.bind("overlayClick", handleOverlayClick);
1310
+ map.Event.bind("overlayDrag", handleOverlayDrag);
1311
+ map.Event.bind("overlayDrop", handleOverlayDrop);
1312
+ return () => {
1313
+ map.Event.unbind("overlayClick", handleOverlayClick);
1314
+ map.Event.unbind("overlayDrag", handleOverlayDrag);
1315
+ map.Event.unbind("overlayDrop", handleOverlayDrop);
1316
+ map.Overlays.remove(rectangle);
1317
+ rectangleRef.current = null;
1318
+ };
1319
+ }, [
1320
+ isReady,
1321
+ map,
1322
+ sphere,
1221
1323
  position,
1222
1324
  size,
1223
1325
  title,
@@ -1231,144 +1333,63 @@ var Rectangle = (0, import_react10.forwardRef)(
1231
1333
  clickable,
1232
1334
  draggable,
1233
1335
  editable,
1234
- zIndex,
1235
- onClick,
1236
- onDrag,
1237
- onDrop
1238
- }, ref) {
1239
- const { map, isReady } = useMapContext();
1240
- const { sphere } = useSphereContext();
1241
- const rectangleRef = (0, import_react10.useRef)(null);
1242
- const callbacksRef = (0, import_react10.useRef)({ onClick, onDrag, onDrop });
1243
- (0, import_react10.useEffect)(() => {
1244
- callbacksRef.current = { onClick, onDrag, onDrop };
1245
- }, [onClick, onDrag, onDrop]);
1246
- (0, import_react10.useEffect)(() => {
1247
- if (!(isReady && map && sphere)) {
1248
- return;
1249
- }
1250
- const options = {};
1251
- if (title) {
1252
- options.title = title;
1253
- }
1254
- if (detail) {
1255
- options.detail = detail;
1256
- }
1257
- if (popup) {
1258
- options.popup = popup;
1259
- }
1260
- if (visibleRange) {
1261
- options.visibleRange = visibleRange;
1262
- }
1263
- if (typeof lineWidth === "number") {
1264
- options.lineWidth = lineWidth;
1265
- }
1266
- if (lineColor) {
1267
- options.lineColor = lineColor;
1268
- }
1269
- if (fillColor) {
1270
- options.fillColor = fillColor;
1271
- }
1272
- if (lineStyle) {
1273
- options.lineStyle = lineStyle;
1274
- }
1275
- if (typeof clickable === "boolean") {
1276
- options.clickable = clickable;
1277
- }
1278
- if (typeof draggable === "boolean") {
1279
- options.draggable = draggable;
1280
- }
1281
- if (typeof editable === "boolean") {
1282
- options.editable = editable;
1283
- }
1284
- if (typeof zIndex === "number") {
1285
- options.zIndex = zIndex;
1336
+ zIndex
1337
+ ]);
1338
+ (0, import_react10.useImperativeHandle)(
1339
+ ref,
1340
+ () => ({
1341
+ getRectangle: () => rectangleRef.current,
1342
+ togglePopup: (show, location) => {
1343
+ rectangleRef.current?.pop(show, location);
1344
+ },
1345
+ getBound: () => rectangleRef.current?.bound() ?? null,
1346
+ getArea: (language) => rectangleRef.current?.size(language) ?? null,
1347
+ updateStyle: (options) => {
1348
+ rectangleRef.current?.update(options);
1286
1349
  }
1287
- const rectangle = new sphere.Rectangle(position, size, options);
1288
- rectangleRef.current = rectangle;
1289
- map.Overlays.add(rectangle);
1290
- const handleOverlayClick = (data) => {
1291
- if (data.overlay === rectangle) {
1292
- callbacksRef.current.onClick?.(rectangle);
1293
- }
1294
- };
1295
- const handleOverlayDrag = (overlay) => {
1296
- if (overlay === rectangle) {
1297
- callbacksRef.current.onDrag?.(rectangle);
1298
- }
1299
- };
1300
- const handleOverlayDrop = (overlay) => {
1301
- if (overlay === rectangle) {
1302
- callbacksRef.current.onDrop?.(rectangle);
1303
- }
1304
- };
1305
- map.Event.bind("overlayClick", handleOverlayClick);
1306
- map.Event.bind("overlayDrag", handleOverlayDrag);
1307
- map.Event.bind("overlayDrop", handleOverlayDrop);
1308
- return () => {
1309
- map.Event.unbind("overlayClick", handleOverlayClick);
1310
- map.Event.unbind("overlayDrag", handleOverlayDrag);
1311
- map.Event.unbind("overlayDrop", handleOverlayDrop);
1312
- map.Overlays.remove(rectangle);
1313
- rectangleRef.current = null;
1314
- };
1315
- }, [
1316
- isReady,
1317
- map,
1318
- sphere,
1319
- position,
1320
- size,
1321
- title,
1322
- detail,
1323
- popup,
1324
- visibleRange,
1325
- lineWidth,
1326
- lineColor,
1327
- fillColor,
1328
- lineStyle,
1329
- clickable,
1330
- draggable,
1331
- editable,
1332
- zIndex
1333
- ]);
1334
- (0, import_react10.useImperativeHandle)(
1335
- ref,
1336
- () => ({
1337
- getRectangle: () => rectangleRef.current,
1338
- togglePopup: (show, location) => {
1339
- rectangleRef.current?.pop(show, location);
1340
- },
1341
- getBound: () => rectangleRef.current?.bound() ?? null,
1342
- getArea: (language) => rectangleRef.current?.size(language) ?? null,
1343
- updateStyle: (options) => {
1344
- rectangleRef.current?.update(options);
1345
- }
1346
- }),
1347
- []
1348
- );
1349
- return null;
1350
- }
1351
- );
1350
+ }),
1351
+ []
1352
+ );
1353
+ return null;
1354
+ }
1352
1355
 
1353
1356
  // src/components/SphereMap.tsx
1354
1357
  var import_react11 = require("react");
1355
1358
  var import_jsx_runtime3 = require("react/jsx-runtime");
1356
- var SphereMap = (0, import_react11.forwardRef)(
1357
- function SphereMap2({
1358
- children,
1359
- zoom = 7,
1360
- zoomRange,
1361
- center,
1362
- language = "th",
1363
- input = true,
1364
- lastView = false,
1365
- ui,
1366
- filter,
1367
- rotate,
1368
- pitch,
1369
- className,
1370
- style,
1371
- id,
1359
+ function SphereMap({
1360
+ children,
1361
+ ref,
1362
+ zoom = 7,
1363
+ zoomRange,
1364
+ center,
1365
+ language = "th",
1366
+ input = true,
1367
+ lastView = false,
1368
+ ui,
1369
+ filter,
1370
+ rotate,
1371
+ pitch,
1372
+ className,
1373
+ style,
1374
+ id,
1375
+ onReady,
1376
+ onZoom,
1377
+ onLocation,
1378
+ onClick,
1379
+ onDoubleClick,
1380
+ onRotate,
1381
+ onPitch,
1382
+ onDrag,
1383
+ onDrop,
1384
+ onIdle,
1385
+ onMouseMove,
1386
+ onError
1387
+ }) {
1388
+ const containerRef = (0, import_react11.useRef)(null);
1389
+ const mapRef = (0, import_react11.useRef)(null);
1390
+ const [isReady, setIsReady] = (0, import_react11.useState)(false);
1391
+ const { sphere, isLoaded, registerMap, unregisterMap } = useSphereContext();
1392
+ const callbacksRef = (0, import_react11.useRef)({
1372
1393
  onReady,
1373
1394
  onZoom,
1374
1395
  onLocation,
@@ -1381,12 +1402,9 @@ var SphereMap = (0, import_react11.forwardRef)(
1381
1402
  onIdle,
1382
1403
  onMouseMove,
1383
1404
  onError
1384
- }, ref) {
1385
- const containerRef = (0, import_react11.useRef)(null);
1386
- const mapRef = (0, import_react11.useRef)(null);
1387
- const [isReady, setIsReady] = (0, import_react11.useState)(false);
1388
- const { sphere, isLoaded, registerMap, unregisterMap } = useSphereContext();
1389
- const callbacksRef = (0, import_react11.useRef)({
1405
+ });
1406
+ (0, import_react11.useEffect)(() => {
1407
+ callbacksRef.current = {
1390
1408
  onReady,
1391
1409
  onZoom,
1392
1410
  onLocation,
@@ -1399,175 +1417,158 @@ var SphereMap = (0, import_react11.forwardRef)(
1399
1417
  onIdle,
1400
1418
  onMouseMove,
1401
1419
  onError
1402
- });
1403
- (0, import_react11.useEffect)(() => {
1404
- callbacksRef.current = {
1405
- onReady,
1406
- onZoom,
1407
- onLocation,
1408
- onClick,
1409
- onDoubleClick,
1410
- onRotate,
1411
- onPitch,
1412
- onDrag,
1413
- onDrop,
1414
- onIdle,
1415
- onMouseMove,
1416
- onError
1420
+ };
1421
+ });
1422
+ const initialPropsRef = (0, import_react11.useRef)({
1423
+ zoom,
1424
+ zoomRange,
1425
+ center,
1426
+ language,
1427
+ input,
1428
+ lastView,
1429
+ ui,
1430
+ filter,
1431
+ rotate,
1432
+ pitch
1433
+ });
1434
+ (0, import_react11.useEffect)(() => {
1435
+ if (!(isLoaded && sphere && containerRef.current)) {
1436
+ return;
1437
+ }
1438
+ const initialProps = initialPropsRef.current;
1439
+ try {
1440
+ const options = {
1441
+ placeholder: containerRef.current,
1442
+ zoom: initialProps.zoom,
1443
+ language: initialProps.language,
1444
+ input: initialProps.input,
1445
+ lastView: initialProps.lastView
1417
1446
  };
1418
- });
1419
- const initialPropsRef = (0, import_react11.useRef)({
1420
- zoom,
1421
- zoomRange,
1422
- center,
1423
- language,
1424
- input,
1425
- lastView,
1426
- ui,
1427
- filter,
1428
- rotate,
1429
- pitch
1430
- });
1431
- (0, import_react11.useEffect)(() => {
1432
- if (!(isLoaded && sphere && containerRef.current)) {
1433
- return;
1434
- }
1435
- const initialProps = initialPropsRef.current;
1436
- try {
1437
- const options = {
1438
- placeholder: containerRef.current,
1439
- zoom: initialProps.zoom,
1440
- language: initialProps.language,
1441
- input: initialProps.input,
1442
- lastView: initialProps.lastView
1443
- };
1444
- if (initialProps.zoomRange) {
1445
- options.zoomRange = initialProps.zoomRange;
1447
+ if (initialProps.zoomRange) {
1448
+ options.zoomRange = initialProps.zoomRange;
1449
+ }
1450
+ if (initialProps.center) {
1451
+ options.location = initialProps.center;
1452
+ }
1453
+ if (initialProps.ui) {
1454
+ options.ui = initialProps.ui;
1455
+ }
1456
+ const map = new sphere.Map(options);
1457
+ mapRef.current = map;
1458
+ map.Event.bind("ready", () => {
1459
+ setIsReady(true);
1460
+ registerMap(map);
1461
+ if (initialProps.filter && window.sphere) {
1462
+ map.enableFilter(window.sphere.Filter[initialProps.filter]);
1446
1463
  }
1447
- if (initialProps.center) {
1448
- options.location = initialProps.center;
1464
+ if (typeof initialProps.rotate === "number") {
1465
+ map.rotate(initialProps.rotate, false);
1449
1466
  }
1450
- if (initialProps.ui) {
1451
- options.ui = initialProps.ui;
1467
+ if (typeof initialProps.pitch === "number") {
1468
+ map.pitch(initialProps.pitch);
1452
1469
  }
1453
- const map = new sphere.Map(options);
1454
- mapRef.current = map;
1455
- map.Event.bind("ready", () => {
1456
- setIsReady(true);
1457
- registerMap(map);
1458
- if (initialProps.filter && window.sphere) {
1459
- map.enableFilter(window.sphere.Filter[initialProps.filter]);
1460
- }
1461
- if (typeof initialProps.rotate === "number") {
1462
- map.rotate(initialProps.rotate, false);
1463
- }
1464
- if (typeof initialProps.pitch === "number") {
1465
- map.pitch(initialProps.pitch);
1466
- }
1467
- callbacksRef.current.onReady?.(map);
1468
- });
1469
- map.Event.bind("zoom", () => {
1470
- const currentZoom = map.zoom();
1471
- callbacksRef.current.onZoom?.(currentZoom);
1472
- });
1473
- map.Event.bind("location", () => {
1474
- const currentLocation = map.location();
1475
- callbacksRef.current.onLocation?.(currentLocation);
1476
- });
1477
- map.Event.bind("click", (location) => {
1478
- callbacksRef.current.onClick?.(location);
1479
- });
1480
- map.Event.bind("doubleClick", (location) => {
1481
- callbacksRef.current.onDoubleClick?.(location);
1482
- });
1483
- map.Event.bind("rotate", () => {
1484
- const angle = map.rotate();
1485
- callbacksRef.current.onRotate?.(angle);
1486
- });
1487
- map.Event.bind("pitch", () => {
1488
- const angle = map.pitch();
1489
- callbacksRef.current.onPitch?.(angle);
1490
- });
1491
- map.Event.bind("drag", () => {
1492
- callbacksRef.current.onDrag?.();
1493
- });
1494
- map.Event.bind("drop", () => {
1495
- callbacksRef.current.onDrop?.();
1496
- });
1497
- map.Event.bind("idle", () => {
1498
- callbacksRef.current.onIdle?.();
1499
- });
1500
- map.Event.bind("mousemove", (location) => {
1501
- callbacksRef.current.onMouseMove?.(location);
1502
- });
1503
- map.Event.bind("error", (error) => {
1504
- callbacksRef.current.onError?.(error);
1505
- });
1506
- } catch (error) {
1507
- callbacksRef.current.onError?.(
1508
- error instanceof Error ? error : new Error(String(error))
1509
- );
1510
- }
1511
- return () => {
1512
- unregisterMap();
1513
- mapRef.current = null;
1514
- setIsReady(false);
1515
- };
1516
- }, [isLoaded, sphere, registerMap, unregisterMap]);
1517
- (0, import_react11.useImperativeHandle)(
1518
- ref,
1519
- () => ({
1520
- getMap: () => mapRef.current,
1521
- setZoom: (newZoom, animate = true) => {
1522
- mapRef.current?.zoom(newZoom, animate);
1523
- },
1524
- setCenter: (location, animate = true) => {
1525
- mapRef.current?.location(location, animate);
1526
- },
1527
- setBound: (bound, options) => {
1528
- mapRef.current?.bound(bound, options);
1529
- },
1530
- goTo: (target, animate = true) => {
1531
- mapRef.current?.goTo(target, animate);
1532
- },
1533
- setRotate: (angle, animate = true) => {
1534
- mapRef.current?.rotate(angle, animate);
1535
- },
1536
- setPitch: (angle) => {
1537
- mapRef.current?.pitch(angle);
1538
- },
1539
- setFilter: (newFilter) => {
1540
- if (mapRef.current && window.sphere) {
1541
- mapRef.current.enableFilter(window.sphere.Filter[newFilter]);
1542
- }
1543
- },
1544
- resize: () => {
1545
- mapRef.current?.resize();
1546
- },
1547
- repaint: () => {
1548
- mapRef.current?.repaint();
1549
- }
1550
- }),
1551
- []
1552
- );
1553
- const containerStyle = {
1554
- width: "100%",
1555
- height: "100%",
1556
- ...style
1470
+ callbacksRef.current.onReady?.(map);
1471
+ });
1472
+ map.Event.bind("zoom", () => {
1473
+ const currentZoom = map.zoom();
1474
+ callbacksRef.current.onZoom?.(currentZoom);
1475
+ });
1476
+ map.Event.bind("location", () => {
1477
+ const currentLocation = map.location();
1478
+ callbacksRef.current.onLocation?.(currentLocation);
1479
+ });
1480
+ map.Event.bind("click", (location) => {
1481
+ callbacksRef.current.onClick?.(location);
1482
+ });
1483
+ map.Event.bind("doubleClick", (location) => {
1484
+ callbacksRef.current.onDoubleClick?.(location);
1485
+ });
1486
+ map.Event.bind("rotate", () => {
1487
+ const angle = map.rotate();
1488
+ callbacksRef.current.onRotate?.(angle);
1489
+ });
1490
+ map.Event.bind("pitch", () => {
1491
+ const angle = map.pitch();
1492
+ callbacksRef.current.onPitch?.(angle);
1493
+ });
1494
+ map.Event.bind("drag", () => {
1495
+ callbacksRef.current.onDrag?.();
1496
+ });
1497
+ map.Event.bind("drop", () => {
1498
+ callbacksRef.current.onDrop?.();
1499
+ });
1500
+ map.Event.bind("idle", () => {
1501
+ callbacksRef.current.onIdle?.();
1502
+ });
1503
+ map.Event.bind("mousemove", (location) => {
1504
+ callbacksRef.current.onMouseMove?.(location);
1505
+ });
1506
+ map.Event.bind("error", (error) => {
1507
+ callbacksRef.current.onError?.(error);
1508
+ });
1509
+ } catch (error) {
1510
+ callbacksRef.current.onError?.(
1511
+ error instanceof Error ? error : new Error(String(error))
1512
+ );
1513
+ }
1514
+ return () => {
1515
+ unregisterMap();
1516
+ mapRef.current = null;
1517
+ setIsReady(false);
1557
1518
  };
1558
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1559
- "div",
1560
- {
1561
- className,
1562
- id,
1563
- ref: containerRef,
1564
- style: containerStyle,
1565
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MapProvider, { isReady, map: mapRef.current, children: isReady && children })
1519
+ }, [isLoaded, sphere, registerMap, unregisterMap]);
1520
+ (0, import_react11.useImperativeHandle)(
1521
+ ref,
1522
+ () => ({
1523
+ getMap: () => mapRef.current,
1524
+ setZoom: (newZoom, animate = true) => {
1525
+ mapRef.current?.zoom(newZoom, animate);
1526
+ },
1527
+ setCenter: (location, animate = true) => {
1528
+ mapRef.current?.location(location, animate);
1529
+ },
1530
+ setBound: (bound, options) => {
1531
+ mapRef.current?.bound(bound, options);
1532
+ },
1533
+ goTo: (target, animate = true) => {
1534
+ mapRef.current?.goTo(target, animate);
1535
+ },
1536
+ setRotate: (angle, animate = true) => {
1537
+ mapRef.current?.rotate(angle, animate);
1538
+ },
1539
+ setPitch: (angle) => {
1540
+ mapRef.current?.pitch(angle);
1541
+ },
1542
+ setFilter: (newFilter) => {
1543
+ if (mapRef.current && window.sphere) {
1544
+ mapRef.current.enableFilter(window.sphere.Filter[newFilter]);
1545
+ }
1546
+ },
1547
+ resize: () => {
1548
+ mapRef.current?.resize();
1549
+ },
1550
+ repaint: () => {
1551
+ mapRef.current?.repaint();
1566
1552
  }
1567
- );
1568
- }
1569
- );
1570
- var SphereMap_default = SphereMap;
1553
+ }),
1554
+ []
1555
+ );
1556
+ const containerStyle = {
1557
+ width: "100%",
1558
+ height: "100%",
1559
+ ...style
1560
+ };
1561
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1562
+ "div",
1563
+ {
1564
+ className,
1565
+ id,
1566
+ ref: containerRef,
1567
+ style: containerStyle,
1568
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MapProvider, { isReady, map: mapRef.current, children: isReady && children })
1569
+ }
1570
+ );
1571
+ }
1571
1572
 
1572
1573
  // src/hooks/useMapEvent.ts
1573
1574
  var import_react12 = require("react");