Skip to content

Commit

Permalink
Change the geometry of Polygon for Rectagle to use CCW ring.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoCardsCai committed Jul 7, 2020
1 parent 5cb9d62 commit 1f11e6c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions modules/edit-modes/package.json
Expand Up @@ -71,6 +71,7 @@
"@turf/transform-scale": ">=4.0.0",
"@turf/transform-translate": ">=4.0.0",
"@turf/union": ">=4.0.0",
"@turf/rewind": ">=4.0.0",
"geojson": "0.5.0",
"lodash.throttle": "^4.1.1",
"viewport-mercator-project": ">=6.0.0"
Expand Down
5 changes: 3 additions & 2 deletions modules/edit-modes/src/lib/draw-90degree-polygon-mode.ts
Expand Up @@ -3,6 +3,7 @@ import bearing from '@turf/bearing';
import lineIntersect from '@turf/line-intersect';
import turfDistance from '@turf/distance';
import { point, lineString as turfLineString } from '@turf/helpers';
import rewind from '@turf/rewind';
import {
generatePointsParallelToLinePoints,
getPickedEditHandle,
Expand Down Expand Up @@ -112,10 +113,10 @@ export class Draw90DegreePolygonMode extends GeoJsonEditMode {
clickedEditHandle.properties.positionIndexes[1] === polygon.coordinates[0].length - 3)
) {
// They clicked the first or last point (or double-clicked), so complete the polygon
const polygonToAdd: Polygon = {
const polygonToAdd: Polygon = rewind({
type: 'Polygon',
coordinates: this.finalizedCoordinates([...polygon.coordinates[0]]),
};
});

this.resetClickSequence();

Expand Down
5 changes: 3 additions & 2 deletions modules/edit-modes/src/lib/draw-polygon-by-dragging-mode.ts
@@ -1,4 +1,5 @@
import throttle from 'lodash.throttle';
import rewind from '@turf/rewind';
import {
ClickEvent,
StartDraggingEvent,
Expand Down Expand Up @@ -39,10 +40,10 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {

if (clickSequence.length > 2) {
// Complete the polygon.
const polygonToAdd: Polygon = {
const polygonToAdd: Polygon = rewind({
type: 'Polygon',
coordinates: [[...clickSequence, clickSequence[0]]],
};
});

this.resetClickSequence();

Expand Down
5 changes: 3 additions & 2 deletions modules/edit-modes/src/lib/draw-polygon-mode.ts
@@ -1,3 +1,4 @@
import rewind from '@turf/rewind';
import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection } from '../types';
import { Polygon, FeatureCollection } from '../geojson-types';
import { getPickedEditHandle } from '../utils';
Expand Down Expand Up @@ -85,10 +86,10 @@ export class DrawPolygonMode extends GeoJsonEditMode {
// They clicked the first or last point (or double-clicked), so complete the polygon

// Remove the hovered position
const polygonToAdd: Polygon = {
const polygonToAdd: Polygon = rewind({
type: 'Polygon',
coordinates: [[...clickSequence, clickSequence[0]]],
};
});

this.resetClickSequence();

Expand Down
3 changes: 2 additions & 1 deletion modules/edit-modes/src/lib/draw-rectangle-mode.ts
@@ -1,10 +1,11 @@
import bboxPolygon from '@turf/bbox-polygon';
import rewind from '@turf/rewind';
import { Position, Polygon, FeatureOf } from '../geojson-types';
import { TwoClickPolygonMode } from './two-click-polygon-mode';

export class DrawRectangleMode extends TwoClickPolygonMode {
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> {
const rectangle = bboxPolygon([coord1[0], coord1[1], coord2[0], coord2[1]]);
const rectangle = rewind(bboxPolygon([coord1[0], coord1[1], coord2[0], coord2[1]]));
rectangle.properties = rectangle.properties || {};
rectangle.properties.shape = 'Rectangle';

Expand Down
@@ -1,3 +1,4 @@
import rewind from '@turf/rewind';
import { generatePointsParallelToLinePoints } from '../utils';
import { Position, Polygon, FeatureOf } from '../geojson-types';
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
Expand All @@ -16,7 +17,7 @@ export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
properties: {
shape: 'Rectangle',
},
geometry: {
geometry: rewind({
type: 'Polygon',
coordinates: [
[
Expand All @@ -30,7 +31,7 @@ export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
coord1,
],
],
},
}),
};
}
}
19 changes: 19 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f11e6c

Please sign in to comment.