Skip to content

Commit

Permalink
feat: add imagery flight dates
Browse files Browse the repository at this point in the history
refs #190
  • Loading branch information
steveoh committed Oct 4, 2022
1 parent 78ae568 commit 6debb4d
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/components/Identify/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const featureClassNames = {
dem: 'SGID10.RASTER.USGS_DEM_10METER',
gnis: 'location.gnis_place_names',
zip: 'boundaries.zip_code_areas',
imageryDate: 'indices.hexagon_service_dates',
};

const fieldNames = {
Expand All @@ -39,7 +40,9 @@ const urls = {
google: 'https://www.google.com/maps?q&layer=c&',
};

const intl = new Intl.DateTimeFormat('en-US', { dateStyle: 'short' });
const outside = 'Outside of Utah';
const loading = 'loading...';

const projectPoint = async (mapPoint, srid) => {
// lat/long coords
Expand All @@ -50,8 +53,6 @@ const projectPoint = async (mapPoint, srid) => {
return project(mapPoint, { wkid: srid });
};

const loading = 'loading...';

const IdentifyInformation = ({ apiKey, wkid = 3857, location }) => {
const [spatial, setSpatial] = useState({
x: 0,
Expand Down Expand Up @@ -151,6 +152,34 @@ const IdentifyInformation = ({ apiKey, wkid = 3857, location }) => {
setZip(data[fieldNames.ZIP5]);
},
],
[
featureClassNames.imageryDate,
'date,resolution',
(data) => {
if (!data) {
setFlightDate({ date: 'unknown', resolution: 'A mystery' });

return;
}

if ((data?.date.length ?? 0) > 0) {
data.date = intl.format(new Date(data['date']));

setFlightDate(data);
} else if ((data?.length ?? 0) > 0) {
const dates = data.map((result) => {
return { date: new Date(result.attributes['date']), resolution: result.attributes['resolution'] };
});
const sorted = dates.sort((a, b) => {
return a.date - b.date;
});

const newest = sorted[sorted.length - 1];
newest.date = intl.format(newest.date);
setFlightDate(newest);
}
},
],
],
[]
);
Expand Down Expand Up @@ -200,10 +229,16 @@ const IdentifyInformation = ({ apiKey, wkid = 3857, location }) => {
result = result.result;

let data;
if (result.length > 0) {

if (result.length === 1) {
data = result[0].attributes || {};
}

if (result.length > 1) {
console.warn('more than one result found', url);
data = result;
}

item[2](data);
} catch (error) {
console.warn(error);
Expand Down Expand Up @@ -324,6 +359,10 @@ const IdentifyInformation = ({ apiKey, wkid = 3857, location }) => {
<strong>US National Grid</strong>
<p className="identify--muted">{grid}</p>
</Col>
<Col>
<strong>Imagery Flight Data</strong>
<p className="identify--muted">{flightDate.date && `${flightDate.resolution} on ${flightDate.date}`}</p>
</Col>
</Container>
);
};
Expand Down

0 comments on commit 6debb4d

Please sign in to comment.