Skip to content

Commit

Permalink
Added Lib property to class MapboxDraw, in order to remove an unsafe …
Browse files Browse the repository at this point in the history
…declaration in platform-frontend
  • Loading branch information
tiagomatosonenetwork committed Oct 24, 2023
1 parent 424a2c7 commit aa63209
Showing 1 changed file with 250 additions and 11 deletions.
261 changes: 250 additions & 11 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ declare namespace MapboxDraw {
interface DrawMultiFeature<
Type extends "MultiPoint" | "MultiLineString" | "MultiPolygon"
> extends Omit<
DrawFeatureBase<
| (Type extends "MultiPoint" ? Array<DrawPoint["coordinates"]> : never)
| (Type extends "MultiLineString"
? Array<DrawLineString["coordinates"]>
: never)
| (Type extends "MultiPolygon"
? Array<DrawPolygon["coordinates"]>
: never)
>,
"coordinates"
> {
DrawFeatureBase<
| (Type extends "MultiPoint" ? Array<DrawPoint["coordinates"]> : never)
| (Type extends "MultiLineString"
? Array<DrawLineString["coordinates"]>
: never)
| (Type extends "MultiPolygon"
? Array<DrawPolygon["coordinates"]>
: never)
>,
"coordinates"
> {
readonly type: Type;
readonly features: Array<
| (Type extends "MultiPoint" ? DrawPoint : never)
Expand Down Expand Up @@ -352,10 +352,249 @@ declare namespace MapboxDraw {
}

type MapboxDrawOptions = ConstructorParameters<typeof MapboxDraw>[0];

interface StringSet {
add(x: string | number): StringSet;
delete(x: string | number): StringSet;
has(x: string | number): boolean;
values(): string | number[];
clear(): StringSet;
}

interface Constants {
readonly classes: {
CONTROL_BASE: "mapboxgl-ctrl";
CONTROL_PREFIX: "mapboxgl-ctrl-";
CONTROL_BUTTON: "mapbox-gl-draw_ctrl-draw-btn";
CONTROL_BUTTON_LINE: "mapbox-gl-draw_line";
CONTROL_BUTTON_POLYGON: "mapbox-gl-draw_polygon";
CONTROL_BUTTON_POINT: "mapbox-gl-draw_point";
CONTROL_BUTTON_TRASH: "mapbox-gl-draw_trash";
CONTROL_BUTTON_COMBINE_FEATURES: "mapbox-gl-draw_combine";
CONTROL_BUTTON_UNCOMBINE_FEATURES: "mapbox-gl-draw_uncombine";
CONTROL_GROUP: "mapboxgl-ctrl-group";
ATTRIBUTION: "mapboxgl-ctrl-attrib";
ACTIVE_BUTTON: "active";
BOX_SELECT: "mapbox-gl-draw_boxselect";
};

readonly sources: {
HOT: "mapbox-gl-draw-hot";
COLD: "mapbox-gl-draw-cold";
};

readonly cursors: {
ADD: "add";
MOVE: "move";
DRAG: "drag";
POINTER: "pointer";
NONE: "none";
};

readonly types: {
POLYGON: "polygon";
LINE: "line_string";
POINT: "point";
};

readonly geojsonTypes: {
FEATURE: "Feature";
POLYGON: "Polygon";
LINE_STRING: "LineString";
POINT: "Point";
FEATURE_COLLECTION: "FeatureCollection";
MULTI_PREFIX: "Multi";
MULTI_POINT: "MultiPoint";
MULTI_LINE_STRING: "MultiLineString";
MULTI_POLYGON: "MultiPolygon";
};

readonly modes: {
DRAW_LINE_STRING: "draw_line_string";
DRAW_POLYGON: "draw_polygon";
DRAW_POINT: "draw_point";
SIMPLE_SELECT: "simple_select";
DIRECT_SELECT: "direct_select";
STATIC: "static";
};

readonly events: {
CREATE: "draw.create";
DELETE: "draw.delete";
UPDATE: "draw.update";
SELECTION_CHANGE: "draw.selectionchange";
MODE_CHANGE: "draw.modechange";
ACTIONABLE: "draw.actionable";
RENDER: "draw.render";
COMBINE_FEATURES: "draw.combine";
UNCOMBINE_FEATURES: "draw.uncombine";
};

readonly updateActions: {
MOVE: "move";
CHANGE_COORDINATES: "change_coordinates";
};

readonly meta: {
FEATURE: "feature";
MIDPOINT: "midpoint";
VERTEX: "vertex";
};

readonly activeStates: {
ACTIVE: "true";
INACTIVE: "false";
};

readonly interactions: [
"scrollZoom",
"boxZoom",
"dragRotate",
"dragPan",
"keyboard",
"doubleClickZoom",
"touchZoomRotate",
];

readonly LAT_MIN: -90;
readonly LAT_RENDERED_MIN: -85;
readonly LAT_MAX: 90;
readonly LAT_RENDERED_MAX: 85;
readonly LNG_MIN: -270;
readonly LNG_MAX: 270;
}

interface Lib {
CommonSelectors: {
isOfMetaType: (
type: Constants["meta"][keyof Constants["meta"]],
) => (e: MapMouseEvent | MapTouchEvent) => boolean;
//isShiftMousedown: (e: MapboxEvent) => boolean;
isActiveFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
isInactiveFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
noTarget: (e: MapMouseEvent | MapTouchEvent) => boolean;
isFeature: (e: MapMouseEvent | MapTouchEvent) => boolean;
isVertex: (e: MapMouseEvent | MapTouchEvent) => boolean;
//isShiftDown: (e: MapboxEvent) => boolean;
isEscapeKey: (e: KeyboardEvent) => boolean;
isEnterKey: (e: KeyboardEvent) => boolean;
isTrue: () => boolean;
};

constrainFeatureMovement(
geojsonFeatures: DrawFeature[],
delta: { lng: number; lat: number },
): { lng: number; lat: number };

createMidPoint(parent: string, startVertex: Feature, endVertex: Feature): Feature<Point> | null;

createSupplementaryPoints(
geojson: GeoJSON.GeoJSON,
options?: { midpoints?: boolean; selectedPaths?: string }
): GeoJSON.Point[];

/**
* Returns GeoJSON for a Point representing the
* vertex of another feature.
*
* @param parentId
* @param coordinates
* @param path Dot-separated numbers indicating exactly
* where the point exists within its parent feature's coordinates.
* @param selected
* @return GeoJSON Point
*/
createVertex(parentId: string, coordinates: Position, path: string, selected: boolean): Feature<Point>;

// TODO: define a proper type for ctx since is not exposed correctly
// https://github.com/mapbox/mapbox-gl-draw/issues/1156

doubleClickZoom: {
enable: (ctx: DrawCustomModeThis) => void; // ?? ctx
disable: (ctx: DrawCustomModeThis) => void; // ?? ctx
};

featuresAt: {
click: (event: MapMouseEvent, bbox: BBox, ctx: DrawCustomModeThis) => Feature[]; // ?? ctx
touch: (event: MapTouchEvent, bbox: BBox, ctx: DrawCustomModeThis) => Feature[]; // ?? ctx
};

getFeatureAtAndSetCursors(event: MapMouseEvent, ctx: DrawCustomModeThis): Feature;

euclideanDistance(a: { x: number; y: number }, b: { x: number; y: number }): number;

isClick(
start: { point?: { x: number; y: number }; time?: number },
end: { point: { x: number; y: number }; time: number },
options?: { fineTolerance?: number; grossTolerance?: number; interval?: number },
): boolean;

isEventAtCoordinates(event: MapMouseEvent, coordinates: Position[]): boolean;

isTap(
start: { point?: { x: number; y: number }; time?: number },
end: { point: { x: number; y: number }; time: number },
options?: { tolerance?: number; interval?: number },
): boolean;

/**
* Returns a bounding box representing the event's location.
*
* @param mapEvent - Mapbox GL JS map event, with a point properties.
* @param [buffer=0]
* @return Bounding box.
*/
mapEventToBoundingBox(mapEvent: MapMouseEvent | MapTouchEvent, buffer?: number): Position[];

ModeHandler: (
mode: any,
DrawContext: any,
) => {
render: any;
stop: () => void;
trash: () => void;
combineFeatures: () => void;
uncombineFeatures: () => void;
drag: (event: any) => void;
click: (event: any) => void;
mousemove: (event: any) => void;
mousedown: (event: any) => void;
mouseup: (event: any) => void;
mouseout: (event: any) => void;
keydown: (event: any) => void;
keyup: (event: any) => void;
touchstart: (event: any) => void;
touchmove: (event: any) => void;
touchend: (event: any) => void;
tap: (event: any) => void;
};

moveFeatures(features: DrawFeature[], delta: { lng: number; lat: number }): void;

/**
* Sort features in the following order Point: 0, LineString: 1, MultiLineString: 1,
* Polygon: 2, then sort polygons by area ascending.
* @param features
*/
sortFeatures(features: DrawFeature[]): DrawFeature[];

stringSetsAreEqual(a: Array<Pick<Feature, "id">>, b: Array<Pick<Feature, "id">>): boolean;

StringSet(items?: Array<string | number>): StringSet;

theme: Array<(FillLayer | LineLayer | CircleLayer) & { id: ThemeLayerId }>;

/**
* Derive a dense array (no `undefined`s) from a single value or array.
*/
toDenseArray(x: any): Array<NonNullable<any>>;
}
}

declare class MapboxDraw implements IControl {
static modes: MapboxDraw.Modes;
static constants: MapboxDraw.Constants;
static lib: MapboxDraw.Lib;

modes: MapboxDraw.DrawModes;

Expand Down

0 comments on commit aa63209

Please sign in to comment.