diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx index 6f1a7e7..f30d6dd 100644 --- a/src/field/FieldList.tsx +++ b/src/field/FieldList.tsx @@ -94,59 +94,12 @@ export default function FieldList() { return totalAcres; }; - // const fieldList = (fields: Field[]) => { - // return fields.map((field, index) => ( - // - // {field.fieldName()} - // {field.landLoc()} - // - // {field.crop() === pond.Grain.GRAIN_CUSTOM - // ? field.customType() - // : GrainDescriber(field.crop()).name} - // - // {field.calculateAcres()} - // - // {field.permissions.includes(pond.Permission.PERMISSION_WRITE) && ( - // - // )} - // - // - // )); - // } - - // const fieldTable = (fields: Field[]) => { - // return ( - // - // - // - // - // Field Name - // Land Location - // Main Crop Type - // Acres ({calcTotalAcres(fields)} Total) - // Create New Plan - // - // - // {fieldList(fields)} - //
- //
- // ) - // } - const columns: Column[] = [ { title: "View", render: row => { return ( - + ) @@ -184,10 +137,9 @@ const columns: Column[] = [ columns={columns} rows={fields} setPage={()=>{}} - hidePagination handleRowsPerPageChange={()=>{}} page={0} - pageSize={10} + pageSize={1} total={fields.length} /> ) diff --git a/src/field/Fieldminimap.tsx b/src/field/Fieldminimap.tsx index 489877b..762a622 100644 --- a/src/field/Fieldminimap.tsx +++ b/src/field/Fieldminimap.tsx @@ -1,24 +1,58 @@ -import { Box } from "@mui/material"; +import { CircularProgress } from "@mui/material"; import { Field } from "models"; -import { useRef } from "react"; -import Map, { MapRef } from "react-map-gl/mapbox"; +import { useEffect, useState } from "react"; +import Map from "react-map-gl/mapbox"; import 'mapbox-gl/dist/mapbox-gl.css'; +import GeoMapLayer from "maps/mapLayers/geoMapLayer"; +import { Feature, FeatureCollection } from "geojson"; +import { GeometryMapping } from "models/GeometryMapping"; interface Props { - field?: Field + field: Field } export default function FieldMinimap(props: Props) { const { field } = props const MAPBOX_TOKEN = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN; + const [geoCollection, setGeoCollection] = useState(); + + useEffect(()=>{ + let fieldData = field.settings.fieldGeoData + if(fieldData){ + let fieldFeature = GeometryMapping.geoJSON(fieldData.geoShape, fieldData.shapes, fieldData.holes) as Feature; + fieldFeature.id = fieldData.objectKey; + fieldFeature.properties = { + title: fieldData.title, + objectKey: fieldData.objectKey, + fill: fieldData.colour, + lineWidth: fieldData.geoShape === "LineString" ? 5 : 2, + origin: fieldData.origin + }; + let collection: FeatureCollection = { + type: "FeatureCollection", + features: [fieldFeature] + }; + setGeoCollection(collection); + } + },[field]) - return ( + return geoCollection ? + ( + {}} /> - - ) + + ) + : + () } \ No newline at end of file diff --git a/src/models/Field.ts b/src/models/Field.ts index 25b3263..3816fce 100644 --- a/src/models/Field.ts +++ b/src/models/Field.ts @@ -5,6 +5,7 @@ import area from "@turf/area"; import { Feature } from "geojson"; import { GeometryMapping } from "./GeometryMapping"; import GrainDescriber from "grain/GrainDescriber"; +import { LngLat, LngLatBounds } from "mapbox-gl"; export class Field { public settings: pond.FieldSettings = pond.FieldSettings.create(); @@ -152,6 +153,42 @@ export class Field { return coords; } + /** + * Returns a LngLatBounds object containing the southwest and northeast corners of a box to contain the field, spacing can also be provided + * to pad the sides of the bounding area + * @param spacing - an optional paramater that will expand the bounding area by the given long lat amount + * @returns LngLatBounds - an object containing the southwest and northeast coordinates of a bounding box + */ + public fieldBounds(spacing?: number): LngLatBounds { + let minLong = 0; + let minLat = 0; + let maxLong = 0; + let maxLat = 0; + if (this.settings.fieldGeoData) { + this.settings.fieldGeoData.shapes.forEach(shape => { + shape.points.forEach(pair => { + if (pair.longitude < minLong || minLong === 0) minLong = pair.longitude; + if (pair.longitude > maxLong || maxLong === 0) maxLong = pair.longitude; + if (pair.latitude < minLat || minLat === 0) minLat = pair.latitude; + if (pair.latitude > maxLat || maxLat === 0) maxLat = pair.latitude; + }); + }); + } + // let southWest = [minLong,minLat] + // let northEast = [maxLong,maxLat] + if(spacing){ + minLong = minLong - spacing + minLat = minLat - spacing + maxLong = maxLong + spacing + maxLat = maxLat + spacing + } + return new LngLatBounds( + new LngLat(minLong, minLat), + new LngLat(maxLong, maxLat) + ); + // return[southWest, northEast] + } + public grainName(): string { if (this.grain() !== pond.Grain.GRAIN_INVALID) { if (this.grain() === pond.Grain.GRAIN_CUSTOM) {