@mapwhit/tilerenderer 0.52.0 → 1.0.0
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/README.md +7 -0
- package/build/min/package.json +1 -1
- package/build/min/src/shaders/_prelude.fragment.glsl.js +2 -2
- package/build/min/src/shaders/_prelude.vertex.glsl.js +2 -2
- package/build/min/src/shaders/background.fragment.glsl.js +2 -2
- package/build/min/src/shaders/background.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/circle.fragment.glsl.js +2 -2
- package/build/min/src/shaders/circle.vertex.glsl.js +2 -2
- package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
- package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
- package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
- package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/fill_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/fill_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/heatmap.fragment.glsl.js +2 -2
- package/build/min/src/shaders/heatmap.vertex.glsl.js +2 -2
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +2 -2
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.fragment.glsl.js +2 -2
- package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +2 -2
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_gradient.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_gradient.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_pattern.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_pattern.vertex.glsl.js +2 -2
- package/build/min/src/shaders/line_sdf.fragment.glsl.js +2 -2
- package/build/min/src/shaders/line_sdf.vertex.glsl.js +2 -2
- package/build/min/src/shaders/raster.fragment.glsl.js +2 -2
- package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.fragment.glsl.js +2 -2
- package/build/min/src/shaders/symbol_icon.vertex.glsl.js +2 -2
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +2 -2
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +2 -2
- package/package.json +3 -3
- package/src/data/array_types.js +1 -36
- package/src/data/bucket/circle_bucket.js +8 -5
- package/src/data/bucket/fill_bucket.js +8 -5
- package/src/data/bucket/fill_extrusion_bucket.js +8 -5
- package/src/data/bucket/heatmap_bucket.js +0 -4
- package/src/data/bucket/line_bucket.js +9 -6
- package/src/data/bucket/pattern_bucket_features.js +2 -2
- package/src/data/bucket/symbol_bucket.js +99 -129
- package/src/data/bucket.js +26 -21
- package/src/data/dem_data.js +0 -3
- package/src/data/feature_index.js +3 -8
- package/src/data/program_configuration.js +24 -33
- package/src/data/segment.js +0 -4
- package/src/render/draw_background.js +3 -3
- package/src/render/draw_circle.js +4 -4
- package/src/render/draw_fill.js +8 -8
- package/src/render/draw_fill_extrusion.js +8 -8
- package/src/render/draw_heatmap.js +4 -4
- package/src/render/draw_line.js +6 -6
- package/src/render/draw_raster.js +6 -6
- package/src/render/draw_symbol.js +16 -16
- package/src/render/glyph_atlas.js +0 -3
- package/src/render/glyph_manager.js +1 -2
- package/src/render/image_atlas.js +0 -4
- package/src/render/image_manager.js +33 -19
- package/src/render/painter.js +13 -14
- package/src/render/program/circle_program.js +4 -4
- package/src/render/program/fill_extrusion_program.js +1 -1
- package/src/render/program/heatmap_program.js +1 -1
- package/src/render/program/hillshade_program.js +6 -6
- package/src/render/program/line_program.js +3 -3
- package/src/render/program/raster_program.js +6 -6
- package/src/source/geojson_source.js +15 -24
- package/src/source/geojson_worker_source.js +40 -68
- package/src/source/geojson_wrapper.js +9 -1
- package/src/source/image_source.js +6 -16
- package/src/source/query_features.js +4 -5
- package/src/source/raster_dem_tile_source.js +45 -64
- package/src/source/raster_tile_source.js +1 -6
- package/src/source/resources/glyphs.js +2 -2
- package/src/source/resources/index.js +3 -9
- package/src/source/rtl_text_plugin.js +58 -31
- package/src/source/source.js +11 -13
- package/src/source/source_cache.js +135 -151
- package/src/source/source_state.js +101 -12
- package/src/source/tile.js +32 -46
- package/src/source/tile_bounds.js +26 -26
- package/src/source/tile_id.js +2 -5
- package/src/source/vector_tile_source.js +14 -14
- package/src/source/vector_tile_worker_source.js +19 -23
- package/src/source/worker_tile.js +122 -119
- package/src/style/create_style_layer.js +1 -1
- package/src/style/pauseable_placement.js +4 -5
- package/src/style/properties.js +1 -8
- package/src/style/query_utils.js +3 -3
- package/src/style/style.js +286 -216
- package/src/style/style_layer/circle_style_layer.js +13 -11
- package/src/style/style_layer/fill_extrusion_style_layer.js +42 -27
- package/src/style/style_layer/fill_style_layer.js +5 -5
- package/src/style/style_layer/heatmap_style_layer.js +1 -1
- package/src/style/style_layer/hillshade_style_layer.js +1 -1
- package/src/style/style_layer/line_style_layer.js +23 -19
- package/src/style/style_layer/symbol_style_layer.js +13 -13
- package/src/style/style_layer.js +71 -30
- package/src/style/style_layer_index.js +16 -41
- package/src/symbol/anchor.js +0 -4
- package/src/symbol/cross_tile_symbol_index.js +2 -5
- package/src/symbol/opacity_state.js +0 -4
- package/src/symbol/placement.js +3 -3
- package/src/symbol/quads.js +4 -4
- package/src/symbol/symbol_layout.js +7 -7
- package/src/symbol/transform_text.js +1 -1
- package/src/ui/map.js +52 -15
- package/src/util/group_layers.js +41 -0
- package/src/util/image.js +0 -5
- package/src/util/key.js +21 -0
- package/src/util/object.js +8 -53
- package/src/worker.js +1 -4
- package/src/source/resources/images.js +0 -68
- package/src/source/worker.js +0 -110
- package/src/source/worker_source.js +0 -14
- package/src/style-spec/deref.js +0 -51
- package/src/style-spec/group_by_layout.js +0 -46
- package/src/util/actor.js +0 -108
- package/src/util/dispatcher.js +0 -65
- package/src/util/global_worker_pool.js +0 -15
- package/src/util/transfer_registry.js +0 -168
- package/src/util/web_worker_transfer.js +0 -43
- package/src/util/worker_pool.js +0 -41
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const refProperties = require('./util/ref_properties');
|
|
2
|
-
|
|
3
|
-
function stringify(obj) {
|
|
4
|
-
if (obj == null) return 'null';
|
|
5
|
-
const type = typeof obj;
|
|
6
|
-
if (type === 'number' || type === 'boolean' || type === 'string') return obj;
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(obj)) {
|
|
9
|
-
return '[' + obj.map(val => stringify(val)).join(',') + ']';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const keys = Object.keys(obj).sort();
|
|
13
|
-
return '{' + keys.map(key => `${key}:${stringify(obj[key])}`).join(',') + '}';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getKey(layer) {
|
|
17
|
-
return refProperties.map(k => stringify(layer[k])).join('/');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = groupByLayout;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Given an array of layers, return an array of arrays of layers where all
|
|
24
|
-
* layers in each group have identical layout-affecting properties. These
|
|
25
|
-
* are the properties that were formerly used by explicit `ref` mechanism
|
|
26
|
-
* for layers: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom',
|
|
27
|
-
* 'filter', and 'layout'.
|
|
28
|
-
*
|
|
29
|
-
* The input is not modified. The output layers are references to the
|
|
30
|
-
* input layers.
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @param {Array<Layer>} layers
|
|
34
|
-
* @returns {Array<Array<Layer>>}
|
|
35
|
-
*/
|
|
36
|
-
function groupByLayout(layers) {
|
|
37
|
-
const groups = {};
|
|
38
|
-
|
|
39
|
-
for (const l of layers) {
|
|
40
|
-
const k = getKey(l);
|
|
41
|
-
const group = (groups[k] ??= []);
|
|
42
|
-
group.push(l);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return Object.values(groups);
|
|
46
|
-
}
|
package/src/util/actor.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const { serialize, deserialize } = require('./web_worker_transfer');
|
|
2
|
-
|
|
3
|
-
module.exports = actor;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An implementation of the [Actor design pattern](http://en.wikipedia.org/wiki/Actor_model)
|
|
7
|
-
* that maintains the relationship between asynchronous tasks and the objects
|
|
8
|
-
* that spin them off - in this case, tasks like parsing parts of styles,
|
|
9
|
-
* owned by the styles
|
|
10
|
-
*
|
|
11
|
-
* @param {WebWorker} target
|
|
12
|
-
* @param {WebWorker} parent
|
|
13
|
-
* @param {string|number} mapId A unique identifier for the Map instance using this Actor.
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function actor(target, parent, mapId, name) {
|
|
18
|
-
const promises = new Map();
|
|
19
|
-
let callbackID = Number.MIN_SAFE_INTEGER;
|
|
20
|
-
target.addEventListener('message', receive, false);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
send,
|
|
24
|
-
receive,
|
|
25
|
-
remove,
|
|
26
|
-
name
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Sends a message from a main-thread map to a Worker or from a Worker back to
|
|
31
|
-
* a main-thread map instance.
|
|
32
|
-
*
|
|
33
|
-
* @param type The name of the target method to invoke or '[source-type].[source-name].name' for a method on a WorkerSource.
|
|
34
|
-
* @param targetMapId A particular mapId to which to send this message.
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
function send(type, data, targetMapId) {
|
|
38
|
-
const id = `${mapId}:${callbackID++}`;
|
|
39
|
-
const p = Promise.withResolvers();
|
|
40
|
-
promises.set(id, p);
|
|
41
|
-
postMessage(targetMapId, id, type, data);
|
|
42
|
-
return p.promise;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function receive(message) {
|
|
46
|
-
const { data } = message;
|
|
47
|
-
const { id, type, targetMapId } = data;
|
|
48
|
-
|
|
49
|
-
if (targetMapId && mapId !== targetMapId) return;
|
|
50
|
-
|
|
51
|
-
if (type === '<response>') {
|
|
52
|
-
const p = promises.get(id);
|
|
53
|
-
if (p) {
|
|
54
|
-
promises.delete(id);
|
|
55
|
-
if (data.error) {
|
|
56
|
-
p.reject(deserialize(data.error));
|
|
57
|
-
} else {
|
|
58
|
-
p.resolve(deserialize(data.data));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (typeof id !== 'undefined') {
|
|
65
|
-
let perform;
|
|
66
|
-
if (parent[type]) {
|
|
67
|
-
// data.type == 'loadTile' etc.
|
|
68
|
-
perform = () => parent[type](data.sourceMapId, deserialize(data.data));
|
|
69
|
-
} else if (parent.getWorkerSource) {
|
|
70
|
-
// data.type == sourcetype.method
|
|
71
|
-
const [sourcetype, method] = type.split('.');
|
|
72
|
-
const params = deserialize(data.data);
|
|
73
|
-
const workerSource = parent.getWorkerSource(data.sourceMapId, sourcetype, params.source);
|
|
74
|
-
perform = () => workerSource[method](params);
|
|
75
|
-
} else {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
const result = await perform();
|
|
80
|
-
postMessage(data.sourceMapId, id, '<response>', result);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
postMessage(data.sourceMapId, id, '<response>', undefined, err);
|
|
83
|
-
}
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
parent[type](deserialize(data.data));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function remove() {
|
|
91
|
-
target.removeEventListener('message', receive, false);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function postMessage(targetMapId, id, type, data, err) {
|
|
95
|
-
const buffers = [];
|
|
96
|
-
const payload = {
|
|
97
|
-
targetMapId,
|
|
98
|
-
sourceMapId: mapId,
|
|
99
|
-
type,
|
|
100
|
-
id,
|
|
101
|
-
data: serialize(data, buffers)
|
|
102
|
-
};
|
|
103
|
-
if (err) {
|
|
104
|
-
payload.error = serialize(err);
|
|
105
|
-
}
|
|
106
|
-
target.postMessage(payload, buffers);
|
|
107
|
-
}
|
|
108
|
-
}
|
package/src/util/dispatcher.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const uniqueId = require('./unique_id');
|
|
2
|
-
const actor = require('./actor');
|
|
3
|
-
|
|
4
|
-
module.exports = dispatcher;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Responsible for sending messages from a {@link Source} to an associated
|
|
8
|
-
* {@link WorkerSource}.
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
function dispatcher(workerPool, parent, makeActor = actor) {
|
|
13
|
-
// exposed to allow stubbing in unit tests
|
|
14
|
-
|
|
15
|
-
let currentActor = -1;
|
|
16
|
-
const id = uniqueId();
|
|
17
|
-
const workers = workerPool.acquire(id);
|
|
18
|
-
const actors = workers.map((worker, i) => makeActor(worker, parent, id, `Worker ${i}`));
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Broadcast a message to all Workers.
|
|
22
|
-
*/
|
|
23
|
-
function broadcast(type, data) {
|
|
24
|
-
const tasks = actors.map(actor => actor.send(type, data));
|
|
25
|
-
return Promise.all(tasks);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Use round robin to send requests to web workers.
|
|
29
|
-
function nextActorId() {
|
|
30
|
-
currentActor += 1;
|
|
31
|
-
if (currentActor === actors.length) {
|
|
32
|
-
currentActor = 0;
|
|
33
|
-
}
|
|
34
|
-
return currentActor;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Send a message to a Worker.
|
|
39
|
-
* @param targetID The ID of the Worker to which to send this message. Omit to allow the dispatcher to choose.
|
|
40
|
-
* @returns The ID of the worker to which the message was sent.
|
|
41
|
-
*/
|
|
42
|
-
function send(type, data, targetID = nextActorId()) {
|
|
43
|
-
return actors[targetID]?.send(type, data) ?? Promise.resolve();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function remove() {
|
|
47
|
-
actors.forEach(actor => actor.remove());
|
|
48
|
-
actors.length = 0;
|
|
49
|
-
workerPool.release(id);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function nextWorkerId(workerId = nextActorId()) {
|
|
53
|
-
return workerId;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
get id() {
|
|
58
|
-
return id;
|
|
59
|
-
},
|
|
60
|
-
broadcast,
|
|
61
|
-
send,
|
|
62
|
-
nextWorkerId,
|
|
63
|
-
remove
|
|
64
|
-
};
|
|
65
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const workerPool = require('./worker_pool');
|
|
2
|
-
|
|
3
|
-
let globalWorkerPool;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates (if necessary) and returns the single, global WorkerPool instance
|
|
7
|
-
* to be shared across each Map
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
module.exports = function getGlobalWorkerPool() {
|
|
11
|
-
if (!globalWorkerPool) {
|
|
12
|
-
globalWorkerPool = workerPool();
|
|
13
|
-
}
|
|
14
|
-
return globalWorkerPool;
|
|
15
|
-
};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
register,
|
|
5
|
-
serialize,
|
|
6
|
-
deserialize
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const registry = new Map();
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Register the given class as serializable.
|
|
13
|
-
*
|
|
14
|
-
* @param options
|
|
15
|
-
* @param options.omit List of properties to omit from serialization (e.g., cached/computed properties)
|
|
16
|
-
* @param options.shallow List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
function register(name, klass, { omit, shallow } = {}) {
|
|
21
|
-
assert(!registry.has(name), `${name} is already registered.`);
|
|
22
|
-
Object.defineProperty(klass, '_classRegistryKey', {
|
|
23
|
-
value: name,
|
|
24
|
-
writeable: false
|
|
25
|
-
});
|
|
26
|
-
registry.set(name, { klass, omit, shallow });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
register('Object', Object);
|
|
30
|
-
register('Set', Set);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Serialize the given object for transfer to or from a web worker.
|
|
34
|
-
*
|
|
35
|
-
* For non-builtin types, recursively serialize each property (possibly
|
|
36
|
-
* omitting certain properties - see register()), and package the result along
|
|
37
|
-
* with the constructor's `name` so that the appropriate constructor can be
|
|
38
|
-
* looked up in `deserialize()`.
|
|
39
|
-
*
|
|
40
|
-
* If a `transferables` array is provided, add any transferable objects (i.e.,
|
|
41
|
-
* any ArrayBuffers or ArrayBuffer views) to the list. (If a copy is needed,
|
|
42
|
-
* this should happen in the client code, before using serialize().)
|
|
43
|
-
*
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
function serialize(input, transferables) {
|
|
47
|
-
if (isSerializablePrimitive(input)) {
|
|
48
|
-
return input;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (input instanceof ArrayBuffer) {
|
|
52
|
-
transferables?.push(input);
|
|
53
|
-
return input;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (ArrayBuffer.isView(input)) {
|
|
57
|
-
transferables?.push(input.buffer);
|
|
58
|
-
return input;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (input instanceof ImageData) {
|
|
62
|
-
transferables?.push(input.data.buffer);
|
|
63
|
-
return input;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (Array.isArray(input)) {
|
|
67
|
-
return input.map(item => serialize(item, transferables));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (typeof input === 'object') {
|
|
71
|
-
const klass = input.constructor;
|
|
72
|
-
const name = klass._classRegistryKey;
|
|
73
|
-
if (!name) {
|
|
74
|
-
throw new Error(`can't serialize object of unregistered class`);
|
|
75
|
-
}
|
|
76
|
-
assert(registry.has(name));
|
|
77
|
-
|
|
78
|
-
// (Temporary workaround) allow a class to provide static
|
|
79
|
-
// `serialize()` and `deserialize()` methods to bypass the generic
|
|
80
|
-
// approach.
|
|
81
|
-
// This temporary workaround lets us use the generic serialization
|
|
82
|
-
// approach for objects whose members include instances of dynamic
|
|
83
|
-
// StructArray types. Once we refactor StructArray to be static,
|
|
84
|
-
// we can remove this complexity.
|
|
85
|
-
const properties = klass.serialize ? klass.serialize(input, transferables) : {};
|
|
86
|
-
|
|
87
|
-
if (!klass.serialize) {
|
|
88
|
-
const { omit, shallow } = registry.get(name);
|
|
89
|
-
for (const key in input) {
|
|
90
|
-
if (!Object.hasOwn(input, key)) continue;
|
|
91
|
-
if (omit?.includes(key)) continue;
|
|
92
|
-
const value = input[key];
|
|
93
|
-
properties[key] = shallow?.includes(key) ? value : serialize(value, transferables);
|
|
94
|
-
}
|
|
95
|
-
if (input instanceof Error) {
|
|
96
|
-
properties.message = input.message;
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// make sure statically serialized object survives transfer of $name property
|
|
100
|
-
assert(!transferables || properties !== transferables[transferables.length - 1]);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (properties.$name) {
|
|
104
|
-
throw new Error('$name property is reserved for worker serialization logic.');
|
|
105
|
-
}
|
|
106
|
-
if (name !== 'Object') {
|
|
107
|
-
properties.$name = name;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return properties;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
throw new Error(`can't serialize object of type ${typeof input}`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function deserialize(input) {
|
|
117
|
-
if (
|
|
118
|
-
isSerializablePrimitive(input) ||
|
|
119
|
-
input instanceof ArrayBuffer ||
|
|
120
|
-
ArrayBuffer.isView(input) ||
|
|
121
|
-
input instanceof ImageData
|
|
122
|
-
) {
|
|
123
|
-
return input;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (Array.isArray(input)) {
|
|
127
|
-
return input.map(deserialize);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (typeof input === 'object') {
|
|
131
|
-
const name = input.$name ?? 'Object';
|
|
132
|
-
|
|
133
|
-
const { klass, shallow } = registry.get(name);
|
|
134
|
-
if (!klass) {
|
|
135
|
-
throw new Error(`can't deserialize unregistered class ${name}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (klass.deserialize) {
|
|
139
|
-
return klass.deserialize(input);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const result = Object.create(klass.prototype);
|
|
143
|
-
|
|
144
|
-
for (const key of Object.keys(input)) {
|
|
145
|
-
if (key === '$name') continue;
|
|
146
|
-
const value = input[key];
|
|
147
|
-
result[key] = shallow?.includes(key) ? value : deserialize(value);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return result;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
throw new Error(`can't deserialize object of type ${typeof input}`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function isSerializablePrimitive(input) {
|
|
157
|
-
return (
|
|
158
|
-
input == null ||
|
|
159
|
-
typeof input === 'boolean' ||
|
|
160
|
-
typeof input === 'number' ||
|
|
161
|
-
typeof input === 'string' ||
|
|
162
|
-
input instanceof Date ||
|
|
163
|
-
input instanceof RegExp ||
|
|
164
|
-
input instanceof Boolean ||
|
|
165
|
-
input instanceof Number ||
|
|
166
|
-
input instanceof String
|
|
167
|
-
);
|
|
168
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const Grid = require('grid-index');
|
|
2
|
-
const { Color } = require('@mapwhit/style-expressions');
|
|
3
|
-
const {
|
|
4
|
-
CompoundExpression,
|
|
5
|
-
definitions: expressions,
|
|
6
|
-
StylePropertyFunction,
|
|
7
|
-
StyleExpression,
|
|
8
|
-
ZoomDependentExpression,
|
|
9
|
-
ZoomConstantExpression
|
|
10
|
-
} = require('@mapwhit/style-expressions');
|
|
11
|
-
|
|
12
|
-
const { register, serialize, deserialize } = require('./transfer_registry');
|
|
13
|
-
module.exports = {
|
|
14
|
-
serialize,
|
|
15
|
-
deserialize
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Grid.serialize = function serializeGrid(grid, transferables) {
|
|
19
|
-
const buffer = grid.toArrayBuffer();
|
|
20
|
-
if (transferables) {
|
|
21
|
-
transferables.push(buffer);
|
|
22
|
-
}
|
|
23
|
-
return { buffer };
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
Grid.deserialize = function deserializeGrid(serialized) {
|
|
27
|
-
return new Grid(serialized.buffer);
|
|
28
|
-
};
|
|
29
|
-
register('Grid', Grid);
|
|
30
|
-
|
|
31
|
-
register('Color', Color);
|
|
32
|
-
register('Error', Error);
|
|
33
|
-
|
|
34
|
-
register('StylePropertyFunction', StylePropertyFunction);
|
|
35
|
-
register('StyleExpression', StyleExpression, { omit: ['_evaluator'] });
|
|
36
|
-
|
|
37
|
-
register('ZoomDependentExpression', ZoomDependentExpression);
|
|
38
|
-
register('ZoomConstantExpression', ZoomConstantExpression);
|
|
39
|
-
register('CompoundExpression', CompoundExpression, { omit: ['_evaluate'] });
|
|
40
|
-
for (const name in expressions) {
|
|
41
|
-
if (expressions[name]._classRegistryKey) continue;
|
|
42
|
-
register(`Expression_${name}`, expressions[name]);
|
|
43
|
-
}
|
package/src/util/worker_pool.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const WebWorker = require('./web_worker');
|
|
3
|
-
const config = require('./config');
|
|
4
|
-
|
|
5
|
-
module.exports = workerPool;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Constructs a worker pool.
|
|
9
|
-
* @private
|
|
10
|
-
*/
|
|
11
|
-
function workerPool(workerCount = config.WORKER_COUNT) {
|
|
12
|
-
const active = {};
|
|
13
|
-
let workers;
|
|
14
|
-
|
|
15
|
-
function acquire(mapId) {
|
|
16
|
-
if (!workers) {
|
|
17
|
-
assert(typeof workerCount === 'number' && workerCount < Number.POSITIVE_INFINITY);
|
|
18
|
-
|
|
19
|
-
workers = new Array(workerCount);
|
|
20
|
-
for (let i = 0; i < workerCount; i++) {
|
|
21
|
-
workers[i] = new WebWorker();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
active[mapId] = true;
|
|
26
|
-
return workers.slice();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function release(mapId) {
|
|
30
|
-
delete active[mapId];
|
|
31
|
-
if (Object.keys(active).length === 0) {
|
|
32
|
-
workers.forEach(w => w.terminate());
|
|
33
|
-
workers = undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
acquire,
|
|
39
|
-
release
|
|
40
|
-
};
|
|
41
|
-
}
|