Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
athomann committed Oct 15, 2021
1 parent d750b0c commit f3ed2a0
Show file tree
Hide file tree
Showing 73 changed files with 330 additions and 226 deletions.
2 changes: 1 addition & 1 deletion examples/react-map-gl-draw/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function getEditHandleStyle({ feature, shape, index, state }) {

switch (shape) {
case 'circle':
//@ts-ignore
// @ts-ignore
style.r = CIRCLE_RADIUS;
break;
case 'rect':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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);

// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Feature<Polygon, { [name: string]: any; }>' ... Remove this comment to see the full error message
return ellipse(centerCoordinates, xSemiAxis, ySemiAxis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Feature<Polygon, { [name: string]: any; }>' ... Remove this comment to see the full error message
return ellipse(centerCoordinates, xSemiAxis, ySemiAxis, options);
}
}
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/draw-line-string-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class DrawLineStringMode extends GeoJsonEditMode {
}));

guides.features.push(...editHandles);
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ type: string; features: any[]; }' is not a... Remove this comment to see the full error message
return guides;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/draw-point-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class DrawPointMode extends GeoJsonEditMode {
type: 'Point',
coordinates: mapCoords,
};
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '{ type: string; coordinates: Pos... Remove this comment to see the full error message
props.onEdit(this.getAddFeatureAction(geometry, props.data));
}

Expand Down
4 changes: 2 additions & 2 deletions modules/edit-modes/src/lib/draw-polygon-by-dragging-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export class DrawPolygonByDraggingMode extends DrawPolygonMode {
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {
this.addClickSequence(event);
const clickSequence = this.getClickSequence();
// @ts-ignore
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cancel' does not exist on type 'Dragging... Remove this comment to see the full error message
if (this.handleDraggingThrottled && this.handleDraggingThrottled.cancel) {
// @ts-ignore
// @ts-expect-error ts-migrate(2339) FIXME: Property 'cancel' does not exist on type 'Dragging... Remove this comment to see the full error message
this.handleDraggingThrottled.cancel();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/draw-polygon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DrawPolygonMode extends GeoJsonEditMode {
}));

guides.features.push(...editHandles);
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ type: string; features: any[]; }' is not a... Remove this comment to see the full error message
return guides;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/draw-rectangle-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class DrawRectangleMode extends TwoClickPolygonMode {
rectangle.properties = rectangle.properties || {};
rectangle.properties.shape = 'Rectangle';

// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Feature<Polygon, { [name: string]: any; }>' ... Remove this comment to see the full error message
return rectangle;
}
}
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/draw-square-from-center-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
square.properties = square.properties || {};
square.properties.shape = 'Square';

// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Feature<Polygon, { [name: string]: any; }>' ... Remove this comment to see the full error message
return square;
}
}
4 changes: 2 additions & 2 deletions modules/edit-modes/src/lib/elevation-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class ElevationMode extends ModifyMode {
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>) {
const editHandle = getPickedEditHandle(event.pointerDownPicks);
const position = editHandle ? editHandle.geometry.coordinates : event.mapCoords;
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Record<string, any>' is not assi... Remove this comment to see the full error message
super.handlePointerMove(this.makeElevatedEvent(event, position, props), props);
}

handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {
const editHandle = getPickedEditHandle(event.picks);
const position = editHandle ? editHandle.geometry.coordinates : event.mapCoords;
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Record<string, any>' is not assi... Remove this comment to see the full error message
super.handleStopDragging(this.makeElevatedEvent(event, position, props), props);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/edit-modes/src/lib/extend-line-string-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
const selectedLineString = this.getSingleSelectedLineString(props);
if (!selectedLineString) {
// nothing to do
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ type: string; features: any[]; }' is not a... Remove this comment to see the full error message
return guides;
}

Expand All @@ -79,7 +79,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
coordinates: [startPosition, mapCoords],
},
});
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ type: string; features: any[]; }' is not a... Remove this comment to see the full error message
return guides;
}

Expand Down
10 changes: 5 additions & 5 deletions modules/edit-modes/src/lib/geojson-edit-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class GeoJsonEditMode implements EditMode<FeatureCollection, GuideFeature
getTentativeGuide(props: ModeProps<FeatureCollection>): TentativeFeature | null | undefined {
const guides = this.getGuides(props);

// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'Readonly<GuideFeature>' is not assignable to... Remove this comment to see the full error message
return guides.features.find((f) => f.properties && f.properties.guideType === 'tentative');
}

Expand All @@ -105,7 +105,7 @@ export class GeoJsonEditMode implements EditMode<FeatureCollection, GuideFeature

const isPolygonal = geometry.type === 'Polygon' || geometry.type === 'MultiPolygon';
if (isPolygonal) {
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'AllGeoJSON' is not assignable to type 'Featu... Remove this comment to see the full error message
return rewind(feature);
}

Expand Down Expand Up @@ -202,10 +202,10 @@ export class GeoJsonEditMode implements EditMode<FeatureCollection, GuideFeature
if (modeConfig.booleanOperation === 'union') {
updatedGeometry = turfUnion(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'difference') {
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Feature' is not assignable to pa... Remove this comment to see the full error message
updatedGeometry = turfDifference(selectedFeature, feature);
} else if (modeConfig.booleanOperation === 'intersection') {
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Feature' is not assignable to pa... Remove this comment to see the full error message
updatedGeometry = turfIntersect(selectedFeature, feature);
} else {
// eslint-disable-next-line no-console,no-undef
Expand Down Expand Up @@ -277,6 +277,6 @@ export function getIntermediatePosition(position1: Position, position2: Position
(position1[0] + position2[0]) / 2.0,
(position1[1] + position2[1]) / 2.0,
];
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'number[]' is not assignable to type 'Positio... Remove this comment to see the full error message
return intermediatePosition;
}
4 changes: 1 addition & 3 deletions modules/edit-modes/src/lib/measure-angle-mode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import turfBearing from '@turf/bearing';
// @ts-ignore
import turfCenter from '@turf/center';
// @ts-ignore
import memoize from '../memoize';

import { ClickEvent, PointerMoveEvent, Tooltip, ModeProps, GuideFeatureCollection } from '../types';
Expand Down Expand Up @@ -30,7 +28,7 @@ export class MeasureAngleMode extends GeoJsonEditMode {
text = formatTooltip(angle);
} else {
// By default, round to 2 decimal places and append units
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'number' is not assignable to par... Remove this comment to see the full error message
text = `${parseFloat(angle).toFixed(2)} ${units}`;
}

Expand Down
3 changes: 1 addition & 2 deletions modules/edit-modes/src/lib/measure-area-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export class MeasureAreaMode extends DrawPolygonMode {
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
const propsWithoutEdit = {
...props,
// @ts-ignore
onEdit: () => {},
};

Expand All @@ -33,7 +32,7 @@ export class MeasureAreaMode extends DrawPolygonMode {
text = formatTooltip(area);
} else {
// By default, round to 2 decimal places and append units
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'number' is not assignable to par... Remove this comment to see the full error message
text = `${parseFloat(area).toFixed(2)} ${units}`;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/measure-distance-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class MeasureDistanceMode extends GeoJsonEditMode {
}));

guides.features.push(...editHandles);
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ type: string; features: any[]; }' is not a... Remove this comment to see the full error message
return guides;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/modify-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ModifyMode extends GeoJsonEditMode {
(lineString, prefix) => {
const lineStringFeature = toLineString(lineString);
const candidateIntermediatePoint = this.getNearestPoint(
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Feature<LineString, { [name: str... Remove this comment to see the full error message
lineStringFeature,
referencePoint,
props.modeConfig && props.modeConfig.viewport
Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/resize-circle-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ResizeCircleMode extends GeoJsonEditMode {
(lineString, prefix) => {
const lineStringFeature = toLineString(lineString);
const candidateIntermediatePoint = this.getNearestPoint(
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Feature<LineString, { [name: str... Remove this comment to see the full error message
lineStringFeature,
referencePoint,
props.modeConfig && props.modeConfig.viewport
Expand Down
17 changes: 6 additions & 11 deletions modules/edit-modes/src/lib/rotate-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export class RotateMode extends GeoJsonEditMode {
_isSinglePointGeometrySelected = (geometry: FeatureCollection | null | undefined): boolean => {
const { features } = geometry || {};
if (Array.isArray(features) && features.length === 1) {
// @ts-ignore
const { type } = getGeom(features[0]);
const { type } = getGeom<any>(features[0]);
return type === 'Point';
}
return false;
Expand Down Expand Up @@ -61,7 +60,7 @@ export class RotateMode extends GeoJsonEditMode {

coordEach(boundingBox, (coord) => {
if (previousCoord) {
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'number[]' is not assignable to p... Remove this comment to see the full error message
const edgeMidpoint = getIntermediatePosition(coord, previousCoord);
if (!topEdgeMidpointCoords || edgeMidpoint[1] > topEdgeMidpointCoords[1]) {
// Get the top edge midpoint of the enveloping box
Expand All @@ -86,15 +85,11 @@ export class RotateMode extends GeoJsonEditMode {
guideType: 'editHandle',
editHandleType: 'rotate',
});
// @ts-ignore
return featureCollection([
// @ts-ignore
polygonToLine(boundingBox),
// @ts-ignore
polygonToLine(boundingBox) as any,
rotateHandle,
// @ts-ignore
lineFromEnvelopeToRotateHandle,
]);
]) as any;
}

handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>) {
Expand Down Expand Up @@ -175,9 +170,9 @@ export class RotateMode extends GeoJsonEditMode {

const centroid = turfCentroid(this._geometryBeingRotated);
const angle = getRotationAngle(centroid, startDragPoint, currentPoint);
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'AllGeoJSON' is not assignable to type 'Featu... Remove this comment to see the full error message
const rotatedFeatures: FeatureCollection = turfTransformRotate(
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'FeatureCollection' is not assign... Remove this comment to see the full error message
this._geometryBeingRotated,
angle,
{
Expand Down
11 changes: 5 additions & 6 deletions modules/edit-modes/src/lib/scale-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class ScaleMode extends GeoJsonEditMode {
_isSinglePointGeometrySelected = (geometry: FeatureCollection | null | undefined): boolean => {
const { features } = geometry || {};
if (Array.isArray(features) && features.length === 1) {
// @ts-ignore
const { type } = getGeom(features[0]);
const { type } = getGeom<any>(features[0]);
return type === 'Point';
}
return false;
Expand Down Expand Up @@ -85,11 +84,11 @@ export class ScaleMode extends GeoJsonEditMode {

const oppositeHandle = this._getOppositeScaleHandle(this._selectedEditHandle);
const origin = getCoord(oppositeHandle);
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'number[]' is not assignable to p... Remove this comment to see the full error message
const scaleFactor = getScaleFactor(origin, startDragPoint, currentPoint);
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'AllGeoJSON' is not assignable to type 'Featu... Remove this comment to see the full error message
const scaledFeatures: FeatureCollection = turfTransformScale(
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'FeatureCollection' is not assign... Remove this comment to see the full error message
this._geometryBeingScaled,
scaleFactor,
{ origin }
Expand Down Expand Up @@ -220,7 +219,7 @@ export class ScaleMode extends GeoJsonEditMode {
});

this._cornerGuidePoints = cornerGuidePoints;
// @ts-ignore
// @ts-expect-error ts-migrate(2322) FIXME: Type 'FeatureCollection<Point, { [name: string]: a... Remove this comment to see the full error message
return featureCollection([polygonToLine(boundingBox), ...this._cornerGuidePoints]);
}
}
Expand Down
11 changes: 5 additions & 6 deletions modules/edit-modes/src/lib/split-polygon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SplitPolygonMode extends GeoJsonEditMode {
// if first point is clicked, then find closest polygon point and build ~90deg vector
const firstPoint = clickSequence[0];
const selectedGeometry = this.getSelectedGeometry(props);
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Geometry' is not assignable to p... Remove this comment to see the full error message
const feature = turfPolygonToLine(selectedGeometry);

const lines = feature.type === 'FeatureCollection' ? feature.features : [feature];
Expand Down Expand Up @@ -122,11 +122,11 @@ export class SplitPolygonMode extends GeoJsonEditMode {
type: 'Point',
coordinates: clickSequence[clickSequence.length - 1],
};
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '{ type: string; coordinates: Pos... Remove this comment to see the full error message
const isPointInPolygon = booleanPointInPolygon(pt, selectedGeometry);
if (clickSequence.length > 1 && tentativeFeature && !isPointInPolygon) {
this.resetClickSequence();
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'TentativeFeature' is not assigna... Remove this comment to see the full error message
const isLineInterectingWithPolygon = lineIntersect(tentativeFeature, selectedGeometry);
if (isLineInterectingWithPolygon.features.length === 0) {
return;
Expand Down Expand Up @@ -157,7 +157,7 @@ export class SplitPolygonMode extends GeoJsonEditMode {
}

const buffer = turfBuffer(tentativeFeature, gap, { units });
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Geometry' is not assignable to p... Remove this comment to see the full error message
const updatedGeometry = turfDifference(selectedGeometry, buffer);
if (!updatedGeometry) {
// eslint-disable-next-line no-console,no-undef
Expand All @@ -169,11 +169,10 @@ export class SplitPolygonMode extends GeoJsonEditMode {
let updatedCoordinates = [];
if (type === 'Polygon') {
// Update the coordinates as per Multipolygon
// @ts-ignore
updatedCoordinates = coordinates.map((c) => [c]);
} else {
// Handle Case when Multipolygon has holes
// @ts-ignore
// @ts-expect-error ts-migrate(2349) FIXME: This expression is not callable.
updatedCoordinates = coordinates.reduce((agg, prev) => {
prev.forEach((p) => {
agg.push([p]);
Expand Down
2 changes: 1 addition & 1 deletion modules/edit-modes/src/lib/transform-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class TransformMode extends CompositeMode {
}
return !guidesToFilterOut.includes('scale');
});
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Readonly<GuideFeature>[]' is not... Remove this comment to see the full error message
compositeGuides = featureCollection(nonEnvelopeGuides);
}
return compositeGuides;
Expand Down
3 changes: 2 additions & 1 deletion modules/edit-modes/src/lib/translate-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class TranslateMode extends GeoJsonEditMode {
const direction = turfBearing(p1, p2);

const movedFeatures = turfTransformTranslate(
// @ts-ignore
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'FeatureCollection' is not assign... Remove this comment to see the full error message
this._geometryBeforeTranslate,
distanceMoved,
direction
Expand All @@ -108,6 +108,7 @@ export class TranslateMode extends GeoJsonEditMode {
const selectedIndexes = props.selectedIndexes;
for (let i = 0; i < selectedIndexes.length; i++) {
const selectedIndex = selectedIndexes[i];
// @ts-expect-error ts-migrate(2339) FIXME: Property 'features' does not exist on type 'AllGeo... Remove this comment to see the full error message
const movedFeature = movedFeatures.features[i];
updatedData = updatedData.replaceGeometry(selectedIndex, movedFeature.geometry);
}
Expand Down
Loading

0 comments on commit f3ed2a0

Please sign in to comment.