@vcmap/core 5.0.0-rc.12 → 5.0.0-rc.13

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/index.d.ts CHANGED
@@ -1153,6 +1153,7 @@ export class CesiumTilesetLayer extends FeatureLayer implements SplitLayer {
1153
1153
  * The class names of the supported maps.
1154
1154
  */
1155
1155
  protected _supportedMaps: string[];
1156
+ protected _url: string | any;
1156
1157
  /**
1157
1158
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
1158
1159
  */
@@ -1193,6 +1194,10 @@ export class CesiumTilesetLayer extends FeatureLayer implements SplitLayer {
1193
1194
  */
1194
1195
  readonly exclusiveGroups: any;
1195
1196
  zIndex: number;
1197
+ /**
1198
+ * returns the currently set locale. Can be used to provide locale specific URLs.
1199
+ */
1200
+ locale: string;
1196
1201
  /**
1197
1202
  * unique Name
1198
1203
  */
@@ -1241,6 +1246,7 @@ export class CzmlLayer extends DataSourceLayer {
1241
1246
  * The class names of the supported maps.
1242
1247
  */
1243
1248
  protected _supportedMaps: string[];
1249
+ protected _url: string | any;
1244
1250
  /**
1245
1251
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
1246
1252
  */
@@ -1281,6 +1287,10 @@ export class CzmlLayer extends DataSourceLayer {
1281
1287
  */
1282
1288
  readonly exclusiveGroups: any;
1283
1289
  zIndex: number;
1290
+ /**
1291
+ * returns the currently set locale. Can be used to provide locale specific URLs.
1292
+ */
1293
+ locale: string;
1284
1294
  /**
1285
1295
  * unique Name
1286
1296
  */
@@ -1354,6 +1364,7 @@ export class DataSourceLayer extends Layer {
1354
1364
  * The class names of the supported maps.
1355
1365
  */
1356
1366
  protected _supportedMaps: string[];
1367
+ protected _url: string | any;
1357
1368
  /**
1358
1369
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
1359
1370
  */
@@ -1394,6 +1405,10 @@ export class DataSourceLayer extends Layer {
1394
1405
  */
1395
1406
  readonly exclusiveGroups: any;
1396
1407
  zIndex: number;
1408
+ /**
1409
+ * returns the currently set locale. Can be used to provide locale specific URLs.
1410
+ */
1411
+ locale: string;
1397
1412
  /**
1398
1413
  * unique Name
1399
1414
  */
@@ -1494,6 +1509,7 @@ export class FeatureLayer extends Layer {
1494
1509
  * The class names of the supported maps.
1495
1510
  */
1496
1511
  protected _supportedMaps: string[];
1512
+ protected _url: string | any;
1497
1513
  /**
1498
1514
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
1499
1515
  */
@@ -1534,6 +1550,10 @@ export class FeatureLayer extends Layer {
1534
1550
  */
1535
1551
  readonly exclusiveGroups: any;
1536
1552
  zIndex: number;
1553
+ /**
1554
+ * returns the currently set locale. Can be used to provide locale specific URLs.
1555
+ */
1556
+ locale: string;
1537
1557
  /**
1538
1558
  * unique Name
1539
1559
  */
@@ -1708,6 +1728,7 @@ export class FeatureStoreLayer extends VectorLayer {
1708
1728
  * The class names of the supported maps.
1709
1729
  */
1710
1730
  protected _supportedMaps: string[];
1731
+ protected _url: string | any;
1711
1732
  /**
1712
1733
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
1713
1734
  */
@@ -1747,6 +1768,10 @@ export class FeatureStoreLayer extends VectorLayer {
1747
1768
  */
1748
1769
  readonly exclusiveGroups: any;
1749
1770
  zIndex: number;
1771
+ /**
1772
+ * returns the currently set locale. Can be used to provide locale specific URLs.
1773
+ */
1774
+ locale: string;
1750
1775
  /**
1751
1776
  * unique Name
1752
1777
  */
@@ -2114,6 +2139,7 @@ export class GeoJSONLayer extends VectorLayer {
2114
2139
  * The class names of the supported maps.
2115
2140
  */
2116
2141
  protected _supportedMaps: string[];
2142
+ protected _url: string | any;
2117
2143
  /**
2118
2144
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
2119
2145
  */
@@ -2153,6 +2179,10 @@ export class GeoJSONLayer extends VectorLayer {
2153
2179
  */
2154
2180
  readonly exclusiveGroups: any;
2155
2181
  zIndex: number;
2182
+ /**
2183
+ * returns the currently set locale. Can be used to provide locale specific URLs.
2184
+ */
2185
+ locale: string;
2156
2186
  /**
2157
2187
  * unique Name
2158
2188
  */
@@ -2314,6 +2344,7 @@ export class Layer extends VcsObject {
2314
2344
  * The class names of the supported maps.
2315
2345
  */
2316
2346
  protected _supportedMaps: string[];
2347
+ protected _url: string | any;
2317
2348
  /**
2318
2349
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
2319
2350
  */
@@ -2349,6 +2380,10 @@ export class Layer extends VcsObject {
2349
2380
  readonly exclusive: boolean;
2350
2381
  exclusiveGroups: any;
2351
2382
  zIndex: any;
2383
+ /**
2384
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
2385
+ */
2386
+ locale: any;
2352
2387
  /**
2353
2388
  * creates an array of layer implementations for the given map.
2354
2389
  * @param map - Map
@@ -2609,6 +2644,7 @@ export class OpenStreetMapLayer extends Layer implements SplitLayer {
2609
2644
  * The class names of the supported maps.
2610
2645
  */
2611
2646
  protected _supportedMaps: string[];
2647
+ protected _url: string | any;
2612
2648
  /**
2613
2649
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
2614
2650
  */
@@ -2649,6 +2685,10 @@ export class OpenStreetMapLayer extends Layer implements SplitLayer {
2649
2685
  */
2650
2686
  readonly exclusiveGroups: any;
2651
2687
  zIndex: number;
2688
+ /**
2689
+ * returns the currently set locale. Can be used to provide locale specific URLs.
2690
+ */
2691
+ locale: string;
2652
2692
  /**
2653
2693
  * unique Name
2654
2694
  */
@@ -2916,6 +2956,7 @@ export class PointCloudLayer extends CesiumTilesetLayer {
2916
2956
  * The class names of the supported maps.
2917
2957
  */
2918
2958
  protected _supportedMaps: string[];
2959
+ protected _url: string | any;
2919
2960
  /**
2920
2961
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
2921
2962
  */
@@ -2956,6 +2997,10 @@ export class PointCloudLayer extends CesiumTilesetLayer {
2956
2997
  */
2957
2998
  readonly exclusiveGroups: any;
2958
2999
  zIndex: number;
3000
+ /**
3001
+ * returns the currently set locale. Can be used to provide locale specific URLs.
3002
+ */
3003
+ locale: string;
2959
3004
  /**
2960
3005
  * unique Name
2961
3006
  */
@@ -3057,6 +3102,7 @@ export class RasterLayer extends Layer implements SplitLayer {
3057
3102
  * The class names of the supported maps.
3058
3103
  */
3059
3104
  protected _supportedMaps: string[];
3105
+ protected _url: string | any;
3060
3106
  /**
3061
3107
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
3062
3108
  */
@@ -3097,6 +3143,10 @@ export class RasterLayer extends Layer implements SplitLayer {
3097
3143
  */
3098
3144
  readonly exclusiveGroups: any;
3099
3145
  zIndex: number;
3146
+ /**
3147
+ * returns the currently set locale. Can be used to provide locale specific URLs.
3148
+ */
3149
+ locale: string;
3100
3150
  /**
3101
3151
  * unique Name
3102
3152
  */
@@ -3165,6 +3215,7 @@ export class SingleImageLayer extends RasterLayer {
3165
3215
  * The class names of the supported maps.
3166
3216
  */
3167
3217
  protected _supportedMaps: string[];
3218
+ protected _url: string | any;
3168
3219
  /**
3169
3220
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
3170
3221
  */
@@ -3205,6 +3256,10 @@ export class SingleImageLayer extends RasterLayer {
3205
3256
  */
3206
3257
  readonly exclusiveGroups: any;
3207
3258
  zIndex: number;
3259
+ /**
3260
+ * returns the currently set locale. Can be used to provide locale specific URLs.
3261
+ */
3262
+ locale: string;
3208
3263
  /**
3209
3264
  * unique Name
3210
3265
  */
@@ -3280,6 +3335,7 @@ export class TerrainLayer extends Layer {
3280
3335
  * The class names of the supported maps.
3281
3336
  */
3282
3337
  protected _supportedMaps: string[];
3338
+ protected _url: string | any;
3283
3339
  /**
3284
3340
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
3285
3341
  */
@@ -3320,6 +3376,10 @@ export class TerrainLayer extends Layer {
3320
3376
  */
3321
3377
  readonly exclusiveGroups: any;
3322
3378
  zIndex: number;
3379
+ /**
3380
+ * returns the currently set locale. Can be used to provide locale specific URLs.
3381
+ */
3382
+ locale: string;
3323
3383
  /**
3324
3384
  * unique Name
3325
3385
  */
@@ -3354,6 +3414,10 @@ export class MVTTileProvider extends TileProvider {
3354
3414
  static getDefaultOptions(): MVTTileProviderOptions;
3355
3415
  url: string;
3356
3416
  idProperty: string | undefined;
3417
+ /**
3418
+ * sets the locale and clears the Cache if the URL is a locale aware Object.
3419
+ */
3420
+ locale: any;
3357
3421
  /**
3358
3422
  * Cesium Webmercator TilingScheme
3359
3423
  */
@@ -3439,6 +3503,7 @@ export class StaticGeoJSONTileProvider extends TileProvider {
3439
3503
  * use setTileCacheSize to change
3440
3504
  */
3441
3505
  readonly tileCacheSize: number;
3506
+ locale: string;
3442
3507
  /**
3443
3508
  * unique Name
3444
3509
  */
@@ -3538,6 +3603,10 @@ export class TileProvider extends VcsObject {
3538
3603
  * use setTileCacheSize to change
3539
3604
  */
3540
3605
  readonly tileCacheSize: number;
3606
+ /**
3607
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
3608
+ */
3609
+ locale: any;
3541
3610
  setTileCacheSize(value: number): Promise<any>;
3542
3611
  /**
3543
3612
  * returns the closest baseLevel for the given resolution
@@ -3618,9 +3687,9 @@ export interface URLTemplateTileProviderOptions extends TileProviderOptions {
3618
3687
  /**
3619
3688
  * replaces {x}, {y}, {z} with the x, y, z tiling coordinates
3620
3689
  * replaces {minx}, {miny}, {maxx}, {maxy} with extent of the tile if tilingExtent is provided
3621
- * replaces {locale} with the current locale
3690
+ * replaces {locale} with the given locale
3622
3691
  */
3623
- export function getURL(url: string, x: number, y: number, z: number, tilingExtent?: import("@vcmap/cesium").Rectangle): string;
3692
+ export function getURL(url: string, x: number, y: number, z: number, tilingExtent?: import("@vcmap/cesium").Rectangle, locale?: string): string;
3624
3693
 
3625
3694
  /**
3626
3695
  * TileProvider loads GeojsonLayer from the provided URL. The URL has placeholders:
@@ -3633,6 +3702,10 @@ export class URLTemplateTileProvider extends TileProvider {
3633
3702
  static readonly className: any;
3634
3703
  static getDefaultOptions(): URLTemplateTileProviderOptions;
3635
3704
  url: string;
3705
+ /**
3706
+ * sets the locale and clears the Cache if the URL is a locale aware Object.
3707
+ */
3708
+ locale: any;
3636
3709
  /**
3637
3710
  * Cesium Webmercator TilingScheme
3638
3711
  */
@@ -3725,6 +3798,7 @@ export class TMSLayer extends RasterLayer {
3725
3798
  * The class names of the supported maps.
3726
3799
  */
3727
3800
  protected _supportedMaps: string[];
3801
+ protected _url: string | any;
3728
3802
  /**
3729
3803
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
3730
3804
  */
@@ -3765,6 +3839,10 @@ export class TMSLayer extends RasterLayer {
3765
3839
  */
3766
3840
  readonly exclusiveGroups: any;
3767
3841
  zIndex: number;
3842
+ /**
3843
+ * returns the currently set locale. Can be used to provide locale specific URLs.
3844
+ */
3845
+ locale: string;
3768
3846
  /**
3769
3847
  * unique Name
3770
3848
  */
@@ -3981,6 +4059,7 @@ export class VectorLayer extends FeatureLayer {
3981
4059
  * The class names of the supported maps.
3982
4060
  */
3983
4061
  protected _supportedMaps: string[];
4062
+ protected _url: string | any;
3984
4063
  /**
3985
4064
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
3986
4065
  */
@@ -4020,6 +4099,10 @@ export class VectorLayer extends FeatureLayer {
4020
4099
  */
4021
4100
  readonly exclusiveGroups: any;
4022
4101
  zIndex: number;
4102
+ /**
4103
+ * returns the currently set locale. Can be used to provide locale specific URLs.
4104
+ */
4105
+ locale: string;
4023
4106
  /**
4024
4107
  * unique Name
4025
4108
  */
@@ -4296,6 +4379,10 @@ export class VectorTileLayer extends FeatureLayer {
4296
4379
  */
4297
4380
  vectorProperties: VectorProperties;
4298
4381
  tileProvider: TileProvider;
4382
+ /**
4383
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
4384
+ */
4385
+ locale: any;
4299
4386
  /**
4300
4387
  * rerenders the specified tiles
4301
4388
  * rendering happens async
@@ -4342,6 +4429,7 @@ export class VectorTileLayer extends FeatureLayer {
4342
4429
  * The class names of the supported maps.
4343
4430
  */
4344
4431
  protected _supportedMaps: string[];
4432
+ protected _url: string | any;
4345
4433
  /**
4346
4434
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
4347
4435
  */
@@ -4485,6 +4573,7 @@ export class WFSLayer extends VectorLayer {
4485
4573
  * The class names of the supported maps.
4486
4574
  */
4487
4575
  protected _supportedMaps: string[];
4576
+ protected _url: string | any;
4488
4577
  /**
4489
4578
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
4490
4579
  */
@@ -4524,6 +4613,10 @@ export class WFSLayer extends VectorLayer {
4524
4613
  */
4525
4614
  readonly exclusiveGroups: any;
4526
4615
  zIndex: number;
4616
+ /**
4617
+ * returns the currently set locale. Can be used to provide locale specific URLs.
4618
+ */
4619
+ locale: string;
4527
4620
  /**
4528
4621
  * unique Name
4529
4622
  */
@@ -4646,6 +4739,7 @@ export class WMSLayer extends RasterLayer {
4646
4739
  * The class names of the supported maps.
4647
4740
  */
4648
4741
  protected _supportedMaps: string[];
4742
+ protected _url: string | any;
4649
4743
  /**
4650
4744
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
4651
4745
  */
@@ -4686,6 +4780,10 @@ export class WMSLayer extends RasterLayer {
4686
4780
  */
4687
4781
  readonly exclusiveGroups: any;
4688
4782
  zIndex: number;
4783
+ /**
4784
+ * returns the currently set locale. Can be used to provide locale specific URLs.
4785
+ */
4786
+ locale: string;
4689
4787
  /**
4690
4788
  * unique Name
4691
4789
  */
@@ -4771,6 +4869,7 @@ export class WMTSLayer extends RasterLayer {
4771
4869
  * The class names of the supported maps.
4772
4870
  */
4773
4871
  protected _supportedMaps: string[];
4872
+ protected _url: string | any;
4774
4873
  /**
4775
4874
  * Called when the zIndex of this layer is changed. Is passed the new zIndex as its only argument.
4776
4875
  */
@@ -4811,6 +4910,10 @@ export class WMTSLayer extends RasterLayer {
4811
4910
  */
4812
4911
  readonly exclusiveGroups: any;
4813
4912
  zIndex: number;
4913
+ /**
4914
+ * returns the currently set locale. Can be used to provide locale specific URLs.
4915
+ */
4916
+ locale: string;
4814
4917
  /**
4815
4918
  * unique Name
4816
4919
  */
@@ -6750,16 +6853,6 @@ export class Collection<T extends any> {
6750
6853
  destroy(): void;
6751
6854
  }
6752
6855
 
6753
- export function getShortLocaleDate(date: Date, locale?: string): string;
6754
-
6755
- export function getShortLocaleTime(date: Date, locale?: string): string;
6756
-
6757
- export function getISODateString(date: Date): string;
6758
-
6759
- export function getDayOfYear(date: Date): number;
6760
-
6761
- export function isLeapYear(date: Date): boolean;
6762
-
6763
6856
  /**
6764
6857
  * Tracks layer exclusivity, added to every {@link LayerCollection}.
6765
6858
  */
@@ -7007,25 +7100,22 @@ export class LayerCollection extends IndexedCollection<Layer> {
7007
7100
  * Set global hider for these maps.
7008
7101
  */
7009
7102
  globalHider: any;
7103
+ locale: any;
7010
7104
  /**
7011
7105
  * Adds a layer to the collection. Can optionally be passed an index at which to insert the layer.
7106
+ * The layer locale will be set to the same locale of the layerCollection. This will trigger a forceRedraw
7107
+ * of the layer if the layer locale is different and the layer is locale aware.
7012
7108
  * @returns returns the layer index or null, if the layers name is not unique
7013
7109
  */
7014
7110
  add(layer: Layer, index?: number): number | null;
7015
7111
  protected _remove(layer: Layer): number;
7016
7112
  }
7017
7113
 
7018
- export function getLocaleChangedEvent(): VcsEvent<string>;
7019
-
7020
7114
  /**
7021
7115
  * returns the default browserLocale, if not possible 'en'
7022
7116
  */
7023
7117
  export function detectBrowserLocale(): string;
7024
7118
 
7025
- export function getCurrentLocale(): string;
7026
-
7027
- export function setCurrentLocale(value: string): void;
7028
-
7029
7119
  export interface MapCollectionInitializationError {
7030
7120
  error: Error;
7031
7121
  map: VcsMap;
@@ -7399,6 +7489,12 @@ export class ViewPoint extends VcsObject {
7399
7489
 
7400
7490
  export class VcsApp {
7401
7491
  readonly id: string;
7492
+ /**
7493
+ * sets the locale of the vcsApp and the linked layerCollection.
7494
+ * This will trigger the localeChanged Event.
7495
+ */
7496
+ locale: any;
7497
+ readonly localeChanged: VcsEvent<string>;
7402
7498
  readonly maps: OverrideMapCollection;
7403
7499
  readonly layers: OverrideLayerCollection;
7404
7500
  readonly obliqueCollections: OverrideCollection<ObliqueCollection>;
package/index.js CHANGED
@@ -116,7 +116,6 @@ export { default as ClippingObject } from './src/util/clipping/clippingObject.js
116
116
  export { default as ClippingObjectManager } from './src/util/clipping/clippingObjectManager.js';
117
117
  export { createClippingPlaneCollection, copyClippingPlanesToCollection, clearClippingPlanes, setClippingPlanes, createClippingFeature, getClippingOptions } from './src/util/clipping/clippingPlaneHelper.js';
118
118
  export { default as Collection } from './src/util/collection.js';
119
- export { getShortLocaleDate, getShortLocaleTime, getISODateString, getDayOfYear, isLeapYear } from './src/util/dateTime.js';
120
119
  export { default as ExclusiveManager } from './src/util/exclusiveManager.js';
121
120
  export { default as Extent } from './src/util/extent.js';
122
121
  export { validateCircle, default as circleToCesium } from './src/util/featureconverter/circleToCesium.js';
@@ -131,7 +130,7 @@ export { getFlatCoordinatesFromSimpleGeometry, getFlatCoordinatesFromGeometry, c
131
130
  export { default as IndexedCollection } from './src/util/indexedCollection.js';
132
131
  export { isMobile } from './src/util/isMobile.js';
133
132
  export { default as LayerCollection } from './src/util/layerCollection.js';
134
- export { getLocaleChangedEvent, detectBrowserLocale, getCurrentLocale, setCurrentLocale } from './src/util/locale.js';
133
+ export { detectBrowserLocale } from './src/util/locale.js';
135
134
  export { default as MapCollection } from './src/util/mapCollection.js';
136
135
  export { coordinateAtDistance, initialBearingBetweenCoords, cartesian2DDistance, cartesian3DDistance } from './src/util/math.js';
137
136
  export { isOverrideCollection, default as makeOverrideCollection } from './src/util/overrideCollection.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcmap/core",
3
- "version": "5.0.0-rc.12",
3
+ "version": "5.0.0-rc.13",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -5,7 +5,6 @@ import Extent from '../util/extent.js';
5
5
  import { vcsLayerName } from './layerSymbols.js';
6
6
  import LayerState from './layerState.js';
7
7
  import VcsEvent from '../vcsEvent.js';
8
- import { getCurrentLocale, getLocaleChangedEvent } from '../util/locale.js';
9
8
  import { layerClassRegistry } from '../classRegistry.js';
10
9
  import GlobalHider from './globalHider.js';
11
10
 
@@ -187,16 +186,10 @@ class Layer extends VcsObject {
187
186
 
188
187
  /**
189
188
  * @type {string|Object}
190
- * @private
189
+ * @protected
191
190
  */
192
191
  this._url = options.url;
193
192
 
194
- /**
195
- * @type {Function}
196
- * @private
197
- */
198
- this._localeChangedListener = null;
199
-
200
193
  /**
201
194
  * @type {number}
202
195
  * @private
@@ -271,6 +264,12 @@ class Layer extends VcsObject {
271
264
  * @api
272
265
  */
273
266
  this.featureProvider = undefined;
267
+
268
+ /**
269
+ * @type {string}
270
+ * @private
271
+ */
272
+ this._locale = 'en';
274
273
  }
275
274
 
276
275
  /**
@@ -335,9 +334,8 @@ class Layer extends VcsObject {
335
334
  if (typeof this._url === 'string') {
336
335
  return this._url;
337
336
  }
338
- const locale = getCurrentLocale();
339
- if (this._url[locale]) {
340
- return this._url[locale];
337
+ if (this._url[this._locale]) {
338
+ return this._url[this._locale];
341
339
  }
342
340
  return Object.values(this._url)[0];
343
341
  }
@@ -445,6 +443,29 @@ class Layer extends VcsObject {
445
443
  }
446
444
  }
447
445
 
446
+ /**
447
+ * returns the currently set locale. Can be used to provide locale specific URLs.
448
+ * @type {string}
449
+ */
450
+ get locale() {
451
+ return this._locale;
452
+ }
453
+
454
+ /**
455
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
456
+ * @param {string} value
457
+ */
458
+ set locale(value) {
459
+ check(value, String);
460
+
461
+ if (this._locale !== value) {
462
+ this._locale = value;
463
+ if (this._url && typeof this._url === 'object' && this._url[this._locale]) {
464
+ this.reload();
465
+ }
466
+ }
467
+ }
468
+
448
469
  /**
449
470
  * creates an array of layer implementations for the given map.
450
471
  * @param {import("@vcmap/core").VcsMap} map Map
@@ -540,25 +561,11 @@ class Layer extends VcsObject {
540
561
  return null;
541
562
  }
542
563
 
543
- /**
544
- * recreates the implementations on locale change, if the url of this layer is an Object
545
- * @param {string} locale
546
- * @private
547
- */
548
- _handleLocaleChange(locale) {
549
- if (this._url && typeof this._url === 'object' && this._url[locale]) {
550
- this.reload();
551
- }
552
- }
553
-
554
564
  /**
555
565
  * initializes the layer, can be used to defer loading
556
566
  * @returns {Promise<void>}
557
567
  */
558
568
  initialize() {
559
- if (!this.initialized) {
560
- this._localeChangedListener = getLocaleChangedEvent().addEventListener(this._handleLocaleChange.bind(this));
561
- }
562
569
  this._initialized = true;
563
570
  return Promise.resolve();
564
571
  }
@@ -779,10 +786,6 @@ class Layer extends VcsObject {
779
786
  impl.destroy();
780
787
  });
781
788
 
782
- if (this._localeChangedListener) {
783
- this._localeChangedListener();
784
- this._localeChangedListener = null;
785
- }
786
789
  this._initialized = false;
787
790
  this._implementations.clear();
788
791
  this.stateChanged.destroy();
@@ -62,6 +62,26 @@ class MVTTileProvider extends TileProvider {
62
62
  this._MVTFormat = new MVT({ featureClass: Feature });
63
63
  }
64
64
 
65
+ /**
66
+ * @type {string}
67
+ */
68
+ get locale() {
69
+ return super.locale;
70
+ }
71
+
72
+ /**
73
+ * sets the locale and clears the Cache if the URL is a locale aware Object.
74
+ * @param {string} value
75
+ */
76
+ set locale(value) {
77
+ if (this.locale !== value) {
78
+ super.locale = value;
79
+ if (this.url.includes('{locale}')) {
80
+ this.clearCache();
81
+ }
82
+ }
83
+ }
84
+
65
85
  /**
66
86
  * @inheritDoc
67
87
  * @param {number} x
@@ -71,7 +91,7 @@ class MVTTileProvider extends TileProvider {
71
91
  */
72
92
  async loader(x, y, z) {
73
93
  const rectangle = this.tilingScheme.tileXYToRectangle(x, y, z);
74
- const url = getURL(this.url, x, y, z, rectangle);
94
+ const url = getURL(this.url, x, y, z, rectangle, this.locale);
75
95
  const extent = rectangleToExtent(rectangle);
76
96
  const center = getCenter(extent);
77
97
  const data = await requestArrayBuffer(url);
@@ -1,5 +1,6 @@
1
1
  import { v4 as uuidv4 } from 'uuid';
2
2
  import RBush from 'rbush';
3
+ import { check } from '@vcsuite/check';
3
4
  import { Rectangle, Math as CesiumMath, WebMercatorTilingScheme, Cartographic } from '@vcmap/cesium';
4
5
  import LRUCache from 'ol/structs/LRUCache.js';
5
6
  import { buffer, createOrUpdateFromCoordinate } from 'ol/extent.js';
@@ -176,6 +177,12 @@ class TileProvider extends VcsObject {
176
177
  * @api
177
178
  */
178
179
  this.tileLoadedEvent = new VcsEvent();
180
+
181
+ /**
182
+ * @type {string}
183
+ * @private
184
+ */
185
+ this._locale = 'en';
179
186
  }
180
187
 
181
188
  /**
@@ -188,6 +195,26 @@ class TileProvider extends VcsObject {
188
195
  return this._tileCacheSize;
189
196
  }
190
197
 
198
+
199
+ /**
200
+ * @type {string}
201
+ */
202
+ get locale() {
203
+ return this._locale;
204
+ }
205
+
206
+ /**
207
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
208
+ * @param {string} value
209
+ */
210
+ set locale(value) {
211
+ check(value, String);
212
+ if (this._locale !== value) {
213
+ this._locale = value;
214
+ }
215
+ }
216
+
217
+
191
218
  /**
192
219
  * @param {number} value
193
220
  * @returns {Promise<*>}
@@ -1,7 +1,6 @@
1
1
  import { Math as CesiumMath, Rectangle } from '@vcmap/cesium';
2
2
  import { parseGeoJSON } from '../geojsonHelpers.js';
3
3
  import TileProvider from './tileProvider.js';
4
- import { getCurrentLocale } from '../../util/locale.js';
5
4
  import { requestJson } from '../../util/fetch.js';
6
5
  import { tileProviderClassRegistry } from '../../classRegistry.js';
7
6
 
@@ -14,16 +13,17 @@ import { tileProviderClassRegistry } from '../../classRegistry.js';
14
13
  /**
15
14
  * replaces {x}, {y}, {z} with the x, y, z tiling coordinates
16
15
  * replaces {minx}, {miny}, {maxx}, {maxy} with extent of the tile if tilingExtent is provided
17
- * replaces {locale} with the current locale
16
+ * replaces {locale} with the given locale
18
17
  *
19
18
  * @param {string} url
20
19
  * @param {number} x
21
20
  * @param {number} y
22
21
  * @param {number} z
23
22
  * @param {import("@vcmap/cesium").Rectangle=} tilingExtent
23
+ * @param {string=} locale
24
24
  * @returns {string}
25
25
  */
26
- export function getURL(url, x, y, z, tilingExtent) {
26
+ export function getURL(url, x, y, z, tilingExtent, locale = 'en') {
27
27
  let replacedURL = url;
28
28
  if (tilingExtent) {
29
29
  const southwest = Rectangle.southwest(tilingExtent);
@@ -43,7 +43,7 @@ export function getURL(url, x, y, z, tilingExtent) {
43
43
  .replace(/\{x\}/, String(x))
44
44
  .replace(/\{y\}/, String(y))
45
45
  .replace(/\{z\}/, String(z))
46
- .replace(/\{locale\}/, getCurrentLocale());
46
+ .replace(/\{locale\}/, locale);
47
47
  return replacedURL;
48
48
  }
49
49
 
@@ -87,6 +87,27 @@ class URLTemplateTileProvider extends TileProvider {
87
87
  this.url = options.url || defaultOptions.url;
88
88
  }
89
89
 
90
+
91
+ /**
92
+ * @type {string}
93
+ */
94
+ get locale() {
95
+ return super.locale;
96
+ }
97
+
98
+ /**
99
+ * sets the locale and clears the Cache if the URL is a locale aware Object.
100
+ * @param {string} value
101
+ */
102
+ set locale(value) {
103
+ if (this.locale !== value) {
104
+ super.locale = value;
105
+ if (this.url.includes('{locale}')) {
106
+ this.clearCache();
107
+ }
108
+ }
109
+ }
110
+
90
111
  /**
91
112
  * @inheritDoc
92
113
  * @param {number} x
@@ -96,7 +117,7 @@ class URLTemplateTileProvider extends TileProvider {
96
117
  */
97
118
  async loader(x, y, z) {
98
119
  const rectangle = this.tilingScheme.tileXYToRectangle(x, y, z);
99
- const url = getURL(this.url, x, y, z, rectangle);
120
+ const url = getURL(this.url, x, y, z, rectangle, this.locale);
100
121
  const data = await requestJson(url);
101
122
  const { features } = parseGeoJSON(data, { dynamicStyle: true });
102
123
  return features;
@@ -138,6 +138,9 @@ class VectorTileLayer extends FeatureLayer {
138
138
  this.tileProvider = options.tileProvider instanceof TileProvider ? // XXX this now throws if not passing in a tileProvider.
139
139
  options.tileProvider :
140
140
  getObjectFromClassRegistry(tileProviderClassRegistry, options.tileProvider);
141
+ if (this.tileProvider) {
142
+ this.tileProvider.locale = this.locale;
143
+ }
141
144
 
142
145
  /**
143
146
  * @type {number|undefined}
@@ -177,6 +180,25 @@ class VectorTileLayer extends FeatureLayer {
177
180
  this._styleZIndex = 0;
178
181
  }
179
182
 
183
+ /**
184
+ * returns the currently set locale. Can be used to provide locale specific URLs.
185
+ * @type {string}
186
+ */
187
+ get locale() {
188
+ return super.locale;
189
+ }
190
+
191
+ /**
192
+ * sets the locale and reloads the layer the if the URL is a locale aware Object.
193
+ * @param {string} value
194
+ */
195
+ set locale(value) {
196
+ if (this.tileProvider) {
197
+ this.tileProvider.locale = super.locale;
198
+ }
199
+ super.locale = value;
200
+ }
201
+
180
202
  /**
181
203
  * initializes the layer, can be used to defer loading
182
204
  * @returns {Promise<void>}
@@ -70,6 +70,15 @@ class LayerCollection extends IndexedCollection {
70
70
  * @private
71
71
  */
72
72
  this._globalHider = new GlobalHider();
73
+
74
+ /**
75
+ * Locale for this layerCollection, will be synchronized by the vcsApp, if part of an vcsApp.
76
+ * This Locale will be set on all Member Layers. On setting the Locale this will trigger a reload of all locale
77
+ * aware layers.
78
+ * @type {string}
79
+ * @private
80
+ */
81
+ this._locale = 'en';
73
82
  }
74
83
 
75
84
  /**
@@ -102,6 +111,27 @@ class LayerCollection extends IndexedCollection {
102
111
  });
103
112
  }
104
113
 
114
+ /**
115
+ * @type {string}
116
+ */
117
+ get locale() {
118
+ return this._locale;
119
+ }
120
+
121
+ /**
122
+ * @param {string} value
123
+ */
124
+ set locale(value) {
125
+ check(value, String);
126
+
127
+ if (this._locale !== value) {
128
+ this._locale = value;
129
+ [...this].forEach((layer) => {
130
+ layer.locale = this._locale;
131
+ });
132
+ }
133
+ }
134
+
105
135
  /**
106
136
  * @param {import("@vcmap/core").Layer} layer
107
137
  * @private
@@ -188,6 +218,8 @@ class LayerCollection extends IndexedCollection {
188
218
 
189
219
  /**
190
220
  * Adds a layer to the collection. Can optionally be passed an index at which to insert the layer.
221
+ * The layer locale will be set to the same locale of the layerCollection. This will trigger a forceRedraw
222
+ * of the layer if the layer locale is different and the layer is locale aware.
191
223
  * @param {import("@vcmap/core").Layer} layer
192
224
  * @param {number=} index
193
225
  * @returns {number|null} returns the layer index or null, if the layers name is not unique
@@ -202,6 +234,7 @@ class LayerCollection extends IndexedCollection {
202
234
  if (insertedAt != null) {
203
235
  layer[this._zIndexSymbol] = layer.zIndex;
204
236
  layer.setGlobalHider(this._globalHider);
237
+ layer.locale = this.locale;
205
238
  this._ensureLocalZIndex(layer);
206
239
  this._listenToLayerEvents(layer);
207
240
  this.exclusiveManager.registerLayer(layer);
@@ -1,20 +1,4 @@
1
- import VcsEvent from '../vcsEvent.js';
2
-
3
- /**
4
- * @type {VcsEvent<string>}
5
- */
6
- let localeChangedEvent;
7
-
8
- /**
9
- * @returns {VcsEvent<string>}
10
- */
11
- export function getLocaleChangedEvent() {
12
- if (!localeChangedEvent) {
13
- localeChangedEvent = new VcsEvent();
14
- }
15
- return localeChangedEvent;
16
- }
17
-
1
+ /* eslint-disable import/prefer-default-export */
18
2
  /**
19
3
  * returns the default browserLocale, if not possible 'en'
20
4
  * @returns {string}
@@ -26,28 +10,3 @@ export function detectBrowserLocale() {
26
10
  }
27
11
  return 'en';
28
12
  }
29
-
30
- /**
31
- * @type {string}
32
- */
33
- let currentLocale;
34
-
35
- /**
36
- * @returns {string}
37
- */
38
- export function getCurrentLocale() {
39
- if (!currentLocale) {
40
- currentLocale = detectBrowserLocale();
41
- }
42
- return currentLocale;
43
- }
44
-
45
- /**
46
- * @param {string} value
47
- */
48
- export function setCurrentLocale(value) {
49
- if (typeof value === 'string') {
50
- currentLocale = value;
51
- getLocaleChangedEvent().raiseEvent(value);
52
- }
53
- }
package/src/vcsApp.js CHANGED
@@ -33,6 +33,7 @@ import ClassRegistry, {
33
33
  styleClassRegistry,
34
34
  tileProviderClassRegistry,
35
35
  } from './classRegistry.js';
36
+ import { detectBrowserLocale } from './util/locale.js';
36
37
 
37
38
  /**
38
39
  * @returns {import("@vcsuite/logger").Logger}
@@ -69,6 +70,20 @@ class VcsApp {
69
70
 
70
71
  const getDynamicContextId = () => this._dynamicContext.id;
71
72
 
73
+ /**
74
+ * represents the current Locale.
75
+ * @type {string}
76
+ * @private
77
+ */
78
+ this._locale = detectBrowserLocale();
79
+
80
+ /**
81
+ * fires if the current Locale changes.
82
+ * @type {VcsEvent<string>}
83
+ * @private
84
+ */
85
+ this._localeChanged = new VcsEvent();
86
+
72
87
  /**
73
88
  * @type {OverrideClassRegistry<VcsMap>}
74
89
  * @private
@@ -104,6 +119,8 @@ class VcsApp {
104
119
  Layer,
105
120
  getLayerIndex,
106
121
  );
122
+ this._layers.locale = this.locale;
123
+
107
124
  /**
108
125
  * @type {OverrideCollection<import("@vcmap/core").ObliqueCollection>}
109
126
  * @private
@@ -184,6 +201,7 @@ class VcsApp {
184
201
  * @private
185
202
  */
186
203
  this._featureProviderClassRegsitry = new OverrideClassRegistry(featureProviderClassRegistry);
204
+
187
205
  vcsApps.set(this._id, this);
188
206
  }
189
207
 
@@ -193,6 +211,40 @@ class VcsApp {
193
211
  */
194
212
  get id() { return this._id; }
195
213
 
214
+ /**
215
+ * @returns {string}
216
+ */
217
+ get locale() {
218
+ return this._locale;
219
+ }
220
+
221
+ /**
222
+ * sets the locale of the vcsApp and the linked layerCollection.
223
+ * This will trigger the localeChanged Event.
224
+ * @param {string} value new locale with 2 letters
225
+ */
226
+ set locale(value) {
227
+ check(value, String);
228
+
229
+ if (value.length !== 2) {
230
+ getLogger().warning('Provide a valid locale, for example "en", "de" with max. 2 letters');
231
+ return;
232
+ }
233
+ if (this._locale !== value) {
234
+ this._locale = value;
235
+ this.layers.locale = value;
236
+ this._localeChanged.raiseEvent(value);
237
+ }
238
+ }
239
+
240
+ /**
241
+ * @type {VcsEvent<string>}
242
+ * @readonly
243
+ */
244
+ get localeChanged() {
245
+ return this._localeChanged;
246
+ }
247
+
196
248
  /**
197
249
  * @type {OverrideMapCollection}
198
250
  * @readonly
@@ -454,6 +506,7 @@ class VcsApp {
454
506
  this._featureProviderClassRegsitry.destroy();
455
507
  this.destroyed.raiseEvent();
456
508
  this.destroyed.destroy();
509
+ this.localeChanged.destroy();
457
510
  }
458
511
  }
459
512
 
@@ -1,60 +0,0 @@
1
- /**
2
- * @param {Date} date
3
- * @param {string=} locale
4
- * @returns {string}
5
- */
6
- export function getShortLocaleDate(date, locale) {
7
- // dateStyle is not within the standard yet
8
- // @ts-ignore
9
- return new Intl.DateTimeFormat(locale, { dateStyle: 'short' }).format(date);
10
- }
11
-
12
- /**
13
- * @param {Date} date
14
- * @param {string=} locale
15
- * @returns {string}
16
- */
17
- export function getShortLocaleTime(date, locale) {
18
- // timeStyle is not within the standard yet
19
- // @ts-ignore
20
- return new Intl.DateTimeFormat(locale, { timeStyle: 'short' }).format(date);
21
- }
22
-
23
- /**
24
- * @param {Date} date
25
- * @returns {string}
26
- */
27
- export function getISODateString(date) {
28
- const month = date.getMonth() + 1;
29
- const day = date.getDate();
30
- return `${date.getFullYear()}-${month > 9 ? '' : 0}${month}-${day > 9 ? '' : 0}${day}`;
31
- }
32
-
33
- /**
34
- * @param {Date} date
35
- * @returns {number}
36
- */
37
- export function getDayOfYear(date) {
38
- const start = new Date(date.getFullYear(), 0, 0);
39
- // TS cant handle date manipulation
40
- // @ts-ignore
41
- const diff = (date - start) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000);
42
- const oneDay = 1000 * 60 * 60 * 24;
43
- return Math.floor(diff / oneDay);
44
- }
45
-
46
- /**
47
- * @param {Date} date
48
- * @returns {boolean}
49
- */
50
- export function isLeapYear(date) {
51
- const currentYear = date.getFullYear();
52
- if (currentYear % 4 !== 0) {
53
- return false;
54
- } else if (currentYear % 100 !== 0) {
55
- return true;
56
- } else if (currentYear % 400 !== 0) {
57
- return false;
58
- }
59
- return true;
60
- }