-
Notifications
You must be signed in to change notification settings - Fork 16
/
App.jsx
199 lines (184 loc) · 6.42 KB
/
App.jsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { BootstrapDartboard as FindAddress } from '@ugrc/dart-board';
import Sherlock, { WebApiProvider } from '@ugrc/sherlock';
import { getAnalytics } from 'firebase/analytics';
import PropTypes from 'prop-types';
import { useCallback, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { AnalyticsProvider, useFirebaseApp, useInitPerformance } from 'reactfire';
import { Button, Card, Collapse } from 'reactstrap';
import MapView from './components/esrijs/MapView';
import Printer from './components/esrijs/Print';
import Header from './components/Header/Header';
import { IdentifyContainer, IdentifyInformation } from './components/Identify/Identify';
import MapLens from './components/MapLens/MapLens';
import Sidebar from './components/Sidebar/Sidebar';
import config from './config';
import '@ugrc/sherlock/src/Sherlock.css';
import './App.css';
const apiKey = import.meta.env.VITE_WEB_API;
const version = import.meta.env.PACKAGE_VERSION;
const ErrorFallback = ({ error }) => {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: 'red' }}>{error.message}</pre>
</div>
);
};
ErrorFallback.propTypes = {
error: PropTypes.object,
};
export default function App() {
const app = useFirebaseApp();
useInitPerformance(async () => {
const { getPerformance } = await import('firebase/performance');
return getPerformance(app);
});
const [zoomToGraphic, setZoomToGraphic] = useState({
zoomToGraphic: {
graphic: {},
level: 0,
},
});
const [showIdentify, setShowIdentify] = useState(false);
const [mapClick, setMapClick] = useState(null);
const [showPrint, setShowPrint] = useState(false);
const [mapView, setMapView] = useState({});
const [sideBarOpen, setSideBarOpen] = useState(window.innerWidth >= config.MIN_DESKTOP_WIDTH);
const onSherlockMatch = (graphics) => {
// summary:
// Zooms to the passed in graphic(s).
// graphics: esri.Graphic[]
// The esri.Graphic(s) that you want to zoom to.
// tags:
// private
console.log('sherlock:zoom');
// check for point feature
setZoomToGraphic({
graphic: graphics,
preserve: false,
});
};
const findAddressOptions = {
apiKey,
wkid: config.WEB_MERCATOR_WKID,
pointSymbol: {
type: 'simple-marker',
style: 'diamond',
color: config.MARKER_FILL_COLOR,
size: '18px',
outline: {
color: config.MARKER_OUTLINE_COLOR,
width: 1,
},
},
events: {
success: (graphic) => {
console.log('findAddress::success');
setZoomToGraphic({
graphic: graphic,
level: 18,
});
},
error: console.error,
},
};
const gnisSherlock = {
provider: new WebApiProvider(apiKey, 'location.gnis_place_names', 'name', {
contextField: 'county',
}),
label: 'Find Point of Interest',
placeHolder: 'place name ...',
maxResultsToDisplay: 10,
onSherlockMatch: onSherlockMatch,
};
const citySherlock = {
provider: new WebApiProvider(apiKey, 'boundaries.municipal_boundaries', 'name'),
label: 'Find City',
placeHolder: 'city name ...',
maxResultsToDisplay: 10,
onSherlockMatch: onSherlockMatch,
};
const onClick = useCallback((event) => {
setShowIdentify(true);
setSideBarOpen(true);
setMapClick(event.mapPoint);
}, []);
const mapOptions = {
zoomToGraphic: zoomToGraphic,
onClick: onClick,
setView: setMapView,
};
const sidebarOptions = {
sideBarOpen: sideBarOpen,
toggleSidebar: () => setSideBarOpen(!sideBarOpen),
};
return (
<AnalyticsProvider sdk={getAnalytics(app)}>
<div className="app">
<Header title="Atlas Utah" version={version} />
{showIdentify ? (
<ErrorBoundary FallbackComponent={ErrorFallback}>
<IdentifyContainer show={setShowIdentify}>
<IdentifyInformation apiKey={apiKey} location={mapClick} />
</IdentifyContainer>
</ErrorBoundary>
) : null}
<ErrorBoundary FallbackComponent={ErrorFallback}>
<Sidebar>
<div className="bg-light border text-center p-1">
<small>
Data and services provided by <a href="https://gis.utah.gov/">UGRC</a>.
</small>
</div>
<p>Click a location on the map for more information</p>
<h4>Find Address</h4>
<div id="geocodeNode">
<ErrorBoundary FallbackComponent={ErrorFallback}>
<FindAddress {...findAddressOptions} />
</ErrorBoundary>
</div>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<div className="mt-3">
<Sherlock {...gnisSherlock}></Sherlock>
</div>
</ErrorBoundary>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<div className="mt-3">
<Sherlock {...citySherlock}></Sherlock>
</div>
</ErrorBoundary>
<Card style={{ marginTop: '1em' }}>
<Button block onClick={() => setShowPrint(!showPrint)}>
Export Map
</Button>
<Collapse isOpen={showPrint}>{showPrint ? <Printer view={mapView}></Printer> : null}</Collapse>
</Card>
<div style={{ marginTop: '1em', border: '#aaa 1px dashed' }}>
<small>
<ul className="list-group list-group-flush">
<li className="list-group-item">
This web application is a <a href="https://github.com/agrc/atlas">GitHub template</a> that you can
use to create your own website.
</li>
<li className="list-group-item">
Submit any application or data <a href="https://github.com/agrc/atlas/issues/new/choose">issues</a>{' '}
via GitHub issues.
</li>
<li className="list-group-item">
Reach out to us on <a href="https://x.com/MapUtah">X</a> if you want to chat.
</li>
</ul>
</small>
</div>
</Sidebar>
</ErrorBoundary>
<MapLens {...sidebarOptions}>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<MapView {...mapOptions} />
</ErrorBoundary>
</MapLens>
</div>
</AnalyticsProvider>
);
}