@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,52 @@
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 GeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer";
25
+ import SizeVariable from "@arcgis/core/renderers/visualVariables/SizeVariable";
26
+ import { useEffect, useMemo } from "react";
27
+ import { useMap } from "../viewer/Context";
28
+
29
+ export const JsonLayer = (props: __esri.GeoJSONLayerProperties) => {
30
+ const { map, view } = useMap();
31
+
32
+ const layer = useMemo(() => {
33
+ return new GeoJSONLayer({
34
+ ...props,
35
+ });
36
+ }, [props]);
37
+
38
+ useEffect(() => {
39
+ if (map && view) {
40
+ layer.when(() => {
41
+ view.goTo(layer.fullExtent);
42
+ });
43
+ map.add(layer);
44
+
45
+ return () => {
46
+ map.remove(layer);
47
+ };
48
+ }
49
+ }, [map, view, layer]);
50
+
51
+ return null;
52
+ };
@@ -0,0 +1,83 @@
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 GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
25
+ import "@arcgis/map-components/components/arcgis-features";
26
+ import {
27
+ createContext,
28
+ ReactElement,
29
+ useContext,
30
+ useEffect,
31
+ useMemo,
32
+ } from "react";
33
+ import { Fill } from "../markers/Fill";
34
+ import { Pin } from "../markers/Pin";
35
+ import { useMap } from "../viewer/Context";
36
+
37
+ const MarkerContext = createContext<__esri.GraphicsLayer>(null!);
38
+
39
+ type MarkerChildren = ReactElement<typeof Fill | typeof Pin>;
40
+
41
+ /**
42
+ * MarkerLayer component for displaying a layer of markers on the map.
43
+ */
44
+ export const MarkerLayer = ({
45
+ children,
46
+ ...props
47
+ }: Omit<__esri.GraphicsLayerProperties, "graphics"> & {
48
+ children?: MarkerChildren | MarkerChildren[];
49
+ }) => {
50
+ const { map, view } = useMap();
51
+
52
+ const layer = useMemo(
53
+ () =>
54
+ new GraphicsLayer(
55
+ Object.assign(
56
+ {
57
+ visible: true,
58
+ listMode: "show",
59
+ },
60
+ props,
61
+ ),
62
+ ),
63
+ [props],
64
+ );
65
+
66
+ useEffect(() => {
67
+ if (map && view) {
68
+ view?.when(() => {
69
+ map?.layers.add(layer);
70
+ });
71
+
72
+ return () => {
73
+ map?.layers.remove(layer);
74
+ };
75
+ }
76
+ }, [layer, map, view]);
77
+
78
+ return (
79
+ <MarkerContext.Provider value={layer}>{children}</MarkerContext.Provider>
80
+ );
81
+ };
82
+
83
+ export const useMarkerLayer = () => useContext(MarkerContext);
@@ -0,0 +1,117 @@
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 Polygon from "@arcgis/core/geometry/Polygon";
25
+ import Graphic from "@arcgis/core/Graphic";
26
+ import SimpleFillSymbol from "@arcgis/core/symbols/SimpleFillSymbol";
27
+ import { LngLatLike, convertLatLng } from "@react-fabric/utilities";
28
+ import { useEffect, useMemo } from "react";
29
+ import { useMarkerLayer } from "../layers/Marker";
30
+ import Color from "color";
31
+ import { useMap } from "../viewer/Context";
32
+
33
+ /**
34
+ * Fill graphic for displaying a fill polygon on the map.
35
+ */
36
+ export const Fill = ({
37
+ coords,
38
+ style = "solid",
39
+ color = "#f00",
40
+ borderWidth,
41
+ borderColor,
42
+ animate,
43
+ ...props
44
+ }: {
45
+ coords: LngLatLike[];
46
+ color?: string;
47
+ style?:
48
+ | "backward-diagonal"
49
+ | "cross"
50
+ | "diagonal-cross"
51
+ | "forward-diagonal"
52
+ | "horizontal"
53
+ | "none"
54
+ | "solid"
55
+ | "vertical";
56
+ borderWidth?: string | number;
57
+ borderColor?: string;
58
+ animate?: boolean;
59
+ } & Omit<__esri.GraphicProperties, "geometry" | "symbol">) => {
60
+ const layer = useMarkerLayer();
61
+ const { is3D } = useMap();
62
+
63
+ const graphic = useMemo(
64
+ () =>
65
+ new Graphic({
66
+ geometry: new Polygon({
67
+ rings: [coords.map(convertLatLng)],
68
+ }),
69
+ symbol: new SimpleFillSymbol(
70
+ Object.assign({
71
+ style,
72
+ color,
73
+ outline: {
74
+ color: borderColor,
75
+ width: borderWidth,
76
+ },
77
+ } as any),
78
+ ),
79
+ ...props,
80
+ }),
81
+ [coords, style, color, borderColor, borderWidth, props],
82
+ );
83
+
84
+ useEffect(() => {
85
+ if (layer && coords) {
86
+ let tmr: any = null;
87
+ layer.when(() => {
88
+ layer.add(graphic);
89
+ if (animate && !is3D) {
90
+ let up = 0.1;
91
+ let sat = 0;
92
+ const symbol = graphic.symbol as SimpleFillSymbol;
93
+ const color = symbol.color.toRgba();
94
+ tmr = setInterval(() => {
95
+ if (sat >= 0.9) up = -0.1;
96
+ if (sat <= 0.1) up = 0.1;
97
+ sat += up;
98
+ symbol.color = Color.rgb([...color])
99
+ .darken(sat)
100
+ .rgb()
101
+ .array();
102
+ requestAnimationFrame(() => {
103
+ graphic.symbol = symbol.clone();
104
+ });
105
+ }, 100);
106
+ }
107
+ });
108
+
109
+ return () => {
110
+ clearInterval(tmr);
111
+ layer.remove(graphic);
112
+ };
113
+ }
114
+ }, [layer, graphic, animate, is3D]);
115
+
116
+ return null;
117
+ };
@@ -0,0 +1,136 @@
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 Point from "@arcgis/core/geometry/Point";
25
+ import Graphic from "@arcgis/core/Graphic";
26
+ import SimpleMarkerSymbol from "@arcgis/core/symbols/SimpleMarkerSymbol";
27
+ import { LngLatLike, getLatitudeLongitude } from "@react-fabric/utilities";
28
+ import { useEffect, useMemo } from "react";
29
+ import { useMarkerLayer } from "../layers/Marker";
30
+ import { useMap } from "../viewer/Context";
31
+
32
+ type Markers = "pin" | "pin-radius" | "marker" | "marker-radius";
33
+ const paths: Record<Markers, string> = {
34
+ marker:
35
+ "M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z",
36
+ "marker-radius":
37
+ "M12,2C15.31,2 18,4.66 18,7.95C18,12.41 12,19 12,19C12,19 6,12.41 6,7.95C6,4.66 8.69,2 12,2M12,6A2,2 0 0,0 10,8A2,2 0 0,0 12,10A2,2 0 0,0 14,8A2,2 0 0,0 12,6M20,19C20,21.21 16.42,23 12,23C7.58,23 4,21.21 4,19C4,17.71 5.22,16.56 7.11,15.83L7.75,16.74C6.67,17.19 6,17.81 6,18.5C6,19.88 8.69,21 12,21C15.31,21 18,19.88 18,18.5C18,17.81 17.33,17.19 16.25,16.74L16.89,15.83C18.78,16.56 20,17.71 20,19Z",
38
+ pin: "M12 14.571c0.589 0 1.165-0.067 1.714-0.201v8.772c0 0.469-0.388 0.857-0.857 0.857h-1.714c-0.469 0-0.857-0.388-0.857-0.857v-8.772c0.549 0.134 1.125 0.201 1.714 0.201zM12 0c3.79 0 6.857 3.067 6.857 6.857s-3.067 6.857-6.857 6.857-6.857-3.067-6.857-6.857 3.067-6.857 6.857-6.857zM12 3c0.241 0 0.429-0.188 0.429-0.429s-0.188-0.429-0.429-0.429c-2.598 0-4.714 2.116-4.714 4.714 0 0.241 0.188 0.429 0.429 0.429s0.429-0.188 0.429-0.429c0-2.129 1.728-3.857 3.857-3.857z",
39
+ "pin-radius":
40
+ "M12.479 20.11v-0.956c3.218 0.095 5.754 1.127 5.754 2.388 0 1.324-2.79 2.458-6.233 2.458s-6.233-1.134-6.233-2.458c0-1.261 2.536-2.294 5.753-2.388v0.956c-2.687 0.066-4.794 0.682-4.794 1.432 0 0.794 2.361 1.558 5.274 1.558s5.273-0.764 5.273-1.558c-0.001-0.75-2.107-1.364-4.794-1.432zM6.734 5.274c0-2.912 2.421-5.274 5.335-5.274s5.274 2.362 5.274 5.274c0 2.503-1.746 4.595-4.086 5.135l-1.257 12.692-1.261-12.728c-2.268-0.59-4.005-2.646-4.005-5.099zM11.999 3.862c0-0.795-0.644-1.438-1.438-1.438s-1.439 0.643-1.439 1.438c0 0.794 0.644 1.438 1.439 1.438s1.438-0.643 1.438-1.438z",
41
+ };
42
+
43
+ /**
44
+ * Pin graphic for displaying a pin on the map.
45
+ */
46
+ export const Pin = ({
47
+ coords,
48
+ style = "circle",
49
+ size = 18,
50
+ color = "#f00",
51
+ path,
52
+ borderWidth,
53
+ borderColor,
54
+ animate,
55
+ ...props
56
+ }: {
57
+ coords: LngLatLike;
58
+ size?: string | number;
59
+ color?: string;
60
+ path?: string;
61
+ style?:
62
+ | "circle"
63
+ | "square"
64
+ | "cross"
65
+ | "x"
66
+ | "diamond"
67
+ | "triangle"
68
+ | Markers;
69
+ borderWidth?: string | number;
70
+ borderColor?: string;
71
+ animate?: boolean;
72
+ } & Omit<__esri.GraphicProperties, "geometry" | "symbol">) => {
73
+ const layer = useMarkerLayer();
74
+ const { is3D } = useMap();
75
+
76
+ const graphic = useMemo(
77
+ () =>
78
+ new Graphic({
79
+ geometry: new Point(getLatitudeLongitude(coords)),
80
+ symbol: new SimpleMarkerSymbol(
81
+ Object.assign(
82
+ {
83
+ style,
84
+ color,
85
+ size,
86
+ outline: {
87
+ color: borderColor,
88
+ width: borderWidth,
89
+ },
90
+ } as any,
91
+ style && style.toString() in paths
92
+ ? {
93
+ path: (paths as any)[style.toString()],
94
+ style: "path",
95
+ }
96
+ : {},
97
+ path ? { path, style: "path" } : {},
98
+ ),
99
+ ),
100
+ ...props,
101
+ }),
102
+ [coords, style, size, color, borderColor, borderWidth, path, props],
103
+ );
104
+
105
+ useEffect(() => {
106
+ if (layer && coords) {
107
+ let tmr: any = null;
108
+ layer.when(() => {
109
+ layer.add(graphic);
110
+ const symbol = graphic.symbol as SimpleMarkerSymbol;
111
+ if (symbol.style === "path")
112
+ symbol.yoffset = (symbol.size as number) / 2;
113
+ if (animate && !is3D) {
114
+ const baseSize = symbol.size;
115
+ let up = 2;
116
+ tmr = setInterval(() => {
117
+ symbol.size += up;
118
+ if (symbol.size > baseSize + 20) up = -2;
119
+ if (symbol.size <= baseSize) up = 2;
120
+ if (symbol.style === "path") symbol.yoffset = symbol.size / 2;
121
+ requestAnimationFrame(() => {
122
+ graphic.symbol = symbol.clone();
123
+ });
124
+ }, 100);
125
+ }
126
+ });
127
+
128
+ return () => {
129
+ clearInterval(tmr);
130
+ layer.remove(graphic);
131
+ };
132
+ }
133
+ }, [layer, graphic, animate, is3D]);
134
+
135
+ return null;
136
+ };
@@ -0,0 +1,99 @@
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 HeatmapRenderer from "@arcgis/core/renderers/HeatmapRenderer";
25
+ import Color from "color";
26
+ import { useMemo } from "react";
27
+
28
+ interface Props {
29
+ /**
30
+ * Field name to be used for heatmap intensity
31
+ */
32
+ field: string;
33
+ /**
34
+ * Colors for the heatmap gradient. Default is a red to yellow gradient.
35
+ *
36
+ * [color]: creates a color gradient from light to dark
37
+ * [color1, color2]: creates a gradient from color1 to color2
38
+ * [color1, color2, color3]: creates a multi-stop gradient color1 to color2 to color3
39
+ */
40
+ colors?: string[];
41
+
42
+ minDensity?: __esri.HeatmapRendererProperties["minDensity"];
43
+ maxDensity?: __esri.HeatmapRendererProperties["maxDensity"];
44
+ }
45
+
46
+ export const useHeatmapRenderer = (props?: Props) => {
47
+ const renderer = useMemo(() => {
48
+ let colorHigh = "#FFE600FF";
49
+ let colorMid = "#FF8C00FF";
50
+ let colorLow = "#FF3300FF";
51
+
52
+ if (props?.colors?.length === 1) {
53
+ colorHigh = Color(props.colors[0]).lightness(95).toString();
54
+ colorLow = Color(props.colors[0]).lightness(25).toString();
55
+ colorMid = Color(colorHigh).mix(Color(colorLow), 0.5).toString();
56
+ }
57
+
58
+ if (props?.colors?.length === 2) {
59
+ colorHigh = props.colors[0];
60
+ colorLow = props.colors[1];
61
+ colorMid = Color(colorHigh).mix(Color(colorLow), 0.5).toString();
62
+ }
63
+
64
+ if (props?.colors?.length === 3) {
65
+ colorHigh = props.colors[0];
66
+ colorMid = props.colors[1];
67
+ colorLow = props.colors[2];
68
+ }
69
+
70
+ const colors =
71
+ props?.colors && props.colors.length > 3
72
+ ? props.colors.map((color, index, arr) => ({
73
+ ratio: (index + 1) / arr.length,
74
+ color: color,
75
+ }))
76
+ : [
77
+ ...Array.from({ length: 6 }, (_, i) => ({
78
+ ratio: (i + 1) / 12,
79
+ color: Color(colorLow)
80
+ .mix(Color(colorMid), i / 6)
81
+ .toString(),
82
+ })),
83
+ ...Array.from({ length: 6 }, (_, i) => ({
84
+ ratio: (i + 6) / 12,
85
+ color: Color(colorMid)
86
+ .mix(Color(colorHigh), i / 6)
87
+ .toString(),
88
+ })),
89
+ ];
90
+
91
+ return new HeatmapRenderer({
92
+ field: props?.field,
93
+ colorStops: [{ color: "#00000000", ratio: 0 }, ...colors],
94
+ minDensity: props?.minDensity ?? 0,
95
+ maxDensity: props?.maxDensity ?? 0.1,
96
+ });
97
+ }, [props]);
98
+ return renderer;
99
+ };
@@ -0,0 +1,99 @@
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 HeatmapRenderer from "@arcgis/core/renderers/HeatmapRenderer";
25
+ import Color from "color";
26
+ import { useMemo } from "react";
27
+
28
+ export interface Props {
29
+ /**
30
+ * Field name to be used for heatmap intensity
31
+ */
32
+ field: string;
33
+ /**
34
+ * Colors for the heatmap gradient. Default is a red to yellow gradient.
35
+ *
36
+ * [color]: creates a color gradient from light to dark
37
+ * [color1, color2]: creates a gradient from color1 to color2
38
+ * [color1, color2, color3]: creates a multi-stop gradient color1 to color2 to color3
39
+ */
40
+ colors?: string[];
41
+
42
+ minDensity?: __esri.HeatmapRendererProperties["minDensity"];
43
+ maxDensity?: __esri.HeatmapRendererProperties["maxDensity"];
44
+ }
45
+
46
+ export const useHeatmapRenderer = (props?: Props) => {
47
+ const renderer = useMemo(() => {
48
+ let colorHigh = "#FFE600FF";
49
+ let colorMid = "#FF8C00FF";
50
+ let colorLow = "#FF3300FF";
51
+
52
+ if (props?.colors?.length === 1) {
53
+ colorHigh = Color(props.colors[0]).lightness(95).toString();
54
+ colorLow = Color(props.colors[0]).lightness(25).toString();
55
+ colorMid = Color(colorHigh).mix(Color(colorLow), 0.5).toString();
56
+ }
57
+
58
+ if (props?.colors?.length === 2) {
59
+ colorHigh = props.colors[0];
60
+ colorLow = props.colors[1];
61
+ colorMid = Color(colorHigh).mix(Color(colorLow), 0.5).toString();
62
+ }
63
+
64
+ if (props?.colors?.length === 3) {
65
+ colorHigh = props.colors[0];
66
+ colorMid = props.colors[1];
67
+ colorLow = props.colors[2];
68
+ }
69
+
70
+ const colors =
71
+ props?.colors && props.colors.length > 3
72
+ ? props.colors.map((color, index, arr) => ({
73
+ ratio: (index + 1) / arr.length,
74
+ color: color,
75
+ }))
76
+ : [
77
+ ...Array.from({ length: 6 }, (_, i) => ({
78
+ ratio: (i + 1) / 12,
79
+ color: Color(colorLow)
80
+ .mix(Color(colorMid), i / 6)
81
+ .toString(),
82
+ })),
83
+ ...Array.from({ length: 6 }, (_, i) => ({
84
+ ratio: (i + 6) / 12,
85
+ color: Color(colorMid)
86
+ .mix(Color(colorHigh), i / 6)
87
+ .toString(),
88
+ })),
89
+ ];
90
+
91
+ return new HeatmapRenderer({
92
+ field: props?.field,
93
+ colorStops: [{ color: "#00000000", ratio: 0 }, ...colors],
94
+ minDensity: props?.minDensity ?? 0,
95
+ maxDensity: props?.maxDensity ?? 0.1,
96
+ });
97
+ }, [props]);
98
+ return renderer;
99
+ };
@@ -0,0 +1,97 @@
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 SimpleRenderer from "@arcgis/core/renderers/SimpleRenderer";
25
+ import { useMemo } from "react";
26
+
27
+ export interface Props {
28
+ /**
29
+ * Color of the marker fill. Default is "blue"
30
+ */
31
+ color?: string;
32
+ /**
33
+ * Size of the marker. Default is 4
34
+ */
35
+ size?: number | string;
36
+ /**
37
+ * Path to a custom marker icon.
38
+ */
39
+ path?: string;
40
+ /**
41
+ * Style of the marker. Default is "circle"
42
+ */
43
+ style?: "circle" | "square" | "cross" | "x" | "diamond" | "triangle";
44
+ /**
45
+ * Border color of the marker. Default is "white"
46
+ */
47
+ borderColor?: string;
48
+ /**
49
+ * Border width of the marker. Default is 1
50
+ */
51
+ borderWidth?: number;
52
+
53
+ sizeField?: string;
54
+ sizeStops?: Array<{ value: number; size: number | string }>;
55
+
56
+ colorField?: string;
57
+ colorStops?: Array<{ value: number; color: string }>;
58
+ }
59
+
60
+ export const useSimpleRenderer = (props?: Props) => {
61
+ const renderer = useMemo(() => {
62
+ const vizVars = [];
63
+ let styleProps: any = { style: props?.style ?? "circle" };
64
+ if (props?.path) {
65
+ styleProps.style = "path";
66
+ styleProps.path = props.path;
67
+ }
68
+ if (props?.sizeStops && props.sizeField) {
69
+ vizVars.push({
70
+ type: "size",
71
+ field: props.sizeField,
72
+ stops: props.sizeStops,
73
+ });
74
+ }
75
+ if (props?.colorStops && props.colorField) {
76
+ vizVars.push({
77
+ type: "color",
78
+ field: props.colorField,
79
+ stops: props.colorStops,
80
+ });
81
+ }
82
+ return new SimpleRenderer({
83
+ symbol: {
84
+ type: "simple-marker",
85
+ ...styleProps,
86
+ color: props?.color ?? "blue",
87
+ size: props?.size ?? 4,
88
+ outline: {
89
+ color: props?.borderColor ?? "white",
90
+ width: props?.borderWidth ?? 1,
91
+ },
92
+ },
93
+ visualVariables: vizVars,
94
+ });
95
+ }, [props]);
96
+ return renderer;
97
+ };