itowns 2.42.1-next.14 → 2.42.1-next.15

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.
@@ -203,7 +203,7 @@ var _default = {
203
203
  _in.crs = _in.crs || readCRS(json);
204
204
  if (out.filteringExtent) {
205
205
  if (typeof out.filteringExtent == 'boolean') {
206
- out.filterExtent = json.extent.as(_in.crs);
206
+ out.filterExtent = options.extent.as(_in.crs);
207
207
  } else if (out.filteringExtent.isExtent) {
208
208
  out.filterExtent = out.filteringExtent;
209
209
  }
@@ -118,12 +118,12 @@ function readPBF(file, options) {
118
118
  }
119
119
 
120
120
  // x,y,z tile coordinates
121
- const x = file.extent.col;
122
- const z = file.extent.zoom;
121
+ const x = options.extent.col;
122
+ const z = options.extent.zoom;
123
123
  // We need to move from TMS to Google/Bing/OSM coordinates
124
124
  // https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/
125
125
  // Only if the layer.origin is top
126
- const y = options.in.isInverted ? file.extent.row : (1 << z) - file.extent.row - 1;
126
+ const y = options.in.isInverted ? options.extent.row : (1 << z) - options.extent.row - 1;
127
127
  const collection = new _Feature.FeatureCollection(options.out);
128
128
  const vFeature = vectorTile.layers[sourceLayers[0]];
129
129
  // TODO: verify if size is correct because is computed with only one feature (vFeature).
@@ -141,7 +141,7 @@ function readPBF(file, options) {
141
141
  const vtFeature = sourceLayer.feature(i);
142
142
  vtFeature.tileNumbers = {
143
143
  x,
144
- y: file.extent.row,
144
+ y: options.extent.row,
145
145
  z
146
146
  };
147
147
  const layers = options.in.layers[layer_id].filter(l => l.filterExpression.filter({
@@ -169,7 +169,7 @@ function readPBF(file, options) {
169
169
  collection.features.sort((a, b) => a.order - b.order);
170
170
  // TODO verify if is needed to updateExtent for previous features.
171
171
  collection.updateExtent();
172
- collection.extent = file.extent;
172
+ collection.extent = options.extent;
173
173
  collection.isInverted = options.in.isInverted;
174
174
  return Promise.resolve(collection);
175
175
  }
@@ -205,6 +205,37 @@ var _default = {
205
205
  }
206
206
  return Promise.resolve(all);
207
207
  });
208
+ },
209
+ get() {
210
+ let format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
211
+ const [type, subtype] = format.split('/');
212
+ switch (type) {
213
+ case 'application':
214
+ switch (subtype) {
215
+ case 'geo+json':
216
+ case 'json':
217
+ return this.json;
218
+ case 'kml':
219
+ case 'gpx':
220
+ return this.xml;
221
+ case 'x-protobuf;type=mapbox-vector':
222
+ case 'gtx':
223
+ return this.arrayBuffer;
224
+ case 'isg':
225
+ case 'gdf':
226
+ default:
227
+ return this.text;
228
+ }
229
+ case 'image':
230
+ switch (subtype) {
231
+ case 'x-bil;bits=32':
232
+ return this.textureFloat;
233
+ default:
234
+ return this.texture;
235
+ }
236
+ default:
237
+ return this.texture;
238
+ }
208
239
  }
209
240
  };
210
241
  exports.default = _default;
@@ -95,7 +95,7 @@ class RasterTile extends THREE.EventDispatcher {
95
95
  this.material.layersNeedUpdate = true;
96
96
  }
97
97
  setTexture(index, texture, offsetScale) {
98
- this.level = texture && index == 0 ? texture.extent.zoom : this.level;
98
+ this.level = texture && texture.extent && index == 0 ? texture.extent.zoom : this.level;
99
99
  this.textures[index] = texture || null;
100
100
  this.offsetScales[index] = offsetScale;
101
101
  this.material.layersNeedUpdate = true;
@@ -23,7 +23,6 @@ class OrientedImageSource extends _Source.default {
23
23
  * to find the good texture for each camera for each panoramic.
24
24
  */
25
25
  constructor(source) {
26
- source.format = source.format || 'json';
27
26
  super(source);
28
27
  this.isOrientedImageSource = true;
29
28
 
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.supportedParsers = exports.supportedFetchers = exports.default = void 0;
7
+ exports.supportedParsers = exports.default = void 0;
8
8
  var _Extent = _interopRequireDefault(require("../Core/Geographic/Extent"));
9
9
  var _GeoJsonParser = _interopRequireDefault(require("../Parser/GeoJsonParser"));
10
10
  var _KMLParser = _interopRequireDefault(require("../Parser/KMLParser"));
@@ -16,9 +16,7 @@ var _VectorTileParser = _interopRequireDefault(require("../Parser/VectorTilePars
16
16
  var _Fetcher = _interopRequireDefault(require("../Provider/Fetcher"));
17
17
  var _Cache = _interopRequireDefault(require("../Core/Scheduler/Cache"));
18
18
  var _Crs = _interopRequireDefault(require("../Core/Geographic/Crs"));
19
- const supportedFetchers = new Map([['image/x-bil;bits=32', _Fetcher.default.textureFloat], ['geojson', _Fetcher.default.json], ['application/json', _Fetcher.default.json], ['application/kml', _Fetcher.default.xml], ['application/gpx', _Fetcher.default.xml], ['application/x-protobuf;type=mapbox-vector', _Fetcher.default.arrayBuffer], ['application/gtx', _Fetcher.default.arrayBuffer], ['application/isg', _Fetcher.default.text], ['application/gdf', _Fetcher.default.text]]);
20
- exports.supportedFetchers = supportedFetchers;
21
- const supportedParsers = new Map([['geojson', _GeoJsonParser.default.parse], ['application/json', _GeoJsonParser.default.parse], ['application/kml', _KMLParser.default.parse], ['application/gpx', _GpxParser.default.parse], ['application/x-protobuf;type=mapbox-vector', _VectorTileParser.default.parse], ['application/gtx', _GTXParser.default.parse], ['application/isg', _ISGParser.default.parse], ['application/gdf', _GDFParser.default.parse]]);
19
+ const supportedParsers = new Map([['application/geo+json', _GeoJsonParser.default.parse], ['application/json', _GeoJsonParser.default.parse], ['application/kml', _KMLParser.default.parse], ['application/gpx', _GpxParser.default.parse], ['application/x-protobuf;type=mapbox-vector', _VectorTileParser.default.parse], ['application/gtx', _GTXParser.default.parse], ['application/isg', _ISGParser.default.parse], ['application/gdf', _GDFParser.default.parse]]);
22
20
  exports.supportedParsers = supportedParsers;
23
21
  const noCache = {
24
22
  getByArray: () => {},
@@ -56,13 +54,6 @@ class InformationsData {
56
54
  */
57
55
  // eslint-disable-next-line
58
56
  class /* istanbul ignore next */ParsingOptions {}
59
- function fetchSourceData(source, extent) {
60
- const url = source.urlFromExtent(extent);
61
- return source.fetcher(url, source.networkOptions).then(f => {
62
- f.extent = extent;
63
- return f;
64
- }, err => source.handlingError(err));
65
- }
66
57
  let uid = 0;
67
58
 
68
59
  /**
@@ -125,8 +116,11 @@ class Source extends InformationsData {
125
116
  this.uid = uid++;
126
117
  this.url = source.url;
127
118
  this.format = source.format;
128
- this.fetcher = source.fetcher || supportedFetchers.get(source.format) || _Fetcher.default.texture;
129
- this.parser = source.parser || supportedParsers.get(source.format) || (d => d);
119
+ this.fetcher = source.fetcher || _Fetcher.default.get(source.format);
120
+ this.parser = source.parser || supportedParsers.get(source.format) || ((d, opt) => {
121
+ d.extent = opt.extent;
122
+ return d;
123
+ });
130
124
  this.isVectorSource = (source.parser || supportedParsers.get(source.format)) != undefined;
131
125
  this.networkOptions = source.networkOptions || {
132
126
  crossOrigin: 'anonymous'
@@ -174,10 +168,12 @@ class Source extends InformationsData {
174
168
  let features = cache.getByArray(key);
175
169
  if (!features) {
176
170
  // otherwise fetch/parse the data
177
- features = cache.setByArray(fetchSourceData(this, extent).then(file => this.parser(file, {
171
+ features = cache.setByArray(this.fetcher(this.urlFromExtent(extent), this.networkOptions).then(file => this.parser(file, {
178
172
  out,
179
- in: this
180
- }), err => this.handlingError(err)), key);
173
+ in: this,
174
+ extent
175
+ })).catch(err => this.handlingError(err)), key);
176
+
181
177
  /* istanbul ignore next */
182
178
  if (this.onParsedFile) {
183
179
  features.then(feat => {
@@ -98,7 +98,6 @@ class TMSSource extends _Source.default {
98
98
  }
99
99
  this.zoom = source.zoom;
100
100
  this.isInverted = source.isInverted || false;
101
- this.url = source.url;
102
101
  this.crs = _Crs.default.formatToTms(source.crs);
103
102
  this.tileMatrixSetLimits = source.tileMatrixSetLimits;
104
103
  this.extentSetlimits = {};
@@ -8,11 +8,24 @@ exports.default = void 0;
8
8
  var _mapboxGlStyleSpec = require("@mapbox/mapbox-gl-style-spec");
9
9
  var _Style = _interopRequireDefault(require("../Core/Style"));
10
10
  var _TMSSource = _interopRequireDefault(require("./TMSSource"));
11
+ var _URLBuilder = _interopRequireDefault(require("../Provider/URLBuilder"));
11
12
  var _Fetcher = _interopRequireDefault(require("../Provider/Fetcher"));
12
13
  var _MapBoxUrlParser = _interopRequireDefault(require("../Parser/MapBoxUrlParser"));
13
14
  function toTMSUrl(url) {
14
15
  return url.replace(/\{/g, '${');
15
16
  }
17
+ function mergeCollections(collections) {
18
+ const collection = collections[0];
19
+ collections.forEach((col, index) => {
20
+ if (index === 0) {
21
+ return;
22
+ }
23
+ col.features.forEach(feature => {
24
+ collection.features.push(feature);
25
+ });
26
+ });
27
+ return collection;
28
+ }
16
29
 
17
30
  /**
18
31
  * @classdesc
@@ -59,6 +72,7 @@ class VectorTilesSource extends _TMSSource.default {
59
72
  source.url = source.url || '.';
60
73
  super(source);
61
74
  const ffilter = source.filter || (() => true);
75
+ this.urls = [];
62
76
  this.layers = {};
63
77
  this.styles = {};
64
78
  let promise;
@@ -88,8 +102,6 @@ class VectorTilesSource extends _TMSSource.default {
88
102
  }
89
103
  return style;
90
104
  }).then(style => {
91
- const s = Object.keys(style.sources)[0];
92
- const os = style.sources[s];
93
105
  style.layers.forEach((layer, order) => {
94
106
  layer.sourceUid = this.uid;
95
107
  if (layer.type === 'background') {
@@ -112,17 +124,30 @@ class VectorTilesSource extends _TMSSource.default {
112
124
  }
113
125
  });
114
126
  if (this.url == '.') {
115
- if (os.url) {
116
- const urlSource = _MapBoxUrlParser.default.normalizeSourceURL(os.url, this.accessToken);
117
- return _Fetcher.default.json(urlSource, this.networkOptions).then(tileJSON => {
118
- if (tileJSON.tiles[0]) {
119
- this.url = toTMSUrl(tileJSON.tiles[0]);
120
- }
121
- });
122
- } else if (os.tiles[0]) {
123
- this.url = toTMSUrl(os.tiles[0]);
124
- }
127
+ const TMSUrlList = Object.values(style.sources).map(sourceVT => {
128
+ if (sourceVT.url) {
129
+ const urlSource = _MapBoxUrlParser.default.normalizeSourceURL(sourceVT.url, this.accessToken);
130
+ return _Fetcher.default.json(urlSource, this.networkOptions).then(tileJSON => {
131
+ if (tileJSON.tiles[0]) {
132
+ return toTMSUrl(tileJSON.tiles[0]);
133
+ }
134
+ });
135
+ } else if (sourceVT.tiles) {
136
+ return Promise.resolve(toTMSUrl(sourceVT.tiles[0]));
137
+ }
138
+ return Promise.reject();
139
+ });
140
+ return Promise.all(TMSUrlList);
125
141
  }
142
+ return Promise.resolve([this.url]);
143
+ }).then(TMSUrlList => {
144
+ this.urls = Array.from(new Set(TMSUrlList));
145
+ });
146
+ }
147
+ urlFromExtent(extent, url) {
148
+ return _URLBuilder.default.xyz(extent, {
149
+ tileMatrixCallback: this.tileMatrixCallback,
150
+ url
126
151
  });
127
152
  }
128
153
  onLayerAdded(options) {
@@ -134,6 +159,30 @@ class VectorTilesSource extends _TMSSource.default {
134
159
  }
135
160
  }
136
161
  }
162
+ loadData(extent, out) {
163
+ const cache = this._featuresCaches[out.crs];
164
+ const key = this.requestToKey(extent);
165
+ // try to get parsed data from cache
166
+ let features = cache.getByArray(key);
167
+ if (!features) {
168
+ // otherwise fetch/parse the data
169
+ features = cache.setByArray(Promise.all(this.urls.map(url => this.fetcher(this.urlFromExtent(extent, url), this.networkOptions).then(file => this.parser(file, {
170
+ out,
171
+ in: this,
172
+ extent
173
+ })))).then(collections => mergeCollections(collections)).catch(err => this.handlingError(err)), key);
174
+
175
+ /* istanbul ignore next */
176
+ if (this.onParsedFile) {
177
+ features.then(feat => {
178
+ this.onParsedFile(feat);
179
+ console.warn('Source.onParsedFile was deprecated');
180
+ return feat;
181
+ });
182
+ }
183
+ }
184
+ return features;
185
+ }
137
186
  }
138
187
  var _default = VectorTilesSource;
139
188
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.42.1-next.14",
3
+ "version": "2.42.1-next.15",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "main": "lib/Main.js",
6
6
  "exports": {