Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds a radius property to the measure circle button #3644

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 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,18 @@ 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 area = MeasureUtil.getAreaOfCircle(geom, map);
const decimalHelper = Math.pow(10, decimalPlacesInTooltips);
const radius = Math.round(geom.getRadius() * decimalHelper) / decimalHelper;
output = `${radius.toString()} m`;
weskamm marked this conversation as resolved.
Show resolved Hide resolved
dnlkoch marked this conversation as resolved.
Show resolved Hide resolved
if (area > (Math.PI * 1000000)) {
output = (Math.round(geom.getRadius() / 1000 * decimalHelper) /
decimalHelper) + ' km';
}
}
} else if (geom instanceof OlGeomPolygon) {
output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic);
// attach area at interior point
Expand Down
Loading