Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
61 changes: 30 additions & 31 deletions modules/editable-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,37 @@
"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/boolean-within": "^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/boolean-within": "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",
Comment thread
charlieforward9 marked this conversation as resolved.
Outdated
"@types/geojson": "^7946.0.14",
"cubic-hermite-spline": "^1.0.1",
"eventemitter3": "^5.0.0",
"lodash.omit": "^4.1.1",
"lodash.throttle": "^4.1.1",
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, GeometryFeatureCollection} 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<GeometryFeatureCollection>) {
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;
}
}
10 changes: 5 additions & 5 deletions modules/editable-layers/src/edit-modes/draw-line-string-mode.ts
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, GeometryFeatureCollection} from '../utils/geojson-types';
import {
ClickEvent,
PointerMoveEvent,
Expand All @@ -22,7 +22,7 @@ export class DrawLineStringMode extends GeoJsonEditMode {
dist = 0;
position: Position = null!;
elems: Position[] = [];
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<GeometryFeatureCollection>) {
const {picks} = event;
const clickedEditHandle = getPickedEditHandle(picks);

Expand Down Expand Up @@ -62,11 +62,11 @@ export class DrawLineStringMode extends GeoJsonEditMode {
}
}

handleDoubleClick(event: DoubleClickEvent, props: ModeProps<FeatureCollection>) {
handleDoubleClick(event: DoubleClickEvent, props: ModeProps<GeometryFeatureCollection>) {
this.finishDrawing(props);
}

finishDrawing(props: ModeProps<FeatureCollection>) {
finishDrawing(props: ModeProps<GeometryFeatureCollection>) {
const clickSequence = this.getClickSequence();
if (clickSequence.length > 1) {
const lineStringToAdd: LineString = {
Expand All @@ -81,7 +81,7 @@ export class DrawLineStringMode extends GeoJsonEditMode {
}
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<GeometryFeatureCollection>) {
const {key} = event;
if (key === 'Enter') {
this.finishDrawing(props);
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, GeometryFeatureCollection, Point} 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<GeometryFeatureCollection>): void {
const geometry: Point = {
type: 'Point',
coordinates: mapCoords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

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

type DraggingHandler = (event: DraggingEvent, props: ModeProps<FeatureCollection>) => void;
type DraggingHandler = (event: DraggingEvent, props: ModeProps<GeometryFeatureCollection>) => void;

export class DrawPolygonByDraggingMode extends DrawPolygonMode {
handleDraggingThrottled: DraggingHandler | null | undefined = null;

handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
handleClick(event: ClickEvent, props: ModeProps<GeometryFeatureCollection>) {
// No-op
}

handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) {
handleStartDragging(event: StartDraggingEvent, props: ModeProps<GeometryFeatureCollection>) {
event.cancelPan();
if (props.modeConfig && props.modeConfig.throttleMs) {
// eslint-disable-next-line @typescript-eslint/unbound-method
Expand All @@ -28,7 +28,7 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {
}
}

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

handleDraggingAux(event: DraggingEvent, props: ModeProps<FeatureCollection>) {
handleDraggingAux(event: DraggingEvent, props: ModeProps<GeometryFeatureCollection>) {
const {picks} = event;
const clickedEditHandle = getPickedEditHandle(picks);

Expand All @@ -69,13 +69,13 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {
}
}

handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>) {
handleDragging(event: DraggingEvent, props: ModeProps<GeometryFeatureCollection>) {
if (this.handleDraggingThrottled) {
this.handleDraggingThrottled(event, props);
}
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<GeometryFeatureCollection>) {
if (event.key === 'Enter') {
const clickSequence = this.getClickSequence();
if (clickSequence.length > 2) {
Expand Down
16 changes: 8 additions & 8 deletions modules/editable-layers/src/edit-modes/draw-polygon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lineIntersect from '@turf/line-intersect';
import { polygon as turfPolygon} from '@turf/helpers';
import booleanWithin from "@turf/boolean-within";

import type {Geometry} from 'geojson'

import {
ClickEvent,
Expand All @@ -16,7 +16,7 @@ import {
GuideFeature,
DoubleClickEvent
} from './types';
import {Position, FeatureCollection, Geometry} from '../utils/geojson-types';
import {Position, FeatureCollection, GeometryFeatureCollection} from '../utils/geojson-types';
import {getPickedEditHandle} from './utils';
import {GeoJsonEditMode} from './geojson-edit-mode';
import { ImmutableFeatureCollection } from './immutable-feature-collection';
Expand Down Expand Up @@ -98,7 +98,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
}

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

handleDoubleClick(_event: DoubleClickEvent, props: ModeProps<FeatureCollection>) {
handleDoubleClick(_event: DoubleClickEvent, props: ModeProps<GeometryFeatureCollection>) {
this.finishDrawing(props);
this.resetClickSequence();
}

handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
handleKeyUp(event: KeyboardEvent, props: ModeProps<GeometryFeatureCollection>) {
if (event.key === "Enter") {
this.finishDrawing(props);
this.resetClickSequence();
Expand All @@ -201,7 +201,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
}

// eslint-disable-next-line max-statements, complexity
finishDrawing(props: ModeProps<FeatureCollection>) {
finishDrawing(props: ModeProps<GeometryFeatureCollection>) {
const clickSequence = this.getClickSequence();
const polygon = [...clickSequence, clickSequence[0]];

Expand Down Expand Up @@ -261,7 +261,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
private tryAddHoleToExistingPolygon(
newPolygon: any,
polygon: Position[],
props: ModeProps<FeatureCollection>
props: ModeProps<GeometryFeatureCollection>
): { handled: boolean } {
for (const [featureIndex, feature] of props.data.features.entries()) {
if (feature.geometry.type === "Polygon") {
Expand All @@ -280,7 +280,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
featureIndex: number,
newPolygon: any,
polygon: Position[],
props: ModeProps<FeatureCollection>
props: ModeProps<GeometryFeatureCollection>
): { handled: boolean } {
const outer = turfPolygon(feature.geometry.coordinates);

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, GeometryFeatureCollection} 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<GeometryFeatureCollection>) {
super.handleStartDragging(event, props);

if (this._geometryBeforeTranslate) {
Expand Down
Loading