mirror of
https://github.com/mapbox/mapbox-gl-draw.git
synced 2026-02-01 14:34:52 +00:00
More typing
This commit is contained in:
parent
34798cf309
commit
fe4d933bb6
21
src/api.ts
21
src/api.ts
@ -11,7 +11,7 @@ import LineString from './feature_types/line_string';
|
||||
import Point from './feature_types/point';
|
||||
import MultiFeature from './feature_types/multi_feature';
|
||||
|
||||
import type { CTX, Draw } from './types/types';
|
||||
import type { CTX, Draw, StrictFeature, MapMouseEvent } from './types/types';
|
||||
|
||||
const featureTypes = {
|
||||
Polygon,
|
||||
@ -32,7 +32,8 @@ export default function (ctx: CTX, api: Draw) {
|
||||
: true;
|
||||
|
||||
api.getFeatureIdsAt = (point) => {
|
||||
const features = featuresAt.click({ point }, null, ctx);
|
||||
const event = { point } as MapMouseEvent;
|
||||
const features = featuresAt.click(event, null, ctx);
|
||||
return features.map(feature => feature.properties.id);
|
||||
};
|
||||
|
||||
@ -42,17 +43,17 @@ export default function (ctx: CTX, api: Draw) {
|
||||
|
||||
api.getSelected = () => {
|
||||
return {
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION,
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION as 'FeatureCollection',
|
||||
features: ctx.store
|
||||
.getSelectedIds()
|
||||
.map(id => ctx.store.get(id))
|
||||
.map(feature => feature.toGeoJSON())
|
||||
.map(feature => feature.toGeoJSON()) as StrictFeature[]
|
||||
};
|
||||
};
|
||||
|
||||
api.getSelectedPoints = () => {
|
||||
return {
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION,
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION as 'FeatureCollection',
|
||||
features: ctx.store.getSelectedCoordinates().map(coordinate => ({
|
||||
type: Constants.geojsonTypes.FEATURE,
|
||||
properties: {},
|
||||
@ -60,7 +61,7 @@ export default function (ctx: CTX, api: Draw) {
|
||||
type: Constants.geojsonTypes.POINT,
|
||||
coordinates: coordinate.coordinates
|
||||
}
|
||||
}))
|
||||
})) as StrictFeature[]
|
||||
};
|
||||
};
|
||||
|
||||
@ -113,7 +114,7 @@ export default function (ctx: CTX, api: Draw) {
|
||||
const originalProperties = internalFeature.properties;
|
||||
internalFeature.properties = feature.properties;
|
||||
if (!isEqual(originalProperties, feature.properties)) {
|
||||
ctx.store.featureChanged(internalFeature.id, { silent });
|
||||
ctx.store.featureChanged(internalFeature.id as string, { silent });
|
||||
}
|
||||
if (
|
||||
!isEqual(
|
||||
@ -134,14 +135,14 @@ export default function (ctx: CTX, api: Draw) {
|
||||
api.get = (id) => {
|
||||
const feature = ctx.store.get(id);
|
||||
if (feature) {
|
||||
return feature.toGeoJSON();
|
||||
return feature.toGeoJSON() as StrictFeature;
|
||||
}
|
||||
};
|
||||
|
||||
api.getAll = () => {
|
||||
return {
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION,
|
||||
features: ctx.store.getAll().map(feature => feature.toGeoJSON())
|
||||
type: Constants.geojsonTypes.FEATURE_COLLECTION as 'FeatureCollection',
|
||||
features: ctx.store.getAll().map(feature => feature.toGeoJSON()) as StrictFeature[]
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import * as Constants from '../constants';
|
||||
import StringSet from './string_set';
|
||||
|
||||
import type { BBox } from 'geojson';
|
||||
import type { CTX, DrawStyleLayer, MapMouseEvent, MapTouchEvent } from '../types/types';
|
||||
import type { CTX, MapMouseEvent, MapTouchEvent } from '../types/types';
|
||||
|
||||
type E = MapMouseEvent | MapTouchEvent;
|
||||
|
||||
|
||||
@ -102,7 +102,6 @@ interface DrawPolygon extends DrawFeatureBase<Position[][]> {
|
||||
}
|
||||
|
||||
interface DrawFeatureBase<Coordinates> {
|
||||
readonly properties: Readonly<Feature['properties']>;
|
||||
readonly coordinates: Coordinates;
|
||||
readonly id: NonNullable<Feature['id']>;
|
||||
readonly type: GeoJsonTypes;
|
||||
@ -115,6 +114,7 @@ interface DrawFeatureBase<Coordinates> {
|
||||
getCoordinate(path: number): Position;
|
||||
updateCoordinate(path: number, lng: number, lat: number): void;
|
||||
setProperty(property: string, value: any): void;
|
||||
properties: Readonly<Feature['properties']>;
|
||||
toGeoJSON(): GeoJSON;
|
||||
}
|
||||
|
||||
@ -167,7 +167,6 @@ interface DrawActionableState {
|
||||
}
|
||||
|
||||
interface DrawFeatureBase<Coordinates> {
|
||||
readonly properties: Readonly<Feature['properties']>;
|
||||
readonly coordinates: Coordinates;
|
||||
readonly id: NonNullable<Feature['id']>;
|
||||
readonly type: GeoJsonTypes;
|
||||
@ -180,6 +179,7 @@ interface DrawFeatureBase<Coordinates> {
|
||||
getCoordinate(path: string): Position;
|
||||
updateCoordinate(path: string, lng: number, lat: number): void;
|
||||
setProperty(property: string, value: any): void;
|
||||
properties: Readonly<Feature['properties']>;
|
||||
toGeoJSON(): GeoJSON;
|
||||
}
|
||||
|
||||
@ -712,11 +712,11 @@ export declare class Draw implements IControl {
|
||||
static modes: Modes;
|
||||
static constants: Constants;
|
||||
static lib: Lib;
|
||||
modes: DrawModes;
|
||||
modes: typeof modes;
|
||||
getDefaultPosition: () => ControlPosition;
|
||||
constructor(options?: DrawOptions);
|
||||
add(geojson: Feature | StrictFeatureCollection | Geometry): string[];
|
||||
get(featureId: string): Feature | undefined;
|
||||
get(featureId: string): StrictFeature | undefined;
|
||||
getFeatureIdsAt(point: { x: number; y: number }): string[];
|
||||
getSelectedIds(): string[];
|
||||
getSelected(): StrictFeatureCollection;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user