// deck.gl-community // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import {FeatureCollection} from '../utils/geojson-types'; import { ModeProps, ClickEvent, PointerMoveEvent, StartDraggingEvent, StopDraggingEvent, DraggingEvent, GuideFeatureCollection, GuideFeature } from './types'; import {GeoJsonEditMode} from './geojson-edit-mode'; export class CompositeMode extends GeoJsonEditMode { _modes: Array; constructor(modes: Array) { super(); this._modes = modes; } _coalesce( callback: (arg0: GeoJsonEditMode) => T, resultEval: ((arg0: T) => boolean | null | undefined) | null = null ): T { let result: T | null = null; for (let i = 0; i < this._modes.length; i++) { // eslint-disable-next-line callback-return result = callback(this._modes[i]); if (resultEval ? resultEval(result) : result) { break; } } return result; } handleClick(event: ClickEvent, props: ModeProps): void { this._coalesce((handler) => handler.handleClick(event, props)); } handlePointerMove(event: PointerMoveEvent, props: ModeProps): void { return this._coalesce((handler) => handler.handlePointerMove(event, props)); } handleStartDragging(event: StartDraggingEvent, props: ModeProps): void { return this._coalesce((handler) => handler.handleStartDragging(event, props)); } handleStopDragging(event: StopDraggingEvent, props: ModeProps): void { return this._coalesce((handler) => handler.handleStopDragging(event, props)); } handleDragging(event: DraggingEvent, props: ModeProps): void { return this._coalesce((handler) => handler.handleDragging(event, props)); } getGuides(props: ModeProps): GuideFeatureCollection { // TODO: Combine the guides *BUT* make sure if none of the results have // changed to return the same object so that "guides !== this.state.guides" // in editable-geojson-layer works. const allGuides: GuideFeature[] = []; for (const mode of this._modes) { allGuides.push(...mode.getGuides(props).features); } return { type: 'FeatureCollection', features: allGuides }; } }