Shapes
Intro: Shape accessor functions let you retrieve and manipulate ad‑hoc or record‑linked shapes (polygons, lines, points) rendered in the map control.
getShapes
Retrieve all shapes associated with a given context identifier (or all if the id represents a broad scope depending on implementation).
Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | Context / grouping id (related entity id or predefined scope). |
Usage:
const shapes = control.getShapes();
console.log(shapes.length);
addOrUpdateShape
Creates or updates an existing shape using the shape parameters. If the ShapeId passed isn't in the shapes table it will create a new shape otherwise it will update an existing
Parameters (CustomShape):
| Field | Type | Required | Description |
|---|---|---|---|
| shapeId | string | Yes (create) | Unique identifier. Reuse to update existing. |
| shapeName | string | Yes | Display name. |
| geoJsonObject | FeatureCollection | Optional | Geometry + properties (omit for name-only update). |
| predefinedShapeId | string | Optional | Reference to a predefined shape configuration. |
| features[].type | string | Yes (geoJsonObject) | GeoJSON feature type (e.g. Feature). |
| features[].properties | object | Optional | Styling / metadata (stroke, fill, etc.). |
| geometry.type | string | Yes (geoJsonObject) | GeoJSON geometry type (Polygon, etc.). |
| geometry.coordinates | number[][][] | Yes (geoJsonObject) | Coordinates matching geometry type. |
Usage:
const shapeGeoJson = {
shapeId: "7e0c4b6a-9f5d-4c2d-b1c3-6a2f9d8352d1",
shapeName: "My Created Shape"
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: { stroke: "#ff0000", fill: "#555555" },
geometry: {
type: "Polygon",
coordinates: [[[115.8376,-32.1152],[115.8385,-32.1158],[115.8403,-32.1172],[115.8376,-32.1152]]]
}
}
]
};
const shapes = control.addOrUpdateShape(shapeGeoJson);
console.log(shapes.length);
note
- Ensure coordinates are in WGS84 ([longitude, latitude]).
- If you only have raw GeoJSON, wrap it inside a MaptaskrShape with id, name, and geoJsonObject.
- Use unique ids when adding multiple shapes.
- Optional fields like minLatitude, maxLatitude, etc. can be precomputed if needed (e.g., for bounding-box queries).
deleteShape
Remove a shape from the map.
Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| shape | MaptaskrShape | Yes | Shape reference; must include the shapeId. |
Usage:
await control.deleteShape(shape);
Deleting is irreversible—confirm with the user if the shape represents authored content.
Performance: Large polygons with many vertices can impact rendering; simplify geometry client‑side if possible before calling addShape or updateShape.