mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-28 10:51:45 +02:00
Account for instances where d3.geoCentroid returns incorrect results
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
|
||||
import { geoCentroid as d3_geoCentroid } from 'd3-geo';
|
||||
import geojsonRewind from '@mapbox/geojson-rewind';
|
||||
|
||||
import { osmNode } from '../osm/node';
|
||||
|
||||
export function actionExtract(entityID) {
|
||||
@@ -45,7 +47,8 @@ export function actionExtract(entityID) {
|
||||
var keysToRetain = ['area'];
|
||||
var buildingKeysToRetain = ['architect', 'building', 'height', 'layer'];
|
||||
|
||||
var extractedLoc = d3_geoCentroid(entity.asGeoJSON(graph));
|
||||
// d3_geoCentroid is wrong for counterclockwise-wound polygons, so wind them clockwise
|
||||
var extractedLoc = d3_geoCentroid(geojsonRewind(Object.assign({}, entity.asGeoJSON(graph)), true));
|
||||
if (!extractedLoc || !isFinite(extractedLoc[0]) || !isFinite(extractedLoc[1])) {
|
||||
extractedLoc = entity.extent(graph).center();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
geoLength as d3_geoLength,
|
||||
geoCentroid as d3_geoCentroid
|
||||
} from 'd3-geo';
|
||||
import geojsonRewind from '@mapbox/geojson-rewind';
|
||||
|
||||
import { t, localizer } from '../../core/localizer';
|
||||
import { displayArea, displayLength, decimalCoordinatePair, dmsCoordinatePair } from '../../util/units';
|
||||
@@ -78,7 +79,8 @@ export function uiPanelMeasurement(context) {
|
||||
closed = (entity.type === 'relation') || (entity.isClosed() && !entity.isDegenerate());
|
||||
var feature = entity.asGeoJSON(graph);
|
||||
length += radiansToMeters(d3_geoLength(toLineString(feature)));
|
||||
centroid = d3_geoCentroid(feature);
|
||||
// d3_geoCentroid is wrong for counterclockwise-wound polygons, so wind them clockwise
|
||||
centroid = d3_geoCentroid(geojsonRewind(Object.assign({}, feature), true));
|
||||
if (closed) {
|
||||
area += steradiansToSqmeters(entity.area(graph));
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"dependencies": {
|
||||
"@ideditor/country-coder": "^3.2.0",
|
||||
"@ideditor/location-conflation": "~0.5.0",
|
||||
"@mapbox/geojson-rewind": "^0.5.0",
|
||||
"@mapbox/sexagesimal": "1.2.0",
|
||||
"@mapbox/togeojson": "0.16.0",
|
||||
"@mapbox/vector-tile": "^1.3.1",
|
||||
|
||||
Reference in New Issue
Block a user