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,486 @@
1
+ import { FEATURE_TYPES } from "./Feature.js";
2
+ import * as maplibre from '@maplibre/maplibre-gl-style-spec';
3
+
4
+ /**
5
+ * An object that can contain any properties (zoom, fill, stroke, point,
6
+ * text or/and icon) and sub properties of a Style.
7
+ * Used for the instanciation of a {@link Style}.
8
+ *
9
+ * @typedef {Object} StyleOptions
10
+ *
11
+ * @property {Object} [zoom] - Level on which to display the feature
12
+ * @property {Number} [zoom.max] - max level
13
+ * @property {Number} [zoom.min] - min level
14
+ *
15
+ * @property {Object} [fill] - Fill style for polygons.
16
+ * @property {String|Function|THREE.Color} [fill.color] - Defines the main fill color. Can be
17
+ * any [valid color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
18
+ * Default is no value, which means no fill.
19
+ * If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
20
+ * @property {Image|Canvas|String|Object|Function} [fill.pattern] - Defines a pattern to fill the
21
+ * surface with. It can be an `Image` to use directly, an url to fetch the pattern or an object containing
22
+ * the url of the image to fetch and the transformation to apply.
23
+ * from. See [this example](http://www.itowns-project.org/itowns/examples/#source_file_geojson_raster)
24
+ * for how to use.
25
+ * @property {Image|String} [fill.pattern.source] - The image or the url to fetch the pattern image
26
+ * @property {Object} [fill.pattern.cropValues] - The x, y, width and height (in pixel) of the sub image to use.
27
+ * @property {THREE.Color} [fill.pattern.color] - Can be any
28
+ * [valid color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
29
+ * It will change the color of the white pixels of the source image.
30
+ * @property {Number|Function} [fill.opacity] - The opacity of the color or of the
31
+ * pattern. Can be between `0.0` and `1.0`. Default is `1.0`.
32
+ * For a `GeometryLayer`, this opacity property isn't used.
33
+ * @property {Number|Function} [fill.base_altitude] - `GeometryLayer` style option, defines altitude
34
+ * for each coordinate.
35
+ * If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
36
+ * then the altitude value is set to 0.
37
+ * @property {Number|Function} [fill.extrusion_height] - `GeometryLayer` style option, if defined,
38
+ * polygons will be extruded by the specified amount
39
+ *
40
+ * @property {Object} [stroke] - Lines and polygons edges.
41
+ * @property {String|Function|THREE.Color} [stroke.color] The color of the line. Can be any [valid
42
+ * color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
43
+ * Default is no value, which means no stroke.
44
+ * If the `Layer` is a `GeometryLayer` you can use `THREE.Color`.
45
+ * @property {Number|Function} [stroke.opacity] - The opacity of the line. Can be between
46
+ * `0.0` and `1.0`. Default is `1.0`.
47
+ * For a `GeometryLayer`, this opacity property isn't used.
48
+ * @property {Number|Function} [stroke.width] - The width of the line. Default is `1.0`.
49
+ * @property {Number|Function} [stroke.base_altitude] - `GeometryLayer` style option, defines altitude
50
+ * for each coordinate.
51
+ * If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
52
+ * then the altitude value is set to 0.
53
+ *
54
+ * @property {Object} [point] - Point style.
55
+ * @property {String|Function} [point.color] - The color of the point. Can be any [valid
56
+ * color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
57
+ * Default is no value, which means points won't be displayed.
58
+ * @property {Number|Function} [point.radius] - The radius of the point, in pixel. Default
59
+ * is `2.0`.
60
+ * @property {String|Function} [point.line] - The color of the border of the point. Can be
61
+ * any [valid color
62
+ * string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
63
+ * Not supported for a `GeometryLayer`.
64
+ * @property {Number|Function} [point.width] - The width of the border, in pixel. Default
65
+ * is `0.0` (no border).
66
+ * @property {Number|Function} [point.opacity] - The opacity of the point. Can be between
67
+ * `0.0` and `1.0`. Default is `1.0`.
68
+ * Not supported for `GeometryLayer`.
69
+ * @property {Number|Function} [point.base_altitude] - `GeometryLayer` style option, defines altitude
70
+ * for each coordinate.
71
+ * If `base_altitude` is `undefined`, the original altitude is kept, and if it doesn't exist
72
+ * then the altitude value is set to 0.
73
+ * @property {Object} [point.model] - 3D model to instantiate at each point position.
74
+ *
75
+ * @property {Object} [text] - All things {@link Label} related. (Supported for Points features, not yet
76
+ * for Lines and Polygons features.)
77
+ * @property {String|Function} [text.field] - A string representing a property key of
78
+ * a `FeatureGeometry` enclosed in brackets, that will be replaced by the value of the
79
+ * property for each geometry. For example, if each geometry contains a `name` property,
80
+ * `text.field` can be set to `{name}`. Default is no value, indicating that no
81
+ * text will be displayed.
82
+ *
83
+ * It's also possible to create more complex expressions. For example, you can combine
84
+ * text that will always be displayed (e.g. `foo`) and variable properties (e.g. `{bar}`)
85
+ * like the following: `foo {bar}`. You can also use multiple variables in one field.
86
+ * Let's say for instance that you have two properties latin name and local name of a
87
+ * place, you can write something like `{name_latin} - {name_local}` which can result
88
+ * in `Marrakesh - مراكش` for example.
89
+ * @property {String|Function} [text.color] - The color of the text. Can be any [valid
90
+ * color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
91
+ * Default is `#000000`.
92
+ * @property {String|Number[]|Function} [text.anchor] - The anchor of the text compared to its
93
+ * position (see {@link Label} for the position). Can be one of the following values: `top`,
94
+ * `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
95
+ * or `bottom-right`. Default is `center`.
96
+ *
97
+ * It can also be defined as an Array of two numbers. Each number defines an offset (in
98
+ * fraction of the label width and height) between the label position and the top-left
99
+ * corner of the text. The first value is the horizontal offset, and the second is the
100
+ * vertical offset. For example, `[-0.5, -0.5]` will be equivalent to `center`.
101
+ * @property {Array|Function} [text.offset] - The offset of the text, depending on its
102
+ * anchor, in pixels. First value is from `left`, second is from `top`. Default
103
+ * is `[0, 0]`.
104
+ * @property {Number|Function} [text.padding] - The padding outside the text, in pixels.
105
+ * Default is `2`.
106
+ * @property {Number|Function} [text.size] - The size of the font, in pixels. Default is
107
+ * `16`.
108
+ * @property {Number|Function} [text.wrap] - The maximum width, in pixels, before the text
109
+ * is wrapped, because the string is too long. Default is `10`.
110
+ * @property {Number|Function} [text.spacing] - The spacing between the letters, in `em`.
111
+ * Default is `0`.
112
+ * @property {String|Function} [text.transform] - A value corresponding to the [CSS
113
+ * property
114
+ * `text-transform`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-transform).
115
+ * Default is `none`.
116
+ * @property {String|Function} [text.justify] - A value corresponding to the [CSS property
117
+ * `text-align`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-align).
118
+ * Default is `center`.
119
+ * @property {Number|Function} [text.opacity] - The opacity of the text. Can be between
120
+ * `0.0` and `1.0`. Default is `1.0`.
121
+ * @property {Array|Function} [text.font] - A list (as an array of string) of font family
122
+ * names, prioritized in the order it is set. Default is `Open Sans Regular,
123
+ * Arial Unicode MS Regular, sans-serif`.
124
+ * @property {String|Function} [text.haloColor] - The color of the halo. Can be any [valid
125
+ * color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
126
+ * Default is `#000000`.
127
+ * @property {Number|Function} [text.haloWidth] - The width of the halo, in pixels.
128
+ * Default is `0`.
129
+ * @property {Number|Function} [text.haloBlur] - The blur value of the halo, in pixels.
130
+ * Default is `0`.
131
+ *
132
+ * @property {Object} [icon] - Defines the appearance of icons attached to label.
133
+ * @property {String} [icon.source] - The url of the icons' image file.
134
+ * @property {String} [icon.id] - The id of the icons' sub-image in a vector tile data set.
135
+ * @property {String} [icon.cropValues] - the x, y, width and height (in pixel) of the sub image to use.
136
+ * @property {String} [icon.anchor] - The anchor of the icon compared to the label position.
137
+ * Can be `left`, `bottom`, `right`, `center`, `top-left`, `top-right`, `bottom-left`
138
+ * or `bottom-right`. Default is `center`.
139
+ * @property {Number} [icon.size] - If the icon's image is passed with `icon.source` and/or
140
+ * `icon.id`, its size when displayed on screen is multiplied by `icon.size`. Default is `1`.
141
+ * @property {String|Function} [icon.color] - The color of the icon. Can be any [valid
142
+ * color string](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
143
+ * It will change the color of the white pixels of the icon source image.
144
+ * @property {Number|Function} [icon.opacity] - The opacity of the icon. Can be between
145
+ * `0.0` and `1.0`. Default is `1.0`.
146
+ */
147
+
148
+ /**
149
+ * generate a StyleOptions from (geojson-like) properties.
150
+ * @param {Object} properties (geojson-like) properties.
151
+ * @param {FeatureContext} featCtx the context of the feature
152
+ *
153
+ * @returns {StyleOptions} containing all properties for itowns.Style
154
+ */
155
+ function setFromProperties(properties, featCtx) {
156
+ const type = featCtx.type;
157
+ const style = {};
158
+ if (type === FEATURE_TYPES.POINT) {
159
+ const point = {
160
+ ...(properties.fill !== undefined && {
161
+ color: properties.fill
162
+ }),
163
+ ...(properties['fill-opacity'] !== undefined && {
164
+ opacity: properties['fill-opacity']
165
+ }),
166
+ ...(properties.stroke !== undefined && {
167
+ line: properties.stroke
168
+ }),
169
+ ...(properties.radius !== undefined && {
170
+ radius: properties.radius
171
+ })
172
+ };
173
+ if (Object.keys(point).length) {
174
+ style.point = point;
175
+ }
176
+ const text = {
177
+ ...(properties['label-color'] !== undefined && {
178
+ color: properties['label-color']
179
+ }),
180
+ ...(properties['label-opacity'] !== undefined && {
181
+ opacity: properties['label-opacity']
182
+ }),
183
+ ...(properties['label-size'] !== undefined && {
184
+ size: properties['label-size']
185
+ })
186
+ };
187
+ if (Object.keys(point).length) {
188
+ style.text = text;
189
+ }
190
+ const icon = {
191
+ ...(properties.icon !== undefined && {
192
+ source: properties.icon
193
+ }),
194
+ ...(properties['icon-scale'] !== undefined && {
195
+ size: properties['icon-scale']
196
+ }),
197
+ ...(properties['icon-opacity'] !== undefined && {
198
+ opacity: properties['icon-opacity']
199
+ }),
200
+ ...(properties['icon-color'] !== undefined && {
201
+ color: properties['icon-color']
202
+ })
203
+ };
204
+ if (Object.keys(icon).length) {
205
+ style.icon = icon;
206
+ }
207
+ } else {
208
+ const stroke = {
209
+ ...(properties.stroke !== undefined && {
210
+ color: properties.stroke
211
+ }),
212
+ ...(properties['stroke-width'] !== undefined && {
213
+ width: properties['stroke-width']
214
+ }),
215
+ ...(properties['stroke-opacity'] !== undefined && {
216
+ opacity: properties['stroke-opacity']
217
+ })
218
+ };
219
+ if (Object.keys(stroke).length) {
220
+ style.stroke = stroke;
221
+ }
222
+ if (type !== FEATURE_TYPES.LINE) {
223
+ const fill = {
224
+ ...(properties.fill !== undefined && {
225
+ color: properties.fill
226
+ }),
227
+ ...(properties['fill-opacity'] !== undefined && {
228
+ opacity: properties['fill-opacity']
229
+ })
230
+ };
231
+ if (Object.keys(fill).length) {
232
+ style.fill = fill;
233
+ }
234
+ }
235
+ }
236
+ return style;
237
+ }
238
+ function readVectorProperty(property, options) {
239
+ if (property != undefined) {
240
+ if (maplibre.expression.isExpression(property)) {
241
+ return maplibre.expression.createExpression(property, options).value;
242
+ } else {
243
+ return property;
244
+ }
245
+ }
246
+ }
247
+ const inv255 = 1 / 255;
248
+ function rgba2rgb(orig) {
249
+ if (!orig) {
250
+ return {};
251
+ } else if (orig.stops || orig.expression) {
252
+ return {
253
+ color: orig
254
+ };
255
+ } else if (typeof orig == 'string') {
256
+ const result = orig.match(/(?:((hsl|rgb)a? *\(([\d.%]+(?:deg|g?rad|turn)?)[ ,]*([\d.%]+)[ ,]*([\d.%]+)[ ,/]*([\d.%]*)\))|(#((?:[\d\w]{3}){1,2})([\d\w]{1,2})?))/i);
257
+ if (result === null) {
258
+ return {
259
+ color: orig,
260
+ opacity: 1.0
261
+ };
262
+ } else if (result[7]) {
263
+ let opacity = 1.0;
264
+ if (result[9]) {
265
+ opacity = parseInt(result[9].length == 1 ? `${result[9]}${result[9]}` : result[9], 16) * inv255;
266
+ }
267
+ return {
268
+ color: `#${result[8]}`,
269
+ opacity
270
+ };
271
+ } else if (result[1]) {
272
+ return {
273
+ color: `${result[2]}(${result[3]},${result[4]},${result[5]})`,
274
+ opacity: result[6] ? Number(result[6]) : 1.0
275
+ };
276
+ }
277
+ }
278
+ }
279
+
280
+ /**
281
+ * generate a StyleOptions from vector tile layer properties.
282
+ * @param {Object} layer vector tile layer.
283
+ * @param {Object} sprites vector tile layer.
284
+ * @param {Boolean} [symbolToCircle=false]
285
+ *
286
+ * @returns {StyleOptions} containing all properties for itowns.Style
287
+ */
288
+ function setFromVectorTileLayer(layer, sprites) {
289
+ let symbolToCircle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
290
+ const style = {
291
+ fill: {},
292
+ stroke: {},
293
+ point: {},
294
+ text: {},
295
+ icon: {}
296
+ };
297
+ layer.layout = layer.layout || {};
298
+ layer.paint = layer.paint || {};
299
+ if (layer.type === 'fill') {
300
+ const {
301
+ color,
302
+ opacity
303
+ } = rgba2rgb(readVectorProperty(layer.paint['fill-color'] || layer.paint['fill-pattern'], {
304
+ type: 'color'
305
+ }));
306
+ style.fill.color = color;
307
+ style.fill.opacity = readVectorProperty(layer.paint['fill-opacity']) || opacity;
308
+ if (layer.paint['fill-pattern']) {
309
+ try {
310
+ style.fill.pattern = {
311
+ id: layer.paint['fill-pattern'],
312
+ source: sprites.source,
313
+ cropValues: sprites[layer.paint['fill-pattern']]
314
+ };
315
+ } catch (err) {
316
+ err.message = `VTlayer '${layer.id}': argument sprites must not be null when using layer.paint['fill-pattern']`;
317
+ throw err;
318
+ }
319
+ }
320
+ if (layer.paint['fill-outline-color']) {
321
+ const {
322
+ color,
323
+ opacity
324
+ } = rgba2rgb(readVectorProperty(layer.paint['fill-outline-color'], {
325
+ type: 'color'
326
+ }));
327
+ style.stroke.color = color;
328
+ style.stroke.opacity = opacity;
329
+ style.stroke.width = 1.0;
330
+ } else {
331
+ style.stroke.width = 0.0;
332
+ }
333
+ } else if (layer.type === 'line') {
334
+ const prepare = readVectorProperty(layer.paint['line-color'], {
335
+ type: 'color'
336
+ });
337
+ const {
338
+ color,
339
+ opacity
340
+ } = rgba2rgb(prepare);
341
+ style.stroke.dasharray = readVectorProperty(layer.paint['line-dasharray']);
342
+ style.stroke.color = color;
343
+ style.stroke.lineCap = layer.layout['line-cap'];
344
+ style.stroke.width = readVectorProperty(layer.paint['line-width']);
345
+ style.stroke.opacity = readVectorProperty(layer.paint['line-opacity']) || opacity;
346
+ } else if (layer.type === 'circle' || symbolToCircle) {
347
+ const {
348
+ color,
349
+ opacity
350
+ } = rgba2rgb(readVectorProperty(layer.paint['circle-color'], {
351
+ type: 'color'
352
+ }));
353
+ style.point.color = color;
354
+ style.point.opacity = opacity;
355
+ style.point.radius = readVectorProperty(layer.paint['circle-radius']);
356
+ } else if (layer.type === 'symbol') {
357
+ // if symbol we shouldn't draw stroke but defaut value is 1.
358
+ style.stroke.width = 0.0;
359
+ // overlapping order
360
+ style.text.zOrder = readVectorProperty(layer.layout['symbol-z-order']);
361
+ if (style.text.zOrder == 'auto') {
362
+ style.text.zOrder = readVectorProperty(layer.layout['symbol-sort-key']) || 'Y';
363
+ } else if (style.text.zOrder == 'viewport-y') {
364
+ style.text.zOrder = 'Y';
365
+ } else if (style.text.zOrder == 'source') {
366
+ style.text.zOrder = 0;
367
+ }
368
+
369
+ // position
370
+ style.text.anchor = readVectorProperty(layer.layout['text-anchor']);
371
+ style.text.offset = readVectorProperty(layer.layout['text-offset']);
372
+ style.text.padding = readVectorProperty(layer.layout['text-padding']);
373
+ style.text.size = readVectorProperty(layer.layout['text-size']);
374
+ style.text.placement = readVectorProperty(layer.layout['symbol-placement']);
375
+ style.text.rotation = readVectorProperty(layer.layout['text-rotation-alignment']);
376
+
377
+ // content
378
+ style.text.field = readVectorProperty(layer.layout['text-field']);
379
+ style.text.wrap = readVectorProperty(layer.layout['text-max-width']); // Units ems
380
+ style.text.spacing = readVectorProperty(layer.layout['text-letter-spacing']);
381
+ style.text.transform = readVectorProperty(layer.layout['text-transform']);
382
+ style.text.justify = readVectorProperty(layer.layout['text-justify']);
383
+
384
+ // appearance
385
+ const {
386
+ color,
387
+ opacity
388
+ } = rgba2rgb(readVectorProperty(layer.paint['text-color'], {
389
+ type: 'color'
390
+ }));
391
+ style.text.color = color;
392
+ style.text.opacity = readVectorProperty(layer.paint['text-opacity']) || opacity !== undefined && opacity;
393
+ style.text.font = readVectorProperty(layer.layout['text-font']);
394
+ const haloColor = readVectorProperty(layer.paint['text-halo-color'], {
395
+ type: 'color'
396
+ });
397
+ if (haloColor) {
398
+ style.text.haloColor = haloColor.color || haloColor;
399
+ style.text.haloWidth = readVectorProperty(layer.paint['text-halo-width']);
400
+ style.text.haloBlur = readVectorProperty(layer.paint['text-halo-blur']);
401
+ }
402
+
403
+ // additional icon
404
+ const iconImg = readVectorProperty(layer.layout['icon-image']);
405
+ if (iconImg) {
406
+ const cropValueDefault = {
407
+ x: 0,
408
+ y: 0,
409
+ width: 1,
410
+ height: 1
411
+ };
412
+ try {
413
+ style.icon.id = iconImg;
414
+ if (iconImg.stops) {
415
+ const iconCropValue = {
416
+ ...(iconImg.base !== undefined && {
417
+ base: iconImg.base
418
+ }),
419
+ stops: iconImg.stops.map(stop => {
420
+ let cropValues = sprites[stop[1]];
421
+ if (stop[1].includes('{')) {
422
+ cropValues = function (p) {
423
+ const id = stop[1].replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
424
+ if (cropValues === undefined) {
425
+ // const warning = `WARNING: "${id}" not found in sprite file`;
426
+ sprites[id] = cropValueDefault; // or return cropValueDefault;
427
+ }
428
+ return sprites[id];
429
+ };
430
+ } else if (cropValues === undefined) {
431
+ // const warning = `WARNING: "${stop[1]}" not found in sprite file`;
432
+ cropValues = cropValueDefault;
433
+ }
434
+ return [stop[0], cropValues];
435
+ })
436
+ };
437
+ style.icon.cropValues = iconCropValue;
438
+ } else {
439
+ style.icon.cropValues = sprites[iconImg];
440
+ if (iconImg.includes('{')) {
441
+ style.icon.cropValues = function (p) {
442
+ const id = iconImg.replace(/\{(.+?)\}/g, (a, b) => p[b] || '').trim();
443
+ if (sprites[id] === undefined) {
444
+ // const warning = `WARNING: "${id}" not found in sprite file`;
445
+ sprites[id] = cropValueDefault; // or return cropValueDefault;
446
+ }
447
+ return sprites[id];
448
+ };
449
+ } else if (sprites[iconImg] === undefined) {
450
+ // const warning = `WARNING: "${iconImg}" not found in sprite file`;
451
+ style.icon.cropValues = cropValueDefault;
452
+ }
453
+ }
454
+ style.icon.source = sprites.source;
455
+ style.icon.size = readVectorProperty(layer.layout['icon-size']) ?? 1;
456
+ const {
457
+ color,
458
+ opacity
459
+ } = rgba2rgb(readVectorProperty(layer.paint['icon-color'], {
460
+ type: 'color'
461
+ }));
462
+ // https://docs.mapbox.com/style-spec/reference/layers/#paint-symbol-icon-color
463
+ if (iconImg.sdf) {
464
+ style.icon.color = color;
465
+ }
466
+ style.icon.opacity = readVectorProperty(layer.paint['icon-opacity']) ?? (opacity !== undefined && opacity);
467
+ } catch (err) {
468
+ err.message = `VTlayer '${layer.id}': argument sprites must not be null when using layer.layout['icon-image']`;
469
+ throw err;
470
+ }
471
+ }
472
+ }
473
+ // VectorTileSet: by default minZoom = 0 and maxZoom = 24
474
+ // https://docs.mapbox.com/style-spec/reference/layers/#maxzoom and #minzoom
475
+ // Should be move to layer properties, when (if) one mapBox layer will be considered as several itowns layers.
476
+ // issue https://github.com/iTowns/itowns/issues/2153 (last point)
477
+ style.zoom = {
478
+ min: layer.minzoom || 0,
479
+ max: layer.maxzoom || 24
480
+ };
481
+ return style;
482
+ }
483
+ export default {
484
+ setFromProperties,
485
+ setFromVectorTileLayer
486
+ };
@@ -0,0 +1,63 @@
1
+ /* babel-plugin-inline-import '../../Renderer/Shader/SampleTestFS.glsl' */
2
+ const SampleTestFS = "uniform sampler2D uni[SAMPLE];\nvoid main() {\n gl_FragColor += texture2D(uni[SAMPLE-1], vec2(0));\n}";
3
+ /* babel-plugin-inline-import '../../Renderer/Shader/SampleTestVS.glsl' */
4
+ const SampleTestVS = "void main() {\n gl_Position = vec4( 0.0, 0.0, 0.0, 1.0 );\n}"; // default values
5
+ let logDepthBufferSupported = false;
6
+ let maxTexturesUnits = 8;
7
+ let maxTextureSize = 4096;
8
+ function _WebGLShader(renderer, type, string) {
9
+ const gl = renderer.getContext();
10
+ const shader = gl.createShader(type);
11
+ gl.shaderSource(shader, string);
12
+ gl.compileShader(shader);
13
+ return shader;
14
+ }
15
+ function isFirefox() {
16
+ return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().includes('firefox');
17
+ }
18
+ export default {
19
+ isLogDepthBufferSupported() {
20
+ return logDepthBufferSupported;
21
+ },
22
+ isFirefox,
23
+ getMaxTextureUnitsCount() {
24
+ return maxTexturesUnits;
25
+ },
26
+ getMaxTextureSize() {
27
+ return maxTextureSize;
28
+ },
29
+ updateCapabilities(renderer) {
30
+ const gl = renderer.getContext();
31
+ maxTexturesUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
32
+ maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
33
+ const program = gl.createProgram();
34
+ const glVertexShader = _WebGLShader(renderer, gl.VERTEX_SHADER, SampleTestVS);
35
+ let fragmentShader = `#define SAMPLE ${maxTexturesUnits}\n`;
36
+ fragmentShader += SampleTestFS;
37
+ const glFragmentShader = _WebGLShader(renderer, gl.FRAGMENT_SHADER, fragmentShader);
38
+ gl.attachShader(program, glVertexShader);
39
+ gl.attachShader(program, glFragmentShader);
40
+ gl.linkProgram(program);
41
+ if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) {
42
+ if (maxTexturesUnits > 16) {
43
+ const info = gl.getProgramInfoLog(program);
44
+ // eslint-disable-next-line no-console
45
+ console.warn(`${info}: using a maximum of 16 texture units instead of the reported value (${maxTexturesUnits})`);
46
+ if (isFirefox()) {
47
+ // eslint-disable-next-line no-console
48
+ console.warn(`It can come from a Mesa/Firefox bug;
49
+ the shader compiles to an error when using more than 16 sampler uniforms,
50
+ see https://bugzilla.mozilla.org/show_bug.cgi?id=777028`);
51
+ }
52
+ maxTexturesUnits = 16;
53
+ } else {
54
+ throw new Error(`The GPU capabilities could not be determined accurately.
55
+ Impossible to link a shader with the Maximum texture units ${maxTexturesUnits}`);
56
+ }
57
+ }
58
+ gl.deleteProgram(program);
59
+ gl.deleteShader(glVertexShader);
60
+ gl.deleteShader(glFragmentShader);
61
+ logDepthBufferSupported = renderer.capabilities.logarithmicDepthBuffer;
62
+ }
63
+ };