-
Notifications
You must be signed in to change notification settings - Fork 13
Alpha 0.1.10/574 add fence functionality to missions #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
1Blademaster
merged 10 commits into
release-alpha-0.1.10
from
alpha-0.1.10/574-add-fence-functionality-to-missions
Aug 16, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c6f319a
Start adding fence functionality to missions
1Blademaster e944b5e
Add circle fence marker display
1Blademaster 414fd13
Add context menu dropdown item
1Blademaster d6f5896
Start adding polygon drawing functionality
1Blademaster 14e49e6
Add polygon update function
1Blademaster 39b448f
Style mission tabs to match marker pin colours
1Blademaster 9dd54bf
Add polygon display to missions map for fence polygons
1Blademaster 8eb4e43
Fix 2 bugs
1Blademaster 398f71a
Address copilot review comments
1Blademaster 505ea9a
Fix bug
1Blademaster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
gcs/src/components/mapComponents/contextMenuSubMenuItem.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { useEffect, useRef, useState } from "react" | ||
|
|
||
| export default function ContextMenuSubMenuItem({ children, title }) { | ||
| const [isHovered, setIsHovered] = useState(false) | ||
| const [submenuPosition, setSubmenuPosition] = useState({ top: 0, left: 0 }) | ||
| const parentRef = useRef(null) | ||
| const subMenuRef = useRef(null) | ||
|
|
||
| useEffect(() => { | ||
| if (isHovered && parentRef.current && subMenuRef.current) { | ||
| const parentRect = parentRef.current.getBoundingClientRect() | ||
| const submenuRect = subMenuRef.current.getBoundingClientRect() | ||
| const viewportWidth = window.innerWidth | ||
|
|
||
| // Calculate whether to position the submenu to the right or left | ||
| const shouldAppearToLeft = | ||
| parentRect.right + submenuRect.width > viewportWidth | ||
|
|
||
| setSubmenuPosition({ | ||
| top: parentRect.top, | ||
| left: shouldAppearToLeft | ||
| ? parentRect.left - submenuRect.width | ||
| : parentRect.right, | ||
| }) | ||
| } | ||
| }, [isHovered]) | ||
|
|
||
| return ( | ||
| <div | ||
| ref={parentRef} | ||
| className="hover:bg-falcongrey-800 hover:cursor-pointer py-1 px-4 rounded" | ||
| onMouseOver={() => setIsHovered(true)} | ||
| onMouseOut={() => setIsHovered(false)} | ||
| > | ||
| <div className="w-full flex justify-between items-center gap-2"> | ||
| <p>{title}</p> | ||
| <span className="text-gray-400">▶</span> | ||
| </div> | ||
| {isHovered && ( | ||
| <div | ||
| ref={subMenuRef} | ||
| className="absolute top-0 left-full bg-falcongrey-700 rounded p-1" | ||
| style={{ | ||
| top: `${submenuPosition.top}px`, | ||
| left: `${submenuPosition.left}px`, | ||
| position: "fixed", // Use fixed to align with the viewport | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| /* | ||
| The FenceItems component returns the markers and lines connecting the | ||
| markers together on the map to display. It also filters out any | ||
| items which should not be displayed on the map as markers or not have lines | ||
| connecting them. It properly parses the type of fence marker. | ||
| */ | ||
|
|
||
| import { useEffect, useState } from "react" | ||
|
|
||
| // Helper imports | ||
| import { intToCoord } from "../../helpers/dataFormatters" | ||
|
|
||
| // Styling imports | ||
| import "maplibre-gl/dist/maplibre-gl.css" | ||
|
|
||
| // Component imports | ||
|
|
||
| // Tailing styling | ||
| import { circle } from "@turf/turf" | ||
| import { Layer, Source } from "react-map-gl" | ||
| import resolveConfig from "tailwindcss/resolveConfig" | ||
| import tailwindConfig from "../../../tailwind.config" | ||
| import { FENCE_ITEM_COMMANDS_LIST } from "../../helpers/mavlinkConstants" | ||
| import DrawLineCoordinates from "./drawLineCoordinates" | ||
| import MarkerPin from "./markerPin" | ||
| const tailwindColors = resolveConfig(tailwindConfig).theme.colors | ||
|
|
||
| function getFenceCommandNumber(value) { | ||
| return parseInt( | ||
| Object.keys(FENCE_ITEM_COMMANDS_LIST).filter( | ||
| (key) => FENCE_ITEM_COMMANDS_LIST[key] === value, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| const polygonCommands = [ | ||
| getFenceCommandNumber("MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION"), | ||
| getFenceCommandNumber("MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION"), | ||
| ] | ||
| const circleCommands = [ | ||
| getFenceCommandNumber("MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION"), | ||
| getFenceCommandNumber("MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION"), | ||
| ] | ||
|
|
||
| export default function FenceItems({ | ||
| fenceItems, | ||
| editable = false, | ||
| dragEndCallback = () => {}, | ||
| }) { | ||
| const [fencePolygonItems, setFencePolygonItems] = useState([]) | ||
| const [fenceCircleItems, setFenceCircleItems] = useState([]) | ||
|
|
||
| useEffect(() => { | ||
| // Filter out fence items based on their type | ||
| const polygonItems = fenceItems.filter((item) => | ||
| polygonCommands.includes(item.command), | ||
| ) | ||
| const circleItems = fenceItems.filter((item) => | ||
| circleCommands.includes(item.command), | ||
| ) | ||
|
|
||
| setFencePolygonItems(polygonItems) | ||
| setFenceCircleItems(circleItems) | ||
| }, [fenceItems]) | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Show mission geo-fence MARKERS */} | ||
| {fencePolygonItems.map((item, index) => { | ||
| return ( | ||
| <MarkerPin | ||
| key={index} | ||
| id={item.id} | ||
| lat={intToCoord(item.x)} | ||
| lon={intToCoord(item.y)} | ||
| colour={tailwindColors.blue[400]} | ||
| draggable={editable} | ||
| dragEndCallback={dragEndCallback} | ||
| /> | ||
| ) | ||
| })} | ||
|
|
||
| {/* Group fencePolygonItems into separate polygons */} | ||
| {(() => { | ||
| const polygons = [] | ||
| let currentPolygon = [] | ||
| let currentPoints = 0 | ||
|
|
||
| fencePolygonItems.forEach((item) => { | ||
| currentPolygon.push(item) | ||
| currentPoints++ | ||
|
|
||
| if (currentPoints === item.param1) { | ||
| polygons.push(currentPolygon) | ||
| currentPolygon = [] | ||
| currentPoints = 0 | ||
| } | ||
| }) | ||
|
|
||
| return polygons.map((polygon, index) => { | ||
| const lastPolygonItem = polygon[polygon.length - 1] | ||
|
|
||
| const color = | ||
| lastPolygonItem.command === 5002 | ||
| ? tailwindColors.red[500] | ||
| : tailwindColors.blue[200] | ||
|
|
||
| return ( | ||
| <DrawLineCoordinates | ||
| key={index} | ||
| coordinates={[ | ||
| ...polygon.map((item) => [ | ||
| intToCoord(item.y), | ||
| intToCoord(item.x), | ||
| ]), | ||
| [intToCoord(polygon[0].y), intToCoord(polygon[0].x)], | ||
| ]} | ||
| colour={color} | ||
| lineProps={{ "line-width": 2, "line-dasharray": [4, 6] }} | ||
| fillLayer={true} | ||
| fillOpacity={lastPolygonItem.command === 5002 ? 0.2 : 0} | ||
| /> | ||
| ) | ||
| }) | ||
| })()} | ||
|
|
||
| {fenceCircleItems.map((item, index) => { | ||
| return ( | ||
| <MarkerPin | ||
| key={index} | ||
| id={item.id} | ||
| lat={intToCoord(item.x)} | ||
| lon={intToCoord(item.y)} | ||
| colour={tailwindColors.blue[400]} | ||
| draggable={editable} | ||
| dragEndCallback={dragEndCallback} | ||
| /> | ||
| ) | ||
| })} | ||
|
|
||
| <Source | ||
| id="circle-source" | ||
| type="geojson" | ||
| data={{ | ||
| type: "FeatureCollection", | ||
| features: fenceCircleItems.map((item) => | ||
| circle([intToCoord(item.y), intToCoord(item.x)], item.param1, { | ||
|
1Blademaster marked this conversation as resolved.
|
||
| steps: 64, // Number of points to create the circle | ||
| units: "meters", // Units for the radius | ||
| properties: { | ||
| color: | ||
| item.command === 5004 | ||
| ? tailwindColors.red[500] | ||
| : tailwindColors.blue[200], | ||
| fillOpacity: item.command === 5004 ? 0.2 : 0, // No fill if inclusion | ||
| }, | ||
| }), | ||
| ), | ||
| }} | ||
| > | ||
| <Layer | ||
| id="fence-circle-fill-layer" | ||
| type="fill" | ||
| paint={{ | ||
| "fill-color": ["get", "color"], | ||
| "fill-opacity": ["get", "fillOpacity"], | ||
| }} | ||
| /> | ||
| <Layer | ||
| id="fence-circle-border-layer" | ||
| type="line" | ||
| paint={{ | ||
| "line-color": ["get", "color"], | ||
| "line-width": 2, | ||
| "line-dasharray": [2, 2], | ||
| }} | ||
| /> | ||
| </Source> | ||
| </> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| The PolygonItems component returns the markers and lines connecting the | ||
| polygon together on the map to display. | ||
| */ | ||
|
|
||
| // Helper imports | ||
|
|
||
| // Styling imports | ||
| import "maplibre-gl/dist/maplibre-gl.css" | ||
|
|
||
| // Component imports | ||
| import DrawLineCoordinates from "./drawLineCoordinates" | ||
| import MarkerPin from "./markerPin" | ||
|
|
||
| // Tailing styling | ||
| import resolveConfig from "tailwindcss/resolveConfig" | ||
| import tailwindConfig from "../../../tailwind.config" | ||
| const tailwindColors = resolveConfig(tailwindConfig).theme.colors | ||
|
|
||
| export default function Polygon({ | ||
| polygonPoints, | ||
| editable = false, | ||
| dragEndCallback = () => {}, | ||
| }) { | ||
| return ( | ||
| <> | ||
| {/* Show polygon MARKERS */} | ||
| {polygonPoints.map((item, index) => { | ||
| return ( | ||
| <MarkerPin | ||
| key={index} | ||
| id={item.id} | ||
| lat={item.lat} | ||
| lon={item.lon} | ||
| colour={tailwindColors.red[400]} | ||
| draggable={editable} | ||
| dragEndCallback={dragEndCallback} | ||
| /> | ||
| ) | ||
| })} | ||
|
|
||
| {/* Show polygon outlines */} | ||
| {polygonPoints.length > 0 && ( | ||
| <DrawLineCoordinates | ||
| coordinates={[ | ||
| ...polygonPoints.map((item) => [item.lon, item.lat]), | ||
| [polygonPoints[0].lon, polygonPoints[0].lat], | ||
| ]} | ||
| colour={tailwindColors.red[200]} | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| This table displays all the fence items. | ||
| */ | ||
|
|
||
| import { Table } from "@mantine/core" | ||
| import React from "react" | ||
| import FenceItemsTableRow from "./fenceItemsTableRow" | ||
|
|
||
| function FenceItemsTableNonMemo({ | ||
| fenceItems, | ||
| updateMissionItem, | ||
| deleteMissionItem, | ||
| updateMissionItemOrder, | ||
| }) { | ||
| return ( | ||
| <Table striped withTableBorder withColumnBorders stickyHeader> | ||
| <Table.Thead> | ||
| <Table.Tr> | ||
| <Table.Th></Table.Th> | ||
| <Table.Th>Command</Table.Th> | ||
| <Table.Th>Param 1</Table.Th> | ||
| <Table.Th></Table.Th> | ||
| <Table.Th></Table.Th> | ||
| <Table.Th></Table.Th> | ||
| <Table.Th>Lat</Table.Th> | ||
| <Table.Th>Lng</Table.Th> | ||
| <Table.Th></Table.Th> | ||
| <Table.Th>Frame</Table.Th> | ||
| <Table.Th></Table.Th> | ||
| </Table.Tr> | ||
| </Table.Thead> | ||
| <Table.Tbody> | ||
| {fenceItems.map((fenceItem, idx) => { | ||
| return ( | ||
| <FenceItemsTableRow | ||
| key={fenceItem.id} | ||
| index={idx} | ||
| fenceItem={fenceItem} | ||
| updateMissionItem={updateMissionItem} | ||
| deleteMissionItem={deleteMissionItem} | ||
| updateMissionItemOrder={updateMissionItemOrder} | ||
| /> | ||
| ) | ||
| })} | ||
| </Table.Tbody> | ||
| </Table> | ||
| ) | ||
| } | ||
|
|
||
| function propsAreEqual(prev, next) { | ||
| return JSON.stringify(prev) === JSON.stringify(next) | ||
| } | ||
| const FenceItemsTable = React.memo(FenceItemsTableNonMemo, propsAreEqual) | ||
|
|
||
| export default FenceItemsTable |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.