@longline/aqua-ui 1.0.233 → 1.0.235
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controls/Gradient/PresetGradients.d.ts +10 -2
- package/controls/Gradient/PresetGradients.js +42 -10
- package/map/Map/Map.d.ts +17 -1
- package/map/Map/Map.js +3 -1
- package/map/layers/IdwLayer/IdwFragmentShader.d.ts +1 -1
- package/map/layers/IdwLayer/IdwFragmentShader.js +1 -1
- package/package.json +1 -1
|
@@ -3,13 +3,21 @@ import { IGradientStop } from "../../Types";
|
|
|
3
3
|
* PresetGradients contains predefined gradient stops for common colors.
|
|
4
4
|
*/
|
|
5
5
|
declare class PresetGradients {
|
|
6
|
-
/** Green gradient from
|
|
6
|
+
/** Green gradient from dark teal to light lime */
|
|
7
7
|
static Green: IGradientStop[];
|
|
8
|
-
/** Blue gradient from
|
|
8
|
+
/** Blue gradient from deep navy to pale cyan */
|
|
9
9
|
static Blue: IGradientStop[];
|
|
10
10
|
/** Red gradient from dark maroon to bright red */
|
|
11
11
|
static Red: IGradientStop[];
|
|
12
12
|
/** Rainbow gradient from teal to yellow */
|
|
13
13
|
static Rainbow: IGradientStop[];
|
|
14
|
+
/** Purple gradient from deep violet to soft pink */
|
|
15
|
+
static Purple: IGradientStop[];
|
|
16
|
+
/** Orange gradient from burnt orange to pale peach */
|
|
17
|
+
static Orange: IGradientStop[];
|
|
18
|
+
/** Gray gradient from dark charcoal to light silver */
|
|
19
|
+
static Gray: IGradientStop[];
|
|
20
|
+
/** Heatmap gradient from dark purple through red to yellow */
|
|
21
|
+
static Heat: IGradientStop[];
|
|
14
22
|
}
|
|
15
23
|
export { PresetGradients };
|
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
var PresetGradients = /** @class */ (function () {
|
|
5
5
|
function PresetGradients() {
|
|
6
6
|
}
|
|
7
|
-
/** Green gradient from
|
|
7
|
+
/** Green gradient from dark teal to light lime */
|
|
8
8
|
PresetGradients.Green = [
|
|
9
|
-
{ pos: 0.00, color: '#
|
|
10
|
-
{ pos: 0.25, color: '#
|
|
9
|
+
{ pos: 0.00, color: '#1a454f' },
|
|
10
|
+
{ pos: 0.25, color: '#307c63' },
|
|
11
11
|
{ pos: 0.50, color: '#4eb274' },
|
|
12
|
-
{ pos: 0.75, color: '#
|
|
13
|
-
{ pos: 1.00, color: '#
|
|
12
|
+
{ pos: 0.75, color: '#7bca5d' },
|
|
13
|
+
{ pos: 1.00, color: '#cae170' },
|
|
14
14
|
];
|
|
15
|
-
/** Blue gradient from
|
|
15
|
+
/** Blue gradient from deep navy to pale cyan */
|
|
16
16
|
PresetGradients.Blue = [
|
|
17
|
-
{ pos: 0.00, color: '#
|
|
18
|
-
{ pos: 0.25, color: '#
|
|
17
|
+
{ pos: 0.00, color: '#002253' },
|
|
18
|
+
{ pos: 0.25, color: '#1a517e' },
|
|
19
19
|
{ pos: 0.50, color: '#4184a6' },
|
|
20
|
-
{ pos: 0.75, color: '#
|
|
21
|
-
{ pos: 1.00, color: '#
|
|
20
|
+
{ pos: 0.75, color: '#72bacc' },
|
|
21
|
+
{ pos: 1.00, color: '#acf0f2' },
|
|
22
22
|
];
|
|
23
23
|
/** Red gradient from dark maroon to bright red */
|
|
24
24
|
PresetGradients.Red = [
|
|
@@ -36,6 +36,38 @@ var PresetGradients = /** @class */ (function () {
|
|
|
36
36
|
{ pos: 0.75, color: '#ffb7b2' },
|
|
37
37
|
{ pos: 1.00, color: '#fff176' },
|
|
38
38
|
];
|
|
39
|
+
/** Purple gradient from deep violet to soft pink */
|
|
40
|
+
PresetGradients.Purple = [
|
|
41
|
+
{ pos: 0.00, color: '#2e003e' },
|
|
42
|
+
{ pos: 0.25, color: '#5a1a7e' },
|
|
43
|
+
{ pos: 0.50, color: '#9b4fa2' },
|
|
44
|
+
{ pos: 0.75, color: '#c58fc9' },
|
|
45
|
+
{ pos: 1.00, color: '#f2d0f7' },
|
|
46
|
+
];
|
|
47
|
+
/** Orange gradient from burnt orange to pale peach */
|
|
48
|
+
PresetGradients.Orange = [
|
|
49
|
+
{ pos: 0.00, color: '#7a2e00' },
|
|
50
|
+
{ pos: 0.25, color: '#b44f00' },
|
|
51
|
+
{ pos: 0.50, color: '#e07a33' },
|
|
52
|
+
{ pos: 0.75, color: '#f0aa66' },
|
|
53
|
+
{ pos: 1.00, color: '#ffe0b2' },
|
|
54
|
+
];
|
|
55
|
+
/** Gray gradient from dark charcoal to light silver */
|
|
56
|
+
PresetGradients.Gray = [
|
|
57
|
+
{ pos: 0.00, color: '#1c1c1c' },
|
|
58
|
+
{ pos: 0.25, color: '#444444' },
|
|
59
|
+
{ pos: 0.50, color: '#777777' },
|
|
60
|
+
{ pos: 0.75, color: '#aaaaaa' },
|
|
61
|
+
{ pos: 1.00, color: '#dddddd' },
|
|
62
|
+
];
|
|
63
|
+
/** Heatmap gradient from dark purple through red to yellow */
|
|
64
|
+
PresetGradients.Heat = [
|
|
65
|
+
{ pos: 0.00, color: '#2c003e' },
|
|
66
|
+
{ pos: 0.25, color: '#7f0034' },
|
|
67
|
+
{ pos: 0.50, color: '#d94a00' },
|
|
68
|
+
{ pos: 0.75, color: '#ff9c00' },
|
|
69
|
+
{ pos: 1.00, color: '#fff700' },
|
|
70
|
+
];
|
|
39
71
|
return PresetGradients;
|
|
40
72
|
}());
|
|
41
73
|
export { PresetGradients };
|
package/map/Map/Map.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { MapMouseEvent, Map as OriginalMap } from 'mapbox-gl';
|
|
3
|
-
import { ViewState } from 'react-map-gl/mapbox';
|
|
3
|
+
import { ViewState, ViewStateChangeEvent } from 'react-map-gl/mapbox';
|
|
4
4
|
interface IMapProps {
|
|
5
5
|
/** @ignore */
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -93,14 +93,30 @@ interface IMapProps {
|
|
|
93
93
|
* Fired when map is loaded.
|
|
94
94
|
*/
|
|
95
95
|
onLoad?: (map: OriginalMap) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Fired when map moves.
|
|
98
|
+
*/
|
|
99
|
+
onMove?: (e: ViewStateChangeEvent) => void;
|
|
100
|
+
/**
|
|
101
|
+
* Fired when map stops moving.
|
|
102
|
+
*/
|
|
103
|
+
onMoveEnd?: (e: ViewStateChangeEvent) => void;
|
|
96
104
|
/**
|
|
97
105
|
* Fired when map is clicked.
|
|
98
106
|
*/
|
|
99
107
|
onClick?: (e: MapMouseEvent) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Fired when map is double-clicked.
|
|
110
|
+
*/
|
|
111
|
+
onDblClick?: (e: MapMouseEvent) => void;
|
|
100
112
|
/**
|
|
101
113
|
* Fired when mouse moves over map.
|
|
102
114
|
*/
|
|
103
115
|
onMouseMove?: (e: MapMouseEvent) => void;
|
|
116
|
+
/**
|
|
117
|
+
* Fired when mouse leaves map.
|
|
118
|
+
*/
|
|
119
|
+
onMouseLeave?: (e: MapMouseEvent) => void;
|
|
104
120
|
}
|
|
105
121
|
declare const useViewState: () => ViewState;
|
|
106
122
|
declare const Map: {
|
package/map/Map/Map.js
CHANGED
|
@@ -215,8 +215,10 @@ var MapBase = function (props) {
|
|
|
215
215
|
};
|
|
216
216
|
var handleMove = function (e) {
|
|
217
217
|
setViewState(e.viewState);
|
|
218
|
+
if (props.onMove)
|
|
219
|
+
props.onMove(e);
|
|
218
220
|
};
|
|
219
|
-
return (React.createElement(GLMap, __assign({}, viewState, { mapboxAccessToken: props.token, style: { width: '100%', height: '100%', minHeight: '300px', font: theme.font.bodyMedium }, logoPosition: props.logoPosition, mapStyle: props.style, minZoom: props.minZoom, maxZoom: props.maxZoom, interactiveLayerIds: props.interactiveLayerIds, doubleClickZoom: true, preserveDrawingBuffer: props.preserveDrawingBuffer, fadeDuration: props.fadeDuration, onMove: handleMove, onMouseMove: props.onMouseMove, onLoad: handleLoad, onClick: props.onClick }),
|
|
221
|
+
return (React.createElement(GLMap, __assign({}, viewState, { mapboxAccessToken: props.token, style: { width: '100%', height: '100%', minHeight: '300px', font: theme.font.bodyMedium }, logoPosition: props.logoPosition, mapStyle: props.style, minZoom: props.minZoom, maxZoom: props.maxZoom, interactiveLayerIds: props.interactiveLayerIds, doubleClickZoom: true, preserveDrawingBuffer: props.preserveDrawingBuffer, fadeDuration: props.fadeDuration, onMove: handleMove, onMoveEnd: props.onMoveEnd, onMouseMove: props.onMouseMove, onMouseLeave: props.onMouseLeave, onLoad: handleLoad, onClick: props.onClick, onDblClick: props.onDblClick }),
|
|
220
222
|
props.clipped && React.createElement(React.Fragment, null,
|
|
221
223
|
React.createElement(Source, { type: "raster", tiles: ["https://api.mapbox.com/raster/v1/mapbox.mapbox-terrain-dem-v1/{z}/{x}/{y}.webp?access_token=".concat(props.token)] },
|
|
222
224
|
React.createElement(Layer, { id: "overlay", type: "raster" })),
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const IdwFragmentShader = " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n uniform sampler2D u_dataTexture;\n uniform vec2 u_dataTextureSize;\n uniform int u_numStations;\n varying vec2 v_pos;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n uniform float u_maxDistance;\n uniform float u_fadeFraction;\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n // GLSL ES 1.00 compatible\n // rgba: vec4 from texture2D (values in [0..1])\n float decodeFloatRGBA(vec4 rgba) {\n // convert to 0..255 and round\n vec4 b = floor(rgba * 255.0 + 0.5);\n\n float b0 = b.r;\n float b1 = b.g;\n float b2 = b.b;\n float b3 = b.a;\n\n // sign: top bit of b3\n float sign = (b3 >= 128.0) ? -1.0 : 1.0;\n\n // exponent: 8 bits where lowest bit comes from b2's top bit\n float exp_low = floor(b2 / 128.0); // 0 or 1\n float exp_high = mod(b3, 128.0); // bits 1..7 of exponent as 0..127\n float exponent = exp_high * 2.0 + exp_low; // full 0..255\n\n // mantissa: 23 bits from b0,b1 and lower 7 bits of b2\n float mantissa = b0 + b1 * 256.0 + mod(b2, 128.0) * 65536.0;\n\n // handle special cases\n if (exponent == 0.0) {\n // zero or subnormal\n if (mantissa == 0.0) {\n return 0.0;\n } else {\n // subnormal numbers: (-1)^s * (mantissa / 2^23) * 2^-126\n return sign * (mantissa / 8388608.0) * exp2(-126.0);\n }\n } else if (exponent == 255.0) {\n // Inf or NaN -- return a large value for Inf, and 0 for NaN\n if (mantissa == 0.0) {\n return sign * 3.402823466e38; // approx FLT_MAX\n } else {\n return 0.0; // NaN -> 0 (or handle as you prefer)\n }\n } else {\n // normalized number: (-1)^s * (1 + mantissa/2^23) * 2^(exponent-127)\n float m = 1.0 + mantissa / 8388608.0;\n return sign * m * exp2(exponent - 127.0);\n }\n } \n\n vec2 texCoordForIndex(float idx, vec2 texSize) {\n float x = mod(idx, texSize.x);\n float y = floor(idx / texSize.x);\n return (vec2(x + 0.5, y + 0.5) / texSize);\n }\n\n // read triple of pixels: idx*3 + 0,1,2\n vec3 getPoint(int index) {\n float base = float(index) * 3.0;\n vec4 c0 = texture2D(u_dataTexture, texCoordForIndex(base + 0.0, u_dataTextureSize)); // x (mercator)\n vec4 c1 = texture2D(u_dataTexture, texCoordForIndex(base + 1.0, u_dataTextureSize)); // y (mercator)\n vec4 c2 = texture2D(u_dataTexture, texCoordForIndex(base + 2.0, u_dataTextureSize)); // value\n float mx = decodeFloatRGBA(c0);\n float my = decodeFloatRGBA(c1);\n float val = decodeFloatRGBA(c2);\n return vec3(mx, my, val);\n }\n\n void main() {\n float num = 0.0;\n float denom = 0.0;\n float power = 3.0; // IDW power\n float minDist = 1e9;\n\n for (int i = 0; i < 1024; i++) { // 1024 is a safe upper bound\n if (i >= u_numStations) break;\n vec3 station = getPoint(i);\n float dx = v_pos.x - station.x;\n float dy = v_pos.y - station.y;\n float d = sqrt(dx*dx + dy*dy);\n minDist = min(minDist, d);\n\n if (d < 1e-6) {\n // Exact match: use station value directly\n num = station.z;\n denom = 1.0;\n // stop looping, we\u2019re done\n break;\n }\n\n float w = 1.0 / pow(d, power);\n num += w * station.z;\n denom += w;\n }\n\n if (minDist > u_maxDistance) {\n // Too far from any station \u2192 discard pixel (transparent)\n discard;\n } \n\n float value = num / denom;\n\n // Normalize value between 0 and 1\n //float minVal = 0.0; // pass as uniform if needed\n //float maxVal = 1.0;\n //float norm = clamp((value - minVal) / (maxVal - minVal), 0.0, 1.0);\n\n // --- FADE TO TRANSPARENT ---\n float u_fadeDistance = u_maxDistance * u_fadeFraction;\n float alpha = 1.0;\n if (minDist > u_maxDistance - u_fadeDistance) {\n // fade linearly from 1 \u2192 0\n alpha = (u_maxDistance - minDist) / u_fadeDistance;\n alpha = clamp(alpha, 0.0, 1.0);\n }\n\n gl_FragColor = vec4(
|
|
1
|
+
declare const IdwFragmentShader = " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n uniform sampler2D u_dataTexture;\n uniform vec2 u_dataTextureSize;\n uniform int u_numStations;\n varying vec2 v_pos;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n uniform float u_maxDistance;\n uniform float u_fadeFraction;\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n // GLSL ES 1.00 compatible\n // rgba: vec4 from texture2D (values in [0..1])\n float decodeFloatRGBA(vec4 rgba) {\n // convert to 0..255 and round\n vec4 b = floor(rgba * 255.0 + 0.5);\n\n float b0 = b.r;\n float b1 = b.g;\n float b2 = b.b;\n float b3 = b.a;\n\n // sign: top bit of b3\n float sign = (b3 >= 128.0) ? -1.0 : 1.0;\n\n // exponent: 8 bits where lowest bit comes from b2's top bit\n float exp_low = floor(b2 / 128.0); // 0 or 1\n float exp_high = mod(b3, 128.0); // bits 1..7 of exponent as 0..127\n float exponent = exp_high * 2.0 + exp_low; // full 0..255\n\n // mantissa: 23 bits from b0,b1 and lower 7 bits of b2\n float mantissa = b0 + b1 * 256.0 + mod(b2, 128.0) * 65536.0;\n\n // handle special cases\n if (exponent == 0.0) {\n // zero or subnormal\n if (mantissa == 0.0) {\n return 0.0;\n } else {\n // subnormal numbers: (-1)^s * (mantissa / 2^23) * 2^-126\n return sign * (mantissa / 8388608.0) * exp2(-126.0);\n }\n } else if (exponent == 255.0) {\n // Inf or NaN -- return a large value for Inf, and 0 for NaN\n if (mantissa == 0.0) {\n return sign * 3.402823466e38; // approx FLT_MAX\n } else {\n return 0.0; // NaN -> 0 (or handle as you prefer)\n }\n } else {\n // normalized number: (-1)^s * (1 + mantissa/2^23) * 2^(exponent-127)\n float m = 1.0 + mantissa / 8388608.0;\n return sign * m * exp2(exponent - 127.0);\n }\n } \n\n vec2 texCoordForIndex(float idx, vec2 texSize) {\n float x = mod(idx, texSize.x);\n float y = floor(idx / texSize.x);\n return (vec2(x + 0.5, y + 0.5) / texSize);\n }\n\n // read triple of pixels: idx*3 + 0,1,2\n vec3 getPoint(int index) {\n float base = float(index) * 3.0;\n vec4 c0 = texture2D(u_dataTexture, texCoordForIndex(base + 0.0, u_dataTextureSize)); // x (mercator)\n vec4 c1 = texture2D(u_dataTexture, texCoordForIndex(base + 1.0, u_dataTextureSize)); // y (mercator)\n vec4 c2 = texture2D(u_dataTexture, texCoordForIndex(base + 2.0, u_dataTextureSize)); // value\n float mx = decodeFloatRGBA(c0);\n float my = decodeFloatRGBA(c1);\n float val = decodeFloatRGBA(c2);\n return vec3(mx, my, val);\n }\n\n void main() {\n float num = 0.0;\n float denom = 0.0;\n float power = 3.0; // IDW power\n float minDist = 1e9;\n\n for (int i = 0; i < 1024; i++) { // 1024 is a safe upper bound\n if (i >= u_numStations) break;\n vec3 station = getPoint(i);\n float dx = v_pos.x - station.x;\n float dy = v_pos.y - station.y;\n float d = sqrt(dx*dx + dy*dy);\n minDist = min(minDist, d);\n\n if (d < 1e-6) {\n // Exact match: use station value directly\n num = station.z;\n denom = 1.0;\n // stop looping, we\u2019re done\n break;\n }\n\n float w = 1.0 / pow(d, power);\n num += w * station.z;\n denom += w;\n }\n\n if (minDist > u_maxDistance) {\n // Too far from any station \u2192 discard pixel (transparent)\n discard;\n } \n\n float value = num / denom;\n\n // Normalize value between 0 and 1\n //float minVal = 0.0; // pass as uniform if needed\n //float maxVal = 1.0;\n //float norm = clamp((value - minVal) / (maxVal - minVal), 0.0, 1.0);\n\n // --- FADE TO TRANSPARENT ---\n float u_fadeDistance = u_maxDistance * u_fadeFraction;\n float alpha = 1.0;\n if (minDist > u_maxDistance - u_fadeDistance) {\n // fade linearly from 1 \u2192 0\n alpha = (u_maxDistance - minDist) / u_fadeDistance;\n alpha = clamp(alpha, 0.0, 1.0);\n }\n\n gl_FragColor = vec4(getGradientColor(value).rgb, alpha);\n }\n\n";
|
|
2
2
|
export { IdwFragmentShader };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var IdwFragmentShader = /*glsl*/ " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n uniform sampler2D u_dataTexture;\n uniform vec2 u_dataTextureSize;\n uniform int u_numStations;\n varying vec2 v_pos;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n uniform float u_maxDistance;\n uniform float u_fadeFraction;\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n // GLSL ES 1.00 compatible\n // rgba: vec4 from texture2D (values in [0..1])\n float decodeFloatRGBA(vec4 rgba) {\n // convert to 0..255 and round\n vec4 b = floor(rgba * 255.0 + 0.5);\n\n float b0 = b.r;\n float b1 = b.g;\n float b2 = b.b;\n float b3 = b.a;\n\n // sign: top bit of b3\n float sign = (b3 >= 128.0) ? -1.0 : 1.0;\n\n // exponent: 8 bits where lowest bit comes from b2's top bit\n float exp_low = floor(b2 / 128.0); // 0 or 1\n float exp_high = mod(b3, 128.0); // bits 1..7 of exponent as 0..127\n float exponent = exp_high * 2.0 + exp_low; // full 0..255\n\n // mantissa: 23 bits from b0,b1 and lower 7 bits of b2\n float mantissa = b0 + b1 * 256.0 + mod(b2, 128.0) * 65536.0;\n\n // handle special cases\n if (exponent == 0.0) {\n // zero or subnormal\n if (mantissa == 0.0) {\n return 0.0;\n } else {\n // subnormal numbers: (-1)^s * (mantissa / 2^23) * 2^-126\n return sign * (mantissa / 8388608.0) * exp2(-126.0);\n }\n } else if (exponent == 255.0) {\n // Inf or NaN -- return a large value for Inf, and 0 for NaN\n if (mantissa == 0.0) {\n return sign * 3.402823466e38; // approx FLT_MAX\n } else {\n return 0.0; // NaN -> 0 (or handle as you prefer)\n }\n } else {\n // normalized number: (-1)^s * (1 + mantissa/2^23) * 2^(exponent-127)\n float m = 1.0 + mantissa / 8388608.0;\n return sign * m * exp2(exponent - 127.0);\n }\n } \n\n vec2 texCoordForIndex(float idx, vec2 texSize) {\n float x = mod(idx, texSize.x);\n float y = floor(idx / texSize.x);\n return (vec2(x + 0.5, y + 0.5) / texSize);\n }\n\n // read triple of pixels: idx*3 + 0,1,2\n vec3 getPoint(int index) {\n float base = float(index) * 3.0;\n vec4 c0 = texture2D(u_dataTexture, texCoordForIndex(base + 0.0, u_dataTextureSize)); // x (mercator)\n vec4 c1 = texture2D(u_dataTexture, texCoordForIndex(base + 1.0, u_dataTextureSize)); // y (mercator)\n vec4 c2 = texture2D(u_dataTexture, texCoordForIndex(base + 2.0, u_dataTextureSize)); // value\n float mx = decodeFloatRGBA(c0);\n float my = decodeFloatRGBA(c1);\n float val = decodeFloatRGBA(c2);\n return vec3(mx, my, val);\n }\n\n void main() {\n float num = 0.0;\n float denom = 0.0;\n float power = 3.0; // IDW power\n float minDist = 1e9;\n\n for (int i = 0; i < 1024; i++) { // 1024 is a safe upper bound\n if (i >= u_numStations) break;\n vec3 station = getPoint(i);\n float dx = v_pos.x - station.x;\n float dy = v_pos.y - station.y;\n float d = sqrt(dx*dx + dy*dy);\n minDist = min(minDist, d);\n\n if (d < 1e-6) {\n // Exact match: use station value directly\n num = station.z;\n denom = 1.0;\n // stop looping, we\u2019re done\n break;\n }\n\n float w = 1.0 / pow(d, power);\n num += w * station.z;\n denom += w;\n }\n\n if (minDist > u_maxDistance) {\n // Too far from any station \u2192 discard pixel (transparent)\n discard;\n } \n\n float value = num / denom;\n\n // Normalize value between 0 and 1\n //float minVal = 0.0; // pass as uniform if needed\n //float maxVal = 1.0;\n //float norm = clamp((value - minVal) / (maxVal - minVal), 0.0, 1.0);\n\n // --- FADE TO TRANSPARENT ---\n float u_fadeDistance = u_maxDistance * u_fadeFraction;\n float alpha = 1.0;\n if (minDist > u_maxDistance - u_fadeDistance) {\n // fade linearly from 1 \u2192 0\n alpha = (u_maxDistance - minDist) / u_fadeDistance;\n alpha = clamp(alpha, 0.0, 1.0);\n }\n\n gl_FragColor = vec4(
|
|
1
|
+
var IdwFragmentShader = /*glsl*/ " \n #ifdef GL_ES\n precision mediump float;\n #endif\n\n uniform sampler2D u_dataTexture;\n uniform vec2 u_dataTextureSize;\n uniform int u_numStations;\n varying vec2 v_pos;\n uniform float u_gradientStops[12];\n uniform vec4 u_gradientColors[12];\n uniform float u_maxDistance;\n uniform float u_fadeFraction;\n\n //\n // Given a value, find its corresponding color in the gradient stops.\n //\n vec4 getGradientColor(float position) {\n // Find left and right stop:\n float left = -1.0;\n float right = 99.0;\n vec4 leftColor;\n vec4 rightColor;\n\n for(int i = 0; i < 12; i++) {\n if (u_gradientStops[i] <= position) {\n left = u_gradientStops[i]; \n leftColor = u_gradientColors[i];\n } else break;\n }\n\n for(int i = 12 - 1; i >= 0; i--) {\n if (u_gradientStops[i] >= position) {\n right = u_gradientStops[i]; \n rightColor = u_gradientColors[i];\n } else break;\n }\n\n // Distance between stops:\n float width = right - left;\n // Distance from left stop:\n float dist = position - left;\n // Right stop weight:\n float weight;\n if(dist == 0.0) {\n weight = dist;\n } else {\n weight = dist / width;\n }\n\n float r = leftColor.x + (rightColor.x - leftColor.x) * weight;\n float g = leftColor.y + (rightColor.y - leftColor.y) * weight;\n float b = leftColor.z + (rightColor.z - leftColor.z) * weight;\n float a = leftColor.w + (rightColor.w - leftColor.w) * weight;\n return vec4(r, g, b, a); \n } \n\n // GLSL ES 1.00 compatible\n // rgba: vec4 from texture2D (values in [0..1])\n float decodeFloatRGBA(vec4 rgba) {\n // convert to 0..255 and round\n vec4 b = floor(rgba * 255.0 + 0.5);\n\n float b0 = b.r;\n float b1 = b.g;\n float b2 = b.b;\n float b3 = b.a;\n\n // sign: top bit of b3\n float sign = (b3 >= 128.0) ? -1.0 : 1.0;\n\n // exponent: 8 bits where lowest bit comes from b2's top bit\n float exp_low = floor(b2 / 128.0); // 0 or 1\n float exp_high = mod(b3, 128.0); // bits 1..7 of exponent as 0..127\n float exponent = exp_high * 2.0 + exp_low; // full 0..255\n\n // mantissa: 23 bits from b0,b1 and lower 7 bits of b2\n float mantissa = b0 + b1 * 256.0 + mod(b2, 128.0) * 65536.0;\n\n // handle special cases\n if (exponent == 0.0) {\n // zero or subnormal\n if (mantissa == 0.0) {\n return 0.0;\n } else {\n // subnormal numbers: (-1)^s * (mantissa / 2^23) * 2^-126\n return sign * (mantissa / 8388608.0) * exp2(-126.0);\n }\n } else if (exponent == 255.0) {\n // Inf or NaN -- return a large value for Inf, and 0 for NaN\n if (mantissa == 0.0) {\n return sign * 3.402823466e38; // approx FLT_MAX\n } else {\n return 0.0; // NaN -> 0 (or handle as you prefer)\n }\n } else {\n // normalized number: (-1)^s * (1 + mantissa/2^23) * 2^(exponent-127)\n float m = 1.0 + mantissa / 8388608.0;\n return sign * m * exp2(exponent - 127.0);\n }\n } \n\n vec2 texCoordForIndex(float idx, vec2 texSize) {\n float x = mod(idx, texSize.x);\n float y = floor(idx / texSize.x);\n return (vec2(x + 0.5, y + 0.5) / texSize);\n }\n\n // read triple of pixels: idx*3 + 0,1,2\n vec3 getPoint(int index) {\n float base = float(index) * 3.0;\n vec4 c0 = texture2D(u_dataTexture, texCoordForIndex(base + 0.0, u_dataTextureSize)); // x (mercator)\n vec4 c1 = texture2D(u_dataTexture, texCoordForIndex(base + 1.0, u_dataTextureSize)); // y (mercator)\n vec4 c2 = texture2D(u_dataTexture, texCoordForIndex(base + 2.0, u_dataTextureSize)); // value\n float mx = decodeFloatRGBA(c0);\n float my = decodeFloatRGBA(c1);\n float val = decodeFloatRGBA(c2);\n return vec3(mx, my, val);\n }\n\n void main() {\n float num = 0.0;\n float denom = 0.0;\n float power = 3.0; // IDW power\n float minDist = 1e9;\n\n for (int i = 0; i < 1024; i++) { // 1024 is a safe upper bound\n if (i >= u_numStations) break;\n vec3 station = getPoint(i);\n float dx = v_pos.x - station.x;\n float dy = v_pos.y - station.y;\n float d = sqrt(dx*dx + dy*dy);\n minDist = min(minDist, d);\n\n if (d < 1e-6) {\n // Exact match: use station value directly\n num = station.z;\n denom = 1.0;\n // stop looping, we\u2019re done\n break;\n }\n\n float w = 1.0 / pow(d, power);\n num += w * station.z;\n denom += w;\n }\n\n if (minDist > u_maxDistance) {\n // Too far from any station \u2192 discard pixel (transparent)\n discard;\n } \n\n float value = num / denom;\n\n // Normalize value between 0 and 1\n //float minVal = 0.0; // pass as uniform if needed\n //float maxVal = 1.0;\n //float norm = clamp((value - minVal) / (maxVal - minVal), 0.0, 1.0);\n\n // --- FADE TO TRANSPARENT ---\n float u_fadeDistance = u_maxDistance * u_fadeFraction;\n float alpha = 1.0;\n if (minDist > u_maxDistance - u_fadeDistance) {\n // fade linearly from 1 \u2192 0\n alpha = (u_maxDistance - minDist) / u_fadeDistance;\n alpha = clamp(alpha, 0.0, 1.0);\n }\n\n gl_FragColor = vec4(getGradientColor(value).rgb, alpha);\n }\n\n";
|
|
2
2
|
export { IdwFragmentShader };
|