@pirireis/webglobeplugins 0.6.12 → 0.6.14

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.
@@ -174,8 +174,8 @@ export class ChainListMap {
174
174
  */
175
175
  textUpdate(chainKey, textWriterObjs, dataPreAdaptor) {
176
176
  const chain = this._chainMap.get(chainKey);
177
- const data = (dataPreAdaptor) ? chain.map(dataPreAdaptor) : chain;
178
177
  if (!chain) return;
178
+ const data = (dataPreAdaptor) ? chain.map(dataPreAdaptor) : chain;
179
179
  const properties = this._chainSideProperties.get(chainKey);
180
180
  textWriterObjs.forEach((writer) => {
181
181
  writer.insertTextBulk(data, properties);
@@ -1,5 +1,6 @@
1
1
  import { LineOnGlobeCache } from '../programs/line-on-globe/naive';
2
2
  import { CircleCache } from '../programs/line-on-globe/circle';
3
+ import { LineToTheOriginCache } from "../programs/line-on-globe/to-the-origin"
3
4
  import { BufferOrchestrator, BufferManager } from "../util/account";
4
5
  import { ChainListMap } from "./chain-list-map";
5
6
  import { mapGetOrThrow } from "../util/check/get";
@@ -76,6 +77,7 @@ export class CircleLineChainPlugin {
76
77
  const { gl, globe } = this;
77
78
  this.lineProgram = LineOnGlobeCache.get(globe);
78
79
  this.circleProgram = CircleCache.get(globe);
80
+ this.lineToTheOriginProgram = LineToTheOriginCache.get(globe);
79
81
  {
80
82
  // createBuffers
81
83
  const bufferType = "DYNAMIC_DRAW";
@@ -134,14 +136,14 @@ export class CircleLineChainPlugin {
134
136
  ...['centerCoords', 'targetCoords', 'dashRatio', 'dashOpacity', 'rgba'].map(key => obj(this.bufferManagersCompMap.get(key))));
135
137
  this.circleVao = this.circleProgram.createVAO(
136
138
  ...["centerCoords", "bigRadius", "rgbaCircle", "circleDashAngle", "dashOpacity"].map(key => obj(this.bufferManagersCompMap.get(key))));
139
+ this.toOriginVao = this.lineToTheOriginProgram.createVAO(
140
+ ...["targetCoords", "rgba"].map(key => obj(this.bufferManagersCompMap.get(key))));
137
141
  }
138
142
 
139
143
  }
140
144
 
141
145
 
142
146
  // API
143
-
144
-
145
147
  setDrawCircleOn(bool) {
146
148
  if (typeof bool !== 'boolean') throw new Error("setDrawCircleOn parameter must be a boolean");
147
149
  this._drawCircleOn = bool;
@@ -377,12 +379,13 @@ export class CircleLineChainPlugin {
377
379
  }
378
380
 
379
381
  draw3D() {
380
- const { gl } = this;
382
+ const { gl, globe } = this;
381
383
  gl.disable(gl.DEPTH_TEST);
382
384
  this.lineProgram.draw(this.lineVao, this.bufferOrchestrator.length, this._opacity);
383
385
  if (this._drawCircleOn) this.circleProgram.draw(this.circleVao, this.bufferOrchestrator.length, this._opacity);
384
386
  this._textContextWriterInjectionMap.forEach((writer) => writer.draw());
385
387
  gl.enable(gl.DEPTH_TEST);
388
+ this.lineToTheOriginProgram.draw(this.toOriginVao, this.bufferOrchestrator.length, this._opacity);
386
389
  }
387
390
  }
388
391
 
@@ -57,14 +57,27 @@ export class PixelPaddingCompassPlugin {
57
57
  this._initOrchestrations()
58
58
  }
59
59
 
60
+
61
+ /**
62
+ * @param {string} key
63
+ * @param {number} long
64
+ * @param {number} lat
65
+ * @typedef properties
66
+ * @property {number} pixelRadiusBig
67
+ * @property {number} pixelRadiusSmall
68
+ * @property {[4 numbers between 0-1]} rgba
69
+ */
60
70
  insert(key, long, lat, properties = null) {
61
71
  this.__insertText(key, null, null, { properties, update: true });
62
72
  this.compassMap.insert(key, long, lat, properties);
63
73
  this.globe.DrawRender();
64
-
65
74
  }
66
75
 
67
76
 
77
+ /**
78
+ *
79
+ * @param {string} key
80
+ */
68
81
  delete(key) {
69
82
  this.compassMap.delete(key);
70
83
  this.globe.DrawRender();
@@ -140,8 +140,6 @@ export default class Plugin {
140
140
  }
141
141
 
142
142
 
143
-
144
-
145
143
  _updateData(ratio, textureData0 = null, textureData1 = null) {
146
144
  if (!textureData0 || !textureData1) {
147
145
  this.isAble = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.6.12",
3
+ "version": "0.6.14",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT"
@@ -1,9 +1,30 @@
1
+
2
+ /**
3
+ * IconData;
4
+ * iconMap, iconCoords for objectArray
5
+ *
6
+ * Pin data:
7
+ * long, lat, payload
8
+ *
9
+ * methods insertPin pin and its data
10
+ * methods deletePin
11
+ *
12
+ * Behaviur injection:
13
+ * hover
14
+ * move
15
+ * pick drop
16
+ * mouseclicks
17
+ * keyboard clicks
18
+ * mouse curser changes ( this can be implemented inside above methods)
19
+ */
20
+
1
21
  import {
2
22
  CSGlobe,
3
23
  CSIconTypes,
4
24
  CSObjectTypes,
5
25
  CSObjectArrayUpdateTypes,
6
26
  } from "@pirireis/webglobe";
27
+ import AlarmTimeLineFadeInFadeOut from "../../plugins/alarms/alarmFadeInFadeOutPlugin/AlarmTimeLineFadeInFadeOutPlugin";
7
28
 
8
29
  /**
9
30
  * @typedef {Object} IconPayload
@@ -30,6 +51,118 @@ import {
30
51
  * @property {PointPayload[]} attribs
31
52
  */
32
53
 
54
+ function addIconMap(globe, mapName = "IconMapName", ICON_MAP_URL, ICON_MAP_JSON_URL) {
55
+ globe.api_AddIconMap('IconMapName', ICON_MAP_URL, ICON_MAP_JSON_URL);
56
+ }
57
+
58
+ class ObjectArray {
59
+ constructor(symbolSet, style) {
60
+ this.symbolSet = symbolSet;
61
+ this.style = style;
62
+ }
63
+
64
+ setSymbolSet(symbolSet) {
65
+ this.symbolSet = symbolSet;
66
+ }
67
+
68
+
69
+ }
70
+
71
+
72
+ class PinPointObjectArray {
73
+ constructor(id,
74
+ globe,
75
+ symbolSet, // iconMapName
76
+ style,
77
+ callBacks = {
78
+ mouseDown: (pinItem, event) => { },
79
+ mouseMove: (pinItem, event) => { },
80
+ mouseUp: (pinItem, event) => { },
81
+ mouseClick: (pinItem, event) => { },
82
+ mouseDblClick: (pinItem, event) => { },
83
+
84
+ } = {}) {
85
+ this.id = id
86
+ this.globe = globe;
87
+ this.symbolSet = symbolSet;
88
+ this.style = style;
89
+ this.iconMapName = iconMapName;
90
+ this.callBacks = callBacks;
91
+
92
+ // this item will be used
93
+
94
+ this.currentItem = null
95
+ }
96
+
97
+
98
+ insertPins(pins) {
99
+
100
+ }
101
+
102
+ deletePins(pinsIDs) {
103
+ const deleteBucket = {
104
+ coords: [],
105
+ coordsZ: [],
106
+ attribs: []
107
+ }
108
+ }
109
+
110
+
111
+ _queryByScreenFindFirst() {
112
+ const { clientX, clientY } = this.globe.api_GetMousePos();
113
+ const allObjects = this.globe.queryByScreen(clientX, clientY);
114
+ for (let i = 0; i < allObjects.length; i++) {
115
+ const { obj, owner } = allObjects[i];
116
+ if (owner === this.objectArray) {
117
+ return obj;
118
+ }
119
+ }
120
+ }
121
+
122
+ // mouseDown(x, y, event) {
123
+ // return false
124
+ // }
125
+
126
+
127
+ // // mouse'a basılıp hareket ettirildiğinde, mouseDown'dan true dönmüşse çağrılır
128
+ // mouseMove(x, y, event) {
129
+
130
+ // }
131
+
132
+ // // mouse bırakıldığında çağrılır
133
+ // mouseUp(x, y, event) {
134
+
135
+ // }
136
+
137
+ // // harita üzerinde tıklandığında çağrılır
138
+ // mouseClick() {
139
+ // return false
140
+ // }
141
+
142
+ // // harita üzerinde çift tıklandığında çağrılır
143
+ // mouseDblClick() {
144
+ // return false
145
+ // }
146
+
147
+
148
+ free() {
149
+ this.globe.api_ClearMouseEvents() // TODO
150
+ }
151
+
152
+ _setMouseEvent() {
153
+ const { globe } = this;
154
+ globe.api_SetMouseEvents()
155
+ }
156
+
157
+ _getIdForGlobe() {
158
+ const { globe, objectArray } = this;
159
+ const callback = () => {
160
+ const allObjects = globe.api_queryByScreen()
161
+ }
162
+ return `${this.id}_pinObjectArrayMouseEvent`;
163
+ }
164
+ }
165
+
33
166
  class ObjectArrayLabels {
34
167
  /**
35
168
  * @param {number | string} id
@@ -244,4 +377,5 @@ class ObjectArrayLabels {
244
377
  }
245
378
  }
246
379
 
247
- export default ObjectArrayLabels;
380
+ export default ObjectArrayLabels;
381
+
@@ -4,7 +4,7 @@ import { createProgram } from "../../util";
4
4
  import { noRegisterGlobeProgramCache, globeProgramCache } from "../programcache";
5
5
  import BufferOffsetManger from "../../util/account/bufferoffsetmanager";
6
6
  import { programCache } from "../rings/distancering/circleflatprogram";
7
- const Radian = Math.PI / 180.0;
7
+
8
8
  const GLOBE_MIDPOINT_COUNT = 100;
9
9
  const ITEM_SIZE = 9;
10
10
 
@@ -0,0 +1,165 @@
1
+ import { createProgram } from "../../util";
2
+ import { longLatRadToCartesian3DWithR, cartesian3DToGLPosition, R_3D } from "../../util/shaderfunctions/geometrytransformations";
3
+ import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems";
4
+ import { noRegisterGlobeProgramCache } from "../programcache";
5
+
6
+ /**
7
+ * Creates beams from long, lat, radian coordinates to origin on global view.
8
+ * Ojects with hight, float over terrain and does not propose information of their actual coordinates.
9
+ * You start drawing after zoom level 9-10
10
+ * Does not work on mercator.
11
+ */
12
+
13
+
14
+ const vertexShaderSource = `#version 300 es
15
+ precision highp float;
16
+ ${CameraUniformBlockString}
17
+ ${R_3D}
18
+ ${longLatRadToCartesian3DWithR}
19
+ ${cartesian3DToGLPosition}
20
+
21
+ in vec2 position2d;
22
+ in vec4 rgba;
23
+ uniform float origin_r;
24
+ flat out vec4 v_rgba;
25
+ out float interpolation_value;
26
+
27
+ void main() {
28
+ if (!is3D) {return;}
29
+ vec3 cartesian;
30
+ if(gl_VertexID == 0) {
31
+ cartesian = longLatRadToCartesian3DWithR(position2d, R_3D);
32
+ interpolation_value = 1.0;
33
+ } else {
34
+ cartesian = longLatRadToCartesian3DWithR(position2d, origin_r);
35
+ interpolation_value = 0.0;
36
+ }
37
+ gl_Position = cartesian3DToGLPosition(cartesian);
38
+ v_rgba = rgba;
39
+ gl_PointSize = 10.0; // for testing
40
+ }
41
+ `;
42
+
43
+ const fragmentShaderSource = `#version 300 es
44
+ precision highp float;
45
+
46
+ uniform float plugin_opacity;
47
+ in float interpolation_value;
48
+ flat in vec4 v_rgba;
49
+ out vec4 color;
50
+ void main(){
51
+ if ( fract( interpolation_value * 100.0) < 0.5) {discard;}
52
+ color = vec4(
53
+ v_rgba.rgb,
54
+ v_rgba.a * plugin_opacity * interpolation_value * 0.9
55
+ );
56
+ }`;
57
+
58
+
59
+ class Logic {
60
+ constructor(globe) {
61
+ this.globe = globe;
62
+ this.gl = globe.gl;
63
+ this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
64
+ this._lastOpacity = 1.0;
65
+ this._lastOriginR = 6378.137 - 1;
66
+ const { gl, program } = this;
67
+ {
68
+ gl.bindAttribLocation(program, 0, "position2d");
69
+ gl.bindAttribLocation(program, 1, "rgba");
70
+
71
+ }
72
+ {
73
+ this._opacityLocation = gl.getUniformLocation(program, "plugin_opacity");
74
+ this._originRLocation = gl.getUniformLocation(program, "origin_r")
75
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
76
+ gl.useProgram(program);
77
+ gl.uniform1f(this._opacityLocation, this._lastOpacity);
78
+ gl.uniform1f(this._originRLocation, this._lastOriginR);
79
+ gl.useProgram(currentProgram);
80
+ }
81
+ {
82
+ this.cameraBlockBindingPoint = 0;
83
+ const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
84
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
85
+ gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
86
+ }
87
+ }
88
+
89
+ draw(vao, length, opacity, originR = null) {
90
+ const { gl, program, globe, cameraBlockTotem, cameraBlockBindingPoint } = this;
91
+ const is3D = globe.api_GetCurrentGeometry() == 0;
92
+ if (!is3D) return;
93
+ const lod = globe.api_GetCurrentLODWithDecimal()
94
+ if (lod < 12) return;
95
+ gl.useProgram(program);
96
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
97
+ gl.bindVertexArray(vao);
98
+ if (opacity !== this._lastOpacity) {
99
+ gl.uniform1f(this._opacityLocation, opacity);
100
+ this._checkOpacity(opacity);
101
+ this._lastOpacity = opacity;
102
+ }
103
+ if (originR !== null && originR !== this._lastOriginR) {
104
+ this._checkOriginR(originR);
105
+ gl.uniform1f(this._originRLocation, originR);
106
+ this._lastOriginR = originR;
107
+ }
108
+
109
+ // gl.disable(gl.DEPTH_TEST);
110
+ gl.drawArraysInstanced(gl.LINE_STRIP, 0, 2, length);
111
+ gl.bindVertexArray(null);
112
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
113
+ // gl.enable(gl.DEPTH_TEST);
114
+ }
115
+
116
+ _checkOpacity(opacity) {
117
+ if (opacity < 0.0 || opacity > 1) throw RangeError("Opacity should be between 0 and 1");
118
+
119
+ }
120
+
121
+ _checkOriginR(r) {
122
+ if (r < 0.0 || r > 6378.137 - 0.3) throw RangeError("r should be between 0 and 6378.137 - 0.3");
123
+ }
124
+
125
+ createVAO(potisionBufferObj, colorBufferObj) {
126
+ const { gl } = this;
127
+ const vao = gl.createVertexArray();
128
+ gl.bindVertexArray(vao);
129
+ {
130
+ const { buffer, stride = 0, offset = 0 } = potisionBufferObj;
131
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
132
+ gl.enableVertexAttribArray(0);
133
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
134
+ gl.vertexAttribDivisor(0, 1);
135
+ }
136
+ {
137
+ const { buffer, stride = 0, offset = 0 } = colorBufferObj;
138
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
139
+ gl.enableVertexAttribArray(1);
140
+ gl.vertexAttribPointer(1, 4, gl.FLOAT, false, stride, offset);
141
+ gl.vertexAttribDivisor(1, 1);
142
+ }
143
+
144
+ gl.bindVertexArray(null);
145
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
146
+ return vao;
147
+
148
+ }
149
+
150
+
151
+ free() {
152
+ if (this.isFreed) return;
153
+ CameraUniformBlockTotemCache.release(this.globe);
154
+ this.isFreed = true;
155
+ }
156
+ }
157
+
158
+ const LineToTheOriginCache = Object.freeze({
159
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
160
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
161
+ })
162
+
163
+ export {
164
+ LineToTheOriginCache
165
+ }
@@ -93,6 +93,14 @@ vec3 longLatRadToCartesian3D( vec2 longLat) {
93
93
  }
94
94
  `;
95
95
 
96
+ export const longLatRadToCartesian3DWithR = `
97
+ vec3 longLatRadToCartesian3DWithR( vec2 longLat, float radius) {
98
+ float x = radius * cos(longLat.y) * cos(longLat.x);
99
+ float y = radius * cos(longLat.y) * sin(longLat.x);
100
+ float z = radius * sin(longLat.y);
101
+ return vec3(x, y, z);
102
+ }
103
+ `;
96
104
 
97
105
  // TODO: Make it precise. It doesnt use haversine formula. If this changes, change the formmula which calculates text position.
98
106
  export const circleLimpFromLongLatRadCenterCartesian3D = R + `
@@ -1,4 +0,0 @@
1
- import HeatWavePlugin from './plugins/heatwaveglobeshell';
2
- import { IsobarRasterToVector } from './isobar/plugin';
3
- export { HeatWavePlugin, IsobarRasterToVector };
4
-
@@ -1,337 +0,0 @@
1
- import { ShapesOnGlobeProgram, latLongToPixelXY } from "../../util";
2
-
3
- import ContourMipmap, { scaleParameters } from "./quadtreecontours";
4
-
5
- import ObjectArrayLabels from "./objectarraylabels";
6
-
7
-
8
-
9
- export class IsobarRasterToVector {
10
-
11
-
12
- /**
13
- * @typedef {Object} IsobarData
14
- * @property {number} threshold
15
- * @property {[number, number, number]} color | rgb color
16
- * @property {string} label
17
- *
18
- * @param {*} id
19
- * @param {Array<IsobarData>} isabors
20
- * @param {number} width
21
- * @param {number} height
22
- * @param {Object} options
23
- * @param {boolean} options.xFlip
24
- * @param {boolean} options.yFlip
25
- * @param {boolean} options.isOn
26
- * @param {boolean} options.isLabelsOn
27
- * @param {Object} options.labelStyle
28
- */
29
- constructor(id, dataManager, isobars, width, height, [minLon, minLat, maxLon, maxLat] = [-180, -90, 180, 90], { xFlip = false, yFlip = true, isOn = true, isLabelsOn = true, labelStyle = null, maxMipmapLevel = null } = {}) {
30
- this.id = id;
31
- this._isobarsCheckAndComplete(isobars);
32
- this.isobars = isobars;
33
- this.contourMipmap = null;
34
- this.width = width;
35
- this.height = height;
36
- this.xFlip = xFlip;
37
- this.yFlip = yFlip;
38
- this.bbox = [minLon, minLat, maxLon, maxLat];
39
- this.dataManager = dataManager;
40
-
41
- this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
42
- this._isOn = isOn;
43
- this._isLabelsOn = isLabelsOn;
44
- this._labelsLayer = null;
45
- this._labelsLayerId = id + '_isobar-labels';
46
- this._lineStrignRanges = [];
47
- this._transpos = new Float32Array(3);
48
- this._maxMipmapLevel = maxMipmapLevel;
49
- this._labelStyle = labelStyle;
50
-
51
- // this._transformationMethod = null;
52
- }
53
-
54
- // API
55
-
56
- setData(data, on = false) {
57
- if (!data) return;
58
- this._data = data;
59
- if (on) this._isOn = true;
60
- if (this._isOn) this._calculateAll(data);
61
- }
62
-
63
- on() {
64
- this._isOn = true;
65
- if (this._data) this._calculateAll(this._data);
66
- }
67
-
68
- off() {
69
- this._isOn = false;
70
- this.clean();
71
- }
72
-
73
-
74
- clean() {
75
- this.flush();
76
- this.globe.DrawRender();
77
- }
78
-
79
- setFlip(xFlip, yFlip) {
80
- if (this.xFlip === xFlip && this.yFlip === yFlip) return;
81
- this.xFlip = xFlip;
82
- this.yFlip = yFlip;
83
- const [minLon, minLat, maxLon, maxLat] = this.bbox;
84
- const { width, height } = this
85
- this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
86
- this._calculateLines();
87
- this.globe.DrawRender();
88
- }
89
-
90
- setBoundingBox([minLon, minLat, maxLon, maxLat]) {
91
- this.bbox = [minLon, minLat, maxLon, maxLat];
92
- const { width, height, xFlip, yFlip } = this;
93
- this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
94
- this._calculateLines();
95
- this.globe.DrawRender();
96
- }
97
-
98
-
99
- setIsLabelsOn(isLabelsOn) {
100
- if (this._isLabelsOn === isLabelsOn) return;
101
- this._isLabelsOn = isLabelsOn;
102
- if (!isLabelsOn) {
103
- this._labelsLayer.removeFromMap();
104
- } else {
105
- if (this._labelsLayer === null) this._createLabelsLayer();
106
- this._labelsLayer.addToMap();
107
- this._createBufferData();
108
- }
109
- }
110
-
111
- getIsobars() {
112
- return this.isobars;
113
- }
114
-
115
- setIsobars(isobars) {
116
- this._isobarsCheckAndComplete(isobars);
117
- this.isobars = isobars;
118
- this._calculateLines();
119
- this.globe.DrawRender();
120
- }
121
-
122
- setWidthHeight(width, height) {
123
- this.width = width;
124
- this.height = height;
125
- const { xFlip, yFlip } = this;
126
- const [minLon, minLat, maxLon, maxLat] = this.bbox;
127
- this._transformationMethod = getTransformationMethod(xFlip, yFlip, width, height, minLon, minLat, maxLon, maxLat);
128
- this._calculateLines();
129
- this.globe.DrawRender();
130
- }
131
-
132
-
133
- getLabelStyle() {
134
- return this._labelsLayer.getLabelStyle();
135
- }
136
-
137
- setOpacity(opacity) {
138
- if (opacity < 0 || opacity > 1) throw new Error("Opacity must be between 0 and 1");
139
- this.program.setOpacity(opacity);
140
- }
141
-
142
-
143
- setLabelStyle(style) {
144
- this._labelStyle = style;
145
- if (this._labelsLayer) this._labelsLayer.setLabelStyle(style);
146
- const lastState = this._isLabelsOn;
147
- this.setIsLabelsOn(false);
148
- this.setIsLabelsOn(lastState);
149
- if (lastState) this._createBufferData();
150
- }
151
-
152
- setMaxMipmapLevel(maxMipmapLevel = null) {
153
- this._maxMipmapLevel = maxMipmapLevel;
154
- this._calculateLines();
155
- this.globe.DrawRender();
156
- }
157
-
158
-
159
- flush() {
160
- this.program.setBufferData(new Float32Array(0));
161
- this._lineStrignRanges = [];
162
- if (this._isLabelsOn) this._labelsLayer.flush();
163
- }
164
-
165
- //
166
- // implicit methods
167
-
168
- init(globe, gl) {
169
- this.gl = gl
170
- this.globe = globe
171
-
172
- this.program = new ShapesOnGlobeProgram(gl, globe, 'line_strip');
173
- if (this._isLabelsOn) {
174
- this._createLabelsLayer();
175
- this._labelsLayer.addToMap();
176
- }
177
-
178
- this.dataManager.register(this.id, (ratio, t1, t2) => {
179
- if (!t1 || !t2) {
180
- this.clean();
181
- return;
182
- }
183
- const data = dataMixer(t1, t2, ratio);
184
- if (this._isOn) this.setData(data);
185
- });
186
- }
187
-
188
-
189
- resize(width, height) {
190
- this.program.resize(width, height);
191
- }
192
-
193
- draw3D(projMatrix, modelviewMatrix, transPos) {
194
- if (!this._ready) return;
195
- this._drawContour(projMatrix, modelviewMatrix, transPos);
196
- }
197
-
198
- _calculateLines() {
199
- this._calculateContours();
200
- this._bufferData = this._createBufferData();
201
- this.program.setBufferData(this._bufferData);
202
- }
203
-
204
- _drawContour(projMatrix, modelviewMatrix, transPos) {
205
- this.program.draw(projMatrix, modelviewMatrix, transPos, this._lineStrignRanges);
206
- }
207
-
208
-
209
-
210
- _calculateIntersections(threshold) {
211
- const { _transformationMethod } = this;
212
- const lines = this.contourMipmap.contour([threshold], { maxMipmapLevel: this._maxMipmapLevel }).map(coords => {
213
- return coords.map(([x, y]) => _transformationMethod(x, y))
214
- }
215
- );
216
- return lines;
217
- }
218
-
219
-
220
- _calculateAll(data) {
221
- this.contourMipmap = new ContourMipmap(data, this.width, this.height);
222
- this._calculateContours();
223
- this._bufferData = this._createBufferData();
224
- this.program.setBufferData(this._bufferData);
225
-
226
- this.globe.DrawRender();
227
- this._ready = true;
228
- }
229
-
230
- _calculateContours() {
231
- const { isobars } = this;
232
- for (const isobar of isobars) {
233
- const { threshold } = isobar;
234
- const lines = this._calculateIntersections(threshold);
235
- isobar.lines = lines;
236
- }
237
- }
238
-
239
-
240
- _isobarsCheckAndComplete(isobars) {
241
- window.isobars = isobars;
242
- if (!Array.isArray(isobars)) throw new Error("isobars must be an array");
243
- if (isobars.length === 0) throw new Error("isobars must contain at least one element");
244
- for (const isobar of isobars) {
245
- if (!isobar || typeof isobar !== 'object') throw new Error("isobar must be an object");
246
- if (typeof isobar.threshold !== 'number') throw new Error("isobar.threshold must be a number");
247
- if (isobar.color) {
248
- if (!Array.isArray(isobar.color) || isobar.color.length !== 3) throw new Error("isobar.color must be an array with 3 elements");
249
- for (const color of isobar.color) {
250
- if (color < 0 || color > 1) throw new Error("isobar.color elements must be between 0 and 1");
251
- }
252
- }
253
- if (!isobar.color) isobar.color = [1, 1, 1];
254
- }
255
- }
256
-
257
- _createBufferData() {
258
- const { isobars } = this;
259
- const pointCount = isobars.reduce((acc, { lines }) => acc + lines.reduce((acc, line) => acc + line.length, 0), 0);
260
- const bufferData = new Float32Array(pointCount * 6);
261
-
262
- let index = 0;
263
- let pointCounter = 0;
264
- this._lineStrignRanges = [];
265
-
266
- // gather label data label
267
- const labelPoints = {
268
- coords: [],
269
- coordsZ: [],
270
- attribs: []
271
- };
272
- const { coords, coordsZ, attribs } = labelPoints;
273
- let fidCounter = 0;
274
- for (const { lines, color, threshold } of isobars) {
275
- for (const line of lines) {
276
- let startIndex = pointCounter;
277
- for (const [x, y] of line) {
278
- const pixXY = latLongToPixelXY(y, x)
279
- bufferData[index++] = pixXY.x;
280
- bufferData[index++] = pixXY.y;
281
- bufferData[index++] = color[0];
282
- bufferData[index++] = color[1];
283
- bufferData[index++] = color[2];
284
- bufferData[index++] = 1.0;
285
- pointCounter++;
286
- }
287
-
288
- coords.push(line[0][0], line[0][1]);
289
- coordsZ.push(0)
290
- attribs.push({ value: threshold, fid: fidCounter++ })
291
- this._lineStrignRanges.push([startIndex, pointCounter - startIndex]);
292
- }
293
- }
294
- if (this._isLabelsOn) this._labelsLayer.setData(labelPoints);
295
-
296
- return bufferData;
297
- }
298
-
299
-
300
-
301
- _createLabelsLayer() {
302
- this._labelsLayer = new ObjectArrayLabels(this._labelsLayerId, this.globe, this._labelStyle);
303
- }
304
-
305
- setGeometry() {
306
- this.program.setGeometry();
307
- }
308
-
309
-
310
- free() {
311
- this.flush();
312
- this.program.free();
313
- if (this._isLabelsOn) this._labelsLayer.removeFromMap();
314
- this.dataManager.unregister(this.id);
315
- }
316
-
317
-
318
-
319
- }
320
-
321
- const getTransformationMethod = (xFlip, yFlip, width, height, minX, minY, maxX, maxY) => {
322
- const { scaleX, scaleY } = scaleParameters(minX, minY, maxX, maxY, width, height);
323
- if (xFlip && yFlip) return (x, y) => [maxX - x * scaleX, maxY - y * scaleY];
324
- if (xFlip && !yFlip) return (x, y) => [maxX - x * scaleX, minY + y * scaleY];
325
- if (!xFlip && yFlip) return (x, y) => [minX + x * scaleX, maxY - y * scaleY];
326
- return (x, y) => [minX + x * scaleX, minY + y * scaleY];
327
- }
328
-
329
- function dataMixer(data1, data2, ratio) {
330
- if (!data1 || !data2) return null;
331
- if (data1.length !== data2.length) throw new Error("Data length mismatch");
332
- const data = new Float32Array(data1.length);
333
- for (let i = 0; i < data1.length; i++) {
334
- data[i] = data1[i] * (1 - ratio) + data2[i] * ratio;
335
- }
336
- return data;
337
- }
@@ -1,338 +0,0 @@
1
- // © 2019 3D Robotics. License: Apache-2.0
2
- /* eslint no-plusplus: "off", prefer-rest-params: "off" */
3
- const OUTSIDE = 0;
4
- const ABOVE = 1;
5
- const BELOW = 2;
6
- const WITHIN = 3;
7
-
8
- // Build mipmap layer N from layer N+1
9
- function mipmapReduce({ min, max, width, height, scale }) {
10
- const outWidth = Math.ceil(width / 2);
11
- const outHeight = Math.ceil(height / 2);
12
-
13
- function reduceWith(data, reduce) {
14
- const out = new Float32Array(outWidth * outHeight);
15
- let x;
16
- let y;
17
-
18
- for (y = 0; y < Math.floor(height / 2); y++) {
19
- for (x = 0; x < Math.floor(width / 2); x++) {
20
- out[y * outWidth + x] = reduce(
21
- data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)],
22
- data[(y * 2 + 1) * width + (x * 2 + 0)], data[(y * 2 + 1) * width + (x * 2 + 1)],
23
- );
24
- }
25
- if (x < outWidth) {
26
- out[y * outWidth + x] = reduce(
27
- data[(y * 2 + 0) * width + (x * 2 + 0)],
28
- data[(y * 2 + 1) * width + (x * 2 + 0)],
29
- );
30
- }
31
- }
32
- if (y < outHeight) {
33
- for (x = 0; x < Math.floor(width / 2); x++) {
34
- out[y * outWidth + x] = reduce(
35
- data[(y * 2 + 0) * width + (x * 2 + 0)], data[(y * 2 + 0) * width + (x * 2 + 1)],
36
- );
37
- }
38
- }
39
- if (x < outWidth && y < outHeight) {
40
- out[y * outWidth + x] = reduce(data[(y * 2 + 0) * width + (x * 2 + 0)]);
41
- }
42
- return out;
43
- }
44
-
45
- function minFinite() {
46
- let r = Infinity;
47
- for (let i = 0; i < arguments.length; i++) { // significantly faster than the code Babel generates for ...args
48
- const v = arguments[i];
49
- if (v < r) r = v;
50
- }
51
- return r;
52
- }
53
-
54
- function maxFinite() {
55
- let r = -Infinity;
56
- for (let i = 0; i < arguments.length; i++) {
57
- const v = arguments[i];
58
- if (v > r) r = v;
59
- }
60
- return r;
61
- }
62
-
63
- return {
64
- min: reduceWith(min, minFinite),
65
- max: reduceWith(max, maxFinite),
66
- width: outWidth,
67
- height: outHeight,
68
- scale: scale * 2,
69
- };
70
- }
71
-
72
- class ContourMipmap {
73
- constructor(raster, width, height) {
74
- // Bottom mipmap layer is just the raster: at each pixel the minimum and maximum are the same
75
- this.levels = [{ min: raster, max: raster, width, height, scale: 1 }];
76
-
77
- while (this.levels[0].width > 1 || this.levels[0].height > 1) {
78
- this.levels.unshift(mipmapReduce(this.levels[0]));
79
- }
80
- }
81
-
82
- // Get the minimum elevation in the mipmap
83
- min() { return this.levels[0].min[0] }
84
-
85
- // Get the maximum elevation in the mipmap
86
- max() { return this.levels[0].max[0] }
87
-
88
- // Get an array of contour levels for a specified contour interval
89
- intervals(interval) {
90
- if (interval <= 0) throw new Error('Contour interval must be positive');
91
-
92
- const min = this.min();
93
- const max = this.max();
94
-
95
- const levels = [];
96
- let level = Math.ceil(min / interval) * interval;
97
- while (level < max) {
98
- levels.push(level);
99
- level += interval;
100
- }
101
- return levels;
102
- }
103
-
104
- // Walk the quadtree for a specified contour level, and pass quadtree nodes
105
- // and contour line segments to the callbacks. This is used for visualizing
106
- // the quadtree; in most cases you should use .contour() instead, which
107
- // assembles the line segments into lines and rings.
108
- evaluateContour(contourLevel, { maxMipmapLevel }, addLine, addNode) {
109
- maxMipmapLevel = maxMipmapLevel || this.levels.length - 1;
110
- // Test the mipmap at the given coordinate and level, returning whether the contour line is ABOVE, BELOW, or WITHIN this mipmap cell
111
- // If the mipmap is out of bounds or NaN at that point, OUTSIDE is returned.
112
- const evaluate = (l, x, y) => {
113
- const ml = this.levels[l];
114
- const i = ml.width * y + x;
115
- if (x >= ml.width || y >= ml.height || !Number.isFinite(ml.min[i]) || !Number.isFinite(ml.max[i])) return OUTSIDE;
116
- if (ml.min[i] >= contourLevel) return ABOVE;
117
- if (ml.max[i] < contourLevel) return BELOW;
118
-
119
- // If we've reached the maximum mipmap level, arbitrarily decide that cells that contain
120
- // the contour elevation go inside the contour line.
121
- if (l >= maxMipmapLevel) return ABOVE;
122
-
123
- return WITHIN;
124
- }
125
-
126
- // Add any vertical contour lines that exist between passed mipmap cell and
127
- // its horizontal neighbor to the right. If the line exists at this mipmap
128
- // level, it is added directly, otherwise split the edge and recurse at a
129
- // more detailed mipmap level.
130
- function edgeH(l, x, y) {
131
- const e1 = evaluate(l, x, y);
132
- const e2 = evaluate(l, x + 1, y);
133
-
134
- if (e1 === ABOVE && e2 === BELOW) {
135
- addLine(l, x + 1, y + 1, x + 1, y);
136
- } else if (e2 === ABOVE && e1 === BELOW) {
137
- // reverse order of coordinates compared to case above so that lines
138
- // go counterclockwise around the region above the contour value
139
- addLine(l, x + 1, y, x + 1, y + 1);
140
- } else if (e1 === WITHIN || e2 === WITHIN) {
141
- edgeH(l + 1, x * 2 + 1, y * 2 + 0);
142
- edgeH(l + 1, x * 2 + 1, y * 2 + 1);
143
- }
144
- }
145
-
146
- // Like edgeH, but for horizontal contour lines between the passed cell
147
- // and its vertical neighbor below.
148
- function edgeV(l, x, y) {
149
- const e1 = evaluate(l, x, y);
150
- const e2 = evaluate(l, x, y + 1);
151
-
152
- if (e1 === ABOVE && e2 === BELOW) {
153
- addLine(l, x, y + 1, x + 1, y + 1);
154
- } else if (e2 === ABOVE && e1 === BELOW) {
155
- addLine(l, x + 1, y + 1, x, y + 1);
156
- } else if (e1 === WITHIN || e2 === WITHIN) {
157
- edgeV(l + 1, x * 2 + 0, y * 2 + 1);
158
- edgeV(l + 1, x * 2 + 1, y * 2 + 1);
159
- }
160
- }
161
-
162
- // Add all contour lines within a mipmap cell.
163
- // It recurses into the four quadrants of the cell, and also uses edgeH and
164
- // edgeV to add the contour lines that exist between quadrants.
165
- function node(l, x, y) {
166
- let e = evaluate(l, x, y);
167
- if (e === WITHIN) {
168
- node(l + 1, x * 2 + 0, y * 2 + 0);
169
- node(l + 1, x * 2 + 1, y * 2 + 0);
170
- node(l + 1, x * 2 + 0, y * 2 + 1);
171
- node(l + 1, x * 2 + 1, y * 2 + 1);
172
- edgeH(l + 1, x * 2 + 0, y * 2 + 0);
173
- edgeV(l + 1, x * 2 + 0, y * 2 + 0);
174
- edgeH(l + 1, x * 2 + 0, y * 2 + 1);
175
- edgeV(l + 1, x * 2 + 1, y * 2 + 0);
176
- } else {
177
- if (addNode) addNode(l, x, y, e);
178
- }
179
- }
180
-
181
- node(0, 0, 0);
182
- }
183
-
184
- // Generate a contour line for a specified value
185
- //
186
- // level: Value in the input array at which to draw a contour line
187
- // opts: {
188
- // maxMipmapLevel: Maximum recursion depth in the mipmap. As if you rescaled
189
- // the input to a maximum dimension of 2^n pixels.
190
- // (default unlimited)
191
- // minPoints: Lines and rings with fewer points are removed. (default 0)
192
- // smoothKernelWidth: Width of the rectangular filter for smoothing (default 2)
193
- // smoothCycles: Number of iterations of smoothing (default 2)
194
- // }
195
- //
196
- // Returns an array of lines, where each line is an array of [x, y] pairs.
197
- contour(level, { maxMipmapLevel, smoothKernelWidth = 2, smoothCycles = 2, minPoints = 0 } = {}) {
198
- // Use the quadtree algorithm to generate line segments that make up the contour
199
- const segments = [];
200
- this.evaluateContour(level, { maxMipmapLevel }, (l, x1, y1, x2, y2) => {
201
- const scale = this.levels[l].scale;
202
-
203
- const start = [scale * x1, scale * y1];
204
- const end = [scale * x2, scale * y2];
205
-
206
- segments.push({ start, end });
207
- });
208
-
209
- segments.sort((a, b) => key(a.start) - key(b.start));
210
-
211
- // .. and then join them together into rings
212
-
213
- // An arbitrary function to use a 2D point as a Map key
214
- function key(a) { return a[0] + a[1] * 65536; }
215
-
216
- const fragmentStart = new Map();
217
- const fragmentEnd = new Map();
218
- const rings = [];
219
-
220
- segments.forEach(({ start, end }) => {
221
- const a = fragmentEnd.get(key(start));
222
- const b = fragmentStart.get(key(end));
223
-
224
- if (a && b) {
225
- fragmentEnd.delete(key(start));
226
- fragmentStart.delete(key(end));
227
-
228
- if (a === b) {
229
- // Close a ring
230
- a.push(end);
231
- rings.push(a);
232
- } else {
233
- // Join two lines together
234
- const c = a.concat(b);
235
- fragmentStart.set(key(c[0]), c);
236
- fragmentEnd.set(key(c[c.length - 1]), c);
237
- }
238
- } else if (a) {
239
- // Extend an existing line from the end
240
- fragmentEnd.delete(key(start));
241
- a.push(end);
242
- fragmentEnd.set(key(end), a);
243
- } else if (b) {
244
- // Extend an existing line from the start
245
- fragmentStart.delete(key(end));
246
- b.unshift(start);
247
- fragmentStart.set(key(start), b);
248
- } else {
249
- // New line doesn't connect to any existing line
250
- const c = [start, end];
251
- fragmentStart.set(key(start), c);
252
- fragmentEnd.set(key(end), c);
253
- }
254
-
255
- if (fragmentStart.size !== fragmentEnd.size) {
256
- // TODO: is there a better assert function to use?
257
- // eslint-disable-next-line
258
- console.error(`Contour remaining fragment size mismatch ${fragmentStart.size} ${fragmentEnd.size}`);
259
- }
260
- });
261
-
262
- const smoothOpts = {
263
- kernelWidth: smoothKernelWidth,
264
- cycles: smoothCycles,
265
- };
266
-
267
- // Closed rings and any unclosed line strings
268
- return [...rings, ...fragmentStart.values()]
269
- .filter(l => l.length >= minPoints && l.length >= smoothKernelWidth * 2)
270
- .map(l => smooth(l, smoothOpts))
271
- }
272
- }
273
-
274
- // Smooth a line by repeatedly applying a rectangular filter to approximate
275
- // a gaussian filter. It detects closed loops and preserves them.
276
- // The line is passed as an array of `[x, y]` pairs.
277
- //
278
- // kernelWidth: Width of the rectangular filter kernel
279
- // cycles: Number of times to apply the kernel
280
- function smooth(line, { kernelWidth = 2, cycles = 2 }) {
281
- const isLoop = line[0][0] === line[line.length - 1][0] && line[0][1] === line[line.length - 1][1];
282
-
283
- let pointAt;
284
- if (isLoop) {
285
- pointAt = i => line[(i + line.length) % line.length];
286
- } else {
287
- pointAt = i => line[Math.min(Math.max(i, 0), line.length - 1)];
288
- }
289
-
290
- const sc = 1.0 / (kernelWidth * 2);
291
-
292
- for (let cycle = 0; cycle < cycles; cycle++) {
293
- let px = 0;
294
- let py = 0;
295
-
296
- if (isLoop) {
297
- for (let i = line.length - kernelWidth; i < line.length; i++) {
298
- px += line[i][0];
299
- py += line[i][1];
300
- }
301
- } else {
302
- px = line[0][0] * kernelWidth;
303
- py = line[0][1] * kernelWidth;
304
- }
305
-
306
- for (let i = 0; i < kernelWidth; i++) {
307
- px += line[i][0];
308
- py += line[i][1];
309
- }
310
-
311
- const res = line.slice();
312
-
313
- for (let i = 0; i < line.length; i++) {
314
- res[i] = [px * sc, py * sc];
315
- px += pointAt(i + kernelWidth)[0] - pointAt(i - kernelWidth)[0];
316
- py += pointAt(i + kernelWidth)[1] - pointAt(i - kernelWidth)[1];
317
- }
318
-
319
- if (isLoop) {
320
- // Keep the loop closed
321
- res[res.length - 1] = res[0].slice();
322
- }
323
-
324
- line = res;
325
- }
326
-
327
- return line;
328
- }
329
-
330
- function scaleParameters(minLongitude, minLatitude, maxLongitude, maxLatitude, width, height) {
331
- const scaleX = (maxLongitude - minLongitude) / width;
332
- const scaleY = (maxLatitude - minLatitude) / height;
333
- return { scaleX, scaleY };
334
- }
335
-
336
-
337
- export default ContourMipmap;
338
- export { scaleParameters };
@@ -1,257 +0,0 @@
1
- import { getColorRampModed, DataManager, PointCoordinatesDataCalculator } from "../../util";
2
-
3
- import { GlobeShellWiggle, Float2LegendWithRatio } from "../../programs";
4
-
5
-
6
- /**
7
- * @param id : string
8
- * @param dataManager : DataManager
9
- * @param colorRampData : {values: string[], thresholds: number[], mode: string}
10
- * @param dataWidthHeight : {width: number, height: number}
11
- * @param options : {bbox: number[], minMaxEdges: {min: number, max: number}, escapeValue: number, resolution: number[], meshPartition: number[]}
12
- */
13
- export default class Plugin {
14
- constructor(id, dataManager, colorRampData, dataWidthHeight,
15
- {
16
- bbox = [-180, -90, 180, 90],
17
- minMaxEdges = { min: -99999, max: 99999 },
18
- escapeValue = 99999,
19
- resolution = [2056, 2056],
20
- } = {}) {
21
- this.id = id;
22
- this.dataManager = dataManager;
23
- this._dataWidthHeight = dataWidthHeight;
24
-
25
- this._isOn = true;
26
- this._bbox = bbox
27
- this._minMaxEdges = minMaxEdges;
28
- this._escapeValue = escapeValue
29
- this._resolution = resolution;
30
-
31
- this._colorRampData = colorRampData; // holds until init
32
-
33
- this._lastTexture0data = null;
34
- this._lastTexture1data = null;
35
-
36
- // output of heatProgram is written to ._coloredHeatTexture
37
- this._frameBuffer = null
38
- this._coloredHeatTexture = null;
39
-
40
- this.isAble = false;
41
- }
42
-
43
-
44
- setHeight(height) {
45
- this.globeShell.setHeight(height);
46
- }
47
-
48
-
49
- drawHeat() {
50
- const gl = this.gl;
51
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
52
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._coloredHeatTexture, 0);
53
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
54
- const currentWidth = gl.canvas.width;
55
- const currentHeight = gl.canvas.height;
56
- gl.viewport(0, 0, ...this._resolution);
57
- this.heatProgram.draw()
58
- gl.viewport(0, 0, currentWidth, currentHeight);
59
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
60
- gl.useProgram(currentProgram);
61
- this.globe.DrawRender();
62
- }
63
-
64
-
65
- setEscapeValue(escapeValue) {
66
- this._escapeValue = escapeValue;
67
- this.heatProgram.setEscapeValue(escapeValue);
68
- }
69
-
70
-
71
- _createPointCoordinatesDataCalculator() {
72
- this.coordinatesDataCalculator = new PointCoordinatesDataCalculator(this._bbox, this._dataWidthHeight.width, this._dataWidthHeight.height);
73
- this.dataManager.register(this._coordinatesDataCalculatorID(), this.coordinatesDataCalculator.updateData.bind(this.coordinatesDataCalculator));
74
- }
75
-
76
-
77
- _coordinatesDataCalculatorID() {
78
- return this.id + "_coordinatesDataCalculator";
79
- }
80
-
81
-
82
- updateTime(time) {
83
- this.dataManager.updateTime(time);
84
- this.globe.DrawRender();
85
- }
86
-
87
- setWiggle({ wiggleInKm = null, wiggleSpeed = null } = {}) {
88
- this.globeShell.setWiggle({ wiggleInKm, wiggleSpeed });
89
- }
90
-
91
-
92
- setMinMaxEdges(min = null, max = null) {
93
- if (min) this._minMaxEdges.min = min;
94
- if (max) this._minMaxEdges.max = max;
95
- this.heatProgram.setMinMaxEdges(this._minMaxEdges.min, this._minMaxEdges.max);
96
- this.drawHeat();
97
- }
98
-
99
-
100
- setBBox(minLon, minLat, maxLon, maxLat) {
101
- this._bbox = [minLon, minLat, maxLon, maxLat];
102
- this.globeShell.setBBox({ minLon, minLat, maxLon, maxLat });
103
- this.drawHeat();
104
- }
105
-
106
-
107
- getPointCoordinatesDataCalculator() {
108
- if (!this.coordinatesDataCalculator) this._createPointCoordinatesDataCalculator();
109
- return this.coordinatesDataCalculator;
110
- }
111
-
112
-
113
- /**
114
- * @param {*} values n + 1 number of color hex values without alpha channel. Ex: ["#ff0000", "#00ff00", "#0000ff"]
115
- * @param {*} thresholds n number of thresholds. Ex: [0, 10, 20]
116
- * @param {*} mode "discrete" or "interpolated"
117
- *
118
- * There are maximum 256 pixels in the color ramp.
119
- * The first values array is minimum edge value which is the first pixel, the second comes one pixel after the first.
120
- */
121
- setColorRamp(values, thresholds, mode = "interpolated") {
122
- const lowest = thresholds[0];
123
- const highest = thresholds[thresholds.length - 1];
124
- const range = highest - lowest;
125
- const clampedThresholds = thresholds.map((t) => (t - lowest) / range);
126
- const colors = getColorRampModed(values, clampedThresholds, mode);
127
- this.heatProgram.setColorRampTextureData(colors, 256);
128
- this.heatProgram.setColorRampRange(lowest, highest);
129
- this.drawHeat();
130
- }
131
-
132
-
133
- off() {
134
- this._isOn = false;
135
- }
136
-
137
-
138
- on() {
139
- this._isOn = true;
140
- }
141
-
142
-
143
-
144
-
145
- _updateData(ratio, textureData0 = null, textureData1 = null) {
146
- if (!textureData0 || !textureData1) {
147
- this.isAble = false;
148
- return;
149
- };
150
- this.heatProgram.setBlendRatio(ratio);
151
- if (this._lastTexture0data !== textureData0 || this._lastTexture1data !== textureData1) {
152
- this.isAble = true;
153
- this._lastTexture0data = textureData0;
154
- this._lastTexture1data = textureData1;
155
- this.heatProgram.setFloatTextureData(textureData0, textureData1, this._dataWidthHeight.width, this._dataWidthHeight.height);
156
- }
157
- this.drawHeat();
158
- }
159
-
160
-
161
- setDataWidthHeight(width, height) {
162
- this._dataWidthHeight = { width, height };
163
- this.heatProgram.setDataWidthHeight(width, height);
164
- this.setGeometry();
165
- }
166
-
167
-
168
- draw3D() {
169
- if (!this._isOn) return;
170
- if (!this.isAble) return;
171
- this.gl.disable(this.gl.DEPTH_TEST);
172
- this.globeShell.draw();
173
- this.gl.enable(this.gl.DEPTH_TEST);
174
- }
175
-
176
-
177
- setOpacity(opacity) {
178
- this.globeShell.setOpacity(opacity);
179
- }
180
-
181
-
182
- _setAfterInit() {
183
- {
184
- const [minLon, minLat, maxLon, maxLat] = this._bbox;
185
- this.globeShell.setBBox({ minLon, minLat, maxLon, maxLat });
186
- }
187
- {
188
- this.setColorRamp(this._colorRampData.values, this._colorRampData.thresholds, this._colorRampData.mode);
189
- delete this._colorRampData;
190
- }
191
- this.setMinMaxEdges(this._minMaxEdges.min, this._minMaxEdges.max);
192
- this.setEscapeValue(this._escapeValue);
193
- }
194
-
195
-
196
- _init(globe, gl) {
197
- this.globeShell = new GlobeShellWiggle(gl, globe, {
198
- minLon: this._bbox[0],
199
- minLat: this._bbox[1],
200
- maxLon: this._bbox[2],
201
- maxLat: this._bbox[3],
202
- color: [1.0, 0.1, 0.4, 0.2],
203
- height: 0,
204
- wiggleInKM: 2,
205
- eastWestTied: false,
206
- displayMesh: false
207
- });
208
- this.heatProgram = new Float2LegendWithRatio(gl);
209
- this._frameBuffer = gl.createFramebuffer();
210
-
211
- this.dataManager.register(this.id, (ratio, t1, t2) => this._updateData(ratio, t1, t2));
212
- this.setResolution(this._resolution[0], this._resolution[1]);
213
- }
214
-
215
-
216
-
217
- init(globe, gl) {
218
- this.globe = globe;
219
- this.gl = gl;
220
- this._init(globe, gl);
221
- this._setAfterInit();
222
- }
223
-
224
- setGeometry() {
225
- // globeShell has an implicit program, registered and sets its own geometry.
226
- return;
227
- }
228
-
229
-
230
- // sets Density of middle texture which is used with framebuffers
231
- setResolution(width, height) {
232
- const gl = this.gl;
233
- this._resolution = [width, height];
234
- this._coloredHeatTexture = gl.createTexture();
235
- gl.bindTexture(gl.TEXTURE_2D, this._coloredHeatTexture);
236
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
237
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
238
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
239
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
240
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
241
- gl.bindTexture(gl.TEXTURE_2D, null);
242
- this.globeShell.setTexture(this._coloredHeatTexture);
243
- }
244
-
245
-
246
- free() {
247
- if (this.coordinatesDataCalculator) {
248
- this.dataManager.unregister(this._coordinatesDataCalculatorID());
249
- this.coordinatesDataCalculator = null;
250
- }
251
- this.dataManager.unregister(this.id);
252
- this.globeShell.free();
253
- this.heatProgram.free();
254
- }
255
-
256
-
257
- }