Skip to content

Commit

Permalink
Fix issue where extracting points could results in off placements (close
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Dec 11, 2020
1 parent b3ad282 commit 0a0e2dc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions modules/actions/extract.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion modules/operations/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
2 changes: 1 addition & 1 deletion modules/svg/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
2 changes: 1 addition & 1 deletion modules/validations/mismatched_geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions test/spec/osm/way.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]]);
Expand All @@ -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]);
Expand Down

0 comments on commit 0a0e2dc

Please sign in to comment.