From 4eb77bdf5c7e6f13ddacf943d8326d29dc22cbd5 Mon Sep 17 00:00:00 2001 From: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> Date: Wed, 26 Oct 2022 15:13:24 +0530 Subject: [PATCH] feat: update typings to be more verbose Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> --- src/layer.ts | 25 +++++++++-------- types/mapbox-gl-interpolate-heatmap.d.ts | 35 +++++++++++++----------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/layer.ts b/src/layer.ts index 32fac487..e694e953 100644 --- a/src/layer.ts +++ b/src/layer.ts @@ -1,28 +1,30 @@ import earcut from 'earcut'; import mapboxgl, { CustomLayerInterface } from 'mapbox-gl'; -type Options = { +type HeatmapLayer = { id: string; - opacity?: number; - minValue?: number; + data: { lat: number; lon: number; val: number }[]; + framebufferFactor?: number; maxValue?: number; + minValue?: number; + opacity?: number; p?: number; - framebufferFactor?: number; - data: { lat: number; lon: number; val: number }[]; aoi?: { lat: number; lon: number }[]; valueToColor?: string; -}; + valueToColor4?: string; + textureCoverSameAreaAsROI?: boolean; + points?: number[][]; +} & CustomLayerInterface; -class MapboxInterpolateHeatmapLayer implements CustomLayerInterface { - framebufferFactor = 0.3; +class MapboxInterpolateHeatmapLayer implements HeatmapLayer { id = ''; + data: { lat: number; lon: number; val: number }[] = []; + framebufferFactor = 0.3; maxValue = -Infinity; minValue = Infinity; opacity = 0.5; p = 3; - data: { lat: number; lon: number; val: number }[] = []; aoi?: { lat: number; lon: number }[] = []; - textureCoverSameAreaAsROI: boolean; valueToColor?: string = ` vec3 valueToColor(float value) { return vec3(max((value-0.5)*2.0, 0.0), 1.0 - 2.0*abs(value - 0.5), max((0.5-value)*2.0, 0.0)); @@ -33,6 +35,7 @@ class MapboxInterpolateHeatmapLayer implements CustomLayerInterface { return vec4(valueToColor(value), defaultOpacity); } `; + textureCoverSameAreaAsROI: boolean; points: number[][] = []; // Custom Props aPositionComputation?: number; @@ -61,7 +64,7 @@ class MapboxInterpolateHeatmapLayer implements CustomLayerInterface { uUi: WebGLUniformLocation | null = null; uXi: WebGLUniformLocation | null = null; - constructor(options: Options) { + constructor(options: HeatmapLayer) { this.id = options.id || ''; this.data = options.data || []; this.aoi = options.aoi || []; diff --git a/types/mapbox-gl-interpolate-heatmap.d.ts b/types/mapbox-gl-interpolate-heatmap.d.ts index 1d617212..85f7e1d7 100644 --- a/types/mapbox-gl-interpolate-heatmap.d.ts +++ b/types/mapbox-gl-interpolate-heatmap.d.ts @@ -1,5 +1,5 @@ /*! - * mapbox-gl-interpolate-heatmap v0.3.1 + * mapbox-gl-interpolate-heatmap v0.4.0 * Mapbox layer for average/interpolation heatmaps * (c) 2021 Vinayak Kulkanri * Released under the MIT License @@ -7,43 +7,46 @@ import mapboxgl, { CustomLayerInterface } from 'mapbox-gl'; -declare type Options = { +declare type HeatmapLayer = { id: string; - opacity?: number; - minValue?: number; - maxValue?: number; - p?: number; - framebufferFactor?: number; data: { lat: number; lon: number; val: number; }[]; + framebufferFactor?: number; + maxValue?: number; + minValue?: number; + opacity?: number; + p?: number; aoi?: { lat: number; lon: number; }[]; valueToColor?: string; -}; -declare class MapboxInterpolateHeatmapLayer implements CustomLayerInterface { - framebufferFactor: number; + valueToColor4?: string; + textureCoverSameAreaAsROI?: boolean; + points?: number[][]; +} & CustomLayerInterface; +declare class MapboxInterpolateHeatmapLayer implements HeatmapLayer { id: string; - maxValue: number; - minValue: number; - opacity: number; - p: number; data: { lat: number; lon: number; val: number; }[]; + framebufferFactor: number; + maxValue: number; + minValue: number; + opacity: number; + p: number; aoi?: { lat: number; lon: number; }[]; - textureCoverSameAreaAsROI: boolean; valueToColor?: string; valueToColor4?: string; + textureCoverSameAreaAsROI: boolean; points: number[][]; aPositionComputation?: number; aPositionDraw?: number; @@ -70,7 +73,7 @@ declare class MapboxInterpolateHeatmapLayer implements CustomLayerInterface { uScreenSizeDraw: WebGLUniformLocation | null; uUi: WebGLUniformLocation | null; uXi: WebGLUniformLocation | null; - constructor(options: Options); + constructor(options: HeatmapLayer); onAdd(map: mapboxgl.Map, gl: WebGLRenderingContext): void; onRemove(map: mapboxgl.Map, gl: WebGLRenderingContext): void; prerender(gl: WebGLRenderingContext, matrix: number[]): void;