Skip to content

Commit

Permalink
feat: adds a radius property to the measure circle button
Browse files Browse the repository at this point in the history
  • Loading branch information
FritzHoing committed Nov 23, 2023
1 parent a57c55d commit 6942024
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Button/MeasureButton/MeasureButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ interface OwnProps {
* Whether the measure is using geodesic or cartesian mode. Geodesic is used by default.
*/
geodesic: boolean;
/**
* If set true, instead of the area, the radius will be measured.
*/
measureRadius?: boolean;
}

export type MeasureType = 'line' | 'polygon' | 'angle' | 'circle';
Expand Down Expand Up @@ -156,7 +160,8 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
},
pressed: false,
onToggle: () => undefined,
geodesic: true
geodesic: true,
measureRadius: false
};

/**
Expand Down Expand Up @@ -831,7 +836,8 @@ class MeasureButton extends React.Component<MeasureButtonProps> {
measureType,
decimalPlacesInTooltips,
map,
geodesic
geodesic,
measureRadius
} = this.props;

if (!this._measureTooltipElement) {
Expand All @@ -852,7 +858,13 @@ class MeasureButton extends React.Component<MeasureButtonProps> {

if (geom instanceof OlGeomCircle) {
measureTooltipCoord = geom.getLastCoordinate();
output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic);
if (!measureRadius) {
output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic);
} else {
const decimalHelper = Math.pow(10, decimalPlacesInTooltips);
const radius = Math.round(geom.getRadius() * decimalHelper) / decimalHelper;
output = `${radius.toString()} m`;
}
} else if (geom instanceof OlGeomPolygon) {
output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic);
// attach area at interior point
Expand Down

0 comments on commit 6942024

Please sign in to comment.