@mapcatch/util 2.0.5-b → 2.0.6
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 +4 -4
- package/dist/catchUtil.min.js +1 -1
- package/package.json +1 -21
- package/src/constants/crs.js +42098 -42098
- package/src/event/event.js +4 -5
- package/src/gl-operations/constants.js +9 -9
- package/src/gl-operations/default_options.js +97 -97
- package/src/gl-operations/index.js +532 -532
- package/src/gl-operations/reglCommands/contours.js +27 -27
- package/src/gl-operations/reglCommands/default.js +45 -45
- package/src/gl-operations/reglCommands/hillshading.js +340 -340
- package/src/gl-operations/reglCommands/index.js +6 -6
- package/src/gl-operations/reglCommands/multiLayers.js +303 -303
- package/src/gl-operations/reglCommands/transitions.js +111 -111
- package/src/gl-operations/reglCommands/util.js +71 -71
- package/src/gl-operations/renderer.js +209 -209
- package/src/gl-operations/shaders/fragment/convertDem.js +25 -25
- package/src/gl-operations/shaders/fragment/convolutionSmooth.js +54 -54
- package/src/gl-operations/shaders/fragment/diffCalc.js +33 -33
- package/src/gl-operations/shaders/fragment/drawResult.js +46 -46
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvAmbientShadows.js +78 -78
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvDirect.js +59 -59
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalBaselayer.js +30 -30
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvFinalColorscale.js +60 -60
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvMergeAndScaleTiles.js +26 -26
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvNormals.js +25 -25
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvSmooth.js +53 -53
- package/src/gl-operations/shaders/fragment/hillshading/hsAdvSoftShadows.js +80 -80
- package/src/gl-operations/shaders/fragment/hillshading/hsPregen.js +54 -54
- package/src/gl-operations/shaders/fragment/interpolateColor.js +65 -65
- package/src/gl-operations/shaders/fragment/interpolateColorOnly.js +49 -49
- package/src/gl-operations/shaders/fragment/interpolateValue.js +136 -136
- package/src/gl-operations/shaders/fragment/multiAnalyze1Calc.js +35 -35
- package/src/gl-operations/shaders/fragment/multiAnalyze2Calc.js +45 -45
- package/src/gl-operations/shaders/fragment/multiAnalyze3Calc.js +53 -53
- package/src/gl-operations/shaders/fragment/multiAnalyze4Calc.js +61 -61
- package/src/gl-operations/shaders/fragment/multiAnalyze5Calc.js +69 -69
- package/src/gl-operations/shaders/fragment/multiAnalyze6Calc.js +77 -77
- package/src/gl-operations/shaders/fragment/single.js +93 -93
- package/src/gl-operations/shaders/transform.js +21 -21
- package/src/gl-operations/shaders/util/computeColor.glsl +85 -85
- package/src/gl-operations/shaders/util/getTexelValue.glsl +10 -10
- package/src/gl-operations/shaders/util/isCloseEnough.glsl +9 -9
- package/src/gl-operations/shaders/util/rgbaToFloat.glsl +17 -17
- package/src/gl-operations/shaders/vertex/double.js +16 -16
- package/src/gl-operations/shaders/vertex/multi3.js +19 -19
- package/src/gl-operations/shaders/vertex/multi4.js +22 -22
- package/src/gl-operations/shaders/vertex/multi5.js +25 -25
- package/src/gl-operations/shaders/vertex/multi6.js +28 -28
- package/src/gl-operations/shaders/vertex/single.js +13 -13
- package/src/gl-operations/shaders/vertex/singleNotTransformed.js +11 -11
- package/src/gl-operations/texture_manager.js +141 -141
- package/src/gl-operations/util.js +336 -336
- package/README.md +0 -44
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flatMap,
|
|
3
|
-
isEmpty
|
|
4
|
-
} from 'lodash'
|
|
5
|
-
import * as util from './util'
|
|
6
|
-
|
|
7
|
-
export default class TextureManager {
|
|
8
|
-
constructor (
|
|
9
|
-
regl,
|
|
10
|
-
tileSize = 256,
|
|
11
|
-
maxTextureDimension,
|
|
12
|
-
flipY = false,
|
|
13
|
-
textureFormat = 'rgba',
|
|
14
|
-
textureType = 'uint8'
|
|
15
|
-
) {
|
|
16
|
-
const tilesAcross = Math.floor(maxTextureDimension / tileSize)
|
|
17
|
-
const pixelsAcross = tilesAcross * tileSize
|
|
18
|
-
const tileCapacity = tilesAcross * tilesAcross
|
|
19
|
-
|
|
20
|
-
const texture = regl.texture({
|
|
21
|
-
width: pixelsAcross,
|
|
22
|
-
height: pixelsAcross,
|
|
23
|
-
flipY: flipY,
|
|
24
|
-
format: textureFormat,
|
|
25
|
-
type: textureType
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const contents = new Map()
|
|
29
|
-
const available = this.allTextureCoordinates(tilesAcross, tileSize)
|
|
30
|
-
|
|
31
|
-
Object.assign(this, {
|
|
32
|
-
tileSize,
|
|
33
|
-
tilesAcross,
|
|
34
|
-
pixelsAcross,
|
|
35
|
-
tileCapacity,
|
|
36
|
-
texture,
|
|
37
|
-
contents,
|
|
38
|
-
available
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
addTile (
|
|
43
|
-
tileCoordinates,
|
|
44
|
-
data
|
|
45
|
-
) {
|
|
46
|
-
const {
|
|
47
|
-
available,
|
|
48
|
-
contents,
|
|
49
|
-
texture,
|
|
50
|
-
tileSize
|
|
51
|
-
} = this
|
|
52
|
-
|
|
53
|
-
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
54
|
-
if (contents.has(hashKey)) {
|
|
55
|
-
const textureCoordinates = contents.get(hashKey)
|
|
56
|
-
// We use a least-recently-used eviction policy for the tile cache. Map iterators are
|
|
57
|
-
// convenient for this, because they return entries in insertion order. But for this to work
|
|
58
|
-
// as expected, every time we access a tile, we need to reinsert it so that it moves to the
|
|
59
|
-
// end of that insertion-order list.
|
|
60
|
-
contents.delete(hashKey)
|
|
61
|
-
contents.set(hashKey, textureCoordinates)
|
|
62
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
63
|
-
}
|
|
64
|
-
if (isEmpty(available)) {
|
|
65
|
-
// Get the first key inserted. Map.prototype.keys() produces an iterable iterator over the keys
|
|
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)
|
|
69
|
-
}
|
|
70
|
-
// remove from list of available positions
|
|
71
|
-
const textureCoordinates = available.pop()
|
|
72
|
-
// store mapping of tile to texture coordinates
|
|
73
|
-
contents.set(hashKey, textureCoordinates)
|
|
74
|
-
|
|
75
|
-
const { x: textureX, y: textureY } = textureCoordinates
|
|
76
|
-
texture.subimage({
|
|
77
|
-
data,
|
|
78
|
-
width: tileSize,
|
|
79
|
-
height: tileSize
|
|
80
|
-
}, textureX, textureY)
|
|
81
|
-
|
|
82
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
removeTile (tileCoordinates) {
|
|
86
|
-
this.removeByHashKey(this.hashTileCoordinates(tileCoordinates))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
clearTiles () {
|
|
90
|
-
for (const hashKey of Array.from(this.contents.keys())) {
|
|
91
|
-
this.removeByHashKey(hashKey)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
destroy () {
|
|
96
|
-
this.texture.destroy()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
removeByHashKey (hashKey) {
|
|
100
|
-
// This method only removes the key. The pixel data remains in the texture.
|
|
101
|
-
if (this.contents.has(hashKey)) {
|
|
102
|
-
const textureCoordinates = this.contents.get(hashKey)
|
|
103
|
-
this.contents.delete(hashKey)
|
|
104
|
-
this.available.push(textureCoordinates)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
formatOutputTextureCoordinates (textureCoordinates) {
|
|
109
|
-
const { x, y } = textureCoordinates
|
|
110
|
-
const { pixelsAcross, tileSize } = this
|
|
111
|
-
return [
|
|
112
|
-
{
|
|
113
|
-
x: x / pixelsAcross,
|
|
114
|
-
y: y / pixelsAcross
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
x: (x + tileSize) / pixelsAcross,
|
|
118
|
-
y: (y + tileSize) / pixelsAcross
|
|
119
|
-
}
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
hashTileCoordinates ({ x, y, z }) {
|
|
124
|
-
return `${x}:${y}:${z}`
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
getTextureCoordinates (tileCoordinates) {
|
|
128
|
-
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
129
|
-
const textureCoordinates = this.contents.get(hashKey)
|
|
130
|
-
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
allTextureCoordinates (tilesAcross, tileSize) {
|
|
134
|
-
return flatMap(util.range(tilesAcross), x =>
|
|
135
|
-
util.range(tilesAcross).map(y => ({
|
|
136
|
-
x: x * tileSize,
|
|
137
|
-
y: y * tileSize
|
|
138
|
-
}))
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
flatMap,
|
|
3
|
+
isEmpty
|
|
4
|
+
} from 'lodash'
|
|
5
|
+
import * as util from './util'
|
|
6
|
+
|
|
7
|
+
export default class TextureManager {
|
|
8
|
+
constructor (
|
|
9
|
+
regl,
|
|
10
|
+
tileSize = 256,
|
|
11
|
+
maxTextureDimension,
|
|
12
|
+
flipY = false,
|
|
13
|
+
textureFormat = 'rgba',
|
|
14
|
+
textureType = 'uint8'
|
|
15
|
+
) {
|
|
16
|
+
const tilesAcross = Math.floor(maxTextureDimension / tileSize)
|
|
17
|
+
const pixelsAcross = tilesAcross * tileSize
|
|
18
|
+
const tileCapacity = tilesAcross * tilesAcross
|
|
19
|
+
|
|
20
|
+
const texture = regl.texture({
|
|
21
|
+
width: pixelsAcross,
|
|
22
|
+
height: pixelsAcross,
|
|
23
|
+
flipY: flipY,
|
|
24
|
+
format: textureFormat,
|
|
25
|
+
type: textureType
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const contents = new Map()
|
|
29
|
+
const available = this.allTextureCoordinates(tilesAcross, tileSize)
|
|
30
|
+
|
|
31
|
+
Object.assign(this, {
|
|
32
|
+
tileSize,
|
|
33
|
+
tilesAcross,
|
|
34
|
+
pixelsAcross,
|
|
35
|
+
tileCapacity,
|
|
36
|
+
texture,
|
|
37
|
+
contents,
|
|
38
|
+
available
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addTile (
|
|
43
|
+
tileCoordinates,
|
|
44
|
+
data
|
|
45
|
+
) {
|
|
46
|
+
const {
|
|
47
|
+
available,
|
|
48
|
+
contents,
|
|
49
|
+
texture,
|
|
50
|
+
tileSize
|
|
51
|
+
} = this
|
|
52
|
+
|
|
53
|
+
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
54
|
+
if (contents.has(hashKey)) {
|
|
55
|
+
const textureCoordinates = contents.get(hashKey)
|
|
56
|
+
// We use a least-recently-used eviction policy for the tile cache. Map iterators are
|
|
57
|
+
// convenient for this, because they return entries in insertion order. But for this to work
|
|
58
|
+
// as expected, every time we access a tile, we need to reinsert it so that it moves to the
|
|
59
|
+
// end of that insertion-order list.
|
|
60
|
+
contents.delete(hashKey)
|
|
61
|
+
contents.set(hashKey, textureCoordinates)
|
|
62
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
63
|
+
}
|
|
64
|
+
if (isEmpty(available)) {
|
|
65
|
+
// Get the first key inserted. Map.prototype.keys() produces an iterable iterator over the keys
|
|
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)
|
|
69
|
+
}
|
|
70
|
+
// remove from list of available positions
|
|
71
|
+
const textureCoordinates = available.pop()
|
|
72
|
+
// store mapping of tile to texture coordinates
|
|
73
|
+
contents.set(hashKey, textureCoordinates)
|
|
74
|
+
|
|
75
|
+
const { x: textureX, y: textureY } = textureCoordinates
|
|
76
|
+
texture.subimage({
|
|
77
|
+
data,
|
|
78
|
+
width: tileSize,
|
|
79
|
+
height: tileSize
|
|
80
|
+
}, textureX, textureY)
|
|
81
|
+
|
|
82
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
removeTile (tileCoordinates) {
|
|
86
|
+
this.removeByHashKey(this.hashTileCoordinates(tileCoordinates))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
clearTiles () {
|
|
90
|
+
for (const hashKey of Array.from(this.contents.keys())) {
|
|
91
|
+
this.removeByHashKey(hashKey)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
destroy () {
|
|
96
|
+
this.texture.destroy()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
removeByHashKey (hashKey) {
|
|
100
|
+
// This method only removes the key. The pixel data remains in the texture.
|
|
101
|
+
if (this.contents.has(hashKey)) {
|
|
102
|
+
const textureCoordinates = this.contents.get(hashKey)
|
|
103
|
+
this.contents.delete(hashKey)
|
|
104
|
+
this.available.push(textureCoordinates)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
formatOutputTextureCoordinates (textureCoordinates) {
|
|
109
|
+
const { x, y } = textureCoordinates
|
|
110
|
+
const { pixelsAcross, tileSize } = this
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
x: x / pixelsAcross,
|
|
114
|
+
y: y / pixelsAcross
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
x: (x + tileSize) / pixelsAcross,
|
|
118
|
+
y: (y + tileSize) / pixelsAcross
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
hashTileCoordinates ({ x, y, z }) {
|
|
124
|
+
return `${x}:${y}:${z}`
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getTextureCoordinates (tileCoordinates) {
|
|
128
|
+
const hashKey = this.hashTileCoordinates(tileCoordinates)
|
|
129
|
+
const textureCoordinates = this.contents.get(hashKey)
|
|
130
|
+
return this.formatOutputTextureCoordinates(textureCoordinates)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
allTextureCoordinates (tilesAcross, tileSize) {
|
|
134
|
+
return flatMap(util.range(tilesAcross), x =>
|
|
135
|
+
util.range(tilesAcross).map(y => ({
|
|
136
|
+
x: x * tileSize,
|
|
137
|
+
y: y * tileSize
|
|
138
|
+
}))
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
}
|