@@ -2,14 +2,12 @@ import Polygon from '@arcgis/core/geometry/Polygon';
2
2
import VectorTileLayer from '@arcgis/core/layers/VectorTileLayer' ;
3
3
import EsriMap from '@arcgis/core/Map' ;
4
4
import MapView from '@arcgis/core/views/MapView' ;
5
- import LayerSelector from '@ugrc/layer-selector ' ;
5
+ import { LayerSelector , type LayerSelectorProps } from '@ugrc/utah-design-system ' ;
6
6
import { useEffect , useRef , useState } from 'react' ;
7
7
import cityExtents from './data/cityExtents' ;
8
8
import { useMap } from './hooks' ;
9
9
import { randomize } from './utils' ;
10
10
11
- import '@ugrc/layer-selector/src/LayerSelector.css' ;
12
-
13
11
const { item : randomExtent } = randomize < __esri . GraphicProperties > ( cityExtents ) ;
14
12
const urls = {
15
13
landownership :
@@ -18,26 +16,12 @@ const urls = {
18
16
'https://www.arcgis.com/sharing/rest/content/items/77202507796a4d5796b7d8e6871e352e/resources/styles/root.json' ,
19
17
} ;
20
18
21
- type LayerFactory = {
22
- Factory : new ( ) => __esri . Layer ;
23
- url : string ;
24
- id : string ;
25
- opacity : number ;
26
- } ;
27
- type SelectorOptions = {
28
- view : MapView ;
29
- quadWord : string ;
30
- baseLayers : Array < string | { token : string ; selected : boolean } | LayerFactory > ;
31
- overlays ?: Array < string | LayerFactory > ;
32
- position : 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' ;
33
- } ;
34
-
35
19
export const MapContainer = ( { onClick } : { onClick ?: __esri . ViewImmediateClickEventHandler } ) => {
36
20
const mapNode = useRef < HTMLDivElement | null > ( null ) ;
37
21
const mapComponent = useRef < EsriMap | null > ( null ) ;
38
22
const mapView = useRef < MapView > ( ) ;
39
23
const clickHandler = useRef < IHandle > ( ) ;
40
- const [ selectorOptions , setSelectorOptions ] = useState < SelectorOptions | null > ( null ) ;
24
+ const [ selectorOptions , setSelectorOptions ] = useState < LayerSelectorProps | null > ( null ) ;
41
25
const { setMapView } = useMap ( ) ;
42
26
43
27
// setup the Map
@@ -59,39 +43,32 @@ export const MapContainer = ({ onClick }: { onClick?: __esri.ViewImmediateClickE
59
43
60
44
setMapView ( mapView . current ) ;
61
45
62
- const selectorOptions : SelectorOptions = {
63
- view : mapView . current ,
64
- quadWord : import . meta. env . VITE_DISCOVER ,
65
- baseLayers : [
66
- 'Hybrid' ,
67
- {
68
- Factory : VectorTileLayer ,
69
- url : urls . liteVector ,
70
- id : 'Lite' ,
71
- opacity : 1 ,
72
- } ,
73
- 'Terrain' ,
74
- 'Topo' ,
75
- 'Color IR' ,
76
- ] ,
77
- overlays : [
78
- 'Address Points' ,
79
- {
80
- Factory : VectorTileLayer ,
81
- url : urls . landownership ,
82
- id : 'Land Ownership' ,
83
- opacity : 0.3 ,
84
- } ,
85
- ] ,
86
- position : 'top-right' ,
46
+ const selectorOptions : LayerSelectorProps = {
47
+ options : {
48
+ view : mapView . current ,
49
+ quadWord : import . meta. env . VITE_DISCOVER ,
50
+ baseLayers : [
51
+ 'Hybrid' ,
52
+ {
53
+ label : 'Lite' ,
54
+ function : ( ) =>
55
+ new VectorTileLayer ( {
56
+ url : urls . liteVector ,
57
+ opacity : 1 ,
58
+ } ) ,
59
+ } ,
60
+ 'Terrain' ,
61
+ 'Topo' ,
62
+ 'Color IR' ,
63
+ ] ,
64
+ referenceLayers : [ 'Address Points' , 'Land Ownership' ] ,
65
+ } ,
87
66
} ;
88
67
89
- const { index : randomBaseMapIndex } = randomize ( selectorOptions . baseLayers ) ;
68
+ const { index : randomBaseMapIndex } = randomize ( selectorOptions . options . baseLayers ) ;
90
69
91
- selectorOptions . baseLayers [ randomBaseMapIndex ] = {
92
- token : selectorOptions . baseLayers [ randomBaseMapIndex ] as string ,
93
- selected : true ,
94
- } ;
70
+ const removed = selectorOptions . options . baseLayers . splice ( randomBaseMapIndex , 1 ) ;
71
+ selectorOptions . options . baseLayers . unshift ( removed [ 0 ] ! ) ;
95
72
96
73
setSelectorOptions ( selectorOptions ) ;
97
74
@@ -114,7 +91,7 @@ export const MapContainer = ({ onClick }: { onClick?: __esri.ViewImmediateClickE
114
91
115
92
return (
116
93
< div ref = { mapNode } className = "size-full" >
117
- { selectorOptions ?. view && < LayerSelector { ...selectorOptions } > </ LayerSelector > }
94
+ { selectorOptions && < LayerSelector { ...selectorOptions } > </ LayerSelector > }
118
95
</ div >
119
96
) ;
120
97
} ;
0 commit comments