UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

124 lines (123 loc) 5.2 kB
import DrawingFeature from './drawingFeature.js'; import MapComponent from '../../components/map/component.js'; import { Feature } from 'ol'; import { Geometry } from 'ol/geom.js'; import VectorSource from 'ol/source/Vector.js'; import VectorLayer from 'ol/layer/Vector.js'; import IGirafeContext from '../context/icontext.js'; import { StyleFunction } from 'ol/style/Style.js'; export default class OlDrawing { private readonly map; private readonly stateLocation; private readonly context; private readonly deleteHandler; private readonly modifiableFeatures; private draw; private modify; private snap; private editContextMenu; private currentShape; private fixedLineLength; private fixedSquareSide; private fixedRectangleWidth; private fixedRectangleHeight; readonly drawingSource: VectorSource; readonly drawingLayer: VectorLayer; private lastClosestFeature; private translate; private transform; private readonly modifyFeatureChangeListeners; defaultStyle: StyleFunction | undefined; private readonly updateGeometryInState; private get state(); private get drawingState(); private get config(); constructor(mapComponent: MapComponent, stateLocation: 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; private addEditInteractions; private removeEditInteractions; 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. */ private hasEditableVertexAtCoordinate; private hasEditableShapeAtCoordinate; /** 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. */ private onFeatureAdded; private getOlFeatureFromDrawingSource; private isOlFeatureInState; createOlFeature(dFeature: DrawingFeature): Feature<Geometry>; setFixedLineLength(length: number): void; setFixedSquareSide(length: number): void; setFixedRectangleWidth(width: number): void; setFixedRectangleHeight(height: number): void; private createLineStringFixedLength; private createSquareFixedLength; private createPolygonFixedLength; private createDiskFixedLength; private createRectangleFixedSides; private addDrawInteraction; centerViewOnFeature(drawingFeature: DrawingFeature): void; private getStyle; private removeDrawInteraction; private removeModifyInteraction; private getDrawingShapeType; private isSquareOrRectangle; private shouldAllowVertexInsertionAtEvent; private getHoveredModifiableFeatureAtPixel; private applyScaleRotateOnModifyStyle; private clearModifyFeatureChangeListeners; private removeSnapInteraction; private removeEditContextMenu; registerInteractions(): void; unregisterInteractions(): void; private canExecute; private fixLastLength; }