itowns 2.44.3-next.30 → 2.44.3-next.32

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.
@@ -20,6 +20,15 @@ function mergeCollections(collections) {
20
20
  return collection;
21
21
  }
22
22
 
23
+ // A deprecated (but still in use) Mapbox spec allows using 'ref' as a propertie to reference an other layer
24
+ // instead of duplicating the following properties: 'type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'
25
+ function getPropertiesFromRefLayer(layers, layer) {
26
+ const refLayer = layers.filter(l => l.id === layer.ref)[0];
27
+ ['type', 'source', 'source-layer', 'minzoom', 'maxzoom', 'filter', 'layout'].forEach(prop => {
28
+ layer[prop] = refLayer[prop];
29
+ });
30
+ }
31
+
23
32
  /**
24
33
  * VectorTilesSource are object containing informations on how to fetch vector
25
34
  * tiles resources.
@@ -69,36 +78,41 @@ class VectorTilesSource extends TMSSource {
69
78
  let promise;
70
79
  this.isVectorTileSource = true;
71
80
  this.accessToken = source.accessToken;
81
+ let mvtStyleUrl;
72
82
  if (source.style) {
73
83
  if (typeof source.style == 'string') {
74
- const styleUrl = urlParser.normalizeStyleURL(source.style, this.accessToken);
75
- promise = Fetcher.json(styleUrl, this.networkOptions);
84
+ mvtStyleUrl = urlParser.normalizeStyleURL(source.style, this.accessToken);
85
+ promise = Fetcher.json(mvtStyleUrl, this.networkOptions);
76
86
  } else {
77
87
  promise = Promise.resolve(source.style);
78
88
  }
79
89
  } else {
80
90
  throw new Error('New VectorTilesSource: style is required');
81
91
  }
82
- this.whenReady = promise.then(style => {
83
- this.jsonStyle = style;
84
- const baseurl = source.sprite || style.sprite;
92
+ this.whenReady = promise.then(mvtStyle => {
93
+ this.jsonStyle = mvtStyle;
94
+ let baseurl = source.sprite || mvtStyle.sprite;
85
95
  if (baseurl) {
96
+ baseurl = new URL(baseurl, mvtStyleUrl).toString();
86
97
  const spriteUrl = urlParser.normalizeSpriteURL(baseurl, '', '.json', this.accessToken);
87
98
  return Fetcher.json(spriteUrl, this.networkOptions).then(sprites => {
88
99
  this.sprites = sprites;
89
100
  const imgUrl = urlParser.normalizeSpriteURL(baseurl, '', '.png', this.accessToken);
90
101
  this.sprites.source = imgUrl;
91
- return style;
102
+ return mvtStyle;
92
103
  });
93
104
  }
94
- return style;
95
- }).then(style => {
96
- style.layers.forEach((layer, order) => {
105
+ return mvtStyle;
106
+ }).then(mvtStyle => {
107
+ mvtStyle.layers.forEach((layer, order) => {
97
108
  layer.sourceUid = this.uid;
98
109
  if (layer.type === 'background') {
99
110
  this.backgroundLayer = layer;
100
111
  } else if (ffilter(layer)) {
101
- const style = Style.setFromVectorTileLayer(layer, this.sprites, order, this.symbolToCircle);
112
+ if (layer['source-layer'] === undefined) {
113
+ getPropertiesFromRefLayer(mvtStyle.layers, layer);
114
+ }
115
+ const style = Style.setFromVectorTileLayer(layer, this.sprites, this.symbolToCircle);
102
116
  this.styles[layer.id] = style;
103
117
  if (!this.layers[layer['source-layer']]) {
104
118
  this.layers[layer['source-layer']] = [];
@@ -106,20 +120,18 @@ class VectorTilesSource extends TMSSource {
106
120
  this.layers[layer['source-layer']].push({
107
121
  id: layer.id,
108
122
  order,
109
- filterExpression: featureFilter(layer.filter),
110
- zoom: {
111
- min: layer.minzoom || 0,
112
- max: layer.maxzoom || 24
113
- }
123
+ filterExpression: featureFilter(layer.filter)
114
124
  });
115
125
  }
116
126
  });
117
127
  if (this.url == '.') {
118
- const TMSUrlList = Object.values(style.sources).map(sourceVT => {
128
+ const TMSUrlList = Object.values(mvtStyle.sources).map(sourceVT => {
119
129
  if (sourceVT.url) {
130
+ sourceVT.url = new URL(sourceVT.url, mvtStyleUrl).toString();
120
131
  const urlSource = urlParser.normalizeSourceURL(sourceVT.url, this.accessToken);
121
132
  return Fetcher.json(urlSource, this.networkOptions).then(tileJSON => {
122
133
  if (tileJSON.tiles[0]) {
134
+ tileJSON.tiles[0] = decodeURIComponent(new URL(tileJSON.tiles[0], urlSource).toString());
123
135
  return toTMSUrl(tileJSON.tiles[0]);
124
136
  }
125
137
  });
@@ -130,7 +142,7 @@ class VectorTilesSource extends TMSSource {
130
142
  });
131
143
  return Promise.all(TMSUrlList);
132
144
  }
133
- return Promise.resolve([this.url]);
145
+ return Promise.resolve([toTMSUrl(this.url)]);
134
146
  }).then(TMSUrlList => {
135
147
  this.urls = Array.from(new Set(TMSUrlList));
136
148
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.44.3-next.30",
3
+ "version": "2.44.3-next.32",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",