@pirireis/webglobeplugins 0.6.11 → 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.
@@ -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 };