terra-draw
Version:
Frictionless map drawing across mapping provider
66 lines (65 loc) • 2.87 kB
TypeScript
import { Feature, Point, Polygon, LineString } from "geojson";
import { Validation } from "../common";
type JSON = string | number | boolean | null | JSONArray | JSONObject;
export interface JSONObject {
[member: string]: JSON;
}
type JSONArray = Array<JSON>;
type DefinedProperties = Record<string, JSON>;
export type GeoJSONStoreGeometries = Polygon | LineString | Point;
export type BBoxPolygon = Feature<Polygon, DefinedProperties>;
export type GeoJSONStoreFeatures = Feature<GeoJSONStoreGeometries, DefinedProperties>;
export type StoreValidation = {
id?: FeatureId;
} & ReturnType<Validation>;
type StoreChangeEvents = "delete" | "create" | "update" | "styling";
export type StoreChangeHandler<OnChangeContext> = (ids: FeatureId[], change: StoreChangeEvents, context?: OnChangeContext) => void;
export type FeatureId = string | number;
export type IdStrategy<Id extends FeatureId> = {
isValidId: (id: Id) => boolean;
getId: () => Id;
};
type GeoJSONStoreConfig<Id extends FeatureId> = {
idStrategy?: IdStrategy<Id>;
tracked?: boolean;
};
export declare const defaultIdStrategy: {
getId: <FeatureId>() => FeatureId;
isValidId: (id: FeatureId) => boolean;
};
export declare class GeoJSONStore<OnChangeContext extends Record<string, JSON> | undefined, Id extends FeatureId = FeatureId> {
constructor(config?: GeoJSONStoreConfig<Id>);
idStrategy: IdStrategy<Id>;
private tracked;
private spatialIndex;
private store;
private _onChange;
private clone;
getId(): FeatureId;
has(id: FeatureId): boolean;
load(data: GeoJSONStoreFeatures[], featureValidation?: (feature: unknown, tracked?: boolean) => StoreValidation, afterFeatureAdded?: (feature: GeoJSONStoreFeatures) => void, context?: OnChangeContext): StoreValidation[];
search(bbox: BBoxPolygon, filter?: (feature: GeoJSONStoreFeatures) => boolean): GeoJSONStoreFeatures[];
registerOnChange(onChange: StoreChangeHandler<OnChangeContext | undefined>): void;
getGeometryCopy<T extends GeoJSONStoreGeometries>(id: FeatureId): T;
getPropertiesCopy(id: FeatureId): DefinedProperties;
updateProperty(propertiesToUpdate: {
id: FeatureId;
property: string;
value: JSON;
}[], context?: OnChangeContext): void;
updateGeometry(geometriesToUpdate: {
id: FeatureId;
geometry: GeoJSONStoreGeometries;
}[], context?: OnChangeContext): void;
create<Id extends FeatureId>(features: {
geometry: GeoJSONStoreGeometries;
properties?: JSONObject;
}[], context?: OnChangeContext): Id[];
delete(ids: FeatureId[], context?: OnChangeContext): void;
copy(id: FeatureId): GeoJSONStoreFeatures;
copyAll(): GeoJSONStoreFeatures[];
copyAllWhere(equals: (properties: JSONObject) => boolean): GeoJSONStoreFeatures[];
clear(): void;
size(): number;
}
export {};