gistda-sphere-react 1.0.0

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.
Files changed (41) hide show
  1. package/README.md +827 -0
  2. package/dist/index.d.mts +1081 -0
  3. package/dist/index.d.ts +1081 -0
  4. package/dist/index.js +2057 -0
  5. package/dist/index.mjs +2013 -0
  6. package/package.json +70 -0
  7. package/src/__tests__/Layer.test.tsx +133 -0
  8. package/src/__tests__/Marker.test.tsx +183 -0
  9. package/src/__tests__/SphereContext.test.tsx +120 -0
  10. package/src/__tests__/SphereMap.test.tsx +240 -0
  11. package/src/__tests__/geometry.test.tsx +454 -0
  12. package/src/__tests__/hooks.test.tsx +173 -0
  13. package/src/__tests__/setup.ts +204 -0
  14. package/src/__tests__/useMapControls.test.tsx +168 -0
  15. package/src/__tests__/useOverlays.test.tsx +265 -0
  16. package/src/__tests__/useRoute.test.tsx +219 -0
  17. package/src/__tests__/useSearch.test.tsx +205 -0
  18. package/src/__tests__/useTags.test.tsx +179 -0
  19. package/src/components/Circle.tsx +189 -0
  20. package/src/components/Dot.tsx +150 -0
  21. package/src/components/Layer.tsx +177 -0
  22. package/src/components/Marker.tsx +204 -0
  23. package/src/components/Polygon.tsx +223 -0
  24. package/src/components/Polyline.tsx +211 -0
  25. package/src/components/Popup.tsx +130 -0
  26. package/src/components/Rectangle.tsx +194 -0
  27. package/src/components/SphereMap.tsx +315 -0
  28. package/src/components/index.ts +18 -0
  29. package/src/context/MapContext.tsx +41 -0
  30. package/src/context/SphereContext.tsx +348 -0
  31. package/src/context/index.ts +15 -0
  32. package/src/hooks/index.ts +42 -0
  33. package/src/hooks/useMapEvent.ts +66 -0
  34. package/src/hooks/useOverlays.ts +278 -0
  35. package/src/hooks/useRoute.ts +232 -0
  36. package/src/hooks/useSearch.ts +143 -0
  37. package/src/hooks/useSphere.ts +18 -0
  38. package/src/hooks/useTags.ts +129 -0
  39. package/src/index.ts +124 -0
  40. package/src/types/index.ts +1 -0
  41. package/src/types/sphere.ts +671 -0
@@ -0,0 +1,129 @@
1
+ import { useCallback, useMemo } from "react";
2
+ import { useMap } from "../context/SphereContext";
3
+ import type { TagOptions, Tile } from "../types";
4
+
5
+ export type TagDataFunction = (tile: Tile) => object[];
6
+
7
+ export interface UseTagsReturn {
8
+ isReady: boolean;
9
+ set: (tag: string | TagDataFunction, options?: TagOptions) => void;
10
+ add: (tag: string | TagDataFunction, options?: TagOptions) => void;
11
+ remove: (tag: string) => void;
12
+ clear: () => void;
13
+ list: () => string[];
14
+ size: () => number;
15
+ enablePopup: (state: boolean) => void;
16
+ setLanguage: (lang: string) => void;
17
+ }
18
+
19
+ export interface TagDefinition {
20
+ id: string;
21
+ label: string;
22
+ }
23
+
24
+ export interface TagCategory {
25
+ name: string;
26
+ tags: TagDefinition[];
27
+ }
28
+
29
+ export const TAG_CATEGORIES: TagCategory[] = [
30
+ {
31
+ name: "Food & Dining",
32
+ tags: [
33
+ { id: "อาหารไทย", label: "Thai Food" },
34
+ { id: "อาหารญี่ปุ่น", label: "Japanese" },
35
+ { id: "อาหารจีน", label: "Chinese" },
36
+ { id: "อาหารเกาหลี", label: "Korean" },
37
+ { id: "อาหารเวียดนาม", label: "Vietnamese" },
38
+ { id: "อาหารอินเดีย", label: "Indian" },
39
+ { id: "อาหารอิตาลี", label: "Italian" },
40
+ { id: "อาหารฝรั่งเศส", label: "French" },
41
+ { id: "อาหารเยอรมัน", label: "German" },
42
+ { id: "อาหารยุโรป", label: "European" },
43
+ ],
44
+ },
45
+ {
46
+ name: "Services",
47
+ tags: [
48
+ { id: "ธนาคาร", label: "Bank" },
49
+ { id: "ATM", label: "ATM" },
50
+ { id: "โรงพยาบาล", label: "Hospital" },
51
+ { id: "ปั๊มน้ำมัน", label: "Gas Station" },
52
+ ],
53
+ },
54
+ {
55
+ name: "Tourism",
56
+ tags: [
57
+ { id: "โรงแรม", label: "Hotel" },
58
+ { id: "วัด", label: "Temple" },
59
+ { id: "พิพิธภัณฑ์", label: "Museum" },
60
+ { id: "ห้างสรรพสินค้า", label: "Shopping Mall" },
61
+ ],
62
+ },
63
+ ];
64
+
65
+ export function useTags(): UseTagsReturn {
66
+ const { map, isReady } = useMap();
67
+
68
+ const set = useCallback(
69
+ (tag: string | TagDataFunction, options?: TagOptions) => {
70
+ map?.Tags?.set(tag, options);
71
+ },
72
+ [map]
73
+ );
74
+
75
+ const add = useCallback(
76
+ (tag: string | TagDataFunction, options?: TagOptions) => {
77
+ map?.Tags?.add(tag, options);
78
+ },
79
+ [map]
80
+ );
81
+
82
+ const remove = useCallback(
83
+ (tag: string) => {
84
+ map?.Tags?.remove(tag);
85
+ },
86
+ [map]
87
+ );
88
+
89
+ const clear = useCallback(() => {
90
+ map?.Tags?.clear();
91
+ }, [map]);
92
+
93
+ const list = useCallback((): string[] => {
94
+ return map?.Tags?.list() ?? [];
95
+ }, [map]);
96
+
97
+ const size = useCallback((): number => {
98
+ return map?.Tags?.size() ?? 0;
99
+ }, [map]);
100
+
101
+ const enablePopup = useCallback(
102
+ (state: boolean) => {
103
+ map?.Tags?.enablePopup(state);
104
+ },
105
+ [map]
106
+ );
107
+
108
+ const setLanguage = useCallback(
109
+ (lang: string) => {
110
+ map?.Tags?.language(lang);
111
+ },
112
+ [map]
113
+ );
114
+
115
+ return useMemo(
116
+ () => ({
117
+ isReady,
118
+ set,
119
+ add,
120
+ remove,
121
+ clear,
122
+ list,
123
+ size,
124
+ enablePopup,
125
+ setLanguage,
126
+ }),
127
+ [isReady, set, add, remove, clear, list, size, enablePopup, setLanguage]
128
+ );
129
+ }
package/src/index.ts ADDED
@@ -0,0 +1,124 @@
1
+ export type {
2
+ CircleProps,
3
+ CircleRef,
4
+ DotProps,
5
+ DotRef,
6
+ LayerProps,
7
+ MarkerProps,
8
+ MarkerRef,
9
+ PolygonProps,
10
+ PolygonRef,
11
+ PolylineProps,
12
+ PolylineRef,
13
+ PopupProps,
14
+ PopupRef,
15
+ RectangleProps,
16
+ RectangleRef,
17
+ SphereMapProps,
18
+ SphereMapRef,
19
+ } from "./components";
20
+ export {
21
+ Circle,
22
+ Dot,
23
+ Layer,
24
+ Map,
25
+ Marker,
26
+ Polygon,
27
+ Polyline,
28
+ Popup,
29
+ Rectangle,
30
+ SphereMap,
31
+ } from "./components";
32
+ export type {
33
+ BuiltInLayer,
34
+ MapContextValue,
35
+ MapControls,
36
+ SphereContextValue,
37
+ SphereProviderProps,
38
+ } from "./context";
39
+ export {
40
+ MapProvider,
41
+ SphereProvider,
42
+ useMap,
43
+ useMapContext,
44
+ useMapControls,
45
+ useSphereContext,
46
+ } from "./context";
47
+ export type {
48
+ AddressResult,
49
+ BaseOverlay,
50
+ CircleData,
51
+ MarkerData,
52
+ OverlayInput,
53
+ PoiResult,
54
+ PolygonData,
55
+ PolylineData,
56
+ RouteGuideStep,
57
+ SearchResult,
58
+ TagCategory,
59
+ TagDataFunction,
60
+ TagDefinition,
61
+ UseOverlaysResult,
62
+ UseRouteReturn,
63
+ UseSearchReturn,
64
+ UseTagsReturn,
65
+ } from "./hooks";
66
+ export {
67
+ TAG_CATEGORIES,
68
+ useCircles,
69
+ useMapClick,
70
+ useMapEvent,
71
+ useMapLocation,
72
+ useMapReady,
73
+ useMapZoom,
74
+ useMarkers,
75
+ useOverlayClick,
76
+ useOverlays,
77
+ usePolygons,
78
+ usePolylines,
79
+ useRoute,
80
+ useSearch,
81
+ useSphere,
82
+ useTags,
83
+ } from "./hooks";
84
+ export type {
85
+ AddressOptions,
86
+ Bound,
87
+ EventHandler,
88
+ EventName,
89
+ FilterType,
90
+ FlyToOptions,
91
+ GeometryOptions,
92
+ Icon,
93
+ LayerOptions,
94
+ LayerType,
95
+ LineStyleType,
96
+ Location,
97
+ MapOptions,
98
+ MarkerOptions,
99
+ NearPoiOptions,
100
+ Point,
101
+ PopupOptions,
102
+ Range,
103
+ RouteLabelType,
104
+ RouteMode,
105
+ RouteType,
106
+ SearchOptions,
107
+ Size,
108
+ SphereCircle,
109
+ SphereDot,
110
+ SphereLayer,
111
+ SphereMap as SphereMapInstance,
112
+ SphereMarker,
113
+ SphereNamespace,
114
+ SphereOverlay,
115
+ SpherePolygon,
116
+ SpherePolyline,
117
+ SpherePopup,
118
+ SphereRectangle,
119
+ SuggestOptions,
120
+ TagOptions,
121
+ TagType,
122
+ Tile,
123
+ UiComponentMode,
124
+ } from "./types";
@@ -0,0 +1 @@
1
+ export * from "./sphere";