Skip to main content
Version: Release 1 - 1.1.3.X

Geometry & Projection Helpers

Why you’d use these helpers

  • Run spatial math (buffers, intersections, boolean checks) without bundling your own Turf build.
  • Convert between projections, clip extents, or reproject individual coordinates with the same projection helpers Maptaskr Power Maps uses internally.
  • Access convenience utilities (distance, centroid, bbox, simplification) via a single cached GeoHelper bundle.

All helpers are available through our extension services. An example would be inside custom action callbacks or Power Automate-triggered extension hooks.

const control = globalThis.MaptaskrControlManager.getControl(controlId);

const Turf = control.getTurfHelper()

const Proj4 = control.getProjHelper()

const GeoHelper = control.getGeoHelper()

API reference

Turf

FunctionDescriptionAcceptsReturns
buffer(feature, radius, { units, steps })Expands geometries by radius in Turf-supported units (meters default).GeoJSON Feature or FeatureCollection, numeric radius.Buffered Feature/FeatureCollection.
union(features, { properties }) Merges overlapping polygons into a single feature while optionally overriding properties.Polygon/MultiPolygon FeatureCollection.Combined Feature or null.
featureCollection(features, { bbox, id })Convenience creator for valid FeatureCollections (useful after manipulating geometries).Array of GeoJSON Feature.FeatureCollection.
difference(features) Subtracts the second polygon from the first in the collection.Polygon/MultiPolygon FeatureCollection.Resulting Feature or null.
intersect(features, { properties }) Computes the intersection of polygons.Polygon/MultiPolygon FeatureCollection.Intersection Feature or null.
booleanDisjoint(featureA, featureB, { ignoreSelfIntersections })Tests whether two geometries share any space.GeoJSON Feature or raw Geometry.boolean.
booleanIntersects(featureA, featureB, { ignoreSelfIntersections })Checks if geometries overlap/touch.GeoJSON Feature or raw Geometry.boolean.

Examples

const turfHelper = control.getTurf();

// Using Buffer
const point = turfHelper.point([-90.54863, 14.616599]);
const buffered = turfHelper.buffer(point, 500, { units: "meters" }); // Creates a 500 m buffer polygon around the point.

// Using Union
const poly1 = turfHelper.polygon(
[
[
[-82.574787, 35.594087],
[-82.574787, 35.615581],
[-82.545261, 35.615581],
[-82.545261, 35.594087],
[-82.574787, 35.594087],
],
],
{ fill: "#0f0" },
);

const poly2 = turfHelper.polygon([
[
[-82.560024, 35.585153],
[-82.560024, 35.602602],
[-82.52964, 35.602602],
[-82.52964, 35.585153],
[-82.560024, 35.585153],
],
]);

const union = turfHelper.union(turfHelper.featureCollection([poly1, poly2])); // Merges overlapping parcels into a single footprint.

// Using collection
var locationA = turfHelper.point([-75.343, 39.984], { name: "Location A" });
var locationB = turfHelper.point([-75.833, 39.284], { name: "Location B" });
var locationC = turfHelper.point([-75.534, 39.123], { name: "Location C" });

var collection = turfHelper.featureCollection([locationA, locationB, locationC]); // Keeps related POIs together for batch operations.

// GeoJSON Feature (or null) representing the first polygon minus the rest.
var polygon1 = turfHelper.polygon(
[
[
[128, -26],
[141, -26],
[141, -21],
[128, -21],
[128, -26],
],
],
{
fill: "#F00",
"fill-opacity": 0.1,
},
);
var polygon2 = turfHelper.polygon(
[
[
[126, -28],
[140, -28],
[140, -20],
[126, -20],
[126, -28],
],
],
{
fill: "#00F",
"fill-opacity": 0.1,
},
);

var difference = turfHelper.difference(turfHelper.featureCollection([polygon1, polygon2])); // Area of polygon1 minus polygon2 (null if no overlap).

// GeoJSON Feature (or null) describing the intersection area.
var poly1 = turfHelper.polygon([
[
[-122.801742, 45.48565],
[-122.801742, 45.60491],
[-122.584762, 45.60491],
[-122.584762, 45.48565],
[-122.801742, 45.48565],
],
]);

var poly2 = turfHelper.polygon([
[
[-122.520217, 45.535693],
[-122.64038, 45.553967],
[-122.720031, 45.526554],
[-122.669906, 45.507309],
[-122.723464, 45.446643],
[-122.532577, 45.408574],
[-122.487258, 45.477466],
[-122.520217, 45.535693],
],
]);

var intersection = turfHelper.intersect(turfHelper.featureCollection([poly1, poly2])); // Returns the shared area or null when polygons do not overlap.

// Boolean indicating features share zero space.
var point = turfHelper.point([2, 2]);
var line = turfHelper.lineString([
[1, 1],
[1, 2],
[1, 3],
[1, 4],
]);

turfHelper.booleanDisjoint(line, point); // true when the line never touches the point.

// Boolean indicating features touch or overlap.
var point1 = turfHelper.point([2, 2]);
var point2 = turfHelper.point([1, 2]);
var line = turfHelper.lineString([
[1, 1],
[1, 3],
[1, 4],
]);

turfHelper.booleanIntersects(line, point1);
//=false — no shared vertex or segment

turfHelper.booleanIntersects(line, point2);
//=true — point2 lies directly on the line
tip

Extension actions receive Maptaskr Power Maps Feature objects. If you need pure GeoJSON, read the .geometry property or call turf.featureCollection([{ ...feature.geometry }]).

Proj4

FunctionDescription
getNameForWkid(wkid) / getWkidForName(name)Lookup helpers to get a projection name from the Power Maps projection registry.
convertExtentTo4326(extent) / convertExtentToTargetProjection(extent, target)Reprojects bounding boxes between spatial references while preserving north/south ordering.
reprojectPoint(coord, sourceWkid, targetWkid)Single-point reprojection (returns a new MaptaskrCoordinate).
getValid4326BoundsForWkid(wkid) Returns a safe lat/long extent for the projection or null if none.
ensureProjection(code)Loads projection metadata on-demand (no-ops if already cached).
getDefault4326Extent() Handy constant for “show me the world” views.
ensureValid4326Extent(extent) Clamps and normalizes extents to stay inside WGS84 limits.
isSupported(code) Quick guard before letting users pick a projection.

Examples

const projHelper = control.getProjHelper();

// String like 'WGS 84 / Pseudo-Mercator'.
const name = projHelper.getNameForWkid(3857);

// WKID number (or undefined if unknown).
const wkid = projHelper.getWkidForName('EPSG:3112');

// Extent converted to geographic coordinates.
const worldExtent = projHelper.convertExtentTo4326(providerExtent);

// Extent converted into the requested projection.
const targetExtent = projHelper.convertExtentToTargetProjection(providerExtent, 7855);

// Coordinate reprojected between WKIDs.
const reprojected = projHelper.reprojectPoint([153, -27], 4326, 3857);

// Extent representing valid lat/long bounds or null.
const safeBounds = projHelper.getValid4326BoundsForWkid(7855);

// Void return; ensures projection metadata is loaded.
projHelper.ensureProjection(2193);

// Default world extent (Extent struct).
const defaultExtent = projHelper.getDefault4326Extent();

// Extent clamped/normalized to valid WGS84 bounds.
const clampedExtent = projHelper.ensureValid4326Extent(userExtent);

// Boolean indicating if the code is supported.
const supported = projHelper.isSupported('EPSG:2193');

GeoHelper

FunctionWhat it does
degToRad(angle) Converts angles to radians (useful before trig math).
getDistance(coordA, coordB, radius)Distance on a sphere with configurable radius.
extentsIntersect(extentA, extentB) Boolean overlap check for Extent objects.
calculateExtent(geometry) Builds a Maptaskr Power Maps Extent around any GeoJSON geometry.
calculateCentroidFromExtent(extent)Returns { latitude, longitude } for the extent center.
intersectExtents(extentA, extentB) Returns the overlapping extent or undefined.
isFeatureInExtent(feature, extent, extentAsGeometry?) Determines if a Maptaskr Power Maps Feature falls inside an extent.
simplifyGeometry(geometry, tolerance)Lightweight Douglas–Peucker simplification for faster drawing.
reprojectGeometry(geometry, source, target, clone)Mass-reprojects all coordinates (optionally cloning first).
getBoundingBox(geometry)Returns { xmin, ymin, xmax, ymax }.
getFlattenedCoordinates(geometry)Flattens nested rings into a simple coordinate array.
calculateCentroid(geometry)Computes the centroid as a MaptaskrCoordinate.

Examples

const geoHelper = control.getGeoHelper();

// Angle in radians.
const radians = geoHelper.degToRad(90);

// Distance in meters (because radius used meters).
const km = geoHelper.getDistance([151, -33], [152, -34], 6371_000);

// Boolean for extent overlap.
const overlaps = geoHelper.extentsIntersect(extentA, extentB);

// Maptaskr Power Maps Extent covering the geometry.
const derivedExtent = geoHelper.calculateExtent(geometry);

// FeatureCentroid containing lat/long.
const centroidFromExtent = geoHelper.calculateCentroidFromExtent(extentA);

// Overlapping extent or undefined.
const intersection = geoHelper.intersectExtents(extentA, extentB);

// Boolean: does the feature fall inside the extent?
const inside = geoHelper.isFeatureInExtent(selectedFeature, extentA);

// Simplified GeoJSON geometry.
const simplified = geoHelper.simplifyGeometry(geometry, 0.001);

// Reprojected geometry (clone depends on the flag).
const reprojection = geoHelper.reprojectGeometry(geometry, 4326, 3857, true);

// Bounding Extent for the geometry.
const bbox = geoHelper.getBoundingBox(geometry);

// Flat array of coordinates.
const coords = geoHelper.getFlattenedCoordinates(geometry);

// MaptaskrCoordinate describing the centroid.
const centroid = geoHelper.calculateCentroid(geometry);

Best practices

  • Stay type-safe. Our TypeScript declarations differentiate between Maptaskr Power Maps Feature (rich metadata) and raw GeoJSON. When a helper expects GeoJSON, pass feature.geometry or convert via turf.featureCollection().
  • Mind your units. Turf defaults to kilometers; pass { units: 'meters' | 'miles' | ... } explicitly if you surface UI inputs in other units.
  • Wrap async usage. Many helper workflows feed back into action execution (e.g., highlight, filtering). Always handle Promise rejections from your own async code before returning control to Maptaskr Power Maps.
  • Guard projections. Call proj4.isSupported(code) before attempting conversions supplied by end users.