UNPKG

@equinor/videx-map

Version:

Component for Pixi-overlay in Leaflet.

114 lines (113 loc) 3.44 kB
import * as PIXI from 'pixi.js'; import Vector2 from '@equinor/videx-vector2'; import { ModuleInterface } from './ModuleInterface'; import { MeshData, MeshNormalData } from './utils/Mesh'; import Highlighter from './utils/fields/Highlighter'; import LabelManager from './utils/fields/LabelManager'; import TriangleDictionary from './utils/TriangleDictionary'; type vec3 = [number, number, number]; interface FillUniform { col1: vec3; col2: vec3; opacity: number; hashed: boolean; hashDisp: number; hashWidth: number; } interface OutlineUniform { color: vec3; width: number; } /** Collection of data describing colors used for fill. */ interface FieldStyle { fillColor1: vec3; fillColor2: vec3; fillOpacity: number; outlineColor: vec3; hashed: boolean; } export interface Field { type: string; geometry: { type: string; /** * The type of data found within coordinates depends on type. * For 'Polygon', coordinates is given as [number, number][][]. * for 'MultiPolygon', coordinates is given as [number, number][][][]. */ coordinates: [number, number][][] | [number, number][][][]; }; properties: { discname: string; group: number; guid?: number; hctype: string; label: string; lat: number; long: number; polygonId: number; status: string; }; } export interface FieldMesh { fill: { mesh: PIXI.Mesh; uniform: FillUniform; }; outline: { mesh: PIXI.Mesh; uniform: OutlineUniform; }; } /** Interface for field config. */ interface Config { /** Initial scale of field hash (Default: 1.0). */ initialHash?: number; /** Minimum scale of field hash (Default: 0.0). */ minHash?: number; /** Maximum scale of field hash (Default: Infinity). */ maxHash?: number; } /** Module for displaying fields. */ export default class FieldModule extends ModuleInterface { /** Vertex shader for the fill. */ static vertexShaderFill: string; /** Fragment shader for the fill. */ static fragmentShaderFill: string; /** Vertex shader for the outlines. */ static vertexShaderOutline: string; /** Fragment shader for the outlines. */ static fragmentShaderOutline: string; /** Collection of fields with meshes. */ fields: FieldMesh[]; /** Settings for how to render fields. */ config: Config; dict: TriangleDictionary<number>; highlighter: Highlighter; labelManager: LabelManager; /** Index of previously highlighted field */ prevField: number; constructor(config?: Config); set(data: Field[]): void; /** * Draw each polygon in a polygon collection. * @param polygons */ drawPolygons(meshData: MeshData, outlineData: MeshNormalData, fieldStyle: FieldStyle, zIndex: number): FieldMesh; /** * Get the fill color of a field. * @param props Properties of field * @returns Color used to fill */ getFieldStyle(guid: number, hctype: string): FieldStyle; /** * Project a collection of polygons. * @param points Points within polygons * @returns Projected polygons */ projectPolygons(points: [number, number][]): Vector2[]; resize(_zoom: number): void; highlight(lat: number, long: number): boolean; tryUnselect(): void; } export {};