Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (20 sloc)
884 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import circle from '@turf/circle'; | |
import distance from '@turf/distance'; | |
import { Position, Polygon, FeatureOf } from '../geojson-types'; | |
import { TwoClickPolygonMode } from './two-click-polygon-mode'; | |
export class DrawCircleFromCenterMode extends TwoClickPolygonMode { | |
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> { | |
// Default turf value for circle is 64 | |
const { steps = 64 } = modeConfig || {}; | |
const options = { steps }; | |
if (steps < 4) { | |
console.warn(`Minimum steps to draw a circle is 4 `); // eslint-disable-line no-console,no-undef | |
options.steps = 4; | |
} | |
const radius = Math.max(distance(coord1, coord2), 0.001); | |
const geometry = circle(coord1, radius, options); | |
geometry.properties = geometry.properties || {}; | |
geometry.properties.shape = 'Circle'; | |
return geometry; | |
} | |
} |