Skip to content

Commit

Permalink
Ability to provide callback to get measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonicclay committed Nov 25, 2019
1 parent 98ef045 commit ed8e31a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/api-reference/modes/overview.md
Expand Up @@ -149,6 +149,10 @@ The following options can be provided in the `modeConfig` object:
* Function to format tooltip text (argument is the numeric distance)
* Default: `(distance) => parseFloat(distance).toFixed(2) + units`

* `measurementCallback` (Function, optional)
* Function to call as measurements are calculated
* Default: `undefined`

## [ElevationMode](https://github.com/uber/nebula.gl/blob/master/modules/edit-modes/src/lib/elevation-mode.js)

User can move a point up and down.
Expand Down
6 changes: 5 additions & 1 deletion modules/edit-modes/src/lib/measure-distance-mode.js
Expand Up @@ -38,7 +38,7 @@ export class MeasureDistanceMode extends BaseGeoJsonEditMode {
let tooltips = DEFAULT_TOOLTIPS;

if (startingPoint && endingPoint) {
const { formatTooltip, turfOptions } = modeConfig || {};
const { formatTooltip, turfOptions, measurementCallback } = modeConfig || {};
const units = (turfOptions && turfOptions.units) || 'kilometers';

const distance = turfDistance(startingPoint, endingPoint, turfOptions);
Expand All @@ -52,6 +52,10 @@ export class MeasureDistanceMode extends BaseGeoJsonEditMode {
text = `${parseFloat(distance).toFixed(2)} ${units}`;
}

if (measurementCallback) {
measurementCallback(distance);
}

tooltips = [
{
position: endingPoint.geometry.coordinates,
Expand Down

0 comments on commit ed8e31a

Please sign in to comment.