UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

102 lines (101 loc) 4.84 kB
import DrawingFeature, { DrawingShape, DrawingState } from './drawingFeature'; import MapComponent from '../map/component'; import State from '../../tools/state/state'; import { Collection, Feature } from 'ol'; import { Geometry, Polygon, SimpleGeometry } from 'ol/geom'; import { SketchCoordType } from 'ol/interaction/Draw'; import { Style } from 'ol/style'; import { Modify, Snap, Draw } from 'ol/interaction'; import VectorSource, { VectorSourceEvent } from 'ol/source/Vector'; import { Projection } from 'ol/proj'; import { Coordinate } from 'ol/coordinate'; import ConfigManager from '../../tools/configuration/configmanager'; import UserInteractionManager from '../../tools/state/userInteractionManager'; import { ContextMenu } from '../map/tools/contextmenu'; export default class OlDrawing { map: MapComponent; toolName: string; state: State; configManager: ConfigManager; userInteractionManager: UserInteractionManager; drawingState: DrawingState; drawingSource: VectorSource; modifiableFeatures: Collection<Feature>; draw: Draw | null; modify: Modify | null; snap: Snap | null; editContextMenu: ContextMenu | null; currentShape: DrawingShape | null; fixedLength: number; constructor(map: MapComponent, toolName: string); private addModifyInteraction; private addSnapInteraction; /** * 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; /** Check if there is a vertex of a selected (=editable) feature within the pixel tolerance of the clicked coordinates. */ hasEditableVertexAtCoordinate(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; /** * 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 getGeoJsonFromOlFeature; private getOlFeatureFromDrawingSource; private isOlFeatureInState; createOlFeature(dFeature: DrawingFeature): Feature<Geometry>; setFixedLength(length: 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; addDrawInteraction(tool: DrawingShape): void; centerViewOnFeature(drawingFeature: DrawingFeature): void; getStyle(dFeature: DrawingFeature, olFeature: Feature<Geometry>): Style[]; ensurePolygonIsProperlyClosed(polygon: Polygon): Coordinate[]; private removeDrawInteraction; private removeModifyInteraction; private removeSnapInteraction; private removeEditContextMenu; registerInteractions(): void; unregisterInteractions(): void; private canExecute; }