From 2b2e1639b85d25696a5b3f7810246aca7f8a6e2c Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Tue, 12 Dec 2023 18:11:01 +0100 Subject: [PATCH] Update ol to 8.2 --- README.md | 106 ++++++++++++++-------------- package-lock.json | 114 +++++++++++++++++++++++------- src/apply.js | 2 +- src/stylefunction.js | 3 +- test/apply.test.js | 153 +++++++++++++++++++++------------------- test/applyStyle.test.js | 24 ++++--- 6 files changed, 243 insertions(+), 159 deletions(-) diff --git a/README.md b/README.md index 01e7fc9f..9a7f41cc 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ and open a browser on the host and port indicated in the console output (usually #### Modules -- [<internal\\>](#modulesinternal_md) +- [\\<internal>](#modulesinternal_md) #### Classes @@ -162,7 +162,7 @@ Renames and re-exports [apply](#apply) #### addMapboxLayer -▸ **addMapboxLayer**(`mapOrGroup`, `mapboxLayer`, `beforeLayerId?`): `Promise`<`void`> +▸ **addMapboxLayer**(`mapOrGroup`, `mapboxLayer`, `beforeLayerId?`): `Promise`\\<`void`> Add a new Mapbox Layer object to the style. The map will be re-rendered. @@ -176,7 +176,7 @@ Add a new Mapbox Layer object to the style. The map will be re-rendered. ##### Returns -`Promise`<`void`> +`Promise`\\<`void`> Resolves when the added layer is available. @@ -184,7 +184,7 @@ Resolves when the added layer is available. #### apply -▸ **apply**(`mapOrGroupOrElement`, `style`, `options?`): `Promise`<`Map` \| `LayerGroup`> +▸ **apply**(`mapOrGroupOrElement`, `style`, `options?`): `Promise`\\<`Map` \| `LayerGroup`> Loads and applies a Mapbox Style object into an OpenLayers Map or LayerGroup. This includes the map background, the layers, and for Map instances that did not @@ -226,7 +226,7 @@ Map or LayerGroup instance, which holds the Mapbox Style object. ##### Returns -`Promise`<`Map` \| `LayerGroup`> +`Promise`\\<`Map` \| `LayerGroup`> A promise that resolves after all layers have been added to the OpenLayers Map instance or LayerGroup, their sources set, and their styles applied. The @@ -237,7 +237,7 @@ argument. #### applyBackground -▸ **applyBackground**(`mapOrLayer`, `glStyle`, `options?`): `Promise`<`any`> +▸ **applyBackground**(`mapOrLayer`, `glStyle`, `options?`): `Promise`\\<`any`> Applies properties of the Mapbox Style's first `background` layer to the provided map or layer (group). @@ -262,7 +262,7 @@ applyBackground(map, 'https://api.maptiler.com/maps/basic/style.json?key=YOUR_OP ##### Returns -`Promise`<`any`> +`Promise`\\<`any`> Promise that resolves when the background is applied. @@ -270,7 +270,7 @@ Promise that resolves when the background is applied. #### applyStyle -▸ **applyStyle**(`layer`, `glStyle`, `sourceOrLayersOrOptions?`, `optionsOrPath?`, `resolutions?`): `Promise`<`any`> +▸ **applyStyle**(`layer`, `glStyle`, `sourceOrLayersOrOptions?`, `optionsOrPath?`, `resolutions?`): `Promise`\\<`any`> Applies a style function to an `ol/layer/VectorTile` or `ol/layer/Vector` with an `ol/source/VectorTile` or an `ol/source/Vector`. If the layer does not have a source @@ -304,7 +304,7 @@ Two additional properties will be set on the provided layer: | Name | Type | Default value | Description | | :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `layer` | `VectorLayer`<`any`> \| `VectorTileLayer` | `undefined` | OpenLayers layer. When the layer has a source configured, it will be modified to use the configuration from the glStyle's `source`. Options specified on the layer's source will override those from the glStyle's `source`, except for `url` and `tileUrlFunction`. When the source projection is the default (`EPSG:3857`), the `tileGrid` will also be overridden. If you'd rather not have ol-mapbox-style modify the source, configure `applyStyle()` with the `updateSource: false` option. | +| `layer` | `VectorLayer`\\<`any`> \| `VectorTileLayer` | `undefined` | OpenLayers layer. When the layer has a source configured, it will be modified to use the configuration from the glStyle's `source`. Options specified on the layer's source will override those from the glStyle's `source`, except for `url` and `tileUrlFunction`. When the source projection is the default (`EPSG:3857`), the `tileGrid` will also be overridden. If you'd rather not have ol-mapbox-style modify the source, configure `applyStyle()` with the `updateSource: false` option. | | `glStyle` | `any` | `undefined` | Mapbox Style object. | | `sourceOrLayersOrOptions?` | `string` \| `string`\[] \| [`Options`](#interfacesinternal_optionsmd) & [`ApplyStyleOptions`](#interfacesinternal_applystyleoptionsmd) | `''` | Options or `source` key or an array of layer `id`s from the Mapbox Style object. When a `source` key is provided, all layers for the specified source will be included in the style function. When layer `id`s are provided, they must be from layers that use the same source. When not provided or a falsey value, all layers using the first source specified in the glStyle will be rendered. | | `optionsOrPath?` | `string` \| [`Options`](#interfacesinternal_optionsmd) & [`ApplyStyleOptions`](#interfacesinternal_applystyleoptionsmd) | `{}` | **Deprecated**. Options. Alternatively the path of the style file (only required when a relative path is used for the `"sprite"` property of the style). | @@ -312,7 +312,7 @@ Two additional properties will be set on the provided layer: ##### Returns -`Promise`<`any`> +`Promise`\\<`any`> Promise which will be resolved when the style can be used for rendering. @@ -331,7 +331,7 @@ features differently. | Name | Type | Description | | :----------- | :------------------------------------------------------------- | :---------------------------------------- | -| `mapOrLayer` | `Map` \| `VectorLayer`<`any`> \| `VectorTileLayer` | Map or layer to set the feature state on. | +| `mapOrLayer` | `Map` \| `VectorLayer`\\<`any`> \| `VectorTileLayer` | Map or layer to set the feature state on. | | `feature` | [`FeatureIdentifier`](#interfacesinternal_featureidentifiermd) | Feature identifier. | ##### Returns @@ -345,7 +345,7 @@ feature identifier. #### getLayer -▸ **getLayer**(`map`, `layerId`): `Layer`<`Source`, `LayerRenderer`<`any`>> +▸ **getLayer**(`map`, `layerId`): `Layer`\\<`Source`, `LayerRenderer`\\<`any`>> Get the OpenLayers layer instance that contains the provided Mapbox Style `layer`. Note that multiple Mapbox Style layers are combined in a single @@ -360,7 +360,7 @@ OpenLayers layer instance when they use the same Mapbox Style `source`. ##### Returns -`Layer`<`Source`, `LayerRenderer`<`any`>> +`Layer`\\<`Source`, `LayerRenderer`\\<`any`>> OpenLayers layer instance. @@ -368,7 +368,7 @@ OpenLayers layer instance. #### getLayers -▸ **getLayers**(`map`, `sourceId`): `Layer`<`Source`, `LayerRenderer`<`any`>>\[] +▸ **getLayers**(`map`, `sourceId`): `Layer`\\<`Source`, `LayerRenderer`\\<`any`>>\[] Get the OpenLayers layer instances for the provided Mapbox Style `source`. @@ -381,7 +381,7 @@ Get the OpenLayers layer instances for the provided Mapbox Style `source`. ##### Returns -`Layer`<`Source`, `LayerRenderer`<`any`>>\[] +`Layer`\\<`Source`, `LayerRenderer`\\<`any`>>\[] OpenLayers layer instances. @@ -437,12 +437,12 @@ Get the the style for a specific Mapbox layer only. This can be useful for creat ##### Parameters -| Name | Type | Description | -| :----------- | :------------------------------------------- | :------------------------------------------ | -| `feature` | `RenderFeature` \| `Feature`<`Geometry`> | OpenLayers feature. | -| `resolution` | `number` | View resolution. | -| `olLayer` | `VectorLayer`<`any`> \| `VectorTileLayer` | OpenLayers layer. | -| `layerId` | `string` | Id of the Mapbox layer to get the style for | +| Name | Type | Description | +| :----------- | :--------------------------------------------- | :------------------------------------------ | +| `feature` | `Feature`\\<`Geometry`> \| `RenderFeature` | OpenLayers feature. | +| `resolution` | `number` | View resolution. | +| `olLayer` | `VectorLayer`\\<`any`> \| `VectorTileLayer` | OpenLayers layer. | +| `layerId` | `string` | Id of the Mapbox layer to get the style for | ##### Returns @@ -527,7 +527,7 @@ The feature state will be stored on the OpenLayers layer matching the feature id | Name | Type | Description | | :----------- | :------------------------------------------------------------- | :-------------------------------------------------------- | -| `mapOrLayer` | `Map` \| `VectorLayer`<`any`> \| `VectorTileLayer` | OpenLayers Map or layer to set the feature state on. | +| `mapOrLayer` | `Map` \| `VectorLayer`\\<`any`> \| `VectorTileLayer` | OpenLayers Map or layer to set the feature state on. | | `feature` | [`FeatureIdentifier`](#interfacesinternal_featureidentifiermd) | Feature identifier. | | `state` | `any` | Feature state. Set to `null` to remove the feature state. | @@ -579,17 +579,17 @@ sure that sprite image loading works: ##### Parameters -| Name | Type | Default value | Description | -| :--------------- | :-------------------------------------------------------------------------------------------------------------------------------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `olLayer` | `VectorLayer`<`any`> \| `VectorTileLayer` | `undefined` | OpenLayers layer to apply the style to. In addition to the style, the layer will get two properties: `mapbox-source` will be the `id` of the `glStyle`'s source used for the layer, and `mapbox-layers` will be an array of the `id`s of the `glStyle`'s layers. | -| `glStyle` | `any` | `undefined` | Mapbox Style object. | -| `sourceOrLayers` | `string` \| `string`\[] | `undefined` | `source` key or an array of layer `id`s from the Mapbox Style object. When a `source` key is provided, all layers for the specified source will be included in the style function. When layer `id`s are provided, they must be from layers that use the same source. | -| `resolutions` | `number`\[] | `defaultResolutions` | Resolutions for mapping resolution to zoom level. | -| `spriteData` | `any` | `undefined` | Sprite data from the url specified in the Mapbox Style object's `sprite` property. Only required if a `sprite` property is specified in the Mapbox Style object. | -| `spriteImageUrl` | `string` \| `Request` \| `Promise`<`string` \| `Request`> | `undefined` | Sprite image url for the sprite specified in the Mapbox Style object's `sprite` property. Only required if a `sprite` property is specified in the Mapbox Style object. | -| `getFonts` | (`arg0`: `string`\[], `arg1`: `string`) => `string`\[] | `undefined` | Function that receives a font stack and the url template from the GL style's `metadata['ol:webfonts']` property (if set) as arguments, and returns a (modified) font stack that is available. Font names are the names used in the Mapbox Style object. If not provided, the font stack will be used as-is. This function can also be used for loading web fonts. | -| `getImage?` | (`arg0`: `VectorLayer`<`any`> \| `VectorTileLayer`, `arg1`: `string`) => `string` \| `HTMLCanvasElement` \| `HTMLImageElement` | `undefined` | Function that returns an image or a URL for an image name. If the result is an HTMLImageElement, it must already be loaded. The layer can be used to call layer.changed() when the loading and processing of the image has finished. This function can be used for icons not in the sprite or to override sprite icons. | -| `...args` | `any` | `undefined` | - | +| Name | Type | Default value | Description | +| :--------------- | :---------------------------------------------------------------------------------------------------------------------------------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `olLayer` | `VectorLayer`\\<`any`> \| `VectorTileLayer` | `undefined` | OpenLayers layer to apply the style to. In addition to the style, the layer will get two properties: `mapbox-source` will be the `id` of the `glStyle`'s source used for the layer, and `mapbox-layers` will be an array of the `id`s of the `glStyle`'s layers. | +| `glStyle` | `any` | `undefined` | Mapbox Style object. | +| `sourceOrLayers` | `string` \| `string`\[] | `undefined` | `source` key or an array of layer `id`s from the Mapbox Style object. When a `source` key is provided, all layers for the specified source will be included in the style function. When layer `id`s are provided, they must be from layers that use the same source. | +| `resolutions` | `number`\[] | `defaultResolutions` | Resolutions for mapping resolution to zoom level. | +| `spriteData` | `any` | `undefined` | Sprite data from the url specified in the Mapbox Style object's `sprite` property. Only required if a `sprite` property is specified in the Mapbox Style object. | +| `spriteImageUrl` | `string` \| `Request` \| `Promise`\\<`string` \| `Request`> | `undefined` | Sprite image url for the sprite specified in the Mapbox Style object's `sprite` property. Only required if a `sprite` property is specified in the Mapbox Style object. | +| `getFonts` | (`arg0`: `string`\[], `arg1`: `string`) => `string`\[] | `undefined` | Function that receives a font stack and the url template from the GL style's `metadata['ol:webfonts']` property (if set) as arguments, and returns a (modified) font stack that is available. Font names are the names used in the Mapbox Style object. If not provided, the font stack will be used as-is. This function can also be used for loading web fonts. | +| `getImage?` | (`arg0`: `VectorLayer`\\<`any`> \| `VectorTileLayer`, `arg1`: `string`) => `string` \| `HTMLCanvasElement` \| `HTMLImageElement` | `undefined` | Function that returns an image or a URL for an image name. If the result is an HTMLImageElement, it must already be loaded. The layer can be used to call layer.changed() when the loading and processing of the image has finished. This function can be used for icons not in the sprite or to override sprite icons. | +| `...args` | `any` | `undefined` | - | ##### Returns @@ -621,7 +621,7 @@ Update a Mapbox Layer object in the style. The map will be re-rendered with the #### updateMapboxSource -▸ **updateMapboxSource**(`mapOrGroup`, `id`, `mapboxSource`): `Promise`<`Source`> +▸ **updateMapboxSource**(`mapOrGroup`, `id`, `mapboxSource`): `Promise`\\<`Source`> Updates a Mapbox source object in the style. The according OpenLayers source will be replaced and the map will be re-rendered. @@ -636,7 +636,7 @@ and the map will be re-rendered. ##### Returns -`Promise`<`Source`> +`Promise`\\<`Source`> Promise that resolves when the source has been updated. @@ -731,9 +731,9 @@ VectorTileLayer.constructor -## Interface: ApplyStyleOptions<> +## Interface: ApplyStyleOptions\\<> -[](#modulesinternal_md).ApplyStyleOptions +[\\<internal>](#modulesinternal_md).ApplyStyleOptions ### Table of contents @@ -772,9 +772,9 @@ specified for the source in the mapbox style definition. -## Interface: FeatureIdentifier<> +## Interface: FeatureIdentifier\\<> -[](#modulesinternal_md).FeatureIdentifier +[\\<internal>](#modulesinternal_md).FeatureIdentifier ### Table of contents @@ -801,9 +801,9 @@ The source id. -## Interface: Options<> +## Interface: Options\\<> -[](#modulesinternal_md).Options +[\\<internal>](#modulesinternal_md).Options ### Table of contents @@ -1079,9 +1079,9 @@ method was used. -## Interface: Options<> +## Interface: Options\\<> -[](#modulesinternal_md).Options +[\\<internal>](#modulesinternal_md).Options ### Table of contents @@ -1115,7 +1115,7 @@ Access token param. For internal use. #### getImage -• **getImage**: (`arg0`: `VectorLayer`<`any`> \| `VectorTileLayer`, `arg1`: `string`) => `string` \| `HTMLCanvasElement` \| `HTMLImageElement` +• **getImage**: (`arg0`: `VectorLayer`\\<`any`> \| `VectorTileLayer`, `arg1`: `string`) => `string` \| `HTMLCanvasElement` \| `HTMLImageElement` ##### Type declaration @@ -1127,10 +1127,10 @@ This function be used for icons not in the sprite or to override sprite icons. ###### Parameters -| Name | Type | -| :----- | :------------------------------------------- | -| `arg0` | `VectorLayer`<`any`> \| `VectorTileLayer` | -| `arg1` | `string` | +| Name | Type | +| :----- | :--------------------------------------------- | +| `arg0` | `VectorLayer`\\<`any`> \| `VectorTileLayer` | +| `arg1` | `string` | ###### Returns @@ -1171,11 +1171,11 @@ as object, when they contain a relative sprite url, or sources referencing data #### transformRequest -• **transformRequest**: (`arg0`: `string`, `arg1`: [`ResourceType`](#ResourceType)) => `string` \| `void` \| `Request` \| `Promise`<`string` \| `Request`> +• **transformRequest**: (`arg0`: `string`, `arg1`: [`ResourceType`](#ResourceType)) => `string` \| `void` \| `Request` \| `Promise`\\<`string` \| `Request`> ##### Type declaration -▸ (`arg0`, `arg1`): `string` \| `void` \| `Request` \| `Promise`<`string` \| `Request`> +▸ (`arg0`, `arg1`): `string` \| `void` \| `Request` \| `Promise`\\<`string` \| `Request`> Function for controlling how `ol-mapbox-style` fetches resources. Can be used for modifying the url, adding headers or setting credentials options. Called with the url and the resource @@ -1191,11 +1191,11 @@ Without a return value the original request will not be modified. ###### Returns -`string` \| `void` \| `Request` \| `Promise`<`string` \| `Request`> +`string` \| `void` \| `Request` \| `Promise`\\<`string` \| `Request`> -## Module: <internal> +## Module: \\<internal> ### Table of contents @@ -1214,4 +1214,4 @@ Without a return value the original request will not be modified. #### ResourceType -Ƭ **ResourceType**<>: `"Style"` \| `"Source"` \| `"Sprite"` \| `"SpriteImage"` \| `"Tiles"` \| `"GeoJSON"` +Ƭ **ResourceType**\\<>: `"Style"` \| `"Source"` \| `"Sprite"` \| `"SpriteImage"` \| `"Tiles"` \| `"GeoJSON"` diff --git a/package-lock.json b/package-lock.json index 5f66f9a0..5e675204 100644 --- a/package-lock.json +++ b/package-lock.json @@ -786,9 +786,9 @@ } }, "node_modules/@petamoriken/float16": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.3.tgz", - "integrity": "sha512-an2OZ7/6er9Jja8EDUvU/tmtGIutdlb6LwXOwgjzoCjDRAsUd8sRZMBjoPEy78Xa9iOp+Kglk2CHgVwZuZbWbw==", + "version": "3.8.4", + "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.4.tgz", + "integrity": "sha512-kB+NJ5Br56ZhElKsf0pM7/PQfrDdDVMRz8f0JM6eVOGE+L89z9hwcst9QvWBBnazzuqGTGtPsJNZoQ1JdNiGSQ==", "peer": true }, "node_modules/@puppeteer/browsers": { @@ -2607,8 +2607,32 @@ "node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "node_modules/color-parse": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/color-parse/-/color-parse-2.0.0.tgz", + "integrity": "sha512-g2Z+QnWsdHLppAbrpcFWo629kLOnOPtpxYV69GCqm92gqSgyXbzlfyN3MXs0412fPBkFmiuS+rXposgBgBa6Kg==", + "peer": true, + "dependencies": { + "color-name": "^1.0.0" + } + }, + "node_modules/color-rgba": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/color-rgba/-/color-rgba-3.0.0.tgz", + "integrity": "sha512-PPwZYkEY3M2THEHHV6Y95sGUie77S7X8v+h1r6LSAPF3/LL2xJ8duUXSrkic31Nzc4odPwHgUbiX/XuTYzQHQg==", + "peer": true, + "dependencies": { + "color-parse": "^2.0.0", + "color-space": "^2.0.0" + } + }, + "node_modules/color-space": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-space/-/color-space-2.0.1.tgz", + "integrity": "sha512-nKqUYlo0vZATVOFHY810BSYjmCARrG7e5R3UE3CQlyjJTvv5kSSmPG1kzm/oDyyqjehM+lW1RnEt9It9GNa5JA==", + "peer": true }, "node_modules/colorette": { "version": "2.0.16", @@ -4998,9 +5022,9 @@ } }, "node_modules/geotiff": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.0.7.tgz", - "integrity": "sha512-FKvFTNowMU5K6lHYY2f83d4lS2rsCNdpUC28AX61x9ZzzqPNaWFElWv93xj0eJFaNyOYA63ic5OzJ88dHpoA5Q==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.1.0.tgz", + "integrity": "sha512-B/iFJuFfRpmPHXf8aIRPRgUWwfaNb6dlsynkM8SWeHAPu7CpyvfqEa43KlBt7xxq5OTVysQacFHxhCn3SZhRKQ==", "peer": true, "dependencies": { "@petamoriken/float16": "^3.4.7", @@ -5009,7 +5033,8 @@ "parse-headers": "^2.0.2", "quick-lru": "^6.1.1", "web-worker": "^1.2.0", - "xml-utils": "^1.0.2" + "xml-utils": "^1.0.2", + "zstddec": "^0.1.0" }, "engines": { "node": ">=10.19" @@ -8284,11 +8309,13 @@ "dev": true }, "node_modules/ol": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/ol/-/ol-8.1.0.tgz", - "integrity": "sha512-cx3SH2plpFS9fM8pp1nCypgQXGJD7Mcb1E3mEySmy5XEw1DUEo+kkNzgtAZz5qupekqi7aU9iBJEjCoMfqvO2Q==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/ol/-/ol-8.2.0.tgz", + "integrity": "sha512-/m1ddd7Jsp4Kbg+l7+ozR5aKHAZNQOBAoNZ5pM9Jvh4Etkf0WGkXr9qXd7PnhmwiC1Hnc2Toz9XjCzBBvexfXw==", "peer": true, "dependencies": { + "color-rgba": "^3.0.0", + "color-space": "^2.0.1", "earcut": "^2.2.3", "geotiff": "^2.0.7", "pbf": "3.2.1", @@ -12152,6 +12179,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/zstddec": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/zstddec/-/zstddec-0.1.0.tgz", + "integrity": "sha512-w2NTI8+3l3eeltKAdK8QpiLo/flRAr2p8AGeakfMZOXBxOg9HIu4LVDxBi81sYgVhFhdJjv1OrB5ssI8uFPoLg==", + "peer": true + }, "node_modules/zwitch": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-1.0.5.tgz", @@ -12725,9 +12758,9 @@ } }, "@petamoriken/float16": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.3.tgz", - "integrity": "sha512-an2OZ7/6er9Jja8EDUvU/tmtGIutdlb6LwXOwgjzoCjDRAsUd8sRZMBjoPEy78Xa9iOp+Kglk2CHgVwZuZbWbw==", + "version": "3.8.4", + "resolved": "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.4.tgz", + "integrity": "sha512-kB+NJ5Br56ZhElKsf0pM7/PQfrDdDVMRz8f0JM6eVOGE+L89z9hwcst9QvWBBnazzuqGTGtPsJNZoQ1JdNiGSQ==", "peer": true }, "@puppeteer/browsers": { @@ -14185,8 +14218,32 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "color-parse": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/color-parse/-/color-parse-2.0.0.tgz", + "integrity": "sha512-g2Z+QnWsdHLppAbrpcFWo629kLOnOPtpxYV69GCqm92gqSgyXbzlfyN3MXs0412fPBkFmiuS+rXposgBgBa6Kg==", + "peer": true, + "requires": { + "color-name": "^1.0.0" + } + }, + "color-rgba": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/color-rgba/-/color-rgba-3.0.0.tgz", + "integrity": "sha512-PPwZYkEY3M2THEHHV6Y95sGUie77S7X8v+h1r6LSAPF3/LL2xJ8duUXSrkic31Nzc4odPwHgUbiX/XuTYzQHQg==", + "peer": true, + "requires": { + "color-parse": "^2.0.0", + "color-space": "^2.0.0" + } + }, + "color-space": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-space/-/color-space-2.0.1.tgz", + "integrity": "sha512-nKqUYlo0vZATVOFHY810BSYjmCARrG7e5R3UE3CQlyjJTvv5kSSmPG1kzm/oDyyqjehM+lW1RnEt9It9GNa5JA==", + "peer": true }, "colorette": { "version": "2.0.16", @@ -15977,9 +16034,9 @@ "dev": true }, "geotiff": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.0.7.tgz", - "integrity": "sha512-FKvFTNowMU5K6lHYY2f83d4lS2rsCNdpUC28AX61x9ZzzqPNaWFElWv93xj0eJFaNyOYA63ic5OzJ88dHpoA5Q==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/geotiff/-/geotiff-2.1.0.tgz", + "integrity": "sha512-B/iFJuFfRpmPHXf8aIRPRgUWwfaNb6dlsynkM8SWeHAPu7CpyvfqEa43KlBt7xxq5OTVysQacFHxhCn3SZhRKQ==", "peer": true, "requires": { "@petamoriken/float16": "^3.4.7", @@ -15988,7 +16045,8 @@ "parse-headers": "^2.0.2", "quick-lru": "^6.1.1", "web-worker": "^1.2.0", - "xml-utils": "^1.0.2" + "xml-utils": "^1.0.2", + "zstddec": "^0.1.0" }, "dependencies": { "quick-lru": { @@ -18415,11 +18473,13 @@ "dev": true }, "ol": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/ol/-/ol-8.1.0.tgz", - "integrity": "sha512-cx3SH2plpFS9fM8pp1nCypgQXGJD7Mcb1E3mEySmy5XEw1DUEo+kkNzgtAZz5qupekqi7aU9iBJEjCoMfqvO2Q==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/ol/-/ol-8.2.0.tgz", + "integrity": "sha512-/m1ddd7Jsp4Kbg+l7+ozR5aKHAZNQOBAoNZ5pM9Jvh4Etkf0WGkXr9qXd7PnhmwiC1Hnc2Toz9XjCzBBvexfXw==", "peer": true, "requires": { + "color-rgba": "^3.0.0", + "color-space": "^2.0.1", "earcut": "^2.2.3", "geotiff": "^2.0.7", "pbf": "3.2.1", @@ -21362,6 +21422,12 @@ "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true }, + "zstddec": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/zstddec/-/zstddec-0.1.0.tgz", + "integrity": "sha512-w2NTI8+3l3eeltKAdK8QpiLo/flRAr2p8AGeakfMZOXBxOg9HIu4LVDxBi81sYgVhFhdJjv1OrB5ssI8uFPoLg==", + "peer": true + }, "zwitch": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-1.0.5.tgz", diff --git a/src/apply.js b/src/apply.js index 9cedfac8..8c562b66 100644 --- a/src/apply.js +++ b/src/apply.js @@ -819,7 +819,7 @@ function setupGeoJSONSource(glSource, styleUrl, options) { ) ); source.set('mapbox-source', glSource); - return source; + return /** @type {VectorSource} */ (source); } function setupGeoJSONLayer(glSource, styleUrl, options) { diff --git a/src/stylefunction.js b/src/stylefunction.js index 99c2e262..7e33669f 100644 --- a/src/stylefunction.js +++ b/src/stylefunction.js @@ -798,8 +798,9 @@ export function stylefunction( 'Point', renderFeatureCoordinates, [], + 2, {}, - null + undefined ); } styleGeom = renderFeature; diff --git a/test/apply.test.js b/test/apply.test.js index 14b9d992..d4ed5236 100644 --- a/test/apply.test.js +++ b/test/apply.test.js @@ -211,42 +211,90 @@ describe('ol-mapbox-style', function () { .catch(done); }); - it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) { - fetch('./fixtures/geojson-wfs.json') - .then(function (response) { - return response.json(); + describe('geojson', function () { + let originalFetch; + const requests = []; + beforeEach(function () { + originalFetch = fetch; + window.fetch = (request) => { + requests.push(request); + return originalFetch(request); + }; + }); + afterEach(function () { + window.fetch = originalFetch; + requests.length = 0; + }); + it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) { + fetch('./fixtures/geojson-wfs.json') + .then(function (response) { + return response.json(); + }) + .then(function (style) { + style.sources.water_areas.data = + style.sources.water_areas.data.replace('3857', '4326'); + apply(target, style, {projection: 'EPSG:4326'}) + .then(function (map) { + const layer = map + .getAllLayers() + .find((x) => x.get('mapbox-source') === 'water_areas'); + const source = layer.getSource(); + source.once('change', () => { + try { + const url = new URL(requests[requests.length - 1].url); + const bbox = url.searchParams.get('bbox'); + const extent = map.getView().calculateExtent(); + should(bbox).be.equal(extent.join(',')); + done(); + } catch (e) { + done(e); + } + }); + source.loadFeatures( + map.getView().calculateExtent(), + 1, + map.getView().getProjection() + ); + }) + .catch(done); + }); + }); + + it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) { + apply(target, './fixtures/geojson-wfs.json', { + transformRequest: (urlStr, type) => { + if (type === 'GeoJSON') { + const url = new URL(urlStr + '&transformRequest=true'); + return new Request(url); + } + }, }) - .then(function (style) { - style.sources.water_areas.data = - style.sources.water_areas.data.replace('3857', '4326'); - apply(target, style, {projection: 'EPSG:4326'}) - .then(function (map) { - const layer = map - .getAllLayers() - .find((x) => x.get('mapbox-source') === 'water_areas'); - const source = layer.getSource(); - const originalFetch = fetch; - const requests = []; - fetch = (request) => { - requests.push(request); - return originalFetch(request); - }; - source.loadFeatures( - map.getView().calculateExtent(), - 1, - map.getView().getProjection() - ); - source.once('change', () => { - window.fetch = originalFetch; - const url = new URL(requests[0].url); - const bbox = url.searchParams.get('bbox'); - const extent = map.getView().calculateExtent(); - should(bbox).be.equal(extent.join(',')); + .then(function (map) { + const layer = map + .getAllLayers() + .find((x) => x.get('mapbox-source') === 'water_areas'); + const source = layer.getSource(); + source.loadFeatures( + map.getView().calculateExtent(), + 1, + get('EPSG:3857') + ); + source.once('change', () => { + try { + const url = new URL(requests[requests.length - 1].url); + should(url.searchParams.get('transformRequest')).be.equal( + 'true' + ); + should(source).be.instanceof(VectorSource); + should(layer.getStyle()).be.a.Function(); done(); - }); - }) - .catch(done); - }); + } catch (e) { + done(e); + } + }); + }) + .catch(done); + }); }); it('sets the correct GeoJON data projection for custom projections', function (done) { @@ -317,43 +365,6 @@ describe('ol-mapbox-style', function () { }); }); - it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) { - apply(target, './fixtures/geojson-wfs.json', { - transformRequest: (urlStr, type) => { - if (type === 'GeoJSON') { - const url = new URL(urlStr + '&transformRequest=true'); - return new Request(url); - } - }, - }) - .then(function (map) { - const layer = map - .getAllLayers() - .find((x) => x.get('mapbox-source') === 'water_areas'); - const source = layer.getSource(); - const originalFetch = fetch; - const requests = []; - fetch = (request) => { - requests.push(request); - return originalFetch(request); - }; - source.loadFeatures( - map.getView().calculateExtent(), - 1, - get('EPSG:3857') - ); - source.once('change', () => { - window.fetch = originalFetch; - const url = new URL(requests[0].url); - should(url.searchParams.get('transformRequest')).be.equal('true'); - should(source).be.instanceof(VectorSource); - should(layer.getStyle()).be.a.Function(); - done(); - }); - }) - .catch(done); - }); - it('handles geojson sources with inline GeoJSON', function (done) { const map = new Map({target: target}); map.getLayers().once('add', function (e) { diff --git a/test/applyStyle.test.js b/test/applyStyle.test.js index 37afb3b8..2bcee97b 100644 --- a/test/applyStyle.test.js +++ b/test/applyStyle.test.js @@ -18,6 +18,20 @@ import {apply, applyStyle} from '../src/apply.js'; import {get} from 'ol/proj.js'; describe('applyStyle with source creation', function () { + let originalFetch; + const requests = []; + beforeEach(function () { + originalFetch = fetch; + window.fetch = (request) => { + requests.push(request); + return originalFetch(request); + }; + }); + afterEach(function () { + window.fetch = originalFetch; + requests.length = 0; + }); + it('accepts incorrect source with simple 3-parameter configuration', function (done) { const layer = new VectorLayer(); applyStyle(layer, '/fixtures/geojson.json', { @@ -63,21 +77,13 @@ describe('applyStyle with source creation', function () { return new Request(url); }, }).then(function () { - const originalFetch = fetch; - /** @type {Array} */ - const requests = []; - fetch = (request) => { - requests.push(request); - return originalFetch(request); - }; layer .getSource() .loadFeatures([0, 0, 10000, 10000], 10, get('EPSG:3857')); layer.getSource().once('change', () => { - window.fetch = originalFetch; try { should(layer.getSource()).be.an.instanceOf(VectorSource); - should(requests[0].url).equal( + should(requests[requests.length - 1].url).equal( `${location.origin}/fixtures/states.geojson?foo=bar` ); should(layer.getStyle()).be.an.instanceOf(Function);