@react-fabric/map 1.0.0-beta.58

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/css/styles.css +40 -0
  4. package/dist/cjs/constants/index.js +49 -0
  5. package/dist/cjs/index.js +69 -0
  6. package/dist/cjs/layers/Json.js +31 -0
  7. package/dist/cjs/layers/Marker.js +47 -0
  8. package/dist/cjs/markers/Fill.js +80 -0
  9. package/dist/cjs/markers/Pin.js +92 -0
  10. package/dist/cjs/renderers/Heatmap.js +62 -0
  11. package/dist/cjs/renderers/Simple.js +51 -0
  12. package/dist/cjs/tools/BasemapGallery.js +80 -0
  13. package/dist/cjs/tools/Home.js +134 -0
  14. package/dist/cjs/tools/LayerList.js +43 -0
  15. package/dist/cjs/tools/ScaleBar.js +36 -0
  16. package/dist/cjs/tools/Zoom.js +40 -0
  17. package/dist/cjs/viewer/Context.js +132 -0
  18. package/dist/cjs/viewer/Viewer.js +29 -0
  19. package/dist/esm/constants/index.js +48 -0
  20. package/dist/esm/index.js +68 -0
  21. package/dist/esm/layers/Json.js +31 -0
  22. package/dist/esm/layers/Marker.js +46 -0
  23. package/dist/esm/markers/Fill.js +80 -0
  24. package/dist/esm/markers/Pin.js +92 -0
  25. package/dist/esm/renderers/Heatmap.js +62 -0
  26. package/dist/esm/renderers/Simple.js +51 -0
  27. package/dist/esm/tools/BasemapGallery.js +80 -0
  28. package/dist/esm/tools/Home.js +115 -0
  29. package/dist/esm/tools/LayerList.js +43 -0
  30. package/dist/esm/tools/ScaleBar.js +36 -0
  31. package/dist/esm/tools/Zoom.js +40 -0
  32. package/dist/esm/viewer/Context.js +131 -0
  33. package/dist/esm/viewer/Viewer.js +29 -0
  34. package/dist/types/constants/index.d.ts +22 -0
  35. package/dist/types/index.d.ts +73 -0
  36. package/dist/types/layers/Json.d.ts +1 -0
  37. package/dist/types/layers/Marker.d.ts +14 -0
  38. package/dist/types/markers/Fill.d.ts +12 -0
  39. package/dist/types/markers/Pin.d.ts +16 -0
  40. package/dist/types/renderers/Cluster.d.ts +19 -0
  41. package/dist/types/renderers/Heatmap.d.ts +18 -0
  42. package/dist/types/renderers/Simple.d.ts +38 -0
  43. package/dist/types/tools/BasemapGallery.d.ts +4 -0
  44. package/dist/types/tools/Home.d.ts +4 -0
  45. package/dist/types/tools/LayerList.d.ts +3 -0
  46. package/dist/types/tools/ScaleBar.d.ts +2 -0
  47. package/dist/types/tools/Zoom.d.ts +2 -0
  48. package/dist/types/types/index.d.ts +34 -0
  49. package/dist/types/viewer/Context.d.ts +16 -0
  50. package/dist/types/viewer/Viewer.d.ts +3 -0
  51. package/package.json +61 -0
  52. package/src/constants/index.ts +44 -0
  53. package/src/index.ts +65 -0
  54. package/src/layers/Json.tsx +52 -0
  55. package/src/layers/Marker.tsx +83 -0
  56. package/src/markers/Fill.tsx +117 -0
  57. package/src/markers/Pin.tsx +136 -0
  58. package/src/renderers/Cluster.tsx +99 -0
  59. package/src/renderers/Heatmap.tsx +99 -0
  60. package/src/renderers/Simple.tsx +97 -0
  61. package/src/tools/BasemapGallery.tsx +91 -0
  62. package/src/tools/Home.tsx +134 -0
  63. package/src/tools/LayerList.tsx +41 -0
  64. package/src/tools/ScaleBar.tsx +29 -0
  65. package/src/tools/Zoom.tsx +31 -0
  66. package/src/types/index.ts +54 -0
  67. package/src/viewer/Context.tsx +160 -0
  68. package/src/viewer/Viewer.tsx +42 -0
@@ -0,0 +1,91 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import Basemap from "@arcgis/core/Basemap";
25
+ import VectorTileLayer from "@arcgis/core/layers/VectorTileLayer";
26
+ import LocalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/LocalBasemapsSource";
27
+ import {
28
+ ArcgisBasemapGallery,
29
+ ArcgisBasemapLayerList,
30
+ ArcgisExpand,
31
+ } from "@arcgis/map-components-react";
32
+ import "@arcgis/map-components/components/arcgis-basemap-gallery";
33
+ import "@arcgis/map-components/components/arcgis-basemap-layer-list";
34
+ import "@arcgis/map-components/components/arcgis-expand";
35
+ import { useMap } from "../viewer/Context";
36
+
37
+ export const BasemapGallery = () => {
38
+ const { basemaps, map } = useMap();
39
+ return (
40
+ <>
41
+ <ArcgisExpand
42
+ className="mb-2"
43
+ expandIcon="basemap"
44
+ collapseIcon="x"
45
+ mode="floating"
46
+ slot="top-right"
47
+ autoCollapse
48
+ >
49
+ <ArcgisBasemapGallery
50
+ source={
51
+ new LocalBasemapsSource({
52
+ basemaps: basemaps.map(
53
+ (map) =>
54
+ new Basemap({
55
+ title: map.title,
56
+ thumbnailUrl: map.thumbnail,
57
+ baseLayers: map.layers.map(
58
+ (layer) =>
59
+ new VectorTileLayer(
60
+ "url" in layer
61
+ ? {
62
+ url: layer.url,
63
+ }
64
+ : {
65
+ portalItem: {
66
+ id: layer.portalId,
67
+ },
68
+ },
69
+ ),
70
+ ),
71
+ }),
72
+ ),
73
+ })
74
+ }
75
+ />
76
+ </ArcgisExpand>
77
+ {(map?.basemap?.baseLayers.length ?? 1) > 1 && (
78
+ <ArcgisExpand
79
+ className="mb-2"
80
+ expandIcon="layer-map"
81
+ collapseIcon="x"
82
+ mode="floating"
83
+ slot="top-right"
84
+ autoCollapse
85
+ >
86
+ <ArcgisBasemapLayerList />
87
+ </ArcgisExpand>
88
+ )}
89
+ </>
90
+ );
91
+ };
@@ -0,0 +1,134 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import * as reactiveUtils from "@arcgis/core/core/reactiveUtils";
25
+ import Point from "@arcgis/core/geometry/Point";
26
+ import Viewpoint from "@arcgis/core/Viewpoint";
27
+ import { ArcgisPlacement } from "@arcgis/map-components-react";
28
+ import "@arcgis/map-components/components/arcgis-placement";
29
+ import { CalciteButton } from "@esri/calcite-components-react";
30
+ import { debounce, getLatitudeLongitude } from "@react-fabric/utilities";
31
+ import { useCallback, useEffect, useRef, useState } from "react";
32
+ import { useMap } from "../viewer/Context";
33
+
34
+ export const Home = ({ enableHistory }: { enableHistory?: boolean }) => {
35
+ const { map, view, disableDrag, center, zoom } = useMap();
36
+
37
+ const isNavigatingHistory = useRef(false);
38
+ const currentIndex = useRef(0);
39
+ const [history, setHistory] = useState<any[]>([]);
40
+ const [activeIndex, setActiveIndex] = useState(0);
41
+
42
+ useEffect(() => {
43
+ currentIndex.current = activeIndex;
44
+ }, [activeIndex]);
45
+
46
+ useEffect(() => {
47
+ if (enableHistory && !disableDrag && view) {
48
+ const addHistory = debounce((viewpoint) => {
49
+ if (!isNavigatingHistory.current) {
50
+ setHistory((h) => {
51
+ // Keep max 25 history entries
52
+ const newHistory = h.slice(0, currentIndex.current + 1).slice(-24);
53
+ // Add new viewpoint to history
54
+ newHistory.push(viewpoint.clone());
55
+ setActiveIndex(newHistory.length - 1);
56
+ return newHistory;
57
+ });
58
+ }
59
+ isNavigatingHistory.current = false;
60
+ });
61
+ const watcher = reactiveUtils.watch(() => view.viewpoint, addHistory);
62
+ return () => {
63
+ watcher.remove();
64
+ };
65
+ }
66
+ }, [disableDrag, enableHistory, view]);
67
+
68
+ const navigate = useCallback(
69
+ (idx: number) => {
70
+ if (history.length > 0 && history[idx] && view) {
71
+ isNavigatingHistory.current = true;
72
+ view.goTo(history[idx]);
73
+ setActiveIndex(idx);
74
+ }
75
+ },
76
+ [history],
77
+ );
78
+
79
+ const gotoHome = useCallback(() => {
80
+ if (view) {
81
+ let extent: any;
82
+ map?.layers.forEach((layer) => {
83
+ if (layer.visible && layer.fullExtent) {
84
+ if (extent) {
85
+ extent = extent.union(layer.fullExtent);
86
+ } else {
87
+ extent = layer.fullExtent;
88
+ }
89
+ }
90
+ });
91
+ view.goTo(
92
+ extent ??
93
+ new Viewpoint({
94
+ scale: view.tileInfo?.zoomToScale(zoom),
95
+ targetGeometry: new Point(getLatitudeLongitude(center)),
96
+ }),
97
+ );
98
+ }
99
+ }, [center, zoom, view, map]);
100
+
101
+ return (
102
+ !disableDrag && (
103
+ <ArcgisPlacement
104
+ slot="top-left"
105
+ className="mb-2 flex flex-col divide-y divide-tint-100"
106
+ >
107
+ {enableHistory && (
108
+ <CalciteButton
109
+ appearance="solid"
110
+ kind="neutral"
111
+ iconStart="arrow-left"
112
+ disabled={activeIndex <= 0}
113
+ onClick={() => navigate(activeIndex - 1)}
114
+ />
115
+ )}
116
+ <CalciteButton
117
+ appearance="solid"
118
+ kind="neutral"
119
+ iconStart="home"
120
+ onClick={() => gotoHome()}
121
+ />
122
+ {enableHistory && (
123
+ <CalciteButton
124
+ appearance="solid"
125
+ kind="neutral"
126
+ iconStart="arrow-right"
127
+ disabled={activeIndex >= history.length - 1}
128
+ onClick={() => navigate(activeIndex + 1)}
129
+ />
130
+ )}
131
+ </ArcgisPlacement>
132
+ )
133
+ );
134
+ };
@@ -0,0 +1,41 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { ArcgisExpand, ArcgisLayerList } from "@arcgis/map-components-react";
25
+ import "@arcgis/map-components/components/arcgis-expand";
26
+ import "@arcgis/map-components/components/arcgis-layer-list";
27
+
28
+ export const LayerList = () => {
29
+ return (
30
+ <ArcgisExpand
31
+ expandIcon="layers"
32
+ className="mb-2"
33
+ collapseIcon="x"
34
+ mode="floating"
35
+ slot="top-right"
36
+ autoCollapse
37
+ >
38
+ <ArcgisLayerList />
39
+ </ArcgisExpand>
40
+ );
41
+ };
@@ -0,0 +1,29 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { ArcgisScaleBar } from "@arcgis/map-components-react";
25
+ import "@arcgis/map-components/components/arcgis-scale-bar";
26
+
27
+ export const ScaleBar = () => {
28
+ return <ArcgisScaleBar slot="bottom-left" />;
29
+ };
@@ -0,0 +1,31 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { ArcgisZoom } from "@arcgis/map-components-react";
25
+ import "@arcgis/map-components/components/arcgis-zoom";
26
+ import { useMap } from "../viewer/Context";
27
+
28
+ export const Zoom = () => {
29
+ const { disableZoom } = useMap();
30
+ return !disableZoom && <ArcgisZoom slot="top-left" className="mb-2" />;
31
+ };
@@ -0,0 +1,54 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import { LngLatLike } from "@react-fabric/utilities";
25
+ import { ReactNode } from "react";
26
+
27
+ export interface FabricBaseMap {
28
+ title?: string;
29
+ thumbnail?: string;
30
+ default?: boolean;
31
+ layers: Array<{ url: string } | { portalId: string }>;
32
+ }
33
+
34
+ export interface MapViewerProps {
35
+ children?: ReactNode;
36
+ /**
37
+ * Initial center position of the map viewer.
38
+ */
39
+ center?: LngLatLike;
40
+ /**
41
+ * Initial zoom level of the map viewer.
42
+ */
43
+ zoom?: number;
44
+ /**
45
+ * Basemaps to be used in the map viewer.
46
+ */
47
+ basemaps?: FabricBaseMap[];
48
+
49
+ enable3D?: boolean;
50
+ disableZoom?: boolean;
51
+ disableDrag?: boolean;
52
+
53
+ onClick?: (loc: { latitude: number; longitude: number }) => void;
54
+ }
@@ -0,0 +1,160 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import Basemap from "@arcgis/core/Basemap";
25
+ import Point from "@arcgis/core/geometry/Point";
26
+ import SpatialReference from "@arcgis/core/geometry/SpatialReference";
27
+ import VectorTileLayer from "@arcgis/core/layers/VectorTileLayer";
28
+ import { ArcgisMap, ArcgisScene } from "@arcgis/map-components-react";
29
+ import "@arcgis/map-components/components/arcgis-map";
30
+ import "@arcgis/map-components/components/arcgis-popup";
31
+ import "@arcgis/map-components/components/arcgis-scene";
32
+ import { CalciteButton } from "@esri/calcite-components-react";
33
+ import { getLatitudeLongitude, LngLatLike } from "@react-fabric/utilities";
34
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
35
+ import { BASEMAPS, DEFAULT_VIEWPOINT } from "../constants";
36
+ import { FabricBaseMap, MapViewerProps } from "../types";
37
+
38
+ const Context = createContext<{
39
+ map?: __esri.Map | null;
40
+ view?: __esri.MapView | __esri.SceneView;
41
+ disableDrag?: boolean;
42
+ disableZoom?: boolean;
43
+ basemaps: FabricBaseMap[];
44
+ center: LngLatLike;
45
+ zoom: number;
46
+ is3D: boolean;
47
+ }>({} as any);
48
+
49
+ export const MapProvider = ({
50
+ children,
51
+ onClick,
52
+ basemaps = BASEMAPS,
53
+ center = DEFAULT_VIEWPOINT.point,
54
+ zoom = DEFAULT_VIEWPOINT.zoom,
55
+ enable3D = false,
56
+ disableDrag = false,
57
+ disableZoom = false,
58
+ }: MapViewerProps) => {
59
+ const [map, setMap] = useState<__esri.Map | null>(null);
60
+ const [view, setView] = useState<__esri.MapView | __esri.SceneView>();
61
+ const [is3D, setIs3D] = useState(false);
62
+
63
+ const defaultBaseMap = useMemo(
64
+ () => basemaps.find((b) => b.default) ?? basemaps[0],
65
+ [basemaps],
66
+ );
67
+
68
+ useEffect(() => {
69
+ view?.navigation.set("actionMap", {
70
+ dragPrimary: disableDrag ? "none" : "pan",
71
+ dragSecondary: !disableDrag && is3D ? "rotate" : "none",
72
+ dragTertiary: disableZoom ? "none" : "zoom",
73
+ mouseWheel: disableZoom ? "none" : "zoom",
74
+ });
75
+ }, [view, disableDrag, disableZoom, is3D]);
76
+
77
+ useEffect(() => {
78
+ if (view && onClick) {
79
+ const handleClick = view.on("click", (event: __esri.ViewClickEvent) => {
80
+ event.button === 0 &&
81
+ onClick({
82
+ latitude: event.mapPoint.latitude ?? 0,
83
+ longitude: event.mapPoint.longitude ?? 0,
84
+ });
85
+ });
86
+ return () => {
87
+ handleClick.remove();
88
+ };
89
+ }
90
+ }, [view, onClick]);
91
+
92
+ const E = useMemo(
93
+ () => (enable3D && is3D ? ArcgisScene : ArcgisMap),
94
+ [is3D, enable3D],
95
+ );
96
+
97
+ return (
98
+ <Context.Provider
99
+ value={{
100
+ map,
101
+ view,
102
+ is3D,
103
+ disableDrag,
104
+ disableZoom,
105
+ basemaps,
106
+ center,
107
+ zoom,
108
+ }}
109
+ >
110
+ <E
111
+ onArcgisViewReadyChange={(e) => {
112
+ e.target.map && setMap(e.target.map);
113
+ e.target.view && setView(e.target.view);
114
+ }}
115
+ className="area-content overflow-hidden"
116
+ basemap={
117
+ new Basemap({
118
+ baseLayers: defaultBaseMap?.layers.map(
119
+ (layer) =>
120
+ new VectorTileLayer(
121
+ "url" in layer
122
+ ? {
123
+ url: layer.url,
124
+ }
125
+ : {
126
+ portalItem: {
127
+ id: layer.portalId,
128
+ },
129
+ },
130
+ ),
131
+ ),
132
+ title: defaultBaseMap?.title,
133
+ thumbnailUrl: defaultBaseMap?.thumbnail,
134
+ })
135
+ }
136
+ zoom={zoom}
137
+ center={new Point(getLatitudeLongitude(center))}
138
+ spatialReference={
139
+ new SpatialReference({
140
+ wkid: 3857,
141
+ })
142
+ }
143
+ >
144
+ {enable3D && (
145
+ <CalciteButton
146
+ appearance="solid"
147
+ kind="neutral"
148
+ slot="top-right"
149
+ className="mb-2"
150
+ iconStart={is3D ? "layer-basemap" : "globe"}
151
+ onClick={() => setIs3D((n) => !n)}
152
+ />
153
+ )}
154
+ {children}
155
+ </E>
156
+ </Context.Provider>
157
+ );
158
+ };
159
+
160
+ export const useMap = () => useContext(Context);
@@ -0,0 +1,42 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ import "@arcgis/core/assets/esri/themes/light/main.css";
25
+ import { Section, useIsDark } from "@react-fabric/core";
26
+ import { useEffect } from "react";
27
+ import { MapViewerProps } from "../types";
28
+ import { MapProvider } from "./Context";
29
+
30
+ export const MapViewer = ({ children, ...props }: MapViewerProps) => {
31
+ const isDark = useIsDark();
32
+
33
+ useEffect(() => {
34
+ document.documentElement.classList.toggle("calcite-mode-dark", isDark);
35
+ }, [isDark]);
36
+
37
+ return (
38
+ <Section className="relative">
39
+ <MapProvider {...props}>{children}</MapProvider>
40
+ </Section>
41
+ );
42
+ };