-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMapComponent.ts
More file actions
69 lines (63 loc) · 2.23 KB
/
MapComponent.ts
File metadata and controls
69 lines (63 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { useEffect } from 'react'
import { Vector3 } from 'three'
import { isClient } from '@etherealengine/engine/src/common/functions/getEnvironment'
import { ComponentType, defineComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions'
import { useEntityContext } from '@etherealengine/engine/src/ecs/functions/EntityFunctions'
import { _updateMap, deserializeMap, SCENE_COMPONENT_MAP } from './MapFunctions'
export const MapComponent = defineComponent({
name: 'EE_maps_scene_component',
jsonID: SCENE_COMPONENT_MAP,
onInit: (entity) => {
return {
apiKey: '',
name: '',
scale: new Vector3(),
style: {},
useTimeOfDay: 0,
useDirectionalShadows: false,
useDeviceGeolocation: false,
startLatitude: '',
startLongitude: '',
showRasterTiles: false,
enableDebug: false
}
},
onSet: (entity, component, json) => {
if (!json) return
component.apiKey.set(json.apiKey!)
component.name.set(json.name!)
component.scale.set(json.scale!)
component.style.set(json.style!)
component.useTimeOfDay.set(json.useTimeOfDay!)
component.useDirectionalShadows.set(json.useDirectionalShadows!)
component.useDeviceGeolocation.set(json.useDeviceGeolocation!)
component.startLatitude.set(json.startLatitude!)
component.startLongitude.set(json.startLongitude!)
component.showRasterTiles.set(json.showRasterTiles!)
component.enableDebug.set(json.enableDebug!)
deserializeMap(entity, component.value)
},
toJSON: (entity, component) => {
return {
apiKey: component.apiKey,
name: component.name,
scale: component.scale,
useTimeOfDay: component.useTimeOfDay,
useDirectionalShadows: component.useDirectionalShadows,
useDeviceGeolocation: component.useDeviceGeolocation,
startLatitude: component.startLatitude,
startLongitude: component.startLongitude,
showRasterTiles: component.showRasterTiles,
enableDebug: component.enableDebug
}
},
reactor: () => {
if (!isClient) return null
const entity = useEntityContext()
useEffect(() => {
_updateMap(entity, {})
}, [entity])
return null
}
})
export type MapComponentType = ComponentType<typeof MapComponent>