@xyo-network/react-map 7.5.7 → 7.5.11
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/browser/Components/MapBox.d.ts.map +1 -1
- package/dist/browser/Components/MapBoxPoints.d.ts.map +1 -1
- package/dist/browser/MapBoxClasses/MapHeat.d.ts.map +1 -1
- package/dist/browser/MapBoxClasses/MapSettings.d.ts.map +1 -1
- package/dist/browser/hooks/useDynamicMapResize.d.ts.map +1 -1
- package/dist/browser/hooks/useQuadKeyPayloadsToFeatures.d.ts.map +1 -1
- package/dist/browser/index.mjs +481 -714
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +159 -36
- package/src/Components/AnimatedHeatMap.tsx +0 -61
- package/src/Components/AnimatedHeatMapLoaded.tsx +0 -61
- package/src/Components/FeaturesToLayersMap.ts +0 -8
- package/src/Components/HeatMapSettings.ts +0 -11
- package/src/Components/LayerAnimator.tsx +0 -119
- package/src/Components/Legend.tsx +0 -36
- package/src/Components/Legends/ColorGradient.tsx +0 -35
- package/src/Components/Legends/index.ts +0 -1
- package/src/Components/MapBox.stories.tsx +0 -92
- package/src/Components/MapBox.tsx +0 -79
- package/src/Components/MapBoxHeat.tsx +0 -19
- package/src/Components/MapBoxPoints.tsx +0 -99
- package/src/Components/MapSettingsComponents/Setting.tsx +0 -36
- package/src/Components/MapSettingsComponents/SettingsBox.tsx +0 -34
- package/src/Components/MapSettingsComponents/index.ts +0 -2
- package/src/Components/index.ts +0 -11
- package/src/Contexts/HeatMapInitializer/Context.ts +0 -7
- package/src/Contexts/HeatMapInitializer/Provider.tsx +0 -93
- package/src/Contexts/HeatMapInitializer/State.ts +0 -8
- package/src/Contexts/HeatMapInitializer/index.ts +0 -3
- package/src/Contexts/HeatMapInitializer/useHeatMapInitializer.tsx +0 -13
- package/src/Contexts/MapBoxInstance/Context.ts +0 -7
- package/src/Contexts/MapBoxInstance/Provider.tsx +0 -26
- package/src/Contexts/MapBoxInstance/State.ts +0 -8
- package/src/Contexts/MapBoxInstance/index.ts +0 -3
- package/src/Contexts/MapBoxInstance/useMapBoxInstance.tsx +0 -13
- package/src/Contexts/MapSettings/Context.ts +0 -7
- package/src/Contexts/MapSettings/Provider.tsx +0 -43
- package/src/Contexts/MapSettings/State.ts +0 -7
- package/src/Contexts/MapSettings/index.ts +0 -3
- package/src/Contexts/MapSettings/useMapSettings.tsx +0 -11
- package/src/Contexts/index.ts +0 -3
- package/src/Layers/Builders/LocationHeatMapLayerBuilder.ts +0 -36
- package/src/Layers/Builders/LocationHeatMapLayerBuilderAnimated.ts +0 -21
- package/src/Layers/Builders/LocationPointsMapLayerBuilder.ts +0 -17
- package/src/Layers/Builders/index.ts +0 -3
- package/src/Layers/CircleLayer.ts +0 -31
- package/src/Layers/Configs/HeatMapFillLayerConfig.ts +0 -13
- package/src/Layers/Configs/HeatMapLineLayerConfig.ts +0 -13
- package/src/Layers/Configs/HeatMapSymbolLayerConfig.ts +0 -18
- package/src/Layers/Configs/LocationPointLayerConfig.ts +0 -15
- package/src/Layers/Configs/index.ts +0 -4
- package/src/Layers/FillLayer.ts +0 -23
- package/src/Layers/LineLayer.ts +0 -24
- package/src/Layers/MapLayer.ts +0 -6
- package/src/Layers/SymbolLayer.ts +0 -23
- package/src/Layers/index.ts +0 -7
- package/src/MapBoxClasses/MapBase.ts +0 -45
- package/src/MapBoxClasses/MapHeat.ts +0 -184
- package/src/MapBoxClasses/MapPoints.ts +0 -39
- package/src/MapBoxClasses/MapSettings.ts +0 -132
- package/src/MapBoxClasses/index.ts +0 -4
- package/src/global.d.ts +0 -1
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useDynamicMapResize.tsx +0 -43
- package/src/hooks/useDynamicPositioning.tsx +0 -68
- package/src/hooks/useQuadKeyPayloadsToFeatures.tsx +0 -54
- package/src/index.ts +0 -5
- package/src/lib/MapBoxBaseProps.ts +0 -20
- package/src/lib/index.ts +0 -1
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import-x/no-internal-modules
|
|
2
|
-
import 'mapbox-gl/dist/mapbox-gl.css'
|
|
3
|
-
|
|
4
|
-
import { MapStyle } from '@xyo-network/react-map-model'
|
|
5
|
-
import type { MapOptions } from 'mapbox-gl'
|
|
6
|
-
import { Map } from 'mapbox-gl'
|
|
7
|
-
import React, {
|
|
8
|
-
useEffect, useRef, useState,
|
|
9
|
-
} from 'react'
|
|
10
|
-
|
|
11
|
-
import { useMapBoxInstance, useMapSettings } from '../Contexts/index.ts'
|
|
12
|
-
import { useDynamicMapResize } from '../hooks/index.ts'
|
|
13
|
-
|
|
14
|
-
export interface MapBoxProps {
|
|
15
|
-
accessToken: string
|
|
16
|
-
darkMode?: boolean
|
|
17
|
-
options?: Partial<MapOptions>
|
|
18
|
-
zoom?: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const MapBox: React.FC<MapBoxProps> = ({
|
|
22
|
-
accessToken, darkMode = false, options, zoom = 2, ...props
|
|
23
|
-
}) => {
|
|
24
|
-
const [map, setMap] = useState<Map>()
|
|
25
|
-
const mapContainerRef = useRef<HTMLDivElement>(null)
|
|
26
|
-
const mapCanvasRef = useRef<HTMLCanvasElement>(null)
|
|
27
|
-
const { setMapBoxInstance, map: mapInstance } = useMapBoxInstance()
|
|
28
|
-
const { mapSettings } = useMapSettings()
|
|
29
|
-
|
|
30
|
-
const activeResize = mapSettings?.dynamicMapResize.value
|
|
31
|
-
useDynamicMapResize(mapContainerRef, mapCanvasRef, mapInstance, activeResize)
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (mapSettings?.preferDark?.value === true) {
|
|
35
|
-
map?.setStyle(`mapbox://styles/${MapStyle.Dark}`)
|
|
36
|
-
} else {
|
|
37
|
-
map?.setStyle(`mapbox://styles/${darkMode ? MapStyle.Dark : MapStyle.Light}`)
|
|
38
|
-
}
|
|
39
|
-
}, [map, darkMode, mapSettings])
|
|
40
|
-
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const map = new Map({
|
|
43
|
-
accessToken,
|
|
44
|
-
center: [0, 0],
|
|
45
|
-
container: mapContainerRef.current ?? '',
|
|
46
|
-
style: `mapbox://styles/${MapStyle.Light}`,
|
|
47
|
-
zoom,
|
|
48
|
-
...options,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
// Allow external components to control the map
|
|
52
|
-
setMapBoxInstance?.(map)
|
|
53
|
-
setMap(map)
|
|
54
|
-
|
|
55
|
-
// save the map canvas ref to help with resizing
|
|
56
|
-
mapCanvasRef.current = document.querySelector('.mapboxgl-canvas') as HTMLCanvasElement | null
|
|
57
|
-
|
|
58
|
-
console.log('Created Map')
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
console.log('Removing Map')
|
|
62
|
-
map.remove()
|
|
63
|
-
}
|
|
64
|
-
}, [mapContainerRef, setMap, options, zoom, setMapBoxInstance, accessToken])
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div
|
|
68
|
-
ref={(el) => { mapContainerRef.current = el }}
|
|
69
|
-
style={{
|
|
70
|
-
bottom: 0,
|
|
71
|
-
left: 0,
|
|
72
|
-
position: 'absolute',
|
|
73
|
-
right: 0,
|
|
74
|
-
top: 0,
|
|
75
|
-
...props,
|
|
76
|
-
}}
|
|
77
|
-
/>
|
|
78
|
-
)
|
|
79
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import type { MapboxFlexBoxProps } from '../lib/index.ts'
|
|
5
|
-
import { MapBox } from './MapBox.tsx'
|
|
6
|
-
import { MapSettingsBox } from './MapSettingsComponents/index.ts'
|
|
7
|
-
|
|
8
|
-
export const MapboxHeatFlexBox: React.FC<MapboxFlexBoxProps> = ({
|
|
9
|
-
accessToken, children, mapBoxOptions, zoom, legend, developerMode, ...props
|
|
10
|
-
}) => {
|
|
11
|
-
return (
|
|
12
|
-
<FlexCol {...props}>
|
|
13
|
-
<MapBox accessToken={accessToken} options={mapBoxOptions} zoom={zoom} />
|
|
14
|
-
<MapSettingsBox developerMode={developerMode} />
|
|
15
|
-
{legend}
|
|
16
|
-
{children}
|
|
17
|
-
</FlexCol>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Alert } from '@mui/material'
|
|
2
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
3
|
-
import type { Feature, Point } from 'geojson'
|
|
4
|
-
import type { MapOptions } from 'mapbox-gl'
|
|
5
|
-
import React, {
|
|
6
|
-
useCallback, useEffect, useMemo,
|
|
7
|
-
} from 'react'
|
|
8
|
-
|
|
9
|
-
import { useMapBoxInstance, useMapSettings } from '../Contexts/index.ts'
|
|
10
|
-
import type { MapboxFlexBoxProps } from '../lib/index.ts'
|
|
11
|
-
import { MapPoints } from '../MapBoxClasses/index.ts'
|
|
12
|
-
import { MapBox } from './MapBox.tsx'
|
|
13
|
-
import { MapSettingsBox } from './MapSettingsComponents/index.ts'
|
|
14
|
-
|
|
15
|
-
export interface MapboxPointsFlexBoxProps extends MapboxFlexBoxProps {
|
|
16
|
-
accessToken: string
|
|
17
|
-
features?: Feature<Point>[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const MapboxPointsFlexBox: React.FC<MapboxPointsFlexBoxProps> = ({
|
|
21
|
-
accessToken,
|
|
22
|
-
features,
|
|
23
|
-
fitToPointsPadding = 20,
|
|
24
|
-
layers,
|
|
25
|
-
zoom,
|
|
26
|
-
...props
|
|
27
|
-
}) => {
|
|
28
|
-
const { mapSettings } = useMapSettings()
|
|
29
|
-
const { map, mapInitialized } = useMapBoxInstance()
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Needed because of a bug in mapbox taking undefined values for the config options of fitToBounds
|
|
33
|
-
* see - https://github.com/mapbox/mapbox-gl-js/issues/10013
|
|
34
|
-
*/
|
|
35
|
-
const customFitToBoundsOptions = (zoom?: number): MapOptions['fitBoundsOptions'] => {
|
|
36
|
-
if (zoom !== undefined) {
|
|
37
|
-
return { maxZoom: zoom }
|
|
38
|
-
}
|
|
39
|
-
return {}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const mapPoints = useMemo(() => {
|
|
43
|
-
return (map && features?.length)
|
|
44
|
-
? new MapPoints({
|
|
45
|
-
features, map, zoom,
|
|
46
|
-
})
|
|
47
|
-
: undefined
|
|
48
|
-
}, [map, features, zoom])
|
|
49
|
-
|
|
50
|
-
const updateFeatures = useCallback(() => {
|
|
51
|
-
if (mapPoints?.isMapReady && features?.length && layers)
|
|
52
|
-
for (const layer of layers) {
|
|
53
|
-
mapPoints.initializeMapSource(layer)
|
|
54
|
-
}
|
|
55
|
-
}, [mapPoints, features, layers])
|
|
56
|
-
|
|
57
|
-
const updateMapSetup = useCallback(() => {
|
|
58
|
-
const { fitToPoints } = mapSettings || {}
|
|
59
|
-
|
|
60
|
-
if (mapPoints && map && fitToPoints?.value === true) {
|
|
61
|
-
mapPoints.initialMapPositioning({
|
|
62
|
-
padding: {
|
|
63
|
-
bottom: fitToPointsPadding, left: fitToPointsPadding, right: fitToPointsPadding, top: fitToPointsPadding,
|
|
64
|
-
},
|
|
65
|
-
...customFitToBoundsOptions(zoom),
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
}, [mapSettings, mapPoints, map, fitToPointsPadding, zoom])
|
|
69
|
-
|
|
70
|
-
const reInitializeMap = useCallback(() => {
|
|
71
|
-
mapPoints?.initialMapPositioning({
|
|
72
|
-
padding: {
|
|
73
|
-
bottom: fitToPointsPadding, left: fitToPointsPadding, right: fitToPointsPadding, top: fitToPointsPadding,
|
|
74
|
-
},
|
|
75
|
-
...customFitToBoundsOptions(zoom),
|
|
76
|
-
})
|
|
77
|
-
updateFeatures()
|
|
78
|
-
}, [mapPoints, fitToPointsPadding, updateFeatures, zoom])
|
|
79
|
-
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (mapInitialized) {
|
|
82
|
-
updateMapSetup()
|
|
83
|
-
reInitializeMap()
|
|
84
|
-
}
|
|
85
|
-
}, [mapInitialized, reInitializeMap, updateMapSetup])
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<FlexCol alignItems="stretch" id="xyo-mapbox-wrap" {...props}>
|
|
89
|
-
{features
|
|
90
|
-
? (
|
|
91
|
-
<>
|
|
92
|
-
<MapBox accessToken={accessToken} zoom={zoom} />
|
|
93
|
-
<MapSettingsBox />
|
|
94
|
-
</>
|
|
95
|
-
)
|
|
96
|
-
: <Alert severity="error">No data to show</Alert>}
|
|
97
|
-
</FlexCol>
|
|
98
|
-
)
|
|
99
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { SwitchProps } from '@mui/material'
|
|
2
|
-
import { FormControlLabel, Switch } from '@mui/material'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import { useMapSettings } from '../../Contexts/index.ts'
|
|
6
|
-
|
|
7
|
-
export interface MapSettingSwitchProps extends SwitchProps {
|
|
8
|
-
developerMode?: boolean
|
|
9
|
-
field: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const MapSettingSwitch: React.FC<MapSettingSwitchProps> = ({
|
|
13
|
-
developerMode, field, ...props
|
|
14
|
-
}) => {
|
|
15
|
-
const { mapSettings, setMapSettings } = useMapSettings()
|
|
16
|
-
const setting = mapSettings?.[field]
|
|
17
|
-
|
|
18
|
-
const onLocalChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
19
|
-
if (setting) {
|
|
20
|
-
setMapSettings?.((previous) => {
|
|
21
|
-
previous[setting.field].value = event.target.checked
|
|
22
|
-
return { ...previous }
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (setting?.devMode && developerMode === false) {
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return setting?.hidden
|
|
32
|
-
? null
|
|
33
|
-
: (
|
|
34
|
-
<FormControlLabel label={setting?.label} control={<Switch checked={setting?.value} onChange={onLocalChange} {...props} />} />
|
|
35
|
-
)
|
|
36
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Paper, Stack } from '@mui/material'
|
|
2
|
-
import { useAppSettings } from '@xylabs/react-app-settings'
|
|
3
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
4
|
-
import { FlexGrowRow, FlexRow } from '@xylabs/react-flexbox'
|
|
5
|
-
import React from 'react'
|
|
6
|
-
|
|
7
|
-
import { useMapSettings } from '../../Contexts/index.ts'
|
|
8
|
-
import { MapSettingSwitch } from './Setting.tsx'
|
|
9
|
-
|
|
10
|
-
export interface MapSettingsBoxProps extends FlexBoxProps {
|
|
11
|
-
developerMode?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const MapSettingsBox: React.FC<MapSettingsBoxProps> = ({ developerMode, ...props }) => {
|
|
15
|
-
const { mapSettings } = useMapSettings()
|
|
16
|
-
const { developerMode: devModeFromContext } = useAppSettings()
|
|
17
|
-
const resolveDeveloperMode = developerMode ?? devModeFromContext
|
|
18
|
-
|
|
19
|
-
return mapSettings && resolveDeveloperMode
|
|
20
|
-
? (
|
|
21
|
-
<FlexGrowRow bottom={36} left={10} position="absolute" {...props}>
|
|
22
|
-
<FlexRow paddingX={2}>
|
|
23
|
-
<Paper>
|
|
24
|
-
<Stack direction="row" spacing={1} marginX={1}>
|
|
25
|
-
{Object.keys(mapSettings).map((key, index) => {
|
|
26
|
-
return <MapSettingSwitch key={index} field={mapSettings[key].field} developerMode={developerMode} />
|
|
27
|
-
})}
|
|
28
|
-
</Stack>
|
|
29
|
-
</Paper>
|
|
30
|
-
</FlexRow>
|
|
31
|
-
</FlexGrowRow>
|
|
32
|
-
)
|
|
33
|
-
: null
|
|
34
|
-
}
|
package/src/Components/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './AnimatedHeatMap.tsx'
|
|
2
|
-
export * from './AnimatedHeatMapLoaded.tsx'
|
|
3
|
-
export * from './FeaturesToLayersMap.ts'
|
|
4
|
-
export * from './HeatMapSettings.ts'
|
|
5
|
-
export * from './LayerAnimator.tsx'
|
|
6
|
-
export * from './Legend.tsx'
|
|
7
|
-
export * from './Legends/index.ts'
|
|
8
|
-
export * from './MapBox.tsx'
|
|
9
|
-
export * from './MapBoxHeat.tsx'
|
|
10
|
-
export * from './MapBoxPoints.tsx'
|
|
11
|
-
export * from './MapSettingsComponents/index.ts'
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { forget } from '@xylabs/sdk-js'
|
|
2
|
-
import type { AnimatedHeatMapColorProps, HeatMapColorProps } from '@xyo-network/react-map-model'
|
|
3
|
-
import type { Feature, Polygon } from 'geojson'
|
|
4
|
-
import type { PropsWithChildren } from 'react'
|
|
5
|
-
import React, { useEffect, useMemo } from 'react'
|
|
6
|
-
|
|
7
|
-
import { useDynamicPositioning } from '../../hooks/index.ts'
|
|
8
|
-
import type { MapLayer } from '../../Layers/index.ts'
|
|
9
|
-
import { MapHeat } from '../../MapBoxClasses/index.ts'
|
|
10
|
-
import { useMapBoxInstance } from '../MapBoxInstance/index.ts'
|
|
11
|
-
import { useMapSettings } from '../MapSettings/index.ts'
|
|
12
|
-
import { HeatMapInitializerContext } from './Context.ts'
|
|
13
|
-
import type { HeatMapInitializerState } from './State.ts'
|
|
14
|
-
|
|
15
|
-
export interface MapInitializerProviderProps {
|
|
16
|
-
featureSets?: Feature<Polygon>[][]
|
|
17
|
-
featureSetsLayers?: MapLayer[]
|
|
18
|
-
features?: Feature<Polygon>[]
|
|
19
|
-
fitToPadding?: number
|
|
20
|
-
heatMapColorProps: HeatMapColorProps | AnimatedHeatMapColorProps
|
|
21
|
-
layers?: MapLayer[]
|
|
22
|
-
zoom?: number
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const HeatMapInitializerProvider: React.FC<PropsWithChildren<MapInitializerProviderProps>> = ({
|
|
26
|
-
children,
|
|
27
|
-
featureSets,
|
|
28
|
-
featureSetsLayers,
|
|
29
|
-
features,
|
|
30
|
-
fitToPadding,
|
|
31
|
-
heatMapColorProps,
|
|
32
|
-
layers,
|
|
33
|
-
zoom,
|
|
34
|
-
}) => {
|
|
35
|
-
const { options } = useDynamicPositioning()
|
|
36
|
-
const { mapSettings } = useMapSettings()
|
|
37
|
-
const { map, mapInitialized } = useMapBoxInstance()
|
|
38
|
-
|
|
39
|
-
const mapHeat = useMemo(() => {
|
|
40
|
-
return (map && features?.length)
|
|
41
|
-
? new MapHeat({
|
|
42
|
-
features, map, zoom,
|
|
43
|
-
})
|
|
44
|
-
: undefined
|
|
45
|
-
}, [map, features, zoom])
|
|
46
|
-
|
|
47
|
-
const value: HeatMapInitializerState = useMemo(() => ({
|
|
48
|
-
MapHeat: mapHeat,
|
|
49
|
-
heatMapColorProps,
|
|
50
|
-
}), [mapHeat, heatMapColorProps])
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (mapInitialized && featureSets?.length && featureSets[0].length > 0 && map && featureSetsLayers?.length) {
|
|
54
|
-
const { lowUsageColor, highUsageColor } = heatMapColorProps as AnimatedHeatMapColorProps
|
|
55
|
-
forget(MapHeat.initializeAnimatedHeatMapSource(featureSetsLayers, featureSets, map, lowUsageColor, highUsageColor))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return () => {
|
|
59
|
-
MapHeat.animationStarted = false
|
|
60
|
-
}
|
|
61
|
-
}, [featureSets, featureSetsLayers, mapInitialized, map, heatMapColorProps])
|
|
62
|
-
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (mapHeat && mapInitialized && features?.length && layers?.length) {
|
|
65
|
-
mapHeat.initializeHeatMapSource(layers)
|
|
66
|
-
}
|
|
67
|
-
}, [mapHeat, features?.length, layers, mapInitialized])
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (mapInitialized) {
|
|
71
|
-
const { fitToPoints } = mapSettings || {}
|
|
72
|
-
|
|
73
|
-
if (map) {
|
|
74
|
-
if (fitToPoints?.value === true) {
|
|
75
|
-
MapHeat.initialMapPositioning(
|
|
76
|
-
{
|
|
77
|
-
padding: {
|
|
78
|
-
bottom: fitToPadding, left: fitToPadding, right: fitToPadding, top: fitToPadding,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
map,
|
|
82
|
-
features,
|
|
83
|
-
)
|
|
84
|
-
} else if (options?.zoom && options.center) {
|
|
85
|
-
map.setZoom(options.zoom)
|
|
86
|
-
map.setCenter(options.center)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, [mapHeat, map, mapSettings, fitToPadding, options, mapInitialized, features])
|
|
91
|
-
|
|
92
|
-
return <HeatMapInitializerContext value={value}>{children}</HeatMapInitializerContext>
|
|
93
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import { use } from 'react'
|
|
3
|
-
|
|
4
|
-
import { HeatMapInitializerContext } from './Context.ts'
|
|
5
|
-
|
|
6
|
-
const useHeatMapInitializer = () => {
|
|
7
|
-
const context = use(HeatMapInitializerContext)
|
|
8
|
-
assertEx('heatMapInitialized' in context, () => 'useHeatMapInitializer must be used within a HeatMapInitializerContext')
|
|
9
|
-
|
|
10
|
-
return context
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { useHeatMapInitializer }
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Map } from 'mapbox-gl'
|
|
2
|
-
import type { PropsWithChildren } from 'react'
|
|
3
|
-
import React, {
|
|
4
|
-
useEffect, useMemo, useState,
|
|
5
|
-
} from 'react'
|
|
6
|
-
|
|
7
|
-
import { MapBoxInstanceContext } from './Context.ts'
|
|
8
|
-
|
|
9
|
-
export const MapBoxInstanceProvider: React.FC<PropsWithChildren> = ({ children }) => {
|
|
10
|
-
const [map, setMapBoxInstance] = useState<Map>()
|
|
11
|
-
const [mapInitialized, setMapInitialized] = useState(false)
|
|
12
|
-
|
|
13
|
-
const value = useMemo(() => ({
|
|
14
|
-
map, mapInitialized, setMapBoxInstance,
|
|
15
|
-
}), [map, mapInitialized, setMapBoxInstance])
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (!mapInitialized && map) {
|
|
19
|
-
map?.on('load', () => {
|
|
20
|
-
setMapInitialized(true)
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
}, [map, mapInitialized, setMapInitialized])
|
|
24
|
-
|
|
25
|
-
return <MapBoxInstanceContext value={value}>{children}</MapBoxInstanceContext>
|
|
26
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import { use } from 'react'
|
|
3
|
-
|
|
4
|
-
import { MapBoxInstanceContext } from './Context.ts'
|
|
5
|
-
|
|
6
|
-
const useMapBoxInstance = () => {
|
|
7
|
-
const context = use(MapBoxInstanceContext)
|
|
8
|
-
assertEx('map' in context, () => 'useMapBoxInstance must be used within a MapBoxInstanceContext')
|
|
9
|
-
|
|
10
|
-
return context
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { useMapBoxInstance }
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { MapSetting } from '@xyo-network/react-map-model'
|
|
2
|
-
import type { PropsWithChildren } from 'react'
|
|
3
|
-
import React, {
|
|
4
|
-
useEffect, useMemo, useState,
|
|
5
|
-
} from 'react'
|
|
6
|
-
|
|
7
|
-
import { MapSettings } from '../../MapBoxClasses/index.ts'
|
|
8
|
-
import { useMapBoxInstance } from '../MapBoxInstance/index.ts'
|
|
9
|
-
import { MapSettingsContext } from './Context.ts'
|
|
10
|
-
import type { MapSettingsState } from './State.ts'
|
|
11
|
-
|
|
12
|
-
export interface MapSettingsProviderProps {
|
|
13
|
-
debugLayerName?: string
|
|
14
|
-
defaultMapSettings?: MapSetting
|
|
15
|
-
requestLocation?: boolean
|
|
16
|
-
zoom?: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const MapSettingsProvider: React.FC<PropsWithChildren<MapSettingsProviderProps>> = ({
|
|
20
|
-
children,
|
|
21
|
-
debugLayerName,
|
|
22
|
-
defaultMapSettings,
|
|
23
|
-
requestLocation,
|
|
24
|
-
zoom = 1,
|
|
25
|
-
}) => {
|
|
26
|
-
const [mapSettings, setMapSettings] = useState<MapSetting>(defaultMapSettings || {})
|
|
27
|
-
const { map, mapInitialized } = useMapBoxInstance()
|
|
28
|
-
|
|
29
|
-
const value: MapSettingsState = useMemo(() => ({
|
|
30
|
-
mapSettings,
|
|
31
|
-
setMapSettings,
|
|
32
|
-
}), [mapSettings, setMapSettings])
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (mapSettings && map && mapInitialized) {
|
|
36
|
-
MapSettings.updateSettings({
|
|
37
|
-
debugLayerName, map, requestLocation, settings: mapSettings, zoom,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}, [debugLayerName, map, mapInitialized, mapSettings, requestLocation, zoom])
|
|
41
|
-
|
|
42
|
-
return <MapSettingsContext value={value}>{children}</MapSettingsContext>
|
|
43
|
-
}
|
package/src/Contexts/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HeatMapFillLayerConfig, HeatMapLineLayerConfig, HeatMapSymbolLayerConfig,
|
|
3
|
-
} from '../Configs/index.ts'
|
|
4
|
-
import { FillLayerBuilder } from '../FillLayer.ts'
|
|
5
|
-
import { LineLayerBuilder } from '../LineLayer.ts'
|
|
6
|
-
import { SymbolLayerBuilder } from '../SymbolLayer.ts'
|
|
7
|
-
|
|
8
|
-
export const MapHeatConstants = {
|
|
9
|
-
LocationDebugLayerId: 'location-debug-id',
|
|
10
|
-
LocationDebugLayerSource: 'location-debug-source',
|
|
11
|
-
LocationFillLayerId: 'location-fill-id',
|
|
12
|
-
LocationFillLayerSource: 'location-fill-source',
|
|
13
|
-
LocationLineLayerId: 'location-line-id',
|
|
14
|
-
LocationLineLayerSource: 'location-line-source',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const LocationHeatMapLayerBuilder = (color: string, alternateColor = '#000') => {
|
|
18
|
-
const {
|
|
19
|
-
LocationFillLayerId,
|
|
20
|
-
LocationFillLayerSource,
|
|
21
|
-
LocationLineLayerId,
|
|
22
|
-
LocationLineLayerSource,
|
|
23
|
-
LocationDebugLayerId,
|
|
24
|
-
LocationDebugLayerSource,
|
|
25
|
-
} = MapHeatConstants
|
|
26
|
-
|
|
27
|
-
const fillLayerConfig = HeatMapFillLayerConfig(color)
|
|
28
|
-
const lineLayerConfig = HeatMapLineLayerConfig(color)
|
|
29
|
-
const debugLayerConfig = HeatMapSymbolLayerConfig(alternateColor)
|
|
30
|
-
|
|
31
|
-
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig)
|
|
32
|
-
const lineLayer = new LineLayerBuilder(LocationLineLayerId, LocationLineLayerSource, lineLayerConfig)
|
|
33
|
-
const debugLayer = new SymbolLayerBuilder(LocationDebugLayerId, LocationDebugLayerSource, debugLayerConfig)
|
|
34
|
-
|
|
35
|
-
return [fillLayer, lineLayer, debugLayer]
|
|
36
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { HeatMapFillLayerConfig } from '../Configs/index.ts'
|
|
2
|
-
import { FillLayerBuilder } from '../FillLayer.ts'
|
|
3
|
-
|
|
4
|
-
const MapHeatConstants = (index: number, type: string) => ({
|
|
5
|
-
LocationDebugLayerId: `location-${type}-debug-id-${index}`,
|
|
6
|
-
LocationDebugLayerSource: `location-${type}-debug-source-${index}`,
|
|
7
|
-
LocationFillLayerId: `location-${type}-fill-id-${index}`,
|
|
8
|
-
LocationFillLayerSource: `location-${type}-fill-source-${index}`,
|
|
9
|
-
LocationLineLayerId: `location-${type}-line-id-${index}`,
|
|
10
|
-
LocationLineLayerSource: `location-${type}-line-source-${index}`,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export const LocationHeatMapLayerBuilderAnimated = (color: string, index: number, type = '') => {
|
|
14
|
-
const { LocationFillLayerId, LocationFillLayerSource } = MapHeatConstants(index, type)
|
|
15
|
-
|
|
16
|
-
const fillLayerConfig = HeatMapFillLayerConfig(color)
|
|
17
|
-
|
|
18
|
-
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig)
|
|
19
|
-
|
|
20
|
-
return fillLayer
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CircleLayerBuilder } from '../CircleLayer.ts'
|
|
2
|
-
import { LocationPointLayerConfig } from '../Configs/index.ts'
|
|
3
|
-
|
|
4
|
-
export const MapPointsConstants = {
|
|
5
|
-
LocationDotsLayerId: 'location-dots',
|
|
6
|
-
LocationDotsLayerSource: 'location-dots-source',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const LocationPointsMapLayerBuilder = (color: string, circleRadius = 6, circleOpacity = 0.8) => {
|
|
10
|
-
const { LocationDotsLayerId, LocationDotsLayerSource } = MapPointsConstants
|
|
11
|
-
|
|
12
|
-
const dotLayerConfig = LocationPointLayerConfig(color, circleRadius, circleOpacity)
|
|
13
|
-
|
|
14
|
-
const dotLayer = new CircleLayerBuilder(LocationDotsLayerId, LocationDotsLayerSource, dotLayerConfig)
|
|
15
|
-
|
|
16
|
-
return [dotLayer]
|
|
17
|
-
}
|