/* * Copyright 2018 Teralytics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import { Feature, FeatureCollection, GeometryObject } from 'geojson'; export type Flow = any; export type LocationProperties = any; export type Location = Feature | any; export type Locations = FeatureCollection | Location[]; export function isFeatureCollection( locations: Locations, ): locations is FeatureCollection { return (locations as FeatureCollection).type === 'FeatureCollection'; } export interface ViewState { latitude: number; longitude: number; zoom: number; bearing?: number; pitch?: number; altitude?: number; } export const enum LocationCircleType { INNER = 'inner', OUTER = 'outer', OUTLINE = 'outline', } export interface LocationCircle { location: Location; type: LocationCircleType; } export interface FlowAccessors { getFlowOriginId: FlowAccessor; getFlowDestId: FlowAccessor; getFlowMagnitude: FlowAccessor; getFlowColor?: FlowAccessor; getAnimatedFlowLineStaggering?: FlowAccessor; } export interface LocationAccessors { getLocationId: LocationAccessor; getLocationCentroid: LocationAccessor<[number, number]>; getLocationTotalIn?: LocationAccessor; getLocationTotalOut?: LocationAccessor; getLocationTotalWithin?: LocationAccessor; } export type Data = Flow | Location | LocationCircle; export enum PickingType { LOCATION = 'location', FLOW = 'flow', LOCATION_AREA = 'location-area', } export type DeckGLLayer = any; export interface PickingInfo { layer: DeckGLLayer; index: number; object: T; x: number; y: number; lngLat: [number, number]; } export type PickingHandler = (info: T, event: { srcEvent: MouseEvent }) => void; export interface LocationPickingInfo extends PickingInfo { type: PickingType.LOCATION; object: Location; totalIn: number; totalOut: number; totalWithin: number; circleRadius: number; } export interface LocationAreaPickingInfo extends PickingInfo { type: PickingType.LOCATION_AREA; object: Location; } export interface FlowPickingInfo extends PickingInfo { type: PickingType.FLOW; object: Flow; origin: Location; dest: Location; } export type FlowLayerPickingInfo = LocationPickingInfo | LocationAreaPickingInfo | FlowPickingInfo; // https://deck.gl/#/documentation/developer-guide/using-layers?section=accessors export interface AccessorObjectInfo { index: number; data: any; target: any[]; } export type FlowAccessor = (flow: Flow, objectInfo?: AccessorObjectInfo) => T; export type LocationAccessor = (location: Location) => T; export type LocationCircleAccessor = (locCircle: LocationCircle) => T; export type NumberScale = (value: number) => number;