Fix issue where extracting points could results in off placements (close #8246)

This commit is contained in:
Quincy Morgan
2020-12-11 12:50:32 -05:00
parent b3ad282f40
commit 0a0e2dcf75
5 changed files with 9 additions and 10 deletions
+4 -5
View File
@@ -1,10 +1,9 @@
import { geoCentroid as d3_geoCentroid } from 'd3-geo';
import geojsonRewind from '@mapbox/geojson-rewind';
import { geoPath as d3_geoPath } from 'd3-geo';
import { osmNode } from '../osm/node';
export function actionExtract(entityID) {
export function actionExtract(entityID, projection) {
var extractedNodeID;
@@ -47,8 +46,8 @@ export function actionExtract(entityID) {
var keysToRetain = ['area'];
var buildingKeysToRetain = ['architect', 'building', 'height', 'layer'];
// d3_geoCentroid is wrong for counterclockwise-wound polygons, so wind them clockwise
var extractedLoc = d3_geoCentroid(geojsonRewind(Object.assign({}, entity.asGeoJSON(graph)), true));
var extractedLoc = d3_geoPath(projection).centroid(entity.asGeoJSON(graph));
extractedLoc = extractedLoc && projection.invert(extractedLoc);
if (!extractedLoc || !isFinite(extractedLoc[0]) || !isFinite(extractedLoc[1])) {
extractedLoc = entity.extent(graph).center();
}