added option to the field minimap and the field bounds for the options to adjust the bounds to make them squared for longer/taller fields
This commit is contained in:
parent
3802691977
commit
b3a8a3b25f
3 changed files with 18 additions and 5 deletions
|
|
@ -136,7 +136,7 @@ const columns: Column<Field>[] = [
|
|||
render: row => {
|
||||
return (
|
||||
<Box margin={1} height={200} width={200}>
|
||||
<FieldMinimap field={row} />
|
||||
<FieldMinimap field={row} squared borderSpacing={0.001}/>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ import { GeometryMapping } from "models/GeometryMapping";
|
|||
|
||||
interface Props {
|
||||
field: Field
|
||||
squared?: boolean
|
||||
borderSpacing?: number
|
||||
}
|
||||
|
||||
export default function FieldMinimap(props: Props) {
|
||||
const { field } = props
|
||||
const { field, squared, borderSpacing } = props
|
||||
const MAPBOX_TOKEN = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN;
|
||||
const [geoCollection, setGeoCollection] = useState<FeatureCollection>();
|
||||
|
||||
|
|
@ -42,7 +44,7 @@ export default function FieldMinimap(props: Props) {
|
|||
<Map
|
||||
zoom={1}
|
||||
maxBounds={
|
||||
field.fieldBounds(.001)
|
||||
field.fieldBounds(borderSpacing, squared)
|
||||
}
|
||||
reuseMaps
|
||||
style={{width: "100%", height: "100%"}}
|
||||
|
|
|
|||
|
|
@ -181,8 +181,20 @@ export class Field {
|
|||
if (squared){
|
||||
//make sure the bounds are squared so as to fit the entire field in the map
|
||||
//get the diff between the longs and the lats
|
||||
let longDiff = maxLong - minLong
|
||||
let latDiff = maxLat - minLat
|
||||
//find which is narrower
|
||||
//take half of the difference between the differences
|
||||
if(longDiff > latDiff){
|
||||
//if the longitude is the narrow bound apply half of the diff between the diffs to the min and max lats
|
||||
let halfDiff = (longDiff - latDiff)/2
|
||||
minLat = minLat - halfDiff
|
||||
maxLat = maxLat + halfDiff
|
||||
} else {
|
||||
//if the longitude is not the narrow bound apply half of the diff between the diffs to the min and max longs
|
||||
let halfDiff = (latDiff - longDiff)/2
|
||||
minLong = minLong - halfDiff
|
||||
maxLong = maxLong + halfDiff
|
||||
}
|
||||
}
|
||||
if(spacing){
|
||||
minLong = minLong - spacing
|
||||
|
|
@ -194,7 +206,6 @@ export class Field {
|
|||
new LngLat(minLong, minLat),
|
||||
new LngLat(maxLong, maxLat)
|
||||
);
|
||||
// return[southWest, northEast]
|
||||
}
|
||||
|
||||
public grainName(): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue