diff --git a/modules/actions/extract.js b/modules/actions/extract.js index d283a42fb..f8375e514 100644 --- a/modules/actions/extract.js +++ b/modules/actions/extract.js @@ -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(); } diff --git a/modules/operations/extract.js b/modules/operations/extract.js index c6d75279d..a6ea27f5f 100644 --- a/modules/operations/extract.js +++ b/modules/operations/extract.js @@ -29,7 +29,7 @@ export function operationExtract(context, selectedIDs) { _extent = _extent ? _extent.extend(entity.extent(graph)) : entity.extent(graph); - return actionExtract(entityID); + return actionExtract(entityID, context.projection); }).filter(Boolean); diff --git a/modules/svg/labels.js b/modules/svg/labels.js index f151631e1..9a91c9434 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -550,7 +550,7 @@ export function svgLabels(projection, context) { function getAreaLabel(entity, width, height) { - var centroid = path.centroid(entity.asGeoJSON(graph, true)); + var centroid = path.centroid(entity.asGeoJSON(graph)); var extent = entity.extent(graph); var areaWidth = projection(extent[1])[0] - projection(extent[0])[0]; diff --git a/modules/validations/mismatched_geometry.js b/modules/validations/mismatched_geometry.js index e1f0e0179..303c34dae 100644 --- a/modules/validations/mismatched_geometry.js +++ b/modules/validations/mismatched_geometry.js @@ -322,7 +322,7 @@ export function validationMismatchedGeometry() { extractOnClick = function(context) { var entityId = this.issue.entityIds[0]; - var action = actionExtract(entityId); + var action = actionExtract(entityId, context.projection); context.perform( action, t('operations.extract.annotation', { n: 1 }) diff --git a/test/spec/osm/way.js b/test/spec/osm/way.js index 13fc07429..177387d63 100644 --- a/test/spec/osm/way.js +++ b/test/spec/osm/way.js @@ -1019,7 +1019,7 @@ describe('iD.osmWay', function() { c = iD.osmNode({loc: [3, 4]}), w = iD.osmWay({tags: {area: 'yes'}, nodes: [a.id, b.id, c.id, a.id]}), graph = iD.coreGraph([a, b, c, w]), - json = w.asGeoJSON(graph, true); + json = w.asGeoJSON(graph); expect(json.type).to.equal('Polygon'); expect(json.coordinates).to.eql([[a.loc, b.loc, c.loc, a.loc]]); @@ -1031,7 +1031,7 @@ describe('iD.osmWay', function() { c = iD.osmNode({loc: [3, 4]}), w = iD.osmWay({tags: {area: 'yes'}, nodes: [a.id, b.id, c.id]}), graph = iD.coreGraph([a, b, c, w]), - json = w.asGeoJSON(graph, true); + json = w.asGeoJSON(graph); expect(json.type).to.equal('LineString'); expect(json.coordinates).to.eql([a.loc, b.loc, c.loc]);