import DrawingFeature, { DrawingShape } from './drawingFeature.js'; import MapComponent from '../map/component.js'; import { Collection, Feature } from 'ol'; import { Geometry, SimpleGeometry } from 'ol/geom.js'; import { SketchCoordType } from 'ol/interaction/Draw.js'; import { Style } from 'ol/style.js'; import { Draw, Modify, Snap, Translate } from 'ol/interaction.js'; import VectorSource, { VectorSourceEvent } from 'ol/source/Vector.js'; import VectorLayer from 'ol/layer/Vector.js'; import { Projection } from 'ol/proj.js'; import { Coordinate } from 'ol/coordinate.js'; import { ContextMenu } from '../map/tools/contextmenu.js'; import IGirafeContext from '../../tools/context/icontext.js'; import { StyleFunction } from 'ol/style/Style.js'; import Transform from 'ol-ext/interaction/Transform.js'; export default class OlDrawing { private readonly map; private readonly toolName; private readonly context; private readonly deleteHandler; modifiableFeatures: Collection; draw: Draw | null; modify: Modify | null; snap: Snap | null; editContextMenu: ContextMenu | null; currentShape: DrawingShape | null; fixedLineLength: number; fixedSquareSide: number; fixedRectangleWidth: number; fixedRectangleHeight: number; drawingSource: VectorSource; drawingLayer: VectorLayer; lastClosestFeature: Feature | null; translate: Translate | null; transform: Transform | null; defaultStyle: StyleFunction | undefined; private readonly updateGeometryInState; private get state(); private get drawingState(); private get config(); constructor(map: MapComponent, toolName: string, context: IGirafeContext, deleteHandler: (featureId: string) => void); private addModifyInteraction; private addSnapInteraction; private addTranslateInteraction; private removeTranslateInteraction; private addTransformInteraction; private removeTransformInteraction; /** * Adds a context menu to the map with a single entry 'remove vertex'. The menu is configured to open * when the user does an alternate click ( = context event) on or near a vertex of a modifiable feature. */ private addEditContextMenu; addEditInteractions(): void; removeEditInteractions(): void; private readonly prepareMenuEntriesForVertex; private readonly prepareMenuEntriesForShape; /** Check if there is a vertex of a selected (=editable) feature within the pixel tolerance of the clicked coordinates. */ hasEditableVertexAtCoordinate(coordinate: Coordinate): boolean; hasEditableShapeAtCoordinate(coordinate: Coordinate): boolean; /** Returns the closest vertex and feature to a coordinate from the drawing source. The feature source can be pre-filtered via an optional filter function. */ private getClosestVertexAndFeature; /** Deletes the vertex the user interacted with last via the modify interaction. Handled events are defined by the modify option properties 'condition' and 'insertVertexCondition'. */ private removeLastInteractedVertex; private removeLastInteractedShape; /** * Adds features to the drawing source if they are missing and updates their style each time a property changes. * Adding them to the source is only necessary if the feature originates from a deserialized state and not * from a drawing action in the map. * * @param {DrawingFeature[]} dFeatures - An array of `DrawingFeature` objects to be added. */ addFeatures(dFeatures: DrawingFeature[]): void; /** * Deletes the provided features from the drawing source. * * @param {DrawingFeature[]} dFeatures - The list of features to be deleted. */ deleteFeatures(dFeatures: DrawingFeature[]): void; /** * Restrict modify interaction to the currently selected features via updating the features collection */ private updateModifiableFeatures; /** * Handles the addition of a feature to the vector source. This method is triggered when a new feature is drawn * and added to the vector source at end of the draw interaction. * It creates a `DrawingFeature` to save in the state, containing a unique id and the feature geometry as a geojson. * To identify the ol feature in the map, it receives the same id as the `DrawingFeature`. * * @param {VectorSourceEvent} e - The add-feature event. */ onFeatureAdded(e: VectorSourceEvent): void; private getOlFeatureFromDrawingSource; private isOlFeatureInState; createOlFeature(dFeature: DrawingFeature): Feature; setFixedLineLength(length: number): void; setFixedSquareSide(length: number): void; setFixedRectangleWidth(width: number): void; setFixedRectangleHeight(height: number): void; createLineStringFixedLength(coordinates: SketchCoordType, geom: SimpleGeometry): SimpleGeometry; createSquareFixedLength(coordinates: SketchCoordType, geom: SimpleGeometry, proj: Projection): SimpleGeometry; createPolygonFixedLength(coordinates: SketchCoordType, geom: SimpleGeometry): SimpleGeometry; createDiskFixedLength(coordinates: SketchCoordType, geom: SimpleGeometry): SimpleGeometry; createRectangleFixedSides(coordinates: SketchCoordType, geom: SimpleGeometry, proj: Projection): SimpleGeometry; addDrawInteraction(tool: DrawingShape): void; centerViewOnFeature(drawingFeature: DrawingFeature): void; getStyle(dFeature: DrawingFeature, olFeature: Feature): Style[]; private removeDrawInteraction; private removeModifyInteraction; private removeSnapInteraction; private removeEditContextMenu; registerInteractions(): void; unregisterInteractions(): void; private canExecute; private fixLastLength; }