itowns 2.45.1-next.0 → 2.45.1-next.1

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.
Files changed (185) hide show
  1. package/dist/455.js +2 -0
  2. package/dist/455.js.map +1 -0
  3. package/dist/debug.js +3 -0
  4. package/dist/debug.js.LICENSE.txt +13 -0
  5. package/dist/debug.js.map +1 -0
  6. package/dist/itowns.js +3 -0
  7. package/dist/itowns.js.LICENSE.txt +5 -0
  8. package/dist/itowns.js.map +1 -0
  9. package/dist/itowns_lasparser.js +2 -0
  10. package/dist/itowns_lasparser.js.map +1 -0
  11. package/dist/itowns_lasworker.js +2 -0
  12. package/dist/itowns_lasworker.js.map +1 -0
  13. package/dist/itowns_potree2worker.js +2 -0
  14. package/dist/itowns_potree2worker.js.map +1 -0
  15. package/dist/itowns_widgets.js +2 -0
  16. package/dist/itowns_widgets.js.map +1 -0
  17. package/lib/Controls/FirstPersonControls.js +308 -0
  18. package/lib/Controls/FlyControls.js +175 -0
  19. package/lib/Controls/GlobeControls.js +1178 -0
  20. package/lib/Controls/PlanarControls.js +1025 -0
  21. package/lib/Controls/StateControl.js +432 -0
  22. package/lib/Controls/StreetControls.js +392 -0
  23. package/lib/Converter/Feature2Mesh.js +612 -0
  24. package/lib/Converter/Feature2Texture.js +174 -0
  25. package/lib/Converter/convertToTile.js +70 -0
  26. package/lib/Converter/textureConverter.js +43 -0
  27. package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
  28. package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
  29. package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
  30. package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
  31. package/lib/Core/3DTiles/C3DTFeature.js +110 -0
  32. package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
  33. package/lib/Core/3DTiles/C3DTileset.js +99 -0
  34. package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
  35. package/lib/Core/AnimationPlayer.js +142 -0
  36. package/lib/Core/CopcNode.js +174 -0
  37. package/lib/Core/Deprecated/Undeprecator.js +74 -0
  38. package/lib/Core/EntwinePointTileNode.js +126 -0
  39. package/lib/Core/Feature.js +488 -0
  40. package/lib/Core/Geographic/GeoidGrid.js +108 -0
  41. package/lib/Core/Label.js +222 -0
  42. package/lib/Core/MainLoop.js +209 -0
  43. package/lib/Core/Picking.js +255 -0
  44. package/lib/Core/PointCloudNode.js +42 -0
  45. package/lib/Core/Potree2Node.js +206 -0
  46. package/lib/Core/Potree2PointAttributes.js +139 -0
  47. package/lib/Core/PotreeNode.js +101 -0
  48. package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
  49. package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
  50. package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
  51. package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
  52. package/lib/Core/Prefab/GlobeView.js +155 -0
  53. package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
  54. package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
  55. package/lib/Core/Prefab/PlanarView.js +62 -0
  56. package/lib/Core/Prefab/TileBuilder.js +82 -0
  57. package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
  58. package/lib/Core/Scheduler/Cache.js +17 -0
  59. package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
  60. package/lib/Core/Scheduler/Scheduler.js +294 -0
  61. package/lib/Core/Style.js +660 -0
  62. package/lib/Core/StyleOptions.js +486 -0
  63. package/lib/Core/System/Capabilities.js +63 -0
  64. package/lib/Core/Tile/Tile.js +205 -0
  65. package/lib/Core/Tile/TileGrid.js +49 -0
  66. package/lib/Core/TileGeometry.js +124 -0
  67. package/lib/Core/TileMesh.js +108 -0
  68. package/lib/Core/View.js +1115 -0
  69. package/lib/Layer/C3DTilesLayer.js +459 -0
  70. package/lib/Layer/ColorLayer.js +154 -0
  71. package/lib/Layer/CopcLayer.js +63 -0
  72. package/lib/Layer/ElevationLayer.js +139 -0
  73. package/lib/Layer/EntwinePointTileLayer.js +71 -0
  74. package/lib/Layer/FeatureGeometryLayer.js +77 -0
  75. package/lib/Layer/GeoidLayer.js +80 -0
  76. package/lib/Layer/GeometryLayer.js +233 -0
  77. package/lib/Layer/InfoLayer.js +64 -0
  78. package/lib/Layer/LabelLayer.js +469 -0
  79. package/lib/Layer/Layer.js +335 -0
  80. package/lib/Layer/LayerUpdateState.js +89 -0
  81. package/lib/Layer/LayerUpdateStrategy.js +80 -0
  82. package/lib/Layer/OGC3DTilesLayer.js +543 -0
  83. package/lib/Layer/OrientedImageLayer.js +227 -0
  84. package/lib/Layer/PointCloudLayer.js +405 -0
  85. package/lib/Layer/Potree2Layer.js +171 -0
  86. package/lib/Layer/PotreeLayer.js +72 -0
  87. package/lib/Layer/RasterLayer.js +37 -0
  88. package/lib/Layer/ReferencingLayerProperties.js +62 -0
  89. package/lib/Layer/TiledGeometryLayer.js +459 -0
  90. package/lib/Loader/LASLoader.js +193 -0
  91. package/lib/Loader/Potree2BrotliLoader.js +261 -0
  92. package/lib/Loader/Potree2Loader.js +207 -0
  93. package/lib/Main.js +113 -0
  94. package/lib/MainBundle.js +4 -0
  95. package/lib/Parser/B3dmParser.js +174 -0
  96. package/lib/Parser/CameraCalibrationParser.js +94 -0
  97. package/lib/Parser/GDFParser.js +72 -0
  98. package/lib/Parser/GTXParser.js +75 -0
  99. package/lib/Parser/GeoJsonParser.js +212 -0
  100. package/lib/Parser/GpxParser.js +25 -0
  101. package/lib/Parser/ISGParser.js +71 -0
  102. package/lib/Parser/KMLParser.js +25 -0
  103. package/lib/Parser/LASParser.js +137 -0
  104. package/lib/Parser/MapBoxUrlParser.js +83 -0
  105. package/lib/Parser/PntsParser.js +131 -0
  106. package/lib/Parser/Potree2BinParser.js +92 -0
  107. package/lib/Parser/PotreeBinParser.js +106 -0
  108. package/lib/Parser/PotreeCinParser.js +29 -0
  109. package/lib/Parser/ShapefileParser.js +78 -0
  110. package/lib/Parser/VectorTileParser.js +215 -0
  111. package/lib/Parser/XbilParser.js +120 -0
  112. package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
  113. package/lib/Parser/iGLTFLoader.js +168 -0
  114. package/lib/Process/3dTilesProcessing.js +304 -0
  115. package/lib/Process/FeatureProcessing.js +76 -0
  116. package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
  117. package/lib/Process/ObjectRemovalHelper.js +97 -0
  118. package/lib/Process/handlerNodeError.js +23 -0
  119. package/lib/Provider/3dTilesProvider.js +149 -0
  120. package/lib/Provider/DataSourceProvider.js +24 -0
  121. package/lib/Provider/Fetcher.js +233 -0
  122. package/lib/Provider/PointCloudProvider.js +45 -0
  123. package/lib/Provider/TileProvider.js +16 -0
  124. package/lib/Provider/URLBuilder.js +116 -0
  125. package/lib/Renderer/Camera.js +281 -0
  126. package/lib/Renderer/Color.js +56 -0
  127. package/lib/Renderer/ColorLayersOrdering.js +115 -0
  128. package/lib/Renderer/CommonMaterial.js +31 -0
  129. package/lib/Renderer/Label2DRenderer.js +192 -0
  130. package/lib/Renderer/LayeredMaterial.js +243 -0
  131. package/lib/Renderer/OBB.js +150 -0
  132. package/lib/Renderer/OrientedImageCamera.js +118 -0
  133. package/lib/Renderer/OrientedImageMaterial.js +167 -0
  134. package/lib/Renderer/PointsMaterial.js +485 -0
  135. package/lib/Renderer/RasterTile.js +243 -0
  136. package/lib/Renderer/RenderMode.js +31 -0
  137. package/lib/Renderer/Shader/ShaderChunk.js +160 -0
  138. package/lib/Renderer/Shader/ShaderUtils.js +47 -0
  139. package/lib/Renderer/SphereHelper.js +17 -0
  140. package/lib/Renderer/WebXR.js +51 -0
  141. package/lib/Renderer/c3DEngine.js +214 -0
  142. package/lib/Source/C3DTilesGoogleSource.js +74 -0
  143. package/lib/Source/C3DTilesIonSource.js +54 -0
  144. package/lib/Source/C3DTilesSource.js +30 -0
  145. package/lib/Source/CopcSource.js +126 -0
  146. package/lib/Source/EntwinePointTileSource.js +72 -0
  147. package/lib/Source/FileSource.js +188 -0
  148. package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
  149. package/lib/Source/OGC3DTilesIonSource.js +34 -0
  150. package/lib/Source/OGC3DTilesSource.js +21 -0
  151. package/lib/Source/OrientedImageSource.js +59 -0
  152. package/lib/Source/Potree2Source.js +167 -0
  153. package/lib/Source/PotreeSource.js +82 -0
  154. package/lib/Source/Source.js +202 -0
  155. package/lib/Source/TMSSource.js +144 -0
  156. package/lib/Source/VectorTilesSource.js +182 -0
  157. package/lib/Source/WFSSource.js +170 -0
  158. package/lib/Source/WMSSource.js +167 -0
  159. package/lib/Source/WMTSSource.js +92 -0
  160. package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
  161. package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
  162. package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
  163. package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
  164. package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
  165. package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
  166. package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
  167. package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
  168. package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
  169. package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
  170. package/lib/Utils/CameraUtils.js +554 -0
  171. package/lib/Utils/DEMUtils.js +350 -0
  172. package/lib/Utils/FeaturesUtils.js +156 -0
  173. package/lib/Utils/Gradients.js +16 -0
  174. package/lib/Utils/ThreeUtils.js +115 -0
  175. package/lib/Utils/gui/C3DTilesStyle.js +218 -0
  176. package/lib/Utils/gui/Main.js +7 -0
  177. package/lib/Utils/gui/Minimap.js +152 -0
  178. package/lib/Utils/gui/Navigation.js +245 -0
  179. package/lib/Utils/gui/Scale.js +104 -0
  180. package/lib/Utils/gui/Searchbar.js +234 -0
  181. package/lib/Utils/gui/Widget.js +80 -0
  182. package/lib/Utils/placeObjectOnGround.js +136 -0
  183. package/lib/Worker/LASLoaderWorker.js +19 -0
  184. package/lib/Worker/Potree2Worker.js +21 -0
  185. package/package.json +2 -2
@@ -0,0 +1,202 @@
1
+ import { Extent, CRS } from '@itowns/geographic';
2
+ import GeoJsonParser from "../Parser/GeoJsonParser.js";
3
+ import KMLParser from "../Parser/KMLParser.js";
4
+ import GDFParser from "../Parser/GDFParser.js";
5
+ import GpxParser from "../Parser/GpxParser.js";
6
+ import GTXParser from "../Parser/GTXParser.js";
7
+ import ISGParser from "../Parser/ISGParser.js";
8
+ import VectorTileParser from "../Parser/VectorTileParser.js";
9
+ import Fetcher from "../Provider/Fetcher.js";
10
+ // import Cache from 'Core/Scheduler/Cache';
11
+ import { LRUCache } from 'lru-cache';
12
+
13
+ /** @private */
14
+ 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
+ const noCache = {
16
+ get: () => {},
17
+ set: a => a,
18
+ clear: () => {}
19
+ };
20
+
21
+ /**
22
+ * This interface describes parsing options.
23
+ * @typedef {Object} ParsingOptions
24
+ * @property {Source} in - data informations contained in the file.
25
+ * @property {FeatureBuildingOptions|Layer} out - options indicates how the features should be built.
26
+ */
27
+
28
+ let uid = 0;
29
+
30
+ /**
31
+ * Sources are object containing informations on how to fetch resources, from a
32
+ * set source.
33
+ *
34
+ * To extend a Source, it is necessary to implement two functions:
35
+ * `urlFromExtent` and `extentInsideLimit`.
36
+ *
37
+ * @extends InformationsData
38
+ *
39
+ * @property {boolean} isSource - Used to checkout whether this source is a
40
+ * Source. Default is true. You should not change this, as it is used internally
41
+ * for optimisation.
42
+ * @property {number} uid - Unique uid mainly used to store data linked to this
43
+ * source into Cache.
44
+ * @property {string} url - The url of the resources that are fetched.
45
+ * @property {string} format - The format of the resources that are fetched.
46
+ * @property {function} fetcher - The method used to fetch the resources from
47
+ * the source. iTowns provides some methods in {@link Fetcher}, but it can be
48
+ * specified a custom one. This method should return a `Promise` containing the
49
+ * fetched resource. If this property is set, it overrides the chosen fetcher
50
+ * method with `format`.
51
+ * @property {Object} networkOptions - Fetch options (passed directly to
52
+ * `fetch()`), see [the syntax for more information](
53
+ * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Syntax).
54
+ * By default, set to `{ crossOrigin: 'anonymous' }`.
55
+ * @property {string} crs - The crs projection of the resources.
56
+ * @property {string} attribution - The intellectual property rights for the
57
+ * resources.
58
+ * @property {Extent} extent - The extent of the resources.
59
+ * @property {function} parser - The method used to parse the resources attached
60
+ * to the layer. iTowns provides some parsers, visible in the `Parser/` folder.
61
+ * If the method is custom, it should return a `Promise` containing the parsed
62
+ * resource. If this property is set, it overrides the default selected parser
63
+ * method with `source.format`. If `source.format` is also empty, no parsing
64
+ * action is done.
65
+ * <br><br>
66
+ * When calling this method, two parameters are passed:
67
+ * <ul>
68
+ * <li>the fetched data, i.e. the data to parse</li>
69
+ * <li>an {@link ParsingOptions} containing severals properties, set when this method is
70
+ * called: it is specific to each call, so the value of each property can vary
71
+ * depending on the current fetched tile for example</li>
72
+ * </ul>
73
+ */
74
+ class Source {
75
+ /**
76
+ * @param {Object} source - An object that can contain all properties of a
77
+ * Source. Only the `url` property is mandatory.
78
+ */
79
+ constructor(source) {
80
+ if (source.projection) {
81
+ console.warn('Source projection parameter is deprecated, use crs instead.');
82
+ source.crs = source.crs || source.projection;
83
+ }
84
+ if (source.crs) {
85
+ CRS.isValid(source.crs);
86
+ }
87
+ this.crs = source.crs;
88
+ this.isSource = true;
89
+ if (!source.url) {
90
+ throw new Error('New Source: url is required');
91
+ }
92
+ this.uid = uid++;
93
+ this.url = source.url;
94
+ this.format = source.format;
95
+ this.fetcher = source.fetcher || Fetcher.get(source.format);
96
+ this.parser = source.parser || supportedParsers.get(source.format) || ((d, opt) => {
97
+ d.extent = opt.extent;
98
+ return d;
99
+ });
100
+ this.isVectorSource = (source.parser || supportedParsers.get(source.format)) != undefined;
101
+ this.networkOptions = source.networkOptions || {
102
+ crossOrigin: 'anonymous'
103
+ };
104
+ this.attribution = source.attribution;
105
+ /** @type {Promise<any>} */
106
+ this.whenReady = Promise.resolve();
107
+ this._featuresCaches = {};
108
+ if (source.extent && !source.extent.isExtent) {
109
+ this.extent = new Extent(this.crs).setFromExtent(source.extent);
110
+ } else {
111
+ this.extent = source.extent;
112
+ }
113
+ }
114
+ handlingError(err) {
115
+ throw new Error(err);
116
+ }
117
+
118
+ /**
119
+ * Generates an url from an extent. This url is a link to fetch the
120
+ * resources inside the extent.
121
+ *
122
+ * @param {Extent} extent - Extent to convert in url.
123
+ * @return {string} The URL constructed from the extent.
124
+ */
125
+ // eslint-disable-next-line
126
+ urlFromExtent() {
127
+ throw new Error('In extended Source, you have to implement the method urlFromExtent!');
128
+ }
129
+ getDataKey(extent) {
130
+ return `z${extent.zoom}r${extent.row}c${extent.col}`;
131
+ }
132
+
133
+ /**
134
+ * Load data from cache or Fetch/Parse data.
135
+ * The loaded data is a Feature or Texture.
136
+ *
137
+ * @param {Extent} extent extent requested parsed data.
138
+ * @param {FeatureBuildingOptions|Layer} out The feature returned options
139
+ * @return {FeatureCollection|Texture} The parsed data.
140
+ */
141
+ loadData(extent, out) {
142
+ const cache = this._featuresCaches[out.crs];
143
+ const key = this.getDataKey(extent);
144
+ // console.log('Source.loadData', key);
145
+ // try to get parsed data from cache
146
+ let features = cache.get(key);
147
+ if (!features) {
148
+ // otherwise fetch/parse the data
149
+ features = this.fetcher(this.urlFromExtent(extent), this.networkOptions).then(file => this.parser(file, {
150
+ out,
151
+ in: this,
152
+ extent
153
+ })).catch(err => this.handlingError(err));
154
+ cache.set(key, features);
155
+ }
156
+ return features;
157
+ }
158
+
159
+ /**
160
+ * Called when layer added.
161
+ *
162
+ * @param {object} options
163
+ */
164
+ onLayerAdded(options) {
165
+ // Added new cache by crs
166
+ if (!this._featuresCaches[options.out.crs]) {
167
+ // Cache feature only if it's vector data, the feature are cached in source.
168
+ // It's not necessary to cache raster in Source,
169
+ // because it's already cached on layer.
170
+ this._featuresCaches[options.out.crs] = this.isVectorSource ? new LRUCache({
171
+ max: 500
172
+ }) : noCache;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Called when layer removed.
178
+ *
179
+ * @param {options} [options={}] options
180
+ */
181
+ onLayerRemoved() {
182
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
183
+ // delete unused cache
184
+ const unusedCache = this._featuresCaches[options.unusedCrs];
185
+ if (unusedCache) {
186
+ unusedCache.clear();
187
+ delete this._featuresCaches[options.unusedCrs];
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Tests if an extent is inside the source limits.
193
+ *
194
+ * @param {Extent} extent - Extent to test.
195
+ * @return {boolean} True if the extent is inside the limit, false otherwise.
196
+ */
197
+ // eslint-disable-next-line
198
+ extentInsideLimit() {
199
+ throw new Error('In extented Source, you have to implement the method extentInsideLimit!');
200
+ }
201
+ }
202
+ export default Source;
@@ -0,0 +1,144 @@
1
+ import Source from "./Source.js";
2
+ import URLBuilder from "../Provider/URLBuilder.js";
3
+ import { Extent } from '@itowns/geographic';
4
+ import { globalExtentTMS } from "../Core/Tile/TileGrid.js";
5
+ import Tile from "../Core/Tile/Tile.js";
6
+ const _tile = new Tile('EPSG:4326', 0, 0, 0);
7
+
8
+ /**
9
+ * An object defining the source of resources to get from a
10
+ * [TMS](https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification) server.
11
+ * It inherits from {@link Source}.
12
+ *
13
+ * @extends Source
14
+ *
15
+ * @property {boolean} isTMSSource - Used to checkout whether this source is a
16
+ * TMSSource. Default is true. You should not change this, as it is used
17
+ * internally for optimisation.
18
+ * @property {boolean} isInverted - The isInverted property is to be set to the
19
+ * correct value, true or false (default being false) if the computation of the
20
+ * coordinates needs to be inverted to match the same scheme as OSM, Google Maps
21
+ * or other system. See [this link](
22
+ * https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/)
23
+ * for more information.
24
+ * @property {Object} tileMatrixSetLimits - it describes the available tile for this layer
25
+ * @property {Object} extentSetlimits - these are the extents of the set of identical zoom tiles.
26
+ * @property {Object} zoom - Object containing the minimum and maximum values of
27
+ * the level, to zoom in the source.
28
+ * @property {number} zoom.min - The minimum level of the source. Default value
29
+ * is 0.
30
+ * @property {number} zoom.max - The maximum level of the source. Default value
31
+ * is 20.
32
+ * @property {function} tileMatrixCallback - a method that create a TileMatrix
33
+ * identifier from the zoom level. For example, if set to `(zoomLevel) => 'EPSG:4326:' + zoomLevel`,
34
+ * the TileMatrix that will be fetched at zoom level 5 will be the one with identifier `EPSG:4326:5`.
35
+ * By default, the method returns the input zoom level.
36
+ *
37
+ * @example <caption><b>Source from OpenStreetMap server :</b></caption>
38
+ * // Create the source
39
+ * const tmsSource = new itowns.TMSSource({
40
+ * format: 'image/png',
41
+ * url: 'http://osm.io/styles/${z}/${x}/${y}.png',
42
+ * attribution: {
43
+ * name: 'OpenStreetMap',
44
+ * url: 'http://www.openstreetmap.org/',
45
+ * },
46
+ * crs: 'EPSG:3857',
47
+ * });
48
+ *
49
+ * // Create the layer
50
+ * const colorLayer = new itowns.ColorLayer('OPENSM', {
51
+ * source: tmsSource,
52
+ * });
53
+ *
54
+ * // Add the layer
55
+ * view.addLayer(colorLayer);
56
+ *
57
+ * @example <caption><b>Source from Mapbox server :</b></caption>
58
+ * // Create the source
59
+ * const orthoSource = new itowns.TMSSource({
60
+ * url: 'https://api.mapbox.com/v4/mapbox.satellite/${z}/${x}/${y}.jpg?access_token=' + accessToken,
61
+ * crs: 'EPSG:3857',
62
+ * };
63
+ *
64
+ * // Create the layer
65
+ * const imageryLayer = new itowns.ColorLayer("Ortho", {
66
+ * source: orthoSource,
67
+ * };
68
+ *
69
+ * // Add the layer to the view
70
+ * view.addLayer(imageryLayer);
71
+ */
72
+ class TMSSource extends Source {
73
+ /**
74
+ * @param {Object} source - An object that can contain all properties of a
75
+ * TMSSource and {@link Source}. Only `url` is mandatory.
76
+ */
77
+ constructor(source) {
78
+ source.format = source.format || 'image/png';
79
+ super(source);
80
+ if (!source.crs) {
81
+ throw new Error('New TMSSource/WMTSSource: crs is required');
82
+ }
83
+ this.isTMSSource = true;
84
+ if (!source.extent) {
85
+ // default to the global extent
86
+ this.extent = globalExtentTMS.get(source.crs);
87
+ }
88
+ this.zoom = source.zoom;
89
+ this.isInverted = source.isInverted || false;
90
+ this.crs = source.crs;
91
+ this.tileMatrixSetLimits = source.tileMatrixSetLimits;
92
+ this.extentSetlimits = {};
93
+ this.tileMatrixCallback = source.tileMatrixCallback || (zoomLevel => zoomLevel);
94
+ if (!this.zoom) {
95
+ if (this.tileMatrixSetLimits) {
96
+ const arrayLimits = Object.keys(this.tileMatrixSetLimits);
97
+ const size = arrayLimits.length;
98
+ const maxZoom = Number(arrayLimits[size - 1]);
99
+ this.zoom = {
100
+ min: maxZoom - size + 1,
101
+ max: maxZoom
102
+ };
103
+ } else {
104
+ this.zoom = {
105
+ min: 0,
106
+ max: Infinity
107
+ };
108
+ }
109
+ }
110
+ }
111
+ urlFromExtent(tile) {
112
+ return URLBuilder.xyz(tile, this);
113
+ }
114
+ onLayerAdded(options) {
115
+ super.onLayerAdded(options);
116
+ // Build extents of the set of identical zoom tiles.
117
+ const parent = options.out.parent;
118
+ // The extents crs is chosen to facilitate in raster tile process.
119
+ const crs = parent ? parent.extent.crs : options.out.crs;
120
+ if (this.tileMatrixSetLimits && !this.extentSetlimits[crs]) {
121
+ this.extentSetlimits[crs] = {};
122
+ _tile.crs = this.crs;
123
+ for (let i = this.zoom.max; i >= this.zoom.min; i--) {
124
+ const tmsl = this.tileMatrixSetLimits[i];
125
+ const {
126
+ west,
127
+ north
128
+ } = _tile.set(i, tmsl.minTileRow, tmsl.minTileCol).toExtent(crs);
129
+ const {
130
+ east,
131
+ south
132
+ } = _tile.set(i, tmsl.maxTileRow, tmsl.maxTileCol).toExtent(crs);
133
+ this.extentSetlimits[crs][i] = new Extent(crs, west, east, south, north);
134
+ }
135
+ }
136
+ }
137
+ extentInsideLimit(extent, zoom) {
138
+ // This layer provides data starting at level = layer.source.zoom.min
139
+ // (the zoom.max property is used when building the url to make
140
+ // sure we don't use invalid levels)
141
+ return zoom >= this.zoom.min && zoom <= this.zoom.max && (this.extentSetlimits[extent.crs] == undefined || this.extentSetlimits[extent.crs][zoom].intersectsExtent(extent));
142
+ }
143
+ }
144
+ export default TMSSource;
@@ -0,0 +1,182 @@
1
+ import { featureFilter } from '@maplibre/maplibre-gl-style-spec';
2
+ import StyleOptions from "../Core/StyleOptions.js";
3
+ import TMSSource from "./TMSSource.js";
4
+ import URLBuilder from "../Provider/URLBuilder.js";
5
+ import Fetcher from "../Provider/Fetcher.js";
6
+ import urlParser from "../Parser/MapBoxUrlParser.js";
7
+ function toTMSUrl(url) {
8
+ return url.replace(/\{/g, '${');
9
+ }
10
+ function mergeCollections(collections) {
11
+ const collection = collections[0];
12
+ collections.forEach((col, index) => {
13
+ if (index === 0) {
14
+ return;
15
+ }
16
+ col.features.forEach(feature => {
17
+ collection.features.push(feature);
18
+ });
19
+ });
20
+ return collection;
21
+ }
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
+
32
+ /**
33
+ * VectorTilesSource are object containing informations on how to fetch vector
34
+ * tiles resources.
35
+ *
36
+ * @property {function} filter - function to filter vector tiles layers, the
37
+ * parameter function is a layer.
38
+ * @property {boolean} [symbolToCircle=false] - If true, all symbols from a tile
39
+ * will be considered as circle, and render as circles.
40
+ */
41
+ class VectorTilesSource extends TMSSource {
42
+ /**
43
+ * @param {Object} source - An object that can contain all properties of a
44
+ * VectorTilesSource and {@link Source}.
45
+ * @param {string|Object} source.style - The URL of the JSON style, of the
46
+ * JSON style directly.
47
+ * @param {string} [source.sprite] - The base URL to load informations about
48
+ * the sprite of the style. If this is set, it overrides the `sprite` value
49
+ * of the `source.style`. A style's sprite property supplies a URL template
50
+ * for loading small images.
51
+ * ```js
52
+ * {
53
+ * sprite: 'http//:xxxxx/maps/sprites/'
54
+ * }
55
+ * ```
56
+ * A valid sprite source must supply two types of files:
57
+ * * An index file, which is a JSON document containing a description of each image contained in the sprite.
58
+ * * Image files, which are PNG images containing the sprite data.
59
+ *
60
+ * For more specification : [the Mapbox sprite Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sprite/)
61
+ *
62
+ * @param {string} [source.url] - The base URL to load the tiles. If no url
63
+ * is specified, it reads it from the loaded style. Read [the Mapbox Style
64
+ * Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/)
65
+ * for more informations.
66
+ * @param {string} [source.accessToken] - Mapbox access token
67
+ */
68
+ constructor(source) {
69
+ source.format = 'application/x-protobuf;type=mapbox-vector';
70
+ source.crs = 'EPSG:3857';
71
+ source.isInverted = true;
72
+ source.url = source.url || '.';
73
+ super(source);
74
+ const ffilter = source.filter || (() => true);
75
+ this.urls = [];
76
+ this.layers = {};
77
+ this.styles = {};
78
+ let promise;
79
+ this.isVectorTileSource = true;
80
+ this.accessToken = source.accessToken;
81
+ let mvtStyleUrl;
82
+ if (source.style) {
83
+ if (typeof source.style == 'string') {
84
+ mvtStyleUrl = urlParser.normalizeStyleURL(source.style, this.accessToken);
85
+ promise = Fetcher.json(mvtStyleUrl, this.networkOptions);
86
+ } else {
87
+ promise = Promise.resolve(source.style);
88
+ }
89
+ } else {
90
+ throw new Error('New VectorTilesSource: style is required');
91
+ }
92
+ this.whenReady = promise.then(mvtStyle => {
93
+ this.jsonStyle = mvtStyle;
94
+ let baseurl = source.sprite || mvtStyle.sprite;
95
+ if (baseurl) {
96
+ baseurl = new URL(baseurl, mvtStyleUrl).toString();
97
+ const spriteUrl = urlParser.normalizeSpriteURL(baseurl, '', '.json', this.accessToken);
98
+ return Fetcher.json(spriteUrl, this.networkOptions).then(sprites => {
99
+ this.sprites = sprites;
100
+ const imgUrl = urlParser.normalizeSpriteURL(baseurl, '', '.png', this.accessToken);
101
+ this.sprites.source = imgUrl;
102
+ return mvtStyle;
103
+ });
104
+ }
105
+ return mvtStyle;
106
+ }).then(mvtStyle => {
107
+ mvtStyle.layers.forEach((layer, order) => {
108
+ layer.sourceUid = this.uid;
109
+ if (layer.type === 'background') {
110
+ this.backgroundLayer = layer;
111
+ } else if (ffilter(layer)) {
112
+ if (layer['source-layer'] === undefined) {
113
+ getPropertiesFromRefLayer(mvtStyle.layers, layer);
114
+ }
115
+ const style = StyleOptions.setFromVectorTileLayer(layer, this.sprites, this.symbolToCircle);
116
+ this.styles[layer.id] = style;
117
+ if (!this.layers[layer['source-layer']]) {
118
+ this.layers[layer['source-layer']] = [];
119
+ }
120
+ this.layers[layer['source-layer']].push({
121
+ id: layer.id,
122
+ order,
123
+ filterExpression: featureFilter(layer.filter)
124
+ });
125
+ }
126
+ });
127
+ if (this.url == '.') {
128
+ const TMSUrlList = Object.values(mvtStyle.sources).map(sourceVT => {
129
+ if (sourceVT.url) {
130
+ sourceVT.url = new URL(sourceVT.url, mvtStyleUrl).toString();
131
+ const urlSource = urlParser.normalizeSourceURL(sourceVT.url, this.accessToken);
132
+ return Fetcher.json(urlSource, this.networkOptions).then(tileJSON => {
133
+ if (tileJSON.tiles[0]) {
134
+ tileJSON.tiles[0] = decodeURIComponent(new URL(tileJSON.tiles[0], urlSource).toString());
135
+ return toTMSUrl(tileJSON.tiles[0]);
136
+ }
137
+ });
138
+ } else if (sourceVT.tiles) {
139
+ return Promise.resolve(toTMSUrl(sourceVT.tiles[0]));
140
+ }
141
+ return Promise.reject();
142
+ });
143
+ return Promise.all(TMSUrlList);
144
+ }
145
+ return Promise.resolve([toTMSUrl(this.url)]);
146
+ }).then(TMSUrlList => {
147
+ this.urls = Array.from(new Set(TMSUrlList));
148
+ });
149
+ }
150
+ urlFromExtent(tile, url) {
151
+ return URLBuilder.xyz(tile, {
152
+ tileMatrixCallback: this.tileMatrixCallback,
153
+ url
154
+ });
155
+ }
156
+ onLayerAdded(options) {
157
+ super.onLayerAdded(options);
158
+ if (options.out.style) {
159
+ if (options.out.isFeatureGeometryLayer && options.out.accurate) {
160
+ console.warn('With VectorTilesSource and FeatureGeometryLayer, the accurate option is always false');
161
+ options.out.accurate = false;
162
+ }
163
+ }
164
+ }
165
+ loadData(extent, out) {
166
+ const cache = this._featuresCaches[out.crs];
167
+ const key = this.getDataKey(extent);
168
+ // try to get parsed data from cache
169
+ let features = cache.get(key);
170
+ if (!features) {
171
+ // otherwise fetch/parse the data
172
+ features = Promise.all(this.urls.map(url => this.fetcher(this.urlFromExtent(extent, url), this.networkOptions).then(file => this.parser(file, {
173
+ out,
174
+ in: this,
175
+ extent
176
+ })))).then(collections => mergeCollections(collections)).catch(err => this.handlingError(err));
177
+ cache.set(key, features);
178
+ }
179
+ return features;
180
+ }
181
+ }
182
+ export default VectorTilesSource;
@@ -0,0 +1,170 @@
1
+ import Source from "./Source.js";
2
+ import URLBuilder from "../Provider/URLBuilder.js";
3
+ import { Extent } from '@itowns/geographic';
4
+ const _extent = new Extent('EPSG:4326');
5
+
6
+ /**
7
+ * An object defining the source of resources to get from a
8
+ * [WFS](http://www.opengeospatial.org/standards/wfs) server. It inherits
9
+ * from {@link Source}.
10
+ *
11
+ * @extends Source
12
+ *
13
+ * @property {boolean} isWFSSource - Used to checkout whether this source is a
14
+ * WFSSource. Default is true. You should not change this, as it is used
15
+ * internally for optimisation.
16
+ * @property {string} typeName - The name of the feature to get, used in the
17
+ * generation of the url.
18
+ * @property {string} version - The version of the WFS server to request on.
19
+ * Default value is '2.0.2'.
20
+ * @property {Object} zoom - Object containing the minimum and maximum values of
21
+ * the level, to zoom in the source.
22
+ * @property {number} zoom.min - The minimum level of the source. Default value
23
+ * is 0.
24
+ * @property {number} zoom.max - The maximum level of the source. Default value
25
+ * is 21.
26
+ * @property {string} bboxDigits - The bbox digits precision used in URL
27
+ * @property {Object} vendorSpecific - An object containing vendor specific
28
+ * parameters. See for example a [list of these parameters for GeoServer]{@link
29
+ * https://docs.geoserver.org/latest/en/user/services/wfs/vendor.html}. This
30
+ * object is read simply with the `key` being the name of the parameter and
31
+ * `value` being the value of the parameter. If used, this property should be
32
+ * set in the constructor parameters.
33
+ *
34
+ * @example
35
+ * // Add color layer with WFS source
36
+ * // Create the source
37
+ * const wfsSource = new itowns.WFSSource({
38
+ * url: 'https://data.geopf.fr/wfs/ows?',
39
+ * version: '2.0.0',
40
+ * typeName: 'BDTOPO_BDD_WLD_WGS84G:bati_remarquable',
41
+ * crs: 'EPSG:4326',
42
+ * extent: {
43
+ * west: 4.568,
44
+ * east: 5.18,
45
+ * south: 45.437,
46
+ * north: 46.03,
47
+ * },
48
+ * zoom: { min: 14, max: 14 },
49
+ * format: 'application/json',
50
+ * });
51
+ *
52
+ * // Create the layer
53
+ * const colorlayer = new itowns.ColorLayer('color_build', {
54
+ * style: {
55
+ * fill: 'red',
56
+ * fillOpacity: 0.5,
57
+ * stroke: 'white',
58
+ * },
59
+ * source: wfsSource,
60
+ * });
61
+ *
62
+ * // Add the layer
63
+ * view.addLayer(colorlayer);
64
+ *
65
+ * @example
66
+ * // Add geometry layer with WFS source
67
+ * // Create the source
68
+ * const wfsSource = new itowns.WFSSource({
69
+ * url: 'https://data.geopf.fr/wfs/ows?',
70
+ * version: '2.0.0',
71
+ * typeName: 'BDTOPO_BDD_WLD_WGS84G:bati_remarquable',
72
+ * crs: 'EPSG:4326',
73
+ * extent: {
74
+ * west: 4.568,
75
+ * east: 5.18,
76
+ * south: 45.437,
77
+ * north: 46.03,
78
+ * },
79
+ * zoom: { min: 14, max: 14 },
80
+ * format: 'application/json',
81
+ * });
82
+ *
83
+ * // Create the layer
84
+ * const geometryLayer = new itowns.FeatureGeometryLayer('mesh_build', {
85
+ * style: {
86
+ * fill: {
87
+ * color: new itowns.THREE.Color(0xffcc00),
88
+ * base_altitude: (p) => p.altitude,
89
+ * extrusion_height: (p) => p.height,
90
+ * }
91
+ * },
92
+ * source: wfsSource,
93
+ * zoom: { min: 14 },
94
+ * };
95
+ *
96
+ * // Add the layer
97
+ * view.addLayer(geometryLayer);
98
+ */
99
+ class WFSSource extends Source {
100
+ /**
101
+ * @param {Object} source - An object that can contain all properties of a
102
+ * WFSSource and {@link Source}. `url`, `typeName` and `crs` are
103
+ * mandatory.
104
+ */
105
+ constructor(source) {
106
+ if (source.projection) {
107
+ console.warn('WFSSource projection parameter is deprecated, use crs instead.');
108
+ source.crs = source.crs || source.projection;
109
+ }
110
+ if (!source.typeName) {
111
+ throw new Error('source.typeName is required in wfs source.');
112
+ }
113
+ if (!source.crs) {
114
+ throw new Error('source.crs is required in wfs source');
115
+ }
116
+ source.format = source.format || 'application/json';
117
+ super(source);
118
+ this.isWFSSource = true;
119
+ this.typeName = source.typeName;
120
+ this.version = source.version || '2.0.2';
121
+ this.bboxDigits = source.bboxDigits;
122
+ this.zoom = {
123
+ min: 0,
124
+ max: Infinity
125
+ };
126
+ const urlObj = new URL(source.url);
127
+ urlObj.searchParams.set('SERVICE', 'WFS');
128
+ urlObj.searchParams.set('REQUEST', 'GetFeature');
129
+ urlObj.searchParams.set('typeName', this.typeName);
130
+ urlObj.searchParams.set('VERSION', this.version);
131
+ urlObj.searchParams.set('SRSNAME', this.crs);
132
+ urlObj.searchParams.set('outputFormat', this.format);
133
+ urlObj.searchParams.set('BBOX', `%bbox,${this.crs}`);
134
+ this.vendorSpecific = source.vendorSpecific;
135
+ for (const name in this.vendorSpecific) {
136
+ if (Object.prototype.hasOwnProperty.call(this.vendorSpecific, name)) {
137
+ urlObj.searchParams.set(name, this.vendorSpecific[name]);
138
+ }
139
+ }
140
+ this.url = decodeURIComponent(urlObj.toString());
141
+ }
142
+ handlingError(err) {
143
+ if (err.response && err.response.status == 400) {
144
+ return err.response.text().then(text => {
145
+ const getCapUrl = `${this.url}SERVICE=WFS&REQUEST=GetCapabilities&VERSION=${this.version}`;
146
+ const xml = new DOMParser().parseFromString(text, 'application/xml');
147
+ const errorElem = xml.querySelector('Exception');
148
+ const errorCode = errorElem.getAttribute('exceptionCode');
149
+ const errorMessage = errorElem.querySelector('ExceptionText').textContent;
150
+ console.error(`Source ${this.typeName}: bad request when fetching data. Server says: "${errorCode}: ${errorMessage}". \nReviewing ${getCapUrl} may help.`, err);
151
+ });
152
+ }
153
+ return super.handlingError(err);
154
+ }
155
+ getDataKey(extent) {
156
+ if (extent.isTile) {
157
+ return super.getDataKey(extent);
158
+ } else {
159
+ return `z${extent.zoom}s${extent.south}w${extent.west}`;
160
+ }
161
+ }
162
+ urlFromExtent(extentOrTile) {
163
+ const extent = extentOrTile.isExtent ? extentOrTile.as(this.crs, _extent) : extentOrTile.toExtent(this.crs, _extent);
164
+ return URLBuilder.bbox(extent, this);
165
+ }
166
+ extentInsideLimit(extent) {
167
+ return this.extent.intersectsExtent(extent);
168
+ }
169
+ }
170
+ export default WFSSource;