Skip to content

Commit

Permalink
- Uses new FeatureType for conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
sophia-massie committed Dec 20, 2024
1 parent 6d82ec5 commit efa3dee
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions react/src/components/AssetDetail/AssetGeometry.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import React from 'react';
import _ from 'lodash';
import * as turf from '@turf/turf';
import { Feature } from '@hazmapper/types';
import { Feature, FeatureType, getFeatureType } from '@hazmapper/types';

interface GeometryAssetProps {
interface AssetGeometryProps {
selectedFeature: Feature;
}

const GeometryAsset: React.FC<GeometryAssetProps> = ({ selectedFeature }) => {
const AssetGeometry: React.FC<AssetGeometryProps> = ({ selectedFeature }) => {
if (!selectedFeature?.geometry) return null;

const bbox =
selectedFeature.geometry.type !== 'Point'
? turf.bbox(selectedFeature)
: null;

const geometryType: FeatureType = getFeatureType(selectedFeature);

return (
<>
{selectedFeature.geometry.type === 'Point' && (
{geometryType === FeatureType.Point && (
<table>
<thead>
<tr>
Expand All @@ -29,17 +31,17 @@ const GeometryAsset: React.FC<GeometryAssetProps> = ({ selectedFeature }) => {
<tbody>
<tr>
<td>Latitude</td>
<td>{selectedFeature.geometry.coordinates[0]}</td>
<td>{turf.bbox(selectedFeature.geometry)[0]}</td>
</tr>
<tr>
<td>Longitude</td>
<td>{selectedFeature.geometry.coordinates[1]}</td>
<td>{turf.bbox(selectedFeature.geometry)[1]}</td>
</tr>
</tbody>
</table>
)}
{(selectedFeature.geometry.type === 'Polygon' ||
selectedFeature.geometry.type === 'MultiPolygon') && (
{(geometryType === FeatureType.Polygon ||
geometryType === FeatureType.MultiPolygon) && (
<table>
<thead>
<tr>
Expand All @@ -56,8 +58,8 @@ const GeometryAsset: React.FC<GeometryAssetProps> = ({ selectedFeature }) => {
</tbody>
</table>
)}
{(selectedFeature.geometry.type === 'LineString' ||
selectedFeature.geometry.type === 'MultiLineString') && (
{(geometryType === FeatureType.LineString ||
geometryType === FeatureType.MultiLineString) && (
<table>
<thead>
<tr>
Expand All @@ -74,7 +76,7 @@ const GeometryAsset: React.FC<GeometryAssetProps> = ({ selectedFeature }) => {
</tbody>
</table>
)}
{selectedFeature.geometry.type !== 'Point' && bbox && (
{geometryType !== FeatureType.Point && bbox && (
<table>
<thead>
{selectedFeature.geometry.type === 'GeometryCollection' && (
Expand Down Expand Up @@ -113,4 +115,4 @@ const GeometryAsset: React.FC<GeometryAssetProps> = ({ selectedFeature }) => {
);
};

export default GeometryAsset;
export default AssetGeometry;

0 comments on commit efa3dee

Please sign in to comment.