@mapcatch/util 1.0.15 → 2.0.1
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/dist/catchUtil.min.esm.js +67927 -14001
- package/dist/catchUtil.min.js +2695 -55
- package/package.json +22 -3
- package/src/constants/annotation_color.js +7 -0
- package/src/constants/annotation_draw_style.js +228 -0
- package/src/constants/annotation_label_style.js +76 -0
- package/src/constants/annotation_style.js +118 -0
- package/src/constants/cameras.js +1 -1
- package/src/constants/crs.js +31473 -31473
- package/src/constants/error_codes.js +44 -0
- package/src/constants/height_colors.js +1 -0
- package/src/constants/index.js +9 -2
- package/src/constants/map_style.js +11 -0
- package/src/constants/measurement_fields.js +3 -3
- package/src/{event.js → event/event.js} +1 -14
- package/src/event/event_bus.js +5 -0
- package/src/event/index.js +2 -0
- package/src/gl-operations/constants.js +9 -11
- package/src/gl-operations/default_options.js +5 -5
- package/src/gl-operations/index.js +166 -239
- package/src/gl-operations/reglCommands/contours.js +20 -20
- package/src/gl-operations/reglCommands/default.js +34 -34
- package/src/gl-operations/reglCommands/hillshading.js +116 -116
- package/src/gl-operations/reglCommands/index.js +6 -6
- package/src/gl-operations/reglCommands/multiLayers.js +55 -55
- package/src/gl-operations/reglCommands/transitions.js +24 -24
- package/src/gl-operations/reglCommands/util.js +54 -54
- package/src/gl-operations/renderer.js +69 -69
- package/src/gl-operations/shaders/transform.js +2 -2
- package/src/gl-operations/shaders/util/rgbaToFloat.glsl +11 -11
- package/src/gl-operations/texture_manager.js +58 -58
- package/src/gl-operations/util.js +154 -154
- package/src/index.js +14 -2
- package/src/measure/index.js +198 -0
- package/src/measure/tile_cache.js +88 -0
- package/src/mvs/index.js +26 -0
- package/src/mvs/protos/index.js +12 -0
- package/src/mvs/protos/proto_10.js +155 -0
- package/src/observation_pretict.js +168 -0
- package/src/photo-parser/exif/gps_tags.js +33 -0
- package/src/photo-parser/exif/ifd1_tags.js +22 -0
- package/src/photo-parser/exif/index.js +130 -0
- package/src/photo-parser/exif/parse_image.js +290 -0
- package/src/photo-parser/exif/string_values.js +137 -0
- package/src/photo-parser/exif/tags.js +75 -0
- package/src/photo-parser/exif/tiff_tags.js +35 -0
- package/src/photo-parser/exif/util.js +103 -0
- package/src/photo-parser/image-size/detector.js +24 -0
- package/src/photo-parser/image-size/fromFile.js +55 -0
- package/src/photo-parser/image-size/index.js +2 -0
- package/src/photo-parser/image-size/lookup.js +37 -0
- package/src/photo-parser/image-size/types/bmp.js +10 -0
- package/src/photo-parser/image-size/types/cur.js +16 -0
- package/src/photo-parser/image-size/types/dds.js +10 -0
- package/src/photo-parser/image-size/types/gif.js +11 -0
- package/src/photo-parser/image-size/types/heif.js +35 -0
- package/src/photo-parser/image-size/types/icns.js +112 -0
- package/src/photo-parser/image-size/types/ico.js +74 -0
- package/src/photo-parser/image-size/types/index.js +43 -0
- package/src/photo-parser/image-size/types/j2c.js +11 -0
- package/src/photo-parser/image-size/types/jp2.js +22 -0
- package/src/photo-parser/image-size/types/jpg.js +157 -0
- package/src/photo-parser/image-size/types/ktx.js +18 -0
- package/src/photo-parser/image-size/types/png.js +36 -0
- package/src/photo-parser/image-size/types/pnm.js +74 -0
- package/src/photo-parser/image-size/types/psd.js +10 -0
- package/src/photo-parser/image-size/types/svg.js +100 -0
- package/src/photo-parser/image-size/types/tga.js +14 -0
- package/src/photo-parser/image-size/types/tiff.js +92 -0
- package/src/photo-parser/image-size/types/utils.js +83 -0
- package/src/photo-parser/image-size/types/webp.js +67 -0
- package/src/photo-parser/index.js +181 -0
- package/src/report/annotations_report.js +446 -0
- package/src/report/index.js +2 -0
- package/src/report/map_util.js +81 -0
- package/src/report/pdf_creator.js +247 -0
- package/src/report/report.js +583 -0
- package/src/transform.js +204 -0
- package/src/util.js +371 -75
- package/CHANGELOG.md +0 -60
- /package/src/constants/{colors.js → dsm_colors.js} +0 -0
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import REGL
|
|
1
|
+
import REGL from 'regl'
|
|
2
2
|
import {
|
|
3
3
|
CLEAR_COLOR,
|
|
4
4
|
MAX_TEXTURE_DIMENSION,
|
|
5
5
|
EARTH_SUN_DISTANCE,
|
|
6
|
-
SUN_RADIUS
|
|
7
|
-
} from './constants'
|
|
6
|
+
SUN_RADIUS
|
|
7
|
+
} from './constants'
|
|
8
8
|
|
|
9
|
-
import TextureManager from './texture_manager'
|
|
10
|
-
import * as util from './util'
|
|
11
|
-
import { vec3 } from
|
|
12
|
-
import * as reglCommands from './reglCommands'
|
|
9
|
+
import TextureManager from './texture_manager'
|
|
10
|
+
import * as util from './util'
|
|
11
|
+
import { vec3 } from 'gl-matrix'
|
|
12
|
+
import * as reglCommands from './reglCommands'
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
export default class Renderer {
|
|
16
|
-
constructor(gloperations, tileSize, nodataValue, scaleInput, sentinelInput, colorscaleMaxLength, sentinelMaxLength) {
|
|
17
|
-
const canvas = document.createElement('canvas')
|
|
18
|
-
let maxTextureDimension = MAX_TEXTURE_DIMENSION
|
|
19
|
-
let normalTextureDimension = 1024
|
|
16
|
+
constructor (gloperations, tileSize, nodataValue, scaleInput, sentinelInput, colorscaleMaxLength, sentinelMaxLength) {
|
|
17
|
+
const canvas = document.createElement('canvas')
|
|
18
|
+
let maxTextureDimension = MAX_TEXTURE_DIMENSION
|
|
19
|
+
let normalTextureDimension = 1024
|
|
20
20
|
|
|
21
21
|
const regl = REGL({
|
|
22
22
|
canvas: canvas,
|
|
23
23
|
// profile: true,
|
|
24
24
|
// extension only used for advanced hillshading
|
|
25
25
|
// TODO: add fallback to rgba if writing to float fails
|
|
26
|
-
optionalExtensions: [
|
|
26
|
+
optionalExtensions: ['OES_texture_float', 'WEBGL_color_buffer_float'],
|
|
27
27
|
onDone: function (err, regl) {
|
|
28
28
|
if (err) {
|
|
29
|
-
console.
|
|
30
|
-
return
|
|
29
|
+
console.error(err)
|
|
30
|
+
return
|
|
31
31
|
} else {
|
|
32
32
|
// cannot use this directly as it seems to cause some issues
|
|
33
33
|
// maxTextureDimension = regl.limits.maxTextureSize;
|
|
34
34
|
if (regl.limits.maxTextureSize > 2048) {
|
|
35
|
-
maxTextureDimension = 2048
|
|
35
|
+
maxTextureDimension = 2048
|
|
36
36
|
}
|
|
37
37
|
if (regl.limits.maxTextureSize > 4096) {
|
|
38
|
-
maxTextureDimension = 4096
|
|
38
|
+
maxTextureDimension = 4096
|
|
39
39
|
}
|
|
40
40
|
if (regl.limits.maxTextureSize > 8192) {
|
|
41
|
-
maxTextureDimension = 8192
|
|
41
|
+
maxTextureDimension = 8192
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// TODO: use lower normal dimension where relevant
|
|
45
45
|
// Currently set to same due to a bug
|
|
46
|
-
normalTextureDimension = maxTextureDimension
|
|
46
|
+
normalTextureDimension = maxTextureDimension
|
|
47
47
|
}
|
|
48
48
|
// TODO: Improve software rendering detection
|
|
49
49
|
if (regl.limits.maxFragmentUniforms === 261) {
|
|
50
|
-
console.warn(
|
|
51
|
-
If you have a GPU, check if drivers are installed ok?
|
|
50
|
+
console.warn('Software rendering detected. Many features of this plugin will fail.\
|
|
51
|
+
If you have a GPU, check if drivers are installed ok?')
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
})
|
|
54
|
+
})
|
|
55
55
|
|
|
56
|
-
const commonDrawConfig = reglCommands.getCommonDrawConfiguration(tileSize, nodataValue)
|
|
56
|
+
const commonDrawConfig = reglCommands.getCommonDrawConfiguration(tileSize, nodataValue)
|
|
57
57
|
const fragMacros = {
|
|
58
58
|
SCALE_MAX_LENGTH: colorscaleMaxLength,
|
|
59
|
-
SENTINEL_MAX_LENGTH: sentinelMaxLength
|
|
60
|
-
}
|
|
59
|
+
SENTINEL_MAX_LENGTH: sentinelMaxLength
|
|
60
|
+
}
|
|
61
61
|
|
|
62
62
|
// Assign object "instance" properties.
|
|
63
63
|
Object.assign(this, {
|
|
@@ -74,27 +74,27 @@ export default class Renderer {
|
|
|
74
74
|
sentinelColormap: util.createColormapTexture(sentinelInput, regl),
|
|
75
75
|
textureManager: new TextureManager(regl, tileSize, normalTextureDimension, false),
|
|
76
76
|
drawTile: reglCommands.createDrawTileCommand(regl, commonDrawConfig, fragMacros)
|
|
77
|
-
})
|
|
77
|
+
})
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
renderTile({ coords, pixelData }, _hillshadeOptions, zoom) {
|
|
80
|
+
renderTile ({ coords, pixelData }, _hillshadeOptions, zoom) {
|
|
81
81
|
const {
|
|
82
82
|
regl,
|
|
83
83
|
textureManager,
|
|
84
|
-
tileSize
|
|
85
|
-
} = this
|
|
86
|
-
this.setCanvasSize(tileSize, tileSize)
|
|
84
|
+
tileSize
|
|
85
|
+
} = this
|
|
86
|
+
this.setCanvasSize(tileSize, tileSize)
|
|
87
87
|
// Add image to the texture and retrieve its texture coordinates.
|
|
88
|
-
const textureBounds = textureManager.addTile(coords, pixelData)
|
|
88
|
+
const textureBounds = textureManager.addTile(coords, pixelData)
|
|
89
89
|
|
|
90
|
-
regl.clear({ color: CLEAR_COLOR })
|
|
90
|
+
regl.clear({ color: CLEAR_COLOR })
|
|
91
91
|
|
|
92
|
-
const zoomdelta = _hillshadeOptions.hsSimpleZoomdelta || 0
|
|
92
|
+
const zoomdelta = _hillshadeOptions.hsSimpleZoomdelta || 0
|
|
93
93
|
|
|
94
|
-
const offset_pixels = Math.max(0.5, 2 ** (zoom + zoomdelta) / 2048)
|
|
95
|
-
const offset_texcoords = offset_pixels / textureManager.texture.width
|
|
94
|
+
const offset_pixels = Math.max(0.5, 2 ** (zoom + zoomdelta) / 2048)
|
|
95
|
+
const offset_texcoords = offset_pixels / textureManager.texture.width
|
|
96
96
|
|
|
97
|
-
if (_hillshadeOptions.hillshadeType ===
|
|
97
|
+
if (_hillshadeOptions.hillshadeType === 'none') {
|
|
98
98
|
this.drawTile({
|
|
99
99
|
canvasSize: [tileSize, tileSize],
|
|
100
100
|
canvasCoordinates: [0, 0],
|
|
@@ -104,9 +104,9 @@ export default class Renderer {
|
|
|
104
104
|
sentinelLength: this.sentinelInput.length,
|
|
105
105
|
scaleColormap: this.scaleColormap,
|
|
106
106
|
sentinelColormap: this.sentinelColormap,
|
|
107
|
-
enableSimpleHillshade: false
|
|
108
|
-
})
|
|
109
|
-
} else if (_hillshadeOptions.hillshadeType ===
|
|
107
|
+
enableSimpleHillshade: false
|
|
108
|
+
})
|
|
109
|
+
} else if (_hillshadeOptions.hillshadeType === 'simple') {
|
|
110
110
|
this.drawTileHsSimple({
|
|
111
111
|
scaleLength: this.scaleInput.length,
|
|
112
112
|
sentinelLength: this.sentinelInput.length,
|
|
@@ -123,29 +123,29 @@ export default class Renderer {
|
|
|
123
123
|
// elevationScale: _hillshadeOptions.hsElevationScale,
|
|
124
124
|
azimuth: _hillshadeOptions.hsSimpleAzimuth,
|
|
125
125
|
altitude: _hillshadeOptions.hsSimpleAltitude,
|
|
126
|
-
slopescale: _hillshadeOptions.hsSimpleSlopescale
|
|
127
|
-
})
|
|
126
|
+
slopescale: _hillshadeOptions.hsSimpleSlopescale
|
|
127
|
+
})
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Since the tile will fill the whole canvas, the offset is simply [0, 0].
|
|
131
|
-
return [0, 0]
|
|
131
|
+
return [0, 0]
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
setCanvasSize(width, height) {
|
|
135
|
-
Object.assign(this.canvas, { width, height })
|
|
134
|
+
setCanvasSize (width, height) {
|
|
135
|
+
Object.assign(this.canvas, { width, height })
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
generateAmbientDirections(iterations) {
|
|
139
|
-
const ambientDirections = []
|
|
138
|
+
generateAmbientDirections (iterations) {
|
|
139
|
+
const ambientDirections = []
|
|
140
140
|
for (let i = 0; i < iterations; i++) {
|
|
141
|
-
const direction = vec3.random(vec3.create(), Math.random())
|
|
142
|
-
ambientDirections.push(direction)
|
|
141
|
+
const direction = vec3.random(vec3.create(), Math.random())
|
|
142
|
+
ambientDirections.push(direction)
|
|
143
143
|
}
|
|
144
|
-
this.ambientDirections = ambientDirections
|
|
144
|
+
this.ambientDirections = ambientDirections
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
generateSunDirections(iterations, sunRadiusMultiplier) {
|
|
148
|
-
const sunDirections = []
|
|
147
|
+
generateSunDirections (iterations, sunRadiusMultiplier) {
|
|
148
|
+
const sunDirections = []
|
|
149
149
|
for (let i = 0; i < iterations; i++) {
|
|
150
150
|
const direction = vec3.normalize(
|
|
151
151
|
vec3.create(),
|
|
@@ -158,36 +158,36 @@ export default class Renderer {
|
|
|
158
158
|
),
|
|
159
159
|
vec3.random(vec3.create(), SUN_RADIUS * sunRadiusMultiplier)
|
|
160
160
|
)
|
|
161
|
-
)
|
|
162
|
-
sunDirections.push(direction)
|
|
161
|
+
)
|
|
162
|
+
sunDirections.push(direction)
|
|
163
163
|
}
|
|
164
|
-
this.sunDirections = sunDirections
|
|
164
|
+
this.sunDirections = sunDirections
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
updateColorscale(scaleInput) {
|
|
168
|
-
this.scaleInputPrevious = this.scaleInput
|
|
169
|
-
this.scaleInput = scaleInput
|
|
170
|
-
this.scaleColormapPrevious = this.scaleColormap
|
|
171
|
-
this.scaleColormap = util.createColormapTexture(scaleInput, this.regl)
|
|
167
|
+
updateColorscale (scaleInput) {
|
|
168
|
+
this.scaleInputPrevious = this.scaleInput
|
|
169
|
+
this.scaleInput = scaleInput
|
|
170
|
+
this.scaleColormapPrevious = this.scaleColormap
|
|
171
|
+
this.scaleColormap = util.createColormapTexture(scaleInput, this.regl)
|
|
172
172
|
}
|
|
173
|
-
updateSentinels(sentinelInput) {
|
|
174
|
-
this.sentinelInputPrevious = this.sentinelInput
|
|
175
|
-
this.sentinelInput = sentinelInput
|
|
176
|
-
this.sentinelColormapPrevious = this.sentinelColormap
|
|
177
|
-
this.sentinelColormap = util.createColormapTexture(sentinelInput, this.regl)
|
|
173
|
+
updateSentinels (sentinelInput) {
|
|
174
|
+
this.sentinelInputPrevious = this.sentinelInput
|
|
175
|
+
this.sentinelInput = sentinelInput
|
|
176
|
+
this.sentinelColormapPrevious = this.sentinelColormap
|
|
177
|
+
this.sentinelColormap = util.createColormapTexture(sentinelInput, this.regl)
|
|
178
178
|
}
|
|
179
|
-
setMaxTextureDimension(newMaxTextureDimension) {
|
|
179
|
+
setMaxTextureDimension (newMaxTextureDimension) {
|
|
180
180
|
const {
|
|
181
181
|
textureManager,
|
|
182
182
|
tileSize,
|
|
183
|
-
regl
|
|
184
|
-
} = this
|
|
183
|
+
regl
|
|
184
|
+
} = this
|
|
185
185
|
|
|
186
|
-
textureManager.destroy()
|
|
186
|
+
textureManager.destroy()
|
|
187
187
|
|
|
188
188
|
Object.assign(this, {
|
|
189
189
|
maxTextureDimension: newMaxTextureDimension,
|
|
190
|
-
textureManager: new TextureManager(regl, tileSize, newMaxTextureDimension, false)
|
|
191
|
-
})
|
|
190
|
+
textureManager: new TextureManager(regl, tileSize, newMaxTextureDimension, false)
|
|
191
|
+
})
|
|
192
192
|
}
|
|
193
193
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var fs = require('fs')
|
|
2
2
|
|
|
3
|
-
function transform(file) {
|
|
3
|
+
function transform (file) {
|
|
4
4
|
let extension = file.split('.').pop()
|
|
5
5
|
let content = fs.readFileSync(file, 'utf-8')
|
|
6
6
|
content = `import glsl from 'glslify'\n\nexport default glsl\`${content}\``
|
|
7
7
|
fs.writeFileSync(file.replace(`.${extension}`, '.js'), content)
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function readDir(dir) {
|
|
10
|
+
function readDir (dir) {
|
|
11
11
|
let list = fs.readdirSync(dir)
|
|
12
12
|
list.forEach(item => {
|
|
13
13
|
let stats = fs.statSync(`${dir}/${item}`)
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
// note: the 0.1s here and there are voodoo related to precision
|
|
4
4
|
float rgbaToFloat(vec4 v, bool littleEndian) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
if (!littleEndian) {
|
|
6
|
+
v = v.abgr;
|
|
7
|
+
}
|
|
8
|
+
vec4 bits = v * 255.0;
|
|
9
|
+
float sign = mix(-1.0, 1.0, step(bits[3], 128.0));
|
|
10
|
+
float expo = floor(mod(bits[3] + 0.1, 128.0)) * 2.0 +
|
|
11
|
+
floor((bits[2] + 0.1) / 128.0) - 127.0;
|
|
12
|
+
float sig = bits[0] +
|
|
13
|
+
bits[1] * 256.0 +
|
|
14
|
+
floor(mod(bits[2] + 0.1, 128.0)) * 256.0 * 256.0;
|
|
15
|
+
return sign * (1.0 + sig / 8388607.0) * pow(2.0, expo);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
#pragma glslify: export(rgbaToFloat)
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
flatMap,
|
|
3
|
-
isEmpty
|
|
4
|
-
} from 'lodash'
|
|
5
|
-
import * as util from './util'
|
|
3
|
+
isEmpty
|
|
4
|
+
} from 'lodash'
|
|
5
|
+
import * as util from './util'
|
|
6
6
|
|
|
7
7
|
export default class TextureManager {
|
|
8
|
-
constructor(
|
|
8
|
+
constructor (
|
|
9
9
|
regl,
|
|
10
10
|
tileSize = 256,
|
|
11
11
|
maxTextureDimension,
|
|
12
12
|
flipY = false,
|
|
13
13
|
textureFormat = 'rgba',
|
|
14
|
-
textureType = 'uint8'
|
|
14
|
+
textureType = 'uint8'
|
|
15
15
|
) {
|
|
16
|
-
const tilesAcross = Math.floor(maxTextureDimension / tileSize)
|
|
17
|
-
const pixelsAcross = tilesAcross * tileSize
|
|
18
|
-
const tileCapacity = tilesAcross * tilesAcross
|
|
16
|
+
const tilesAcross = Math.floor(maxTextureDimension / tileSize)
|
|
17
|
+
const pixelsAcross = tilesAcross * tileSize
|
|
18
|
+
const tileCapacity = tilesAcross * tilesAcross
|
|
19
19
|
|
|
20
20
|
const texture = regl.texture({
|
|
21
21
|
width: pixelsAcross,
|
|
22
22
|
height: pixelsAcross,
|
|
23
23
|
flipY: flipY,
|
|
24
24
|
format: textureFormat,
|
|
25
|
-
type: textureType
|
|
26
|
-
})
|
|
25
|
+
type: textureType
|
|
26
|
+
})
|
|
27
27
|
|
|
28
|
-
const contents = new Map()
|
|
29
|
-
const available = this.allTextureCoordinates(tilesAcross, tileSize)
|
|
28
|
+
const contents = new Map()
|
|
29
|
+
const available = this.allTextureCoordinates(tilesAcross, tileSize)
|
|
30
30
|
|
|
31
31
|
Object.assign(this, {
|
|
32
32
|
tileSize,
|
|
@@ -35,107 +35,107 @@ export default class TextureManager {
|
|
|
35
35
|
tileCapacity,
|
|
36
36
|
texture,
|
|
37
37
|
contents,
|
|
38
|
-
available
|
|
39
|
-
})
|
|
38
|
+
available
|
|
39
|
+
})
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
addTile(
|
|
42
|
+
addTile (
|
|
43
43
|
tileCoordinates,
|
|
44
|
-
data
|
|
44
|
+
data
|
|
45
45
|
) {
|
|
46
46
|
const {
|
|
47
47
|
available,
|
|
48
48
|
contents,
|
|
49
49
|
texture,
|
|
50
|
-
tileSize
|
|
51
|
-
} = this
|
|
50
|
+
tileSize
|
|
51
|
+
} = this
|
|
52
52
|
|
|
53
|
-
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
53
|
+
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
54
54
|
if (contents.has(hashKey)) {
|
|
55
|
-
const textureCoordinates = contents.get(hashKey)
|
|
55
|
+
const textureCoordinates = contents.get(hashKey)
|
|
56
56
|
// We use a least-recently-used eviction policy for the tile cache. Map iterators are
|
|
57
57
|
// convenient for this, because they return entries in insertion order. But for this to work
|
|
58
58
|
// as expected, every time we access a tile, we need to reinsert it so that it moves to the
|
|
59
59
|
// end of that insertion-order list.
|
|
60
|
-
contents.delete(hashKey)
|
|
61
|
-
contents.set(hashKey, textureCoordinates)
|
|
62
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
60
|
+
contents.delete(hashKey)
|
|
61
|
+
contents.set(hashKey, textureCoordinates)
|
|
62
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
63
63
|
}
|
|
64
64
|
if (isEmpty(available)) {
|
|
65
65
|
// Get the first key inserted. Map.prototype.keys() produces an iterable iterator over the keys
|
|
66
66
|
// in the order of insertion, so we can just use the iterator's first value.
|
|
67
|
-
const firstInsertedKey = contents.keys().next().value
|
|
68
|
-
this.removeByHashKey(firstInsertedKey)
|
|
67
|
+
const firstInsertedKey = contents.keys().next().value
|
|
68
|
+
this.removeByHashKey(firstInsertedKey)
|
|
69
69
|
}
|
|
70
70
|
// remove from list of available positions
|
|
71
|
-
const textureCoordinates = available.pop()
|
|
71
|
+
const textureCoordinates = available.pop()
|
|
72
72
|
// store mapping of tile to texture coordinates
|
|
73
|
-
contents.set(hashKey, textureCoordinates)
|
|
73
|
+
contents.set(hashKey, textureCoordinates)
|
|
74
74
|
|
|
75
|
-
const { x: textureX, y: textureY } = textureCoordinates
|
|
75
|
+
const { x: textureX, y: textureY } = textureCoordinates
|
|
76
76
|
texture.subimage({
|
|
77
77
|
data,
|
|
78
78
|
width: tileSize,
|
|
79
|
-
height: tileSize
|
|
80
|
-
}, textureX, textureY)
|
|
79
|
+
height: tileSize
|
|
80
|
+
}, textureX, textureY)
|
|
81
81
|
|
|
82
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
82
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
removeTile(tileCoordinates) {
|
|
86
|
-
this.removeByHashKey(this.hashTileCoordinates(tileCoordinates))
|
|
85
|
+
removeTile (tileCoordinates) {
|
|
86
|
+
this.removeByHashKey(this.hashTileCoordinates(tileCoordinates))
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
clearTiles() {
|
|
89
|
+
clearTiles () {
|
|
90
90
|
for (const hashKey of Array.from(this.contents.keys())) {
|
|
91
|
-
this.removeByHashKey(hashKey)
|
|
91
|
+
this.removeByHashKey(hashKey)
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
destroy() {
|
|
96
|
-
this.texture.destroy()
|
|
95
|
+
destroy () {
|
|
96
|
+
this.texture.destroy()
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
removeByHashKey(hashKey) {
|
|
99
|
+
removeByHashKey (hashKey) {
|
|
100
100
|
// This method only removes the key. The pixel data remains in the texture.
|
|
101
101
|
if (this.contents.has(hashKey)) {
|
|
102
|
-
const textureCoordinates = this.contents.get(hashKey)
|
|
103
|
-
this.contents.delete(hashKey)
|
|
104
|
-
this.available.push(textureCoordinates)
|
|
102
|
+
const textureCoordinates = this.contents.get(hashKey)
|
|
103
|
+
this.contents.delete(hashKey)
|
|
104
|
+
this.available.push(textureCoordinates)
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
formatOutputTextureCoordinates(textureCoordinates) {
|
|
109
|
-
const { x, y } = textureCoordinates
|
|
110
|
-
const { pixelsAcross, tileSize } = this
|
|
108
|
+
formatOutputTextureCoordinates (textureCoordinates) {
|
|
109
|
+
const { x, y } = textureCoordinates
|
|
110
|
+
const { pixelsAcross, tileSize } = this
|
|
111
111
|
return [
|
|
112
112
|
{
|
|
113
113
|
x: x / pixelsAcross,
|
|
114
|
-
y: y / pixelsAcross
|
|
114
|
+
y: y / pixelsAcross
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
117
|
x: (x + tileSize) / pixelsAcross,
|
|
118
|
-
y: (y + tileSize) / pixelsAcross
|
|
119
|
-
}
|
|
120
|
-
]
|
|
118
|
+
y: (y + tileSize) / pixelsAcross
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
hashTileCoordinates({ x, y, z }) {
|
|
124
|
-
return `${x}:${y}:${z}
|
|
123
|
+
hashTileCoordinates ({ x, y, z }) {
|
|
124
|
+
return `${x}:${y}:${z}`
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
getTextureCoordinates(tileCoordinates) {
|
|
128
|
-
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
129
|
-
const textureCoordinates = this.contents.get(hashKey)
|
|
130
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
127
|
+
getTextureCoordinates (tileCoordinates) {
|
|
128
|
+
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
129
|
+
const textureCoordinates = this.contents.get(hashKey)
|
|
130
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
allTextureCoordinates(tilesAcross, tileSize) {
|
|
133
|
+
allTextureCoordinates (tilesAcross, tileSize) {
|
|
134
134
|
return flatMap(util.range(tilesAcross), x =>
|
|
135
135
|
util.range(tilesAcross).map(y => ({
|
|
136
136
|
x: x * tileSize,
|
|
137
|
-
y: y * tileSize
|
|
138
|
-
}))
|
|
139
|
-
)
|
|
137
|
+
y: y * tileSize
|
|
138
|
+
}))
|
|
139
|
+
)
|
|
140
140
|
}
|
|
141
141
|
}
|