Skip to content

Commit

Permalink
feature: Add group aggregations and length attribute helper. (origo-m…
Browse files Browse the repository at this point in the history
…ap#1708)

* Added group aggregations and length attribute helper.

* Uses ol/sphere for measurements

* Automatic units for area en length and aligning result i infowindow

* Lint...

---------

Co-authored-by: Stefan Forsgren <stefan@forsgren@xlent.se>
  • Loading branch information
steff-o and Stefan Forsgren committed Apr 3, 2023
1 parent 0a35356 commit f042087
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 51 deletions.
74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scss/_infowindow.scss
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,7 @@
transform: none;
}
}

.groupfootercontainer {
margin-left:36px;
}
2 changes: 2 additions & 0 deletions src/geom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import getcenter from './geometry/getcenter';
import getarea from './geometry/getarea';
import getlength from './geometry/getlength';

const geom = {};
geom.center = getcenter;
geom.area = getarea;
geom.length = getlength;

export default geom;
17 changes: 9 additions & 8 deletions src/geometry/getarea.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import round from '../utils/round';
import { getArea as olGetArea } from 'ol/sphere';
import formatAreaString from '../utils/formatareastring';

export default function getArea(geometryIn, decimals) {
let area = geometryIn.getArea ? geometryIn.getArea() : 0;
if (decimals) {
area = round(area, decimals);
} else {
area = round(area, '2');
export default function getArea(geometryIn, decimals, map) {
let area = 0;
const geomType = geometryIn.getType();
if (geomType === 'Polygon' || geomType === 'MultiPolygon') {
area = olGetArea(geometryIn, { projection: map.getView().getProjection() });
}
return area;

return formatAreaString(area, { decimals: decimals || 2 });
}
13 changes: 13 additions & 0 deletions src/geometry/getlength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getLength as olGetLength } from 'ol/sphere';
import formatLengthString from '../utils/formatlengthstring';

export default function getLength(geometryIn, decimals, map) {
let length = 0;

const geomType = geometryIn.getType();
if (geomType === 'LineString' || geomType === 'LinearRing' || geomType === 'MultiLineString') {
length = olGetLength(geometryIn, { projection: map.getView().getProjection() });
}

return formatLengthString(length, { decimals: decimals || 2 });
}
Loading

0 comments on commit f042087

Please sign in to comment.