Skip to content

[editable-layers] Update to turf 7 and use geojson types #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions modules/editable-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,36 @@
"src"
],
"dependencies": {
"@turf/along": "^6.5.0",
"@turf/area": "^6.5.0",
"@turf/bbox": "^6.5.0",
"@turf/bbox-polygon": "^6.5.0",
"@turf/bearing": "^6.5.0",
"@turf/boolean-point-in-polygon": "^6.5.0",
"@turf/buffer": "^6.5.0",
"@turf/center": "^6.5.0",
"@turf/centroid": "^6.5.0",
"@turf/circle": "^6.5.0",
"@turf/clone": "^6.5.0",
"@turf/destination": "^6.5.0",
"@turf/difference": "^6.5.0",
"@turf/distance": "^6.5.0",
"@turf/ellipse": "^6.5.0",
"@turf/helpers": "^6.5.0",
"@turf/intersect": "^6.5.0",
"@turf/invariant": "^6.5.0",
"@turf/line-intersect": "^6.5.0",
"@turf/meta": "^6.5.0",
"@turf/midpoint": "^6.5.0",
"@turf/nearest-point-on-line": "^6.5.0",
"@turf/point-to-line-distance": "^6.5.0",
"@turf/polygon-to-line": "^6.5.0",
"@turf/rewind": "^6.5.0",
"@turf/transform-rotate": "^6.5.0",
"@turf/transform-scale": "^6.5.0",
"@turf/transform-translate": "^6.5.0",
"@turf/union": "^6.5.0",
"@turf/along": "^7.2.0",
"@turf/area": "^7.2.0",
"@turf/bbox": "^7.2.0",
"@turf/bbox-polygon": "^7.2.0",
"@turf/bearing": "^7.2.0",
"@turf/boolean-point-in-polygon": "^7.2.0",
"@turf/buffer": "^7.2.0",
"@turf/center": "^7.2.0",
"@turf/centroid": "^7.2.0",
"@turf/circle": "^7.2.0",
"@turf/clone": "^7.2.0",
"@turf/destination": "^7.2.0",
"@turf/difference": "^7.2.0",
"@turf/distance": "^7.2.0",
"@turf/ellipse": "^7.2.0",
"@turf/helpers": "^7.2.0",
"@turf/intersect": "^7.2.0",
"@turf/invariant": "^7.2.0",
"@turf/line-intersect": "^7.2.0",
"@turf/meta": "^7.2.0",
"@turf/midpoint": "^7.2.0",
"@turf/nearest-point-on-line": "^7.2.0",
"@turf/point-to-line-distance": "^7.2.0",
"@turf/polygon-to-line": "^7.2.0",
"@turf/rewind": "^7.2.0",
"@turf/transform-rotate": "^7.2.0",
"@turf/transform-scale": "^7.2.0",
"@turf/transform-translate": "^7.2.0",
"@turf/union": "^7.2.0",
"@types/geojson": "^7946.0.14",
"cubic-hermite-spline": "^1.0.1",
"eventemitter3": "^5.0.0",
"lodash.throttle": "^4.1.1",
"uuid": "9.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
GuideFeatureCollection,
TentativeFeature
} from './types';
import {Polygon, LineString, Position, FeatureCollection} from '../utils/geojson-types';
import {Polygon, LineString, Position, FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {GeoJsonEditMode} from './geojson-edit-mode';

export class Draw90DegreePolygonMode extends GeoJsonEditMode {
Expand Down Expand Up @@ -98,7 +98,7 @@ export class Draw90DegreePolygonMode extends GeoJsonEditMode {
super.handlePointerMove(event, props);
}

handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const {picks} = event;
const tentativeFeature = this.getTentativeGuide(props);
this.addClickSequence(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class DrawCircleByDiameterMode extends TwoClickPolygonMode {
geometry.properties.editProperties.center = centerCoordinates;
// calculate area of circle with turf function
this.areaCircle = area(geometry);
// @ts-expect-error turf types diff

return geometry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class DrawCircleFromCenterMode extends TwoClickPolygonMode {
geometry.properties.editProperties.center = coord1;
// calculate area of circle with turf function
this.areaCircle = area(geometry);
// @ts-expect-error turf types diff

return geometry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DrawEllipseByBoundingBoxMode extends TwoClickPolygonMode {
const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);

const geometry = ellipse(centerCoordinates, xSemiAxis, ySemiAxis);
const geometry = ellipse(centerCoordinates, xSemiAxis, ySemiAxis, {});

geometry.properties = geometry.properties || {};
geometry.properties.editProperties = geometry.properties.editProperties || {};
Expand All @@ -32,7 +32,7 @@ export class DrawEllipseByBoundingBoxMode extends TwoClickPolygonMode {
geometry.properties.editProperties.ySemiAxis = {value: ySemiAxis, unit: 'kilometers'};
geometry.properties.editProperties.angle = 0;
geometry.properties.editProperties.center = centerCoordinates;
// @ts-expect-error fix return types

return geometry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class DrawEllipseUsingThreePointsMode extends ThreeClickPolygonMode {
const xSemiAxis = Math.max(distance(centerCoordinates, point(coord3)), 0.001);
const ySemiAxis = Math.max(distance(coord1, coord2), 0.001) / 2;
const options = {angle: bearing(coord1, coord2)};
// @ts-expect-error fix return types
const geometry = ellipse(centerCoordinates, xSemiAxis, ySemiAxis, options);

geometry.properties = geometry.properties || {};
Expand All @@ -31,7 +30,7 @@ export class DrawEllipseUsingThreePointsMode extends ThreeClickPolygonMode {
geometry.properties.editProperties.ySemiAxis = {value: ySemiAxis, unit: 'kilometers'};
geometry.properties.editProperties.angle = options.angle;
geometry.properties.editProperties.center = centerCoordinates;
// @ts-expect-error fix return types

return geometry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import distance from '@turf/distance';
import {memoize} from '../utils/memoize';
import {LineString, FeatureCollection, Position} from '../utils/geojson-types';
import {LineString, FeatureCollection, Position, SingleGeometry} from '../utils/geojson-types';
import {
ClickEvent,
PointerMoveEvent,
Expand All @@ -21,7 +21,7 @@ export class DrawLineStringMode extends GeoJsonEditMode {
dist = 0;
position: Position = null!;
elems: Position[] = [];
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const {picks} = event;
const clickedEditHandle = getPickedEditHandle(picks);

Expand Down Expand Up @@ -71,7 +71,7 @@ export class DrawLineStringMode extends GeoJsonEditMode {
}
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const {key} = event;
if (key === 'Enter') {
const clickSequence = this.getClickSequence();
Expand Down
4 changes: 2 additions & 2 deletions modules/editable-layers/src/edit-modes/draw-point-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) vis.gl contributors

import {ClickEvent, PointerMoveEvent, ModeProps, TentativeFeature} from './types';
import {FeatureCollection, Point} from '../utils/geojson-types';
import {FeatureCollection, Point, SingleGeometry} from '../utils/geojson-types';
import {GeoJsonEditMode} from './geojson-edit-mode';

export class DrawPointMode extends GeoJsonEditMode {
Expand All @@ -23,7 +23,7 @@ export class DrawPointMode extends GeoJsonEditMode {
};
}

handleClick({mapCoords}: ClickEvent, props: ModeProps<FeatureCollection>): void {
handleClick({mapCoords}: ClickEvent, props: ModeProps<FeatureCollection<SingleGeometry>>): void {
const geometry: Point = {
type: 'Point',
coordinates: mapCoords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import throttle from 'lodash.throttle';
import {ClickEvent, StartDraggingEvent, StopDraggingEvent, DraggingEvent, ModeProps} from './types';
import {Polygon, FeatureCollection} from '../utils/geojson-types';
import {Polygon, FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {getPickedEditHandle} from './utils';
import {DrawPolygonMode} from './draw-polygon-mode';

Expand All @@ -28,7 +28,7 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {
}
}

handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
this.addClickSequence(event);
const clickSequence = this.getClickSequence();
// @ts-expect-error cancel() not typed
Expand Down Expand Up @@ -75,7 +75,7 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {
}
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
if (event.key === 'Enter') {
const clickSequence = this.getClickSequence();
if (clickSequence.length > 2) {
Expand Down
6 changes: 3 additions & 3 deletions modules/editable-layers/src/edit-modes/draw-polygon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TentativeFeature,
GuideFeature
} from './types';
import {Polygon, FeatureCollection} from '../utils/geojson-types';
import {Polygon, FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {getPickedEditHandle} from './utils';
import {GeoJsonEditMode} from './geojson-edit-mode';

Expand Down Expand Up @@ -84,7 +84,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
}

// eslint-disable-next-line complexity
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const {picks} = event;
const clickedEditHandle = getPickedEditHandle(picks);
const clickSequence = this.getClickSequence();
Expand Down Expand Up @@ -143,7 +143,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
}
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
if (event.key === 'Enter') {
const clickSequence = this.getClickSequence();
if (clickSequence.length > 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
rectangle.properties = rectangle.properties || {};
rectangle.properties.shape = 'Rectangle';

// @ts-expect-error turf typing too wide
return rectangle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class DrawRectangleMode extends TwoClickPolygonMode {
rectangle.properties = rectangle.properties || {};
rectangle.properties.shape = 'Rectangle';

// @ts-expect-error turf typing too wide
return rectangle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
square.properties = square.properties || {};
square.properties.shape = 'Square';

// @ts-expect-error turf typing too wide
return square;
}
}
2 changes: 1 addition & 1 deletion modules/editable-layers/src/edit-modes/draw-square-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class DrawSquareMode extends TwoClickPolygonMode {
square.properties = square.properties || {};
square.properties.shape = 'Square';

// @ts-expect-error turf types too wide

return square;
}
}
4 changes: 2 additions & 2 deletions modules/editable-layers/src/edit-modes/duplicate-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// Copyright (c) vis.gl contributors

import {StartDraggingEvent, ModeProps} from './types';
import {FeatureCollection} from '../utils/geojson-types';
import {FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {TranslateMode} from './translate-mode';

export class DuplicateMode extends TranslateMode {
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) {
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
super.handleStartDragging(event, props);

if (this._geometryBeforeTranslate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {Position, LineString, FeatureCollection} from '../utils/geojson-types';
import {Position, LineString, FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection} from './types';
import {GeoJsonEditMode} from './geojson-edit-mode';
import {ImmutableFeatureCollection} from './immutable-feature-collection';

export class ExtendLineStringMode extends GeoJsonEditMode {
getSingleSelectedLineString(props: ModeProps<FeatureCollection>): LineString | null | undefined {
getSingleSelectedLineString(props: ModeProps<FeatureCollection<SingleGeometry>>): LineString | null | undefined {
const selectedGeometry = this.getSelectedGeometry(props);

if (selectedGeometry && selectedGeometry.type === 'LineString') {
Expand All @@ -17,7 +17,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
return null;
}

handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const {selectedIndexes} = props;
const selectedLineString = this.getSingleSelectedLineString(props);

Expand Down Expand Up @@ -49,7 +49,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
});
}

getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection {
getGuides(props: ModeProps<FeatureCollection<SingleGeometry>>): GuideFeatureCollection {
const guides: GuideFeatureCollection = {
type: 'FeatureCollection',
features: []
Expand Down
14 changes: 7 additions & 7 deletions modules/editable-layers/src/edit-modes/extrude-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getPickedIntermediateEditHandle,
shouldCancelPan
} from './utils';
import {FeatureCollection} from '../utils/geojson-types';
import {FeatureCollection, SingleGeometry} from '../utils/geojson-types';
import {ModeProps, StartDraggingEvent, StopDraggingEvent, DraggingEvent} from './types';
import {ModifyMode} from './modify-mode';
import {ImmutableFeatureCollection} from './immutable-feature-collection';
Expand All @@ -19,7 +19,7 @@ export class ExtrudeMode extends ModifyMode {

isPointAdded = false;

handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>): void {
handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection<SingleGeometry>>): void {
const editHandle = getPickedEditHandle(event.pointerDownPicks);

if (editHandle) {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ExtrudeMode extends ModifyMode {
}
}

handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) {
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
if (shouldCancelPan(event)) {
event.cancelPan();
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export class ExtrudeMode extends ModifyMode {
}
}

handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection<SingleGeometry>>) {
const selectedFeatureIndexes = props.selectedIndexes;
const editHandle = getPickedEditHandle(event.pointerDownPicks);
if (selectedFeatureIndexes.length && editHandle) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class ExtrudeMode extends ModifyMode {
coordinatesSize(
positionIndexes: number[] | null | undefined,
featureIndex: number,
{features}: FeatureCollection
{features}: FeatureCollection<SingleGeometry>
) {
let size = 0;
if (Array.isArray(positionIndexes)) {
Expand Down Expand Up @@ -190,7 +190,7 @@ export class ExtrudeMode extends ModifyMode {
positionIndexes: number[] | null | undefined,
featureIndex: number,
size: number,
features: FeatureCollection
features: FeatureCollection<SingleGeometry>
) {
if (!Array.isArray(positionIndexes)) {
return false;
Expand Down Expand Up @@ -239,7 +239,7 @@ export class ExtrudeMode extends ModifyMode {
getPointForPositionIndexes(
positionIndexes: number[] | null | undefined,
featureIndex: number,
{features}: FeatureCollection
{features}: FeatureCollection<SingleGeometry>
) {
let p1;
if (Array.isArray(positionIndexes)) {
Expand Down
Loading