itowns 2.44.3-next.35 → 2.44.3-next.37

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.
@@ -8,38 +8,17 @@ import GTXParser from "../Parser/GTXParser.js";
8
8
  import ISGParser from "../Parser/ISGParser.js";
9
9
  import VectorTileParser from "../Parser/VectorTileParser.js";
10
10
  import Fetcher from "../Provider/Fetcher.js";
11
- import Cache from "../Core/Scheduler/Cache.js";
11
+ // import Cache from 'Core/Scheduler/Cache';
12
+ import { LRUCache } from 'lru-cache';
12
13
 
13
14
  /** @private */
14
15
  export const supportedParsers = new Map([['application/geo+json', GeoJsonParser.parse], ['application/json', GeoJsonParser.parse], ['application/kml', KMLParser.parse], ['application/gpx', GpxParser.parse], ['application/x-protobuf;type=mapbox-vector', VectorTileParser.parse], ['application/gtx', GTXParser.parse], ['application/isg', ISGParser.parse], ['application/gdf', GDFParser.parse]]);
15
16
  const noCache = {
16
- getByArray: () => {},
17
- setByArray: a => a,
17
+ get: () => {},
18
+ set: a => a,
18
19
  clear: () => {}
19
20
  };
20
21
 
21
- /**
22
- * @property {string} crs - data crs projection.
23
- * @property {boolean} isInverted - This option is to be set to the
24
- * correct value, true or false (default being false), if the computation of
25
- * the coordinates needs to be inverted to same scheme as OSM, Google Maps
26
- * or other system. See [this link](
27
- * https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates)
28
- * for more informations.
29
- *
30
- */
31
- class InformationsData {
32
- constructor(options) {
33
- if (options.projection) {
34
- console.warn('Source projection parameter is deprecated, use crs instead.');
35
- options.crs = options.crs || options.projection;
36
- }
37
- if (options.crs) {
38
- CRS.isValid(options.crs);
39
- }
40
- this.crs = options.crs;
41
- }
42
- }
43
22
  /**
44
23
  * This interface describes parsing options.
45
24
  * @typedef {Object} ParsingOptions
@@ -93,13 +72,20 @@ let uid = 0;
93
72
  * depending on the current fetched tile for example</li>
94
73
  * </ul>
95
74
  */
96
- class Source extends InformationsData {
75
+ class Source {
97
76
  /**
98
77
  * @param {Object} source - An object that can contain all properties of a
99
78
  * Source. Only the `url` property is mandatory.
100
79
  */
101
80
  constructor(source) {
102
- super(source);
81
+ if (source.projection) {
82
+ console.warn('Source projection parameter is deprecated, use crs instead.');
83
+ source.crs = source.crs || source.projection;
84
+ }
85
+ if (source.crs) {
86
+ CRS.isValid(source.crs);
87
+ }
88
+ this.crs = source.crs;
103
89
  this.isSource = true;
104
90
  if (!source.url) {
105
91
  throw new Error('New Source: url is required');
@@ -141,8 +127,8 @@ class Source extends InformationsData {
141
127
  urlFromExtent() {
142
128
  throw new Error('In extended Source, you have to implement the method urlFromExtent!');
143
129
  }
144
- requestToKey(extent) {
145
- return [extent.zoom, extent.row, extent.col];
130
+ getDataKey(extent) {
131
+ return `z${extent.zoom}r${extent.row}c${extent.col}`;
146
132
  }
147
133
 
148
134
  /**
@@ -155,23 +141,18 @@ class Source extends InformationsData {
155
141
  */
156
142
  loadData(extent, out) {
157
143
  const cache = this._featuresCaches[out.crs];
158
- const key = this.requestToKey(extent);
144
+ const key = this.getDataKey(extent);
145
+ // console.log('Source.loadData', key);
159
146
  // try to get parsed data from cache
160
- let features = cache.getByArray(key);
147
+ let features = cache.get(key);
161
148
  if (!features) {
162
149
  // otherwise fetch/parse the data
163
- features = cache.setByArray(this.fetcher(this.urlFromExtent(extent), this.networkOptions).then(file => this.parser(file, {
150
+ features = this.fetcher(this.urlFromExtent(extent), this.networkOptions).then(file => this.parser(file, {
164
151
  out,
165
152
  in: this,
166
153
  extent
167
- })).catch(err => this.handlingError(err)), key);
168
- if (this.onParsedFile) {
169
- features.then(feat => {
170
- this.onParsedFile(feat);
171
- console.warn('Source.onParsedFile was deprecated');
172
- return feat;
173
- });
174
- }
154
+ })).catch(err => this.handlingError(err));
155
+ cache.set(key, features);
175
156
  }
176
157
  return features;
177
158
  }
@@ -187,7 +168,9 @@ class Source extends InformationsData {
187
168
  // Cache feature only if it's vector data, the feature are cached in source.
188
169
  // It's not necessary to cache raster in Source,
189
170
  // because it's already cached on layer.
190
- this._featuresCaches[options.out.crs] = this.isVectorSource ? new Cache() : noCache;
171
+ this._featuresCaches[options.out.crs] = this.isVectorSource ? new LRUCache({
172
+ max: 500
173
+ }) : noCache;
191
174
  }
192
175
  }
193
176
 
@@ -164,23 +164,17 @@ class VectorTilesSource extends TMSSource {
164
164
  }
165
165
  loadData(extent, out) {
166
166
  const cache = this._featuresCaches[out.crs];
167
- const key = this.requestToKey(extent);
167
+ const key = this.getDataKey(extent);
168
168
  // try to get parsed data from cache
169
- let features = cache.getByArray(key);
169
+ let features = cache.get(key);
170
170
  if (!features) {
171
171
  // otherwise fetch/parse the data
172
- features = cache.setByArray(Promise.all(this.urls.map(url => this.fetcher(this.urlFromExtent(extent, url), this.networkOptions).then(file => this.parser(file, {
172
+ features = Promise.all(this.urls.map(url => this.fetcher(this.urlFromExtent(extent, url), this.networkOptions).then(file => this.parser(file, {
173
173
  out,
174
174
  in: this,
175
175
  extent
176
- })))).then(collections => mergeCollections(collections)).catch(err => this.handlingError(err)), key);
177
- if (this.onParsedFile) {
178
- features.then(feat => {
179
- this.onParsedFile(feat);
180
- console.warn('Source.onParsedFile was deprecated');
181
- return feat;
182
- });
183
- }
176
+ })))).then(collections => mergeCollections(collections)).catch(err => this.handlingError(err));
177
+ cache.set(key, features);
184
178
  }
185
179
  return features;
186
180
  }
@@ -152,11 +152,11 @@ class WFSSource extends Source {
152
152
  }
153
153
  return super.handlingError(err);
154
154
  }
155
- requestToKey(extent) {
155
+ getDataKey(extent) {
156
156
  if (extent.isTile) {
157
- return super.requestToKey(extent);
157
+ return super.getDataKey(extent);
158
158
  } else {
159
- return [extent.zoom, extent.south, extent.west];
159
+ return `z${extent.zoom}s${extent.south}w${extent.west}`;
160
160
  }
161
161
  }
162
162
  urlFromExtent(extentOrTile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.44.3-next.35",
3
+ "version": "2.44.3-next.37",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",
@@ -66,6 +66,7 @@
66
66
  "copc": "^0.0.6",
67
67
  "earcut": "^3.0.0",
68
68
  "js-priority-queue": "^0.1.5",
69
+ "lru-cache": "^11.0.1",
69
70
  "pbf": "^4.0.1",
70
71
  "shpjs": "^6.1.0",
71
72
  "threads": "^1.7.0"