Introduction
The CalculateMapArea
, written in Java, is an extension designed for the MIT App Inventor platform. It facilitates drawing and calculating areas on a map. This overview is aimed at users familiar with the block-based language of MIT App Inventor but not necessarily with Java.
Constructor
- CalculateMapArea(ComponentContainer container): Initializes the extension with the given component container.
Properties Setters and Getters
- SetLineMapDraw(boolean isLineString): Defines whether to draw a LineString on the map.
- GetLineMapDraw(): Returns a boolean indicating if a LineString is being drawn.
- SetPolygonMapDraw(boolean isPolygon): Sets the drawing mode to polygon if true.
- SetPolygonMapDraw(): Retrieves the boolean status indicating if the polygon drawing mode is set.
Drawing and Map Component Methods
- SetMapComponent(Map map): Associates a Map component with the extension for drawing.
- AddPoint(double latitude, double longitude): Adds a point to the current drawing (polygon or line string) based on latitude and longitude.
- DrawLineString(): Renders the LineString on the map using the added points.
- SetLineStyle(int color, int strokeWidth): Defines the style of the line (color and stroke width).
- SetPolygonStyle(int fillColor, int strokeColor, int strokeWidth): Sets the style for the polygon (fill color, stroke color, and stroke width).
- DrawMarker(): Draws markers on the map for each point added.
- DrawPolygon(): Renders the polygon on the map using the specified points.
Utility and Calculation Methods
- GetOrderedPointsYailList(): Returns an ordered list of points (YailList) for the drawn shape.
- CalculateArea(): Calculates and returns the area of the drawn polygon.
- calculateDistance(double lat1, double lon1, double lat2, double lon2): Computes the distance between two points, considering Earth's curvature.
- CalculateTotalLineDistance(): Calculates the total distance of the line segments added.
- ResetArea(YailList featuresToRemove): Resets the area points and removes specified features from the map.
Event
- ReportError(String errorMessage): Triggers an event to report an error with a custom message.
Explanation in Block Language Context
In the context of MIT App Inventor's block language:
- Constructors are like initialization blocks that set up the extension.
- Setters and Getters (SetLineMapDraw, GetLineMapDraw, etc.) are blocks that set or retrieve properties.
- Drawing methods (AddPoint, DrawLineString, etc.) are action blocks that modify the map.
- Utility functions (CalculateArea, calculateDistance, etc.) are similar to blocks that perform calculations or specific tasks.
- Events (ReportError) work like event handlers in App Inventor, triggering when specific conditions are met.
This class essentially allows users to draw shapes on a map and calculate related data, like area and distances, using a familiar block-like approach.
Files
- AIX: com.bosonshiggs.calculatemaparea.aix (53.6 KB)
- AIA: CalculateMapArea.aia (57.1 KB)
- JAVA: GitHub - iagolirapasssos/CalculateMapArea: The CalculateMapArea, written in Java, is an extension designed for the MIT App Inventor platform. It facilitates drawing and calculating areas on a map. This overview is aimed at users familiar with the block-based language of MIT App Inventor but not necessarily with Java.