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