maplibre-gl-layers 0.5.0 → 0.6.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/dist/SpriteLayer.d.ts +2 -2
- package/dist/easing.d.ts +2 -2
- package/dist/index.cjs +168 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +168 -12
- package/dist/index.mjs.map +1 -1
- package/dist/interpolation.d.ts +2 -2
- package/dist/location.d.ts +2 -2
- package/dist/math.d.ts +2 -2
- package/dist/numericInterpolation.d.ts +2 -2
- package/dist/rotationInterpolation.d.ts +2 -2
- package/dist/types.d.ts +35 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.6.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 481f544de02fd3e71a2ba6c28bbb7eeb98b49eff
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export * from './types.ts';
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.6.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 481f544de02fd3e71a2ba6c28bbb7eeb98b49eff
|
|
9
9
|
*/
|
|
10
10
|
const UNLIMITED_SPRITE_SCALING_OPTIONS = {
|
|
11
11
|
metersPerPixel: 1,
|
|
@@ -25,6 +25,18 @@ const STANDARD_SPRITE_SCALING_OPTIONS = {
|
|
|
25
25
|
spriteMinPixel: 24,
|
|
26
26
|
spriteMaxPixel: 100
|
|
27
27
|
};
|
|
28
|
+
const DEFAULT_TEXTURE_FILTERING_OPTIONS = {
|
|
29
|
+
minFilter: "linear",
|
|
30
|
+
magFilter: "linear",
|
|
31
|
+
generateMipmaps: false,
|
|
32
|
+
maxAnisotropy: 1
|
|
33
|
+
};
|
|
34
|
+
const BETTER_TEXTURE_FILTERING_OPTIONS = {
|
|
35
|
+
minFilter: "linear-mipmap-linear",
|
|
36
|
+
magFilter: "linear",
|
|
37
|
+
generateMipmaps: true,
|
|
38
|
+
maxAnisotropy: 8
|
|
39
|
+
};
|
|
28
40
|
var maplibreGl$1 = { exports: {} };
|
|
29
41
|
/**
|
|
30
42
|
* MapLibre GL JS
|
|
@@ -22002,6 +22014,91 @@ const MIN_CLIP_Z_EPSILON = 1e-7;
|
|
|
22002
22014
|
const EPS_NDC = 1e-6;
|
|
22003
22015
|
const ORDER_MAX = 16;
|
|
22004
22016
|
const ORDER_BUCKET = 16;
|
|
22017
|
+
const MIN_FILTER_VALUES = [
|
|
22018
|
+
"nearest",
|
|
22019
|
+
"linear",
|
|
22020
|
+
"nearest-mipmap-nearest",
|
|
22021
|
+
"nearest-mipmap-linear",
|
|
22022
|
+
"linear-mipmap-nearest",
|
|
22023
|
+
"linear-mipmap-linear"
|
|
22024
|
+
];
|
|
22025
|
+
const MAG_FILTER_VALUES = [
|
|
22026
|
+
"nearest",
|
|
22027
|
+
"linear"
|
|
22028
|
+
];
|
|
22029
|
+
const MIPMAP_MIN_FILTERS = /* @__PURE__ */ new Set([
|
|
22030
|
+
"nearest-mipmap-nearest",
|
|
22031
|
+
"nearest-mipmap-linear",
|
|
22032
|
+
"linear-mipmap-nearest",
|
|
22033
|
+
"linear-mipmap-linear"
|
|
22034
|
+
]);
|
|
22035
|
+
const filterRequiresMipmaps = (filter) => MIPMAP_MIN_FILTERS.has(filter);
|
|
22036
|
+
const resolveTextureFilteringOptions = (options) => {
|
|
22037
|
+
var _a, _b;
|
|
22038
|
+
const minCandidate = options == null ? void 0 : options.minFilter;
|
|
22039
|
+
const minFilter = MIN_FILTER_VALUES.includes(
|
|
22040
|
+
minCandidate
|
|
22041
|
+
) ? minCandidate : DEFAULT_TEXTURE_FILTERING_OPTIONS.minFilter;
|
|
22042
|
+
const magCandidate = options == null ? void 0 : options.magFilter;
|
|
22043
|
+
const magFilter = MAG_FILTER_VALUES.includes(
|
|
22044
|
+
magCandidate
|
|
22045
|
+
) ? magCandidate : DEFAULT_TEXTURE_FILTERING_OPTIONS.magFilter;
|
|
22046
|
+
let generateMipmaps = (_a = options == null ? void 0 : options.generateMipmaps) != null ? _a : DEFAULT_TEXTURE_FILTERING_OPTIONS.generateMipmaps;
|
|
22047
|
+
if (filterRequiresMipmaps(minFilter)) {
|
|
22048
|
+
generateMipmaps = true;
|
|
22049
|
+
}
|
|
22050
|
+
let maxAnisotropy = (_b = options == null ? void 0 : options.maxAnisotropy) != null ? _b : DEFAULT_TEXTURE_FILTERING_OPTIONS.maxAnisotropy;
|
|
22051
|
+
if (!Number.isFinite(maxAnisotropy) || maxAnisotropy < 1) {
|
|
22052
|
+
maxAnisotropy = 1;
|
|
22053
|
+
}
|
|
22054
|
+
return {
|
|
22055
|
+
minFilter,
|
|
22056
|
+
magFilter,
|
|
22057
|
+
generateMipmaps,
|
|
22058
|
+
maxAnisotropy
|
|
22059
|
+
};
|
|
22060
|
+
};
|
|
22061
|
+
const ANISOTROPY_EXTENSION_NAMES = [
|
|
22062
|
+
"EXT_texture_filter_anisotropic",
|
|
22063
|
+
"WEBKIT_EXT_texture_filter_anisotropic",
|
|
22064
|
+
"MOZ_EXT_texture_filter_anisotropic"
|
|
22065
|
+
];
|
|
22066
|
+
const resolveAnisotropyExtension = (glContext) => {
|
|
22067
|
+
for (const name of ANISOTROPY_EXTENSION_NAMES) {
|
|
22068
|
+
const extension = glContext.getExtension(name);
|
|
22069
|
+
if (extension) {
|
|
22070
|
+
return extension;
|
|
22071
|
+
}
|
|
22072
|
+
}
|
|
22073
|
+
return null;
|
|
22074
|
+
};
|
|
22075
|
+
const isPowerOfTwo = (value) => value > 0 && (value & value - 1) === 0;
|
|
22076
|
+
const resolveGlMinFilter = (glContext, filter) => {
|
|
22077
|
+
switch (filter) {
|
|
22078
|
+
case "nearest":
|
|
22079
|
+
return glContext.NEAREST;
|
|
22080
|
+
case "nearest-mipmap-nearest":
|
|
22081
|
+
return glContext.NEAREST_MIPMAP_NEAREST;
|
|
22082
|
+
case "nearest-mipmap-linear":
|
|
22083
|
+
return glContext.NEAREST_MIPMAP_LINEAR;
|
|
22084
|
+
case "linear-mipmap-nearest":
|
|
22085
|
+
return glContext.LINEAR_MIPMAP_NEAREST;
|
|
22086
|
+
case "linear-mipmap-linear":
|
|
22087
|
+
return glContext.LINEAR_MIPMAP_LINEAR;
|
|
22088
|
+
case "linear":
|
|
22089
|
+
default:
|
|
22090
|
+
return glContext.LINEAR;
|
|
22091
|
+
}
|
|
22092
|
+
};
|
|
22093
|
+
const resolveGlMagFilter = (glContext, filter) => {
|
|
22094
|
+
switch (filter) {
|
|
22095
|
+
case "nearest":
|
|
22096
|
+
return glContext.NEAREST;
|
|
22097
|
+
case "linear":
|
|
22098
|
+
default:
|
|
22099
|
+
return glContext.LINEAR;
|
|
22100
|
+
}
|
|
22101
|
+
};
|
|
22005
22102
|
const calculatePerspectiveRatio = (mapInstance, location2) => {
|
|
22006
22103
|
var _a, _b, _c;
|
|
22007
22104
|
const transform = mapInstance.transform;
|
|
@@ -22630,6 +22727,9 @@ const createSpriteLayer = (options) => {
|
|
|
22630
22727
|
var _a;
|
|
22631
22728
|
const id = (_a = options == null ? void 0 : options.id) != null ? _a : "sprite-layer";
|
|
22632
22729
|
const resolvedScaling = resolveScalingOptions(options == null ? void 0 : options.spriteScaling);
|
|
22730
|
+
const resolvedTextureFiltering = resolveTextureFilteringOptions(
|
|
22731
|
+
options == null ? void 0 : options.textureFiltering
|
|
22732
|
+
);
|
|
22633
22733
|
let gl = null;
|
|
22634
22734
|
let map = null;
|
|
22635
22735
|
let program = null;
|
|
@@ -22638,6 +22738,8 @@ const createSpriteLayer = (options) => {
|
|
|
22638
22738
|
let attribUvLocation = -1;
|
|
22639
22739
|
let uniformTextureLocation = null;
|
|
22640
22740
|
let uniformOpacityLocation = null;
|
|
22741
|
+
let anisotropyExtension = null;
|
|
22742
|
+
let maxSupportedAnisotropy = 1;
|
|
22641
22743
|
const images = /* @__PURE__ */ new Map();
|
|
22642
22744
|
const queuedTextureIds = /* @__PURE__ */ new Set();
|
|
22643
22745
|
const queueTextureUpload = (image) => {
|
|
@@ -23020,16 +23122,6 @@ const createSpriteLayer = (options) => {
|
|
|
23020
23122
|
glContext.TEXTURE_WRAP_T,
|
|
23021
23123
|
glContext.CLAMP_TO_EDGE
|
|
23022
23124
|
);
|
|
23023
|
-
glContext.texParameteri(
|
|
23024
|
-
glContext.TEXTURE_2D,
|
|
23025
|
-
glContext.TEXTURE_MIN_FILTER,
|
|
23026
|
-
glContext.LINEAR
|
|
23027
|
-
);
|
|
23028
|
-
glContext.texParameteri(
|
|
23029
|
-
glContext.TEXTURE_2D,
|
|
23030
|
-
glContext.TEXTURE_MAG_FILTER,
|
|
23031
|
-
glContext.LINEAR
|
|
23032
|
-
);
|
|
23033
23125
|
glContext.pixelStorei(glContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
|
|
23034
23126
|
glContext.texImage2D(
|
|
23035
23127
|
glContext.TEXTURE_2D,
|
|
@@ -23039,6 +23131,52 @@ const createSpriteLayer = (options) => {
|
|
|
23039
23131
|
glContext.UNSIGNED_BYTE,
|
|
23040
23132
|
image.bitmap
|
|
23041
23133
|
);
|
|
23134
|
+
let minFilterEnum = resolveGlMinFilter(
|
|
23135
|
+
glContext,
|
|
23136
|
+
resolvedTextureFiltering.minFilter
|
|
23137
|
+
);
|
|
23138
|
+
const magFilterEnum = resolveGlMagFilter(
|
|
23139
|
+
glContext,
|
|
23140
|
+
resolvedTextureFiltering.magFilter
|
|
23141
|
+
);
|
|
23142
|
+
let usedMipmaps = false;
|
|
23143
|
+
if (resolvedTextureFiltering.generateMipmaps) {
|
|
23144
|
+
const isWebGL2 = typeof WebGL2RenderingContext !== "undefined" && glContext instanceof WebGL2RenderingContext;
|
|
23145
|
+
const canUseMipmaps = isWebGL2 || isPowerOfTwo(image.width) && isPowerOfTwo(image.height);
|
|
23146
|
+
if (canUseMipmaps) {
|
|
23147
|
+
glContext.generateMipmap(glContext.TEXTURE_2D);
|
|
23148
|
+
usedMipmaps = true;
|
|
23149
|
+
} else {
|
|
23150
|
+
minFilterEnum = glContext.LINEAR;
|
|
23151
|
+
}
|
|
23152
|
+
}
|
|
23153
|
+
if (!usedMipmaps && filterRequiresMipmaps(resolvedTextureFiltering.minFilter)) {
|
|
23154
|
+
minFilterEnum = glContext.LINEAR;
|
|
23155
|
+
}
|
|
23156
|
+
glContext.texParameteri(
|
|
23157
|
+
glContext.TEXTURE_2D,
|
|
23158
|
+
glContext.TEXTURE_MIN_FILTER,
|
|
23159
|
+
minFilterEnum
|
|
23160
|
+
);
|
|
23161
|
+
glContext.texParameteri(
|
|
23162
|
+
glContext.TEXTURE_2D,
|
|
23163
|
+
glContext.TEXTURE_MAG_FILTER,
|
|
23164
|
+
magFilterEnum
|
|
23165
|
+
);
|
|
23166
|
+
if (usedMipmaps && anisotropyExtension && resolvedTextureFiltering.maxAnisotropy > 1) {
|
|
23167
|
+
const ext = anisotropyExtension;
|
|
23168
|
+
const targetAnisotropy = Math.min(
|
|
23169
|
+
resolvedTextureFiltering.maxAnisotropy,
|
|
23170
|
+
maxSupportedAnisotropy
|
|
23171
|
+
);
|
|
23172
|
+
if (targetAnisotropy > 1) {
|
|
23173
|
+
glContext.texParameterf(
|
|
23174
|
+
glContext.TEXTURE_2D,
|
|
23175
|
+
ext.TEXTURE_MAX_ANISOTROPY_EXT,
|
|
23176
|
+
targetAnisotropy
|
|
23177
|
+
);
|
|
23178
|
+
}
|
|
23179
|
+
}
|
|
23042
23180
|
image.texture = texture;
|
|
23043
23181
|
});
|
|
23044
23182
|
};
|
|
@@ -23081,6 +23219,20 @@ const createSpriteLayer = (options) => {
|
|
|
23081
23219
|
const onAdd = (mapInstance, glContext) => {
|
|
23082
23220
|
map = mapInstance;
|
|
23083
23221
|
gl = glContext;
|
|
23222
|
+
anisotropyExtension = resolveAnisotropyExtension(glContext);
|
|
23223
|
+
if (anisotropyExtension) {
|
|
23224
|
+
const ext = anisotropyExtension;
|
|
23225
|
+
const supported = glContext.getParameter(
|
|
23226
|
+
ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
|
23227
|
+
);
|
|
23228
|
+
if (typeof supported === "number" && Number.isFinite(supported) && supported >= 1) {
|
|
23229
|
+
maxSupportedAnisotropy = supported;
|
|
23230
|
+
} else {
|
|
23231
|
+
maxSupportedAnisotropy = 1;
|
|
23232
|
+
}
|
|
23233
|
+
} else {
|
|
23234
|
+
maxSupportedAnisotropy = 1;
|
|
23235
|
+
}
|
|
23084
23236
|
canvasElement = mapInstance.getCanvas();
|
|
23085
23237
|
const registerDisposer = (disposer) => {
|
|
23086
23238
|
inputListenerDisposers.push(disposer);
|
|
@@ -23215,6 +23367,8 @@ const createSpriteLayer = (options) => {
|
|
|
23215
23367
|
attribUvLocation = -1;
|
|
23216
23368
|
uniformTextureLocation = null;
|
|
23217
23369
|
uniformOpacityLocation = null;
|
|
23370
|
+
anisotropyExtension = null;
|
|
23371
|
+
maxSupportedAnisotropy = 1;
|
|
23218
23372
|
};
|
|
23219
23373
|
const render = (glContext, _options) => {
|
|
23220
23374
|
hitTestEntries.length = 0;
|
|
@@ -24739,6 +24893,8 @@ const createSpriteLayer = (options) => {
|
|
|
24739
24893
|
return spriteLayout;
|
|
24740
24894
|
};
|
|
24741
24895
|
export {
|
|
24896
|
+
BETTER_TEXTURE_FILTERING_OPTIONS,
|
|
24897
|
+
DEFAULT_TEXTURE_FILTERING_OPTIONS,
|
|
24742
24898
|
STANDARD_SPRITE_SCALING_OPTIONS,
|
|
24743
24899
|
UNLIMITED_SPRITE_SCALING_OPTIONS,
|
|
24744
24900
|
applyAutoRotation,
|