Skip to content

Commit

Permalink
feat: update typings to be more verbose
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
  • Loading branch information
vinayakkulkarni committed Oct 26, 2022
1 parent 760579d commit 4eb77bd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
25 changes: 14 additions & 11 deletions src/layer.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -33,6 +35,7 @@ class MapboxInterpolateHeatmapLayer implements CustomLayerInterface {
return vec4(valueToColor(value), defaultOpacity);
}
`;
textureCoverSameAreaAsROI: boolean;
points: number[][] = [];
// Custom Props
aPositionComputation?: number;
Expand Down Expand Up @@ -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 || [];
Expand Down
35 changes: 19 additions & 16 deletions types/mapbox-gl-interpolate-heatmap.d.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
/*!
* mapbox-gl-interpolate-heatmap v0.3.1
* mapbox-gl-interpolate-heatmap v0.4.0
* Mapbox layer for average/interpolation heatmaps
* (c) 2021 Vinayak Kulkanri<inbox.vinayak@gmail.com>
* Released under the MIT License
*/

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;
Expand All @@ -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;
Expand Down

0 comments on commit 4eb77bd

Please # to comment.