Skip to content

GPS Draw Tool

Matthew Logan edited this page Nov 7, 2024 · 3 revisions

Overview

This document outlines core functionality of the Map drawing tool that leverages the Users GPS To create GeoShapes. The tool currently supports workflows for Polygons and LineStrings.

---
  title: Sequence Diagram for GPS Draw Tool
---
sequenceDiagram
    actor User
    participant Frontend
    participant Redux
    participant Callback
User->>Frontend: User Selects draw me tool
Frontend->>Redux: Dispatch Action Fired
Redux->>Frontend: new prompt added to Prompt[]
Frontend->>User: User Prompted for GeoShape
User->>Frontend: User Selects LineString
Frontend->>Callback: Callback action performed
Callback->>Redux: Dispatch action fired
Redux->>Frontend: Tracking started
Redux->>Frontend: Alert added to Alert[]
Frontend->>User: User sees tracking has begun
loop While user tracking
  Frontend->>Redux: GPS Fires Update
  Redux->>Frontend: Coordinate appended, UI Updates
end
User->>Frontend: User Stops Tracking
Frontend->>Redux: Dispatch action fired
Redux->>Redux: Validation Performed
alt is errors
  Redux->>Frontend: Errors pushed to Alert[]
  Frontend->>User: User sees alert errors
  User->>Frontend: User Corrects errors, presses Stop Tracking
  Frontend->>Redux: Dispach Action Fired
end
Redux->>Frontend: new prompt added to Prompt[]
Frontend->>User: User Prompted for buffer radius
User->>Frontend: User inputs "5 meters"
Frontend->>Callback: Callback Action performed
Callback->>Redux: Dispatch action called
Redux->>Frontend: Shape & UI Updated, Tracking stopped

Loading

Core Functionality

  • Shape Selection: Users initiate the drawing process by selecting the Track me Button followed by the Draw Type (Polygon or Linestring) from a prompt

  • GPS Data Collection: Once a shape is chosen, the tool begins collecting the GPS Coordinates, storing them in an array. These coordinates are continuously plotted on the map to provide real-time visual feedback

  • Shape Completion: Users finalize the shape by toggling the draw tool button. The tool then validated the shape based on the selected type. Some checks include:

    • Minimum number of coordinates
    • No intersecting sections
    • Minimum area covered by the shape
  • Shape Editing: Users can edit shapes while on the go my simply selecting the shape on the map. They can adjust points or add new ones.

  • Linestring Buffering: For Linestrings, a post-drawing prompt allows users to add a buffer margin, converting the Linestring into a Polygon

Developing

The GPS Draw Tool branches across multiple files, and makes use of in-house tools such as the prompt and alert systems to pass information around

State

The GeoTracking tool is managed by the Activity track_me_draw_geo state object. It contains the following values:

{
  track_me_draw_geo: {
    isTracking: boolean;
    type: GeoShapes | null;
    drawingShape: boolean;
  };
}

The draw tool can be started by making a dispatch to redux with The GeoTracking tools are scoped to the static GeoTracking class to give an Object Oriented approach

  dispatch(GeoTracking.start(input as GeoShapes))

And stopped with

  dispatch(GeoTracking.stop());

Starting

There are currently two ways a user can start the drawing tool:

  • While in an Activity Record, select "CLICK TO DRAW A GEOMETRY BY TRACING YOUR GPS MOVEMENT".
  • Expand the "Find Me" button on the Map view, then select "Track my Path".

Both actions will result in a prompt modal appearing to collect the user's desired shape to build. Completing this prompt will result in the class being started.

While Tracking is Occuring

While the GPS Draw tool is active, it will fire requests to MAP_SET_COORDS with each GPS update. This Redux handler will validate that the new coordinate has a minimum distance from the last entry in the coordinates array. If the gap is sufficient, the new coordinate will be appended.

During the runtime of the GPS draw tool, all shapes are treated as linestrings to avoid handlers throwing errors over shapes not meeting specific criteria. They are cast to their correct shape and handled at end time.

Ending Tracking

When the user wants to end the tracking process, GeoTracking.stop() is called and picked up by its Redux handler.

If the user has 0 coordinates in their array, the tool exits early as if the tracking never occurred.

The handler checks the existing shape created by the user and runs validation on it. With a switch case, specific rules can be added for any applicable shapes being drawn to ensure correctness.

For example, a shape is considered invalid (improper) if it has sections that intersect each other.

If there is an error, the handler will fire a prompt alerting the user of the error. At this stage, the user can abandon their progress or go back and edit their shape so that it complies.

If the shape is a Linestring, a user will be prompted to add a Buffer radius. This buffering is handled by turf.js

The GeoTracking.stop() event is fired, ending the tracking. Alerts.create() is called to notify the user of its conclusion, and finally, the new geometry is passed onto to its final destination: ACTIVITY_UPDATE_GEO_REQUEST Where all shapes are handled.