@local-logic/maps 0.0.4 → 0.0.6

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 (153) hide show
  1. package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
  2. package/dist/index-B43MtiHH.js +30 -0
  3. package/dist/index-BAAE2pMq.js +64 -0
  4. package/dist/index-BHjgd5HB.js +29 -0
  5. package/dist/index-BZ2605rA.js +39 -0
  6. package/dist/index-B_LO5X9C.js +46 -0
  7. package/dist/index-BbrOUWDy.js +29 -0
  8. package/dist/index-Bd-X-1Gd.js +42 -0
  9. package/dist/index-CPq7k7F4.js +63 -0
  10. package/dist/index-CTk5bvm9.js +155 -0
  11. package/dist/index-CXLLvdx4.js +670 -0
  12. package/dist/index-CXjxZmYt.js +144 -0
  13. package/dist/index-DHw9gU4K.js +29 -0
  14. package/dist/index-DVitM43i.js +137 -0
  15. package/dist/index-J1MKzGEM.js +31 -0
  16. package/dist/index-qqbvBkdn.js +7 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.es.js +4 -0
  19. package/dist/index.modern-EsUgbhzI.js +908 -0
  20. package/dist/index.umd.js +3181 -0
  21. package/dist/logo-control-NE-LlsRy.js +607 -0
  22. package/dist/mapbox-gl-D58OubwB.js +32266 -0
  23. package/dist/maplibre-gl-CfOZKUDd.js +20722 -0
  24. package/dist/scale-control-CyJd4u6j.js +716 -0
  25. package/dist/src/components/Map/Root/BaseMap/Empty/index.d.ts +3 -0
  26. package/dist/src/components/Map/Root/BaseMap/Empty/index.d.ts.map +1 -0
  27. package/dist/src/components/Map/Root/BaseMap/Google/index.d.ts +11 -0
  28. package/dist/src/components/Map/Root/BaseMap/Google/index.d.ts.map +1 -0
  29. package/dist/src/components/Map/Root/BaseMap/Mapbox/index.d.ts +4 -0
  30. package/dist/src/components/Map/Root/BaseMap/Mapbox/index.d.ts.map +1 -0
  31. package/dist/src/components/Map/Root/BaseMap/Maptiler/index.d.ts +4 -0
  32. package/dist/src/components/Map/Root/BaseMap/Maptiler/index.d.ts.map +1 -0
  33. package/dist/src/components/Map/Root/BaseMap/index.d.ts +4 -0
  34. package/dist/src/components/Map/Root/BaseMap/index.d.ts.map +1 -0
  35. package/dist/src/components/Map/Root/BaseMap/styles.d.ts +2 -0
  36. package/dist/src/components/Map/Root/BaseMap/styles.d.ts.map +1 -0
  37. package/dist/src/components/Map/Root/BaseMap/types.d.ts +3 -0
  38. package/dist/src/components/Map/Root/BaseMap/types.d.ts.map +1 -0
  39. package/dist/src/components/Map/Root/Layers/Google/index.d.ts +4 -0
  40. package/dist/src/components/Map/Root/Layers/Google/index.d.ts.map +1 -0
  41. package/dist/src/components/Map/Root/Layers/Mapbox/index.d.ts +4 -0
  42. package/dist/src/components/Map/Root/Layers/Mapbox/index.d.ts.map +1 -0
  43. package/dist/src/components/Map/Root/Layers/Maptiler/index.d.ts +4 -0
  44. package/dist/src/components/Map/Root/Layers/Maptiler/index.d.ts.map +1 -0
  45. package/dist/src/components/Map/Root/Layers/index.d.ts +4 -0
  46. package/dist/src/components/Map/Root/Layers/index.d.ts.map +1 -0
  47. package/dist/src/components/Map/Root/Layers/types.d.ts +13 -0
  48. package/dist/src/components/Map/Root/Layers/types.d.ts.map +1 -0
  49. package/dist/src/components/Map/Root/Layers/utils.d.ts +6 -0
  50. package/dist/src/components/Map/Root/Layers/utils.d.ts.map +1 -0
  51. package/dist/src/components/Map/Root/Markers/Cluster/index.d.ts +6 -0
  52. package/dist/src/components/Map/Root/Markers/Cluster/index.d.ts.map +1 -0
  53. package/dist/src/components/Map/Root/Markers/Cluster/styles.d.ts +2 -0
  54. package/dist/src/components/Map/Root/Markers/Cluster/styles.d.ts.map +1 -0
  55. package/dist/src/components/Map/Root/Markers/Google/index.d.ts +4 -0
  56. package/dist/src/components/Map/Root/Markers/Google/index.d.ts.map +1 -0
  57. package/dist/src/components/Map/Root/Markers/Mapbox/index.d.ts +4 -0
  58. package/dist/src/components/Map/Root/Markers/Mapbox/index.d.ts.map +1 -0
  59. package/dist/src/components/Map/Root/Markers/Maptiler/index.d.ts +4 -0
  60. package/dist/src/components/Map/Root/Markers/Maptiler/index.d.ts.map +1 -0
  61. package/dist/src/components/Map/Root/Markers/index.d.ts +4 -0
  62. package/dist/src/components/Map/Root/Markers/index.d.ts.map +1 -0
  63. package/dist/src/components/Map/Root/Markers/styles.d.ts +5 -0
  64. package/dist/src/components/Map/Root/Markers/styles.d.ts.map +1 -0
  65. package/dist/src/components/Map/Root/Markers/types.d.ts +28 -0
  66. package/dist/src/components/Map/Root/Markers/types.d.ts.map +1 -0
  67. package/dist/src/components/Map/Root/Popup/Google/index.d.ts +4 -0
  68. package/dist/src/components/Map/Root/Popup/Google/index.d.ts.map +1 -0
  69. package/dist/src/components/Map/Root/Popup/Mapbox/index.d.ts +4 -0
  70. package/dist/src/components/Map/Root/Popup/Mapbox/index.d.ts.map +1 -0
  71. package/dist/src/components/Map/Root/Popup/Maptiler/index.d.ts +4 -0
  72. package/dist/src/components/Map/Root/Popup/Maptiler/index.d.ts.map +1 -0
  73. package/dist/src/components/Map/Root/Popup/index.d.ts +4 -0
  74. package/dist/src/components/Map/Root/Popup/index.d.ts.map +1 -0
  75. package/dist/src/components/Map/Root/Popup/styles.d.ts +2 -0
  76. package/dist/src/components/Map/Root/Popup/styles.d.ts.map +1 -0
  77. package/dist/src/components/Map/Root/Popup/types.d.ts +10 -0
  78. package/dist/src/components/Map/Root/Popup/types.d.ts.map +1 -0
  79. package/dist/src/components/Map/Root/constants.d.ts +7 -0
  80. package/dist/src/components/Map/Root/constants.d.ts.map +1 -0
  81. package/dist/src/components/Map/Root/context.d.ts +11 -0
  82. package/dist/src/components/Map/Root/context.d.ts.map +1 -0
  83. package/dist/src/components/Map/Root/index.d.ts +11 -0
  84. package/dist/src/components/Map/Root/index.d.ts.map +1 -0
  85. package/dist/src/components/Map/Root/types.d.ts +26 -0
  86. package/dist/src/components/Map/Root/types.d.ts.map +1 -0
  87. package/dist/src/components/Map/index.d.ts +2 -0
  88. package/dist/src/components/Map/index.d.ts.map +1 -0
  89. package/dist/src/components/Map/index.stories.d.ts +8 -0
  90. package/dist/src/components/Map/index.stories.d.ts.map +1 -0
  91. package/dist/src/components/Map/index.test.d.ts +2 -0
  92. package/dist/src/components/Map/index.test.d.ts.map +1 -0
  93. package/dist/src/components/Map/storybook-data.d.ts +18 -0
  94. package/dist/src/components/Map/storybook-data.d.ts.map +1 -0
  95. package/dist/src/index.d.ts +2 -0
  96. package/dist/src/index.d.ts.map +1 -0
  97. package/dist/style.css +1 -0
  98. package/{src/components/Map/Root/Popup/styles.ts → dist/styles-uPzJnzVS.js} +4 -1
  99. package/dist/utils-YqJg0vBb.js +25 -0
  100. package/package.json +14 -3
  101. package/.env.example +0 -3
  102. package/.storybook/defaults.ts +0 -40
  103. package/.storybook/globals.css +0 -32
  104. package/.storybook/main.ts +0 -19
  105. package/.storybook/preview.tsx +0 -28
  106. package/CHANGELOG.md +0 -27
  107. package/eslint.config.mjs +0 -46
  108. package/lint-staged.config.cjs +0 -4
  109. package/postcss.config.cjs +0 -6
  110. package/prettier.config.cjs +0 -1
  111. package/src/components/Map/Root/BaseMap/Empty/index.tsx +0 -7
  112. package/src/components/Map/Root/BaseMap/Google/index.tsx +0 -96
  113. package/src/components/Map/Root/BaseMap/Mapbox/index.tsx +0 -66
  114. package/src/components/Map/Root/BaseMap/Maptiler/index.tsx +0 -59
  115. package/src/components/Map/Root/BaseMap/index.tsx +0 -34
  116. package/src/components/Map/Root/BaseMap/styles.ts +0 -1
  117. package/src/components/Map/Root/BaseMap/types.ts +0 -3
  118. package/src/components/Map/Root/Layers/Google/index.tsx +0 -97
  119. package/src/components/Map/Root/Layers/Mapbox/index.tsx +0 -74
  120. package/src/components/Map/Root/Layers/Maptiler/index.tsx +0 -74
  121. package/src/components/Map/Root/Layers/index.tsx +0 -32
  122. package/src/components/Map/Root/Layers/types.ts +0 -15
  123. package/src/components/Map/Root/Layers/utils.ts +0 -64
  124. package/src/components/Map/Root/Markers/Cluster/index.tsx +0 -27
  125. package/src/components/Map/Root/Markers/Cluster/styles.ts +0 -11
  126. package/src/components/Map/Root/Markers/Google/index.tsx +0 -49
  127. package/src/components/Map/Root/Markers/Mapbox/index.tsx +0 -52
  128. package/src/components/Map/Root/Markers/Maptiler/index.tsx +0 -52
  129. package/src/components/Map/Root/Markers/index.tsx +0 -81
  130. package/src/components/Map/Root/Markers/styles.ts +0 -37
  131. package/src/components/Map/Root/Markers/types.ts +0 -32
  132. package/src/components/Map/Root/Popup/Google/index.tsx +0 -57
  133. package/src/components/Map/Root/Popup/Google/popup.css +0 -15
  134. package/src/components/Map/Root/Popup/Mapbox/index.tsx +0 -36
  135. package/src/components/Map/Root/Popup/Mapbox/popup.css +0 -15
  136. package/src/components/Map/Root/Popup/Maptiler/index.tsx +0 -37
  137. package/src/components/Map/Root/Popup/Maptiler/popup.css +0 -15
  138. package/src/components/Map/Root/Popup/index.tsx +0 -32
  139. package/src/components/Map/Root/Popup/types.ts +0 -20
  140. package/src/components/Map/Root/constants.ts +0 -6
  141. package/src/components/Map/Root/context.tsx +0 -15
  142. package/src/components/Map/Root/index.tsx +0 -30
  143. package/src/components/Map/Root/types.ts +0 -30
  144. package/src/components/Map/index.stories.tsx +0 -133
  145. package/src/components/Map/index.test.tsx +0 -16
  146. package/src/components/Map/index.tsx +0 -1
  147. package/src/components/Map/storybook-data.ts +0 -255
  148. package/src/index.ts +0 -1
  149. package/tailwind.config.cjs +0 -1
  150. package/tsconfig.json +0 -14
  151. package/tsconfig.node.json +0 -8
  152. package/vite-env.d.ts +0 -13
  153. package/vite.config.ts +0 -46
@@ -1,96 +0,0 @@
1
- import React, { useState, useEffect } from "react";
2
-
3
- import {
4
- APIProvider,
5
- Map as GoogleMap,
6
- ControlPosition,
7
- useMap,
8
- } from "@vis.gl/react-google-maps";
9
-
10
- import { useRootElement } from "../../context";
11
- import { defaultMapValues } from "../../constants";
12
-
13
- import type { BaseMapProps } from "../types";
14
-
15
- const zoomPositionMap = {
16
- "top-left": ControlPosition.LEFT_TOP,
17
- "top-right": ControlPosition.RIGHT_TOP,
18
- "bottom-left": ControlPosition.LEFT_BOTTOM,
19
- "bottom-right": ControlPosition.RIGHT_BOTTOM,
20
- };
21
- const mapId = "a7ff20eb973126bb";
22
-
23
- const MapControl = ({ isMapLoaded }: { isMapLoaded: boolean }) => {
24
- const map = useMap();
25
-
26
- const { setBounds } = useRootElement();
27
-
28
- useEffect(() => {
29
- if (!isMapLoaded || !map) {
30
- return;
31
- }
32
-
33
- const bounds = map.getBounds()?.toJSON();
34
-
35
- if (bounds) {
36
- setBounds([bounds.west, bounds.south, bounds.east, bounds.north]);
37
- }
38
- }, [isMapLoaded, map]);
39
-
40
- return null;
41
- };
42
-
43
- /**
44
- * Map IDS:
45
- * https://console.cloud.google.com/google/maps-apis/studio/maps?project=engineering-internal-396021
46
- *
47
- * Map styles:
48
- * https://console.cloud.google.com/google/maps-apis/studio/styles?project=engineering-internal-396021
49
- */
50
- export default function GoogleBaseMap({ children }: BaseMapProps) {
51
- const [isMapLoaded, setIsMapLoaded] = useState(false);
52
- const {
53
- mapProvider,
54
- center,
55
- zoom = defaultMapValues.zoom,
56
- pitch = defaultMapValues.pitch,
57
- bearing = defaultMapValues.bearing,
58
- cooperativeGestures = defaultMapValues.cooperativeGestures,
59
- zoomPosition,
60
- } = useRootElement();
61
-
62
- if (mapProvider.name !== "google") {
63
- return null;
64
- }
65
-
66
- const handleMapLoaded = () => {
67
- setIsMapLoaded(true);
68
- };
69
-
70
- return (
71
- <APIProvider apiKey={mapProvider.apiKey}>
72
- <MapControl isMapLoaded={isMapLoaded} />
73
- <GoogleMap
74
- mapId={mapId}
75
- defaultCenter={{
76
- lat: center.latitude,
77
- lng: center.longitude,
78
- }}
79
- defaultZoom={zoom}
80
- defaultTilt={pitch}
81
- defaultHeading={bearing}
82
- gestureHandling={!cooperativeGestures ? "greedy" : "cooperative"}
83
- streetViewControl={false}
84
- fullscreenControl={false}
85
- clickableIcons={false}
86
- mapTypeControl={false}
87
- zoomControlOptions={{
88
- position: zoomPosition && zoomPositionMap[zoomPosition],
89
- }}
90
- onTilesLoaded={handleMapLoaded}
91
- >
92
- {children}
93
- </GoogleMap>
94
- </APIProvider>
95
- );
96
- }
@@ -1,66 +0,0 @@
1
- import React, { useEffect } from "react";
2
-
3
- import Mapbox, { NavigationControl, useMap } from "react-map-gl/mapbox";
4
- import "mapbox-gl/dist/mapbox-gl.css";
5
-
6
- import type { BBox } from "geojson";
7
-
8
- import { useRootElement } from "../../context";
9
- import { defaultMapValues } from "../../constants";
10
-
11
- import type { BaseMapProps } from "../types";
12
-
13
- const MapControl = () => {
14
- const { current: map } = useMap();
15
- const { setBounds } = useRootElement();
16
-
17
- useEffect(() => {
18
- if (!map) {
19
- return;
20
- }
21
-
22
- const bounds = map.getBounds();
23
-
24
- if (!bounds) {
25
- return;
26
- }
27
-
28
- setBounds(bounds.toArray().flat() as BBox);
29
- }, [map]);
30
-
31
- return null;
32
- };
33
-
34
- export default function MapboxBaseMap({ children }: BaseMapProps) {
35
- const {
36
- mapProvider,
37
- center,
38
- zoom = defaultMapValues.zoom,
39
- pitch = defaultMapValues.pitch,
40
- bearing = defaultMapValues.bearing,
41
- cooperativeGestures = defaultMapValues.cooperativeGestures,
42
- zoomPosition,
43
- } = useRootElement();
44
-
45
- if (mapProvider.name !== "mapbox") {
46
- return null;
47
- }
48
-
49
- return (
50
- <Mapbox
51
- mapboxAccessToken={mapProvider.apiKey}
52
- initialViewState={{
53
- ...center,
54
- zoom,
55
- pitch,
56
- bearing,
57
- }}
58
- cooperativeGestures={cooperativeGestures}
59
- mapStyle={`mapbox://styles/mapbox/streets-v9`}
60
- >
61
- <MapControl />
62
- {zoomPosition && <NavigationControl position={zoomPosition} />}
63
- {children}
64
- </Mapbox>
65
- );
66
- }
@@ -1,59 +0,0 @@
1
- import React, { useEffect } from "react";
2
-
3
- import Maplibre, { NavigationControl, useMap } from "react-map-gl/maplibre";
4
- import "maplibre-gl/dist/maplibre-gl.css";
5
-
6
- import type { BBox } from "geojson";
7
-
8
- import { useRootElement } from "../../context";
9
- import { defaultMapValues } from "../../constants";
10
-
11
- import type { BaseMapProps } from "../types";
12
-
13
- const MapControl = () => {
14
- const { current: map } = useMap();
15
- const { setBounds } = useRootElement();
16
-
17
- useEffect(() => {
18
- if (!map) {
19
- return;
20
- }
21
-
22
- setBounds(map.getBounds().toArray().flat() as BBox);
23
- }, [map]);
24
-
25
- return null;
26
- };
27
-
28
- export default function MaptilerBaseMap({ children }: BaseMapProps) {
29
- const {
30
- mapProvider,
31
- center,
32
- zoom = defaultMapValues.zoom,
33
- pitch = defaultMapValues.pitch,
34
- bearing = defaultMapValues.bearing,
35
- cooperativeGestures = defaultMapValues.cooperativeGestures,
36
- zoomPosition,
37
- } = useRootElement();
38
-
39
- if (mapProvider.name !== "maptiler") {
40
- return null;
41
- }
42
-
43
- return (
44
- <Maplibre
45
- initialViewState={{
46
- ...center,
47
- zoom,
48
- pitch,
49
- bearing,
50
- }}
51
- cooperativeGestures={cooperativeGestures}
52
- mapStyle={`https://api.maptiler.com/maps/${mapProvider.maptilerTheme}/style.json?key=${mapProvider.apiKey}`}
53
- >
54
- <MapControl />
55
- {zoomPosition && <NavigationControl position={zoomPosition} />}
56
- {children}
57
- </Maplibre>
58
- );
59
- }
@@ -1,34 +0,0 @@
1
- import React, { lazy, useMemo } from "react";
2
-
3
- import { useRootElement } from "../context";
4
-
5
- import type { BaseMapProps } from "./types";
6
- import * as styles from "./styles";
7
-
8
- const MaptilerBaseMap = lazy(() => import("./Maptiler"));
9
- const GoogleBaseMap = lazy(() => import("./Google"));
10
- const MapboxBaseMap = lazy(() => import("./Mapbox"));
11
- const EmptyBaseMap = lazy(() => import("./Empty"));
12
-
13
- export const BaseMap = ({ children }: BaseMapProps) => {
14
- const { mapProvider } = useRootElement();
15
-
16
- const BaseMapProvider = useMemo(() => {
17
- switch (mapProvider?.name) {
18
- case "maptiler":
19
- return MaptilerBaseMap;
20
- case "google":
21
- return GoogleBaseMap;
22
- case "mapbox":
23
- return MapboxBaseMap;
24
- default:
25
- return EmptyBaseMap;
26
- }
27
- }, [mapProvider]);
28
-
29
- return (
30
- <div className={styles.wrapper}>
31
- <BaseMapProvider>{children}</BaseMapProvider>
32
- </div>
33
- );
34
- };
@@ -1 +0,0 @@
1
- export const wrapper = `w-full h-full`;
@@ -1,3 +0,0 @@
1
- import type { RootProps } from "../types";
2
-
3
- export type BaseMapProps = Pick<RootProps, "children">;
@@ -1,97 +0,0 @@
1
- import React, { useState, useEffect, useContext } from "react";
2
-
3
- // Work inspired from:
4
- // https://github.com/visgl/react-google-maps/blob/main/examples/geometry/src/components/polygon.tsx
5
- // https://visgl.github.io/react-google-maps/examples/geometry
6
-
7
- import { GoogleMapsContext } from "@vis.gl/react-google-maps";
8
-
9
- import { getGooglePolygonFromLocalLogicGeometry } from "../utils";
10
-
11
- import type { Props, Layer as LayerType } from "../types";
12
-
13
- function getLayerPaint(type: LayerType["type"], color: string) {
14
- switch (type) {
15
- case "fill":
16
- return {
17
- fillColor: color,
18
- fillOpacity: 0.25,
19
- };
20
- case "line":
21
- return {
22
- strokeColor: color,
23
- strokeWeight: 2,
24
- };
25
- default:
26
- return {};
27
- }
28
- }
29
-
30
- export default function GoogleLayers({ sources }: Props) {
31
- const [map, setMap] = useState<google.maps.Map | null>(null);
32
- const [polygonRefs, setPolygonRefs] = useState<google.maps.Polygon[]>([]);
33
- const mapContext = useContext(GoogleMapsContext);
34
-
35
- useEffect(() => {
36
- if (!mapContext) {
37
- return;
38
- }
39
-
40
- setMap(mapContext.map);
41
- }, [mapContext]);
42
-
43
- useEffect(() => {
44
- // Remove existing polygons
45
- polygonRefs.forEach((polygonRef) => {
46
- polygonRef?.setMap(null);
47
- });
48
-
49
- if (!map || typeof sources === "undefined" || sources.length === 0) {
50
- return;
51
- }
52
-
53
- // Create new polygons
54
- const newPolygons = sources.map((source) => {
55
- const polygonOptions = {
56
- paths: getGooglePolygonFromLocalLogicGeometry(source.geometry),
57
- };
58
-
59
- if (Array.isArray(source.layer)) {
60
- source.layer.forEach((layer) => {
61
- const layerPaint = getLayerPaint(layer.type, layer.color);
62
- Object.assign(polygonOptions, layerPaint);
63
- });
64
- } else {
65
- const layerPaint = getLayerPaint(source.layer.type, source.layer.color);
66
- Object.assign(polygonOptions, layerPaint);
67
- }
68
-
69
- const newPolygon = new google.maps.Polygon({
70
- // Set default options otherwise the polygon remains visible (even if eg: we only want the outline)
71
- // We then overrider the default options with the layer options
72
- strokeWeight: 0,
73
- fillOpacity: 0,
74
- ...polygonOptions,
75
- });
76
- newPolygon.setMap(map);
77
-
78
- return newPolygon;
79
- });
80
-
81
- setPolygonRefs(newPolygons);
82
- // Set the map for each polygon
83
- newPolygons.forEach((polygonRef) => {
84
- polygonRef.setMap(map);
85
- });
86
-
87
- // Clean up the polygons when the component unmounts or when sources change
88
- // eslint-disable-next-line consistent-return
89
- return () => {
90
- newPolygons.forEach((polygonRef) => {
91
- polygonRef?.setMap(null);
92
- });
93
- };
94
- }, [map, sources]);
95
-
96
- return <></>;
97
- }
@@ -1,74 +0,0 @@
1
- import React, { useMemo } from "react";
2
-
3
- import { Source, Layer } from "react-map-gl/mapbox";
4
-
5
- import { getFeatureCollectionFromLocalLogicGeometry } from "../utils";
6
-
7
- import type { Props, Layer as LayerType } from "../types";
8
-
9
- function getLayerPaint(type: LayerType["type"], color: string) {
10
- switch (type) {
11
- case "fill":
12
- return {
13
- "fill-color": color,
14
- "fill-opacity": 0.15,
15
- };
16
- case "line":
17
- return {
18
- "line-color": color,
19
- "line-width": 2,
20
- };
21
- default:
22
- return {};
23
- }
24
- }
25
-
26
- export default function MapboxLayers({ sources }: Props) {
27
- const geometrySources = useMemo(() => {
28
- if (!Array.isArray(sources) || sources.length === 0) {
29
- return [];
30
- }
31
-
32
- return sources.map((geometry) => ({
33
- ...geometry,
34
- geoJson: geometry.geometry
35
- ? getFeatureCollectionFromLocalLogicGeometry(geometry.geometry)
36
- : null,
37
- }));
38
- }, [sources]);
39
-
40
- if (geometrySources?.length === 0) {
41
- return null;
42
- }
43
-
44
- return (
45
- <>
46
- {geometrySources?.map((source) => (
47
- <div key={source.key}>
48
- {source.geoJson && (
49
- <Source id={source.key} key={source.key} type="geojson" data={source.geoJson}>
50
- {source.layer &&
51
- (Array.isArray(source.layer) ? (
52
- source.layer.map((layer, index) => (
53
- <Layer
54
- key={`${source.key}-${index}`}
55
- {...{
56
- ...{ type: layer.type, paint: getLayerPaint(layer.type, layer.color) },
57
- }}
58
- />
59
- ))
60
- ) : (
61
- <Layer
62
- {...{
63
- type: source.layer.type,
64
- paint: getLayerPaint(source.layer.type, source.layer.color),
65
- }}
66
- />
67
- ))}
68
- </Source>
69
- )}
70
- </div>
71
- ))}
72
- </>
73
- );
74
- }
@@ -1,74 +0,0 @@
1
- import React, { useMemo } from "react";
2
-
3
- import { Source, Layer } from "react-map-gl/maplibre";
4
-
5
- import { getFeatureCollectionFromLocalLogicGeometry } from "../utils";
6
-
7
- import type { Props, Layer as LayerType } from "../types";
8
-
9
- function getLayerPaint(type: LayerType["type"], color: string) {
10
- switch (type) {
11
- case "fill":
12
- return {
13
- "fill-color": color,
14
- "fill-opacity": 0.25,
15
- };
16
- case "line":
17
- return {
18
- "line-color": color,
19
- "line-width": 2,
20
- };
21
- default:
22
- return {};
23
- }
24
- }
25
-
26
- export default function MaptilerLayers({ sources }: Props) {
27
- const geometrySources = useMemo(() => {
28
- if (!Array.isArray(sources) || sources.length === 0) {
29
- return [];
30
- }
31
-
32
- return sources.map((geometry) => ({
33
- ...geometry,
34
- geoJson: geometry.geometry
35
- ? getFeatureCollectionFromLocalLogicGeometry(geometry.geometry)
36
- : null,
37
- }));
38
- }, [sources]);
39
-
40
- if (geometrySources?.length === 0) {
41
- return null;
42
- }
43
-
44
- return (
45
- <>
46
- {geometrySources?.map((source) => (
47
- <div key={source.key}>
48
- {source.geoJson && (
49
- <Source id={source.key} key={source.key} type="geojson" data={source.geoJson}>
50
- {source.layer &&
51
- (Array.isArray(source.layer) ? (
52
- source.layer.map((layer, index) => (
53
- <Layer
54
- key={`${source.key}-${index}`}
55
- {...{
56
- ...{ type: layer.type, paint: getLayerPaint(layer.type, layer.color) },
57
- }}
58
- />
59
- ))
60
- ) : (
61
- <Layer
62
- {...{
63
- type: source.layer.type,
64
- paint: getLayerPaint(source.layer.type, source.layer.color),
65
- }}
66
- />
67
- ))}
68
- </Source>
69
- )}
70
- </div>
71
- ))}
72
- </>
73
- );
74
- }
@@ -1,32 +0,0 @@
1
- import React, { lazy, useMemo } from "react";
2
-
3
- import type { Props } from "./types";
4
-
5
- import { useRootElement } from "../context";
6
-
7
- const MaptilerLayers = lazy(() => import("./Maptiler"));
8
- const GoogleLayers = lazy(() => import("./Google"));
9
- const MapboxLayers = lazy(() => import("./Mapbox"));
10
-
11
- export function Layers(props: Props) {
12
- const { mapProvider } = useRootElement();
13
-
14
- const BaseLayers = useMemo(() => {
15
- switch (mapProvider?.name) {
16
- case "maptiler":
17
- return MaptilerLayers;
18
- case "google":
19
- return GoogleLayers;
20
- case "mapbox":
21
- return MapboxLayers;
22
- default:
23
- return null;
24
- }
25
- }, [mapProvider]);
26
-
27
- if (!BaseLayers) {
28
- return null;
29
- }
30
-
31
- return <BaseLayers {...props} />;
32
- }
@@ -1,15 +0,0 @@
1
- export type Layer = {
2
- type: "fill" | "line";
3
- color: string;
4
- };
5
-
6
- export type Source = {
7
- key: string;
8
- layer: Layer | Layer[];
9
- // Expected [lat, lng] format
10
- geometry: number[][][][];
11
- };
12
-
13
- export type Props = {
14
- sources?: Source[];
15
- };
@@ -1,64 +0,0 @@
1
- import type { FeatureCollection, MultiPolygon } from "geojson";
2
-
3
- type Geometry =
4
- | number[][]
5
- | number[][][]
6
- | number[][][][]
7
- | string[][]
8
- | string[][][]
9
- | string[][][][];
10
-
11
- export function getFeatureCollectionFromLocalLogicGeometry(geometry: Geometry = []) {
12
- /* Geometries need formatting before being added as a Source in the Map.
13
- * Geometries from v3/schools have a format of [lat, lng]
14
- * Geojson accepts polygons with a format of [lng, lat]
15
- */
16
-
17
- const geometryLatLngFormat = (arr: object): object =>
18
- Object.values(arr).map((a) => {
19
- if (Array.isArray(a[0])) {
20
- return geometryLatLngFormat(a);
21
- }
22
-
23
- return [a[1], a[0]];
24
- });
25
-
26
- const finalCoordinates = geometryLatLngFormat(geometry);
27
-
28
- const responseObject = {
29
- type: "FeatureCollection",
30
- features: [
31
- {
32
- type: "Feature",
33
- geometry: {
34
- type: "MultiPolygon",
35
- coordinates: finalCoordinates,
36
- },
37
- },
38
- ],
39
- } as FeatureCollection<MultiPolygon>;
40
-
41
- return responseObject;
42
- }
43
-
44
- export function getGooglePolygonFromLocalLogicGeometry(geometry: Geometry = []) {
45
- /* Geometries need formatting before being added as a Source in the Map.
46
- * Geometries from v3/schools have a format of [lat, lng]
47
- * Google Maps accepts polygons with a format of { lat: number, lng: number }
48
- */
49
-
50
- const geometryLatLngFormat = (arr: object): object =>
51
- Object.values(arr).map((a) => {
52
- if (Array.isArray(a[0])) {
53
- return geometryLatLngFormat(a.flat());
54
- }
55
-
56
- return { lat: a[0], lng: a[1] };
57
- });
58
-
59
- const finalCoordinates = geometryLatLngFormat(
60
- geometry
61
- ) as google.maps.MVCArray<google.maps.LatLng>;
62
-
63
- return finalCoordinates;
64
- }
@@ -1,27 +0,0 @@
1
- import React, { useMemo } from "react";
2
-
3
- import type { ClusterPoint } from "../types";
4
-
5
- import * as styles from "./styles";
6
-
7
- export function Cluster({ cluster }: { cluster: ClusterPoint }) {
8
- // Taking a somewhat similar calculation to what LocalLogic SDK used to
9
- // do for cluster diameter (bigger depending on count)
10
- const diameter = useMemo(
11
- () => 20 + cluster.properties.point_count * 4,
12
- [cluster.properties.point_count]
13
- );
14
-
15
- return (
16
- <div
17
- className={styles.container}
18
- style={{
19
- width: `${diameter}px`,
20
- height: `${diameter}px`,
21
- fontSize: `${diameter / 2.5}px`,
22
- }}
23
- >
24
- {cluster.properties.point_count}
25
- </div>
26
- );
27
- }
@@ -1,11 +0,0 @@
1
- export const container = `
2
- rounded-full leading-none font-sans border-2
3
- border-solid shadow-sm
4
- flex justify-center items-center
5
- bg-primary-100 text-base-white border-base-white
6
- transition-all
7
-
8
- hover:bg-base-white
9
- hover:text-primary-100
10
- hover:border-primary-100
11
- `;