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

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();
}

View File

@@ -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);

View File

@@ -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];

View File

@@ -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 })

View File

@@ -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]);