122 lines
4.5 KiB
TypeScript
122 lines
4.5 KiB
TypeScript
import { BehaviorConfig, TerraDrawModeBehavior } from "./base.behavior";
|
|
import { FeatureId } from "../extend";
|
|
import { GeoJSONStoreFeatures, GeoJSONStoreGeometries, JSONObject, JSON } from "../store/store";
|
|
import { Polygon, Position, LineString, Point } from "geojson";
|
|
import { Actions, GuidancePointProperties, UpdateTypes, Validation } from "../common";
|
|
type MutateFeatureBehaviorOptions = {
|
|
validate: Validation | undefined;
|
|
};
|
|
export declare const Mutations: {
|
|
readonly InsertBefore: "insert-before";
|
|
readonly InsertAfter: "insert-after";
|
|
readonly Update: "update";
|
|
readonly Delete: "delete";
|
|
readonly Replace: "replace";
|
|
};
|
|
type InsertBeforeMutation = {
|
|
type: typeof Mutations.InsertBefore;
|
|
index: number;
|
|
coordinate: Position;
|
|
};
|
|
type InsertAfterMutation = {
|
|
type: typeof Mutations.InsertAfter;
|
|
index: number;
|
|
coordinate: Position;
|
|
};
|
|
type UpdateMutation = {
|
|
type: typeof Mutations.Update;
|
|
index: number;
|
|
coordinate: Position;
|
|
};
|
|
type DeleteMutation = {
|
|
type: typeof Mutations.Delete;
|
|
index: number;
|
|
};
|
|
export type ReplaceMutation<ReplacedGeometry extends GeoJSONStoreGeometries> = {
|
|
type: typeof Mutations.Replace;
|
|
coordinates: ReplacedGeometry["coordinates"];
|
|
};
|
|
export type CoordinateMutation = InsertBeforeMutation | InsertAfterMutation | UpdateMutation | DeleteMutation;
|
|
type ValidProperties = Record<string, JSON | undefined>;
|
|
type FinishContext = {
|
|
updateType: UpdateTypes.Finish;
|
|
action: Actions;
|
|
};
|
|
type MutateContext = FinishContext | {
|
|
updateType: UpdateTypes.Commit | UpdateTypes.Provisional;
|
|
};
|
|
export type UpdateGeometry<G extends GeoJSONStoreGeometries> = {
|
|
featureId: FeatureId;
|
|
coordinateMutations?: ReplaceMutation<G> | CoordinateMutation[];
|
|
propertyMutations?: ValidProperties;
|
|
context: MutateContext;
|
|
};
|
|
export declare class MutateFeatureBehavior extends TerraDrawModeBehavior {
|
|
constructor(config: BehaviorConfig, options: MutateFeatureBehaviorOptions);
|
|
private options;
|
|
createPoint({ coordinates, properties, context, }: {
|
|
coordinates: Position;
|
|
properties: JSONObject;
|
|
context?: FinishContext;
|
|
}): (GeoJSONStoreFeatures<{
|
|
type: "Point";
|
|
coordinates: Position;
|
|
}> & {
|
|
id: FeatureId;
|
|
}) | undefined;
|
|
createLineString({ coordinates, properties, }: {
|
|
coordinates: LineString["coordinates"];
|
|
properties: JSONObject;
|
|
}): GeoJSONStoreFeatures<{
|
|
type: "LineString";
|
|
coordinates: Position[];
|
|
}> & {
|
|
id: FeatureId;
|
|
};
|
|
createPolygon({ coordinates, properties, }: {
|
|
coordinates: Polygon["coordinates"][0];
|
|
properties: JSONObject;
|
|
}): GeoJSONStoreFeatures<Polygon> & {
|
|
id: FeatureId;
|
|
};
|
|
createPolygon({ coordinates, properties, context, }: {
|
|
coordinates: Polygon["coordinates"][0];
|
|
properties: JSONObject;
|
|
context: FinishContext;
|
|
}): (GeoJSONStoreFeatures<Polygon> & {
|
|
id: FeatureId;
|
|
}) | undefined;
|
|
createGuidancePoint({ coordinate, type, }: {
|
|
coordinate: Position;
|
|
type: GuidancePointProperties;
|
|
}): FeatureId;
|
|
createGuidancePoints({ coordinates, type, additionalProperties, }: {
|
|
coordinates: Position[];
|
|
type: GuidancePointProperties;
|
|
additionalProperties?: (index: number) => JSONObject;
|
|
}): FeatureId[];
|
|
updatePoint({ featureId, coordinateMutations, propertyMutations, context, }: UpdateGeometry<Point>): GeoJSONStoreFeatures<Point> | null;
|
|
updatePolygon({ featureId, coordinateMutations, context, propertyMutations, }: UpdateGeometry<Polygon>): GeoJSONStoreFeatures<Polygon> | null;
|
|
updateLineString({ featureId, coordinateMutations, context, propertyMutations, }: UpdateGeometry<LineString>): GeoJSONStoreFeatures<LineString> | null;
|
|
deleteFeatureIfPresent(featureId: FeatureId | undefined): void;
|
|
deleteFeaturesIfPresent(featureIds: FeatureId[]): void;
|
|
setDeselected(featureIds: FeatureId[]): void;
|
|
setSelected(featureId: FeatureId): void;
|
|
updateGuidancePoints(guidancePoints: {
|
|
featureId: FeatureId;
|
|
coordinate: Position;
|
|
}[]): void;
|
|
private handleCreateFeature;
|
|
private handleMutateFeature;
|
|
private mutateFeature;
|
|
private applyCoordinateMutations;
|
|
private isReplaceMutation;
|
|
private createFeatureWithGeometry;
|
|
private validateGeometryWithUpdateType;
|
|
private buildFeatureWithGeometry;
|
|
private createFeatures;
|
|
private updateFeatureGeometries;
|
|
private updateFeatureProperties;
|
|
}
|
|
export {};
|