@mapcomponents/react-maplibre 0.1.57 → 0.1.59

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 (276) hide show
  1. package/.eslintignore +11 -0
  2. package/.eslintrc.js +20 -0
  3. package/.github/workflows/check-formatting.yml +46 -0
  4. package/.prettierignore +11 -0
  5. package/.prettierrc.json +6 -0
  6. package/CHANGELOG.md +18 -0
  7. package/coverage/clover.xml +229 -77
  8. package/coverage/coverage-final.json +43 -37
  9. package/coverage/lcov-report/index.html +65 -20
  10. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +83 -83
  11. package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
  12. package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +66 -66
  13. package/coverage/lcov-report/src/components/MlCenterPosition/index.html +1 -1
  14. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +30 -30
  15. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
  16. package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx.html +202 -0
  17. package/coverage/lcov-report/src/components/MlCreatePdfForm/index.html +116 -0
  18. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +99 -99
  19. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +1 -1
  20. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +66 -66
  21. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
  22. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +221 -221
  23. package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
  24. package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.tsx.html +308 -308
  25. package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +497 -497
  26. package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
  27. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx.html +85 -85
  28. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
  29. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx.html +469 -0
  30. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/index.html +116 -0
  31. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +140 -140
  32. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
  33. package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +37 -37
  34. package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
  35. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +179 -179
  36. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
  37. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.html +113 -113
  38. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
  39. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +181 -181
  40. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +58 -58
  41. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
  42. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
  43. package/coverage/lcov-report/src/components/MlMarker/MlMarker.tsx.html +108 -108
  44. package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
  45. package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +39 -39
  46. package/coverage/lcov-report/src/components/MlMeasureTool/index.html +1 -1
  47. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +183 -183
  48. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
  49. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +163 -163
  50. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
  51. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +50 -50
  52. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.js.html +30 -30
  53. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
  54. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +83 -83
  55. package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
  56. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +204 -204
  57. package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
  58. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +180 -180
  59. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
  60. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +163 -163
  61. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
  62. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +136 -136
  63. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +1 -1
  64. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +53 -53
  65. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
  66. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx.html +123 -123
  67. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
  68. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +35 -35
  69. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
  70. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.tsx.html +155 -155
  71. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
  72. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +255 -255
  73. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
  74. package/coverage/lcov-report/src/contexts/MapContext.tsx.html +66 -66
  75. package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +1 -1
  76. package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +48 -48
  77. package/coverage/lcov-report/src/contexts/index.html +1 -1
  78. package/coverage/lcov-report/src/hooks/exportMap/index.html +131 -0
  79. package/coverage/lcov-report/src/hooks/exportMap/index.ts.html +175 -0
  80. package/coverage/lcov-report/src/hooks/exportMap/lib.ts.html +646 -0
  81. package/coverage/lcov-report/src/hooks/index.html +48 -18
  82. package/coverage/lcov-report/src/hooks/useLayer.ts.html +230 -188
  83. package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +232 -0
  84. package/coverage/lcov-report/src/hooks/useMap.ts.html +72 -69
  85. package/coverage/lcov-report/src/hooks/useMapState.ts.html +145 -145
  86. package/coverage/lcov-report/src/hooks/useSource.ts.html +337 -0
  87. package/coverage/lcov-report/src/hooks/useWms.js.html +72 -72
  88. package/coverage/lcov-report/src/index.html +1 -1
  89. package/coverage/lcov-report/src/index.ts.html +11 -2
  90. package/coverage/lcov.info +448 -151
  91. package/dist/components/MlCreatePdfForm/MlCreatePdfForm.d.ts +24 -0
  92. package/dist/components/MlCreatePdfForm/MlCreatePdfForm.stories.d.ts +13 -0
  93. package/dist/components/MlCreatePdfForm/lib/PdfContext.d.ts +21 -0
  94. package/dist/components/MlCreatePdfForm/lib/PdfForm.d.ts +10 -0
  95. package/dist/components/MlCreatePdfForm/lib/PdfPreview.d.ts +13 -0
  96. package/dist/components/MlCreatePdfForm/lib/pdf.templates.d.ts +11 -0
  97. package/dist/components/MlFeatureEditor/lib/create_vertex.d.ts +1 -1
  98. package/dist/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.d.ts +22 -0
  99. package/dist/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.stories.d.ts +10 -0
  100. package/dist/components/MlLayerSwipe/MlLayerSwipe.d.ts +1 -1
  101. package/dist/components/MlWmsLayer/MlWmsLayer.d.ts +2 -2
  102. package/dist/decorators/MapContextDecoratorHooks.d.ts +2 -0
  103. package/dist/hooks/exportMap/index.d.ts +11 -0
  104. package/dist/hooks/exportMap/lib.d.ts +36 -0
  105. package/dist/hooks/useLayer.d.ts +6 -5
  106. package/dist/hooks/useLayerEvent.d.ts +2 -0
  107. package/dist/hooks/useMap.d.ts +1 -1
  108. package/dist/hooks/useMapState.stories.d.ts +2 -2
  109. package/dist/hooks/useSource.d.ts +17 -0
  110. package/dist/hooks/useSources.stories.d.ts +13 -0
  111. package/dist/index.d.ts +3 -0
  112. package/dist/index.esm.js +1055 -315
  113. package/dist/index.esm.js.map +1 -1
  114. package/eslintErrorTest.js +10 -0
  115. package/package.json +7 -1
  116. package/public/thumbnails/MlCreatePdfForm.png +0 -0
  117. package/src/components/MapLibreMap/MapLibreMap.stories.js +72 -72
  118. package/src/components/MapLibreMap/MapLibreMap.test.js +60 -60
  119. package/src/components/MapLibreMap/MapLibreMap.tsx +82 -82
  120. package/src/components/MapLibreMap/lib/MapLibreGlWrapper.test.js +343 -343
  121. package/src/components/MapLibreMap/lib/MapLibreGlWrapper.ts +619 -619
  122. package/src/components/MlBasicComponent.js +25 -25
  123. package/src/components/MlCenterPosition/MlCenterPosition.stories.js +6 -6
  124. package/src/components/MlCenterPosition/MlCenterPosition.tsx +65 -65
  125. package/src/components/MlComponentTemplate/MlComponentTemplate.stories.js +5 -5
  126. package/src/components/MlComponentTemplate/MlComponentTemplate.tsx +23 -23
  127. package/src/components/MlCreatePdfButton/{MlCreatePdfButton.meta.json → MlCreatePdfButton.meta_.json} +0 -0
  128. package/src/components/MlCreatePdfButton/MlCreatePdfButton.stories.js +16 -16
  129. package/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx +29 -29
  130. package/src/components/MlCreatePdfButton/lib/createPdf.ts +175 -175
  131. package/src/components/MlCreatePdfButton/lib/nominatimMap.ts +51 -51
  132. package/src/components/MlCreatePdfForm/MlCreatePdfForm.doc.de.md +3 -0
  133. package/src/components/MlCreatePdfForm/MlCreatePdfForm.meta.json +15 -0
  134. package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +152 -0
  135. package/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx +39 -0
  136. package/src/components/MlCreatePdfForm/lib/PdfContext.tsx +53 -0
  137. package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +161 -0
  138. package/src/components/MlCreatePdfForm/lib/PdfPreview.tsx +399 -0
  139. package/src/components/MlCreatePdfForm/lib/pdf.templates.ts +82 -0
  140. package/src/components/MlFeatureEditor/MlFeatureEditor.stories.js +55 -55
  141. package/src/components/MlFeatureEditor/MlFeatureEditor.test.js +105 -105
  142. package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +119 -119
  143. package/src/components/MlFeatureEditor/custom-direct-select-mode.js +208 -208
  144. package/src/components/MlFeatureEditor/custom-polygon-mode.js +148 -148
  145. package/src/components/MlFeatureEditor/custom-select-mode.js +314 -314
  146. package/src/components/MlFeatureEditor/lib/common_selectors.js +34 -34
  147. package/src/components/MlFeatureEditor/lib/constants.js +61 -61
  148. package/src/components/MlFeatureEditor/lib/constrain_feature_movement.js +51 -51
  149. package/src/components/MlFeatureEditor/lib/create_midpoint.js +30 -30
  150. package/src/components/MlFeatureEditor/lib/create_supplementary_points.js +82 -82
  151. package/src/components/MlFeatureEditor/lib/create_vertex.js +16 -16
  152. package/src/components/MlFeatureEditor/lib/double_click_zoom.js +23 -23
  153. package/src/components/MlFeatureEditor/lib/euclidean_distance.js +3 -3
  154. package/src/components/MlFeatureEditor/lib/features_at.js +23 -23
  155. package/src/components/MlFeatureEditor/lib/get_features_and_set_cursor.js +15 -15
  156. package/src/components/MlFeatureEditor/lib/is_click.js +8 -8
  157. package/src/components/MlFeatureEditor/lib/is_event_at_coordinates.js +2 -2
  158. package/src/components/MlFeatureEditor/lib/is_tap.js +6 -6
  159. package/src/components/MlFeatureEditor/lib/map_event_to_bounding_box.js +4 -4
  160. package/src/components/MlFeatureEditor/lib/mode_handler.js +105 -105
  161. package/src/components/MlFeatureEditor/lib/mouse_event_point.js +5 -5
  162. package/src/components/MlFeatureEditor/lib/move_features.js +33 -33
  163. package/src/components/MlFeatureEditor/lib/sort_features.js +25 -25
  164. package/src/components/MlFeatureEditor/lib/string_set.js +36 -36
  165. package/src/components/MlFeatureEditor/lib/string_sets_are_equal.js +2 -2
  166. package/src/components/MlFeatureEditor/lib/theme.js +230 -230
  167. package/src/components/MlFeatureEditor/lib/to_dense_array.js +1 -1
  168. package/src/components/MlFeatureEditor/lib/utils.js +40 -40
  169. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.stories.js +9 -9
  170. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.test.js +4 -4
  171. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx +65 -65
  172. package/src/components/MlFollowGps/MlFollowGps.stories.js +6 -6
  173. package/src/components/MlFollowGps/MlFollowGps.test.js +44 -44
  174. package/src/components/MlFollowGps/MlFollowGps.tsx +220 -220
  175. package/src/components/MlGPXViewer/MlGPXViewer.stories.js +15 -15
  176. package/src/components/MlGPXViewer/MlGPXViewer.test.js +12 -12
  177. package/src/components/MlGPXViewer/MlGPXViewer.tsx +345 -345
  178. package/src/components/MlGPXViewer/gpxConverter.js +496 -496
  179. package/src/components/MlGPXViewer/util/GeoJsonContext.ts +4 -4
  180. package/src/components/MlGPXViewer/util/GeoJsonProvider.tsx +16 -16
  181. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +34 -34
  182. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.test.js +8 -8
  183. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +84 -84
  184. package/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.ts +21 -21
  185. package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.ts +27 -27
  186. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.doc.de.md +3 -0
  187. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.meta_.json +15 -0
  188. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.stories.js +19 -0
  189. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx +128 -0
  190. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.stories.js +28 -28
  191. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.test.js +8 -8
  192. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx +162 -162
  193. package/src/components/MlLayer/MlLayer.stories.js +5 -5
  194. package/src/components/MlLayer/MlLayer.test.js +86 -86
  195. package/src/components/MlLayer/MlLayer.tsx +36 -36
  196. package/src/components/MlLayerMagnify/MlLayerMagnify.stories.js +21 -21
  197. package/src/components/MlLayerMagnify/MlLayerMagnify.test.js +54 -54
  198. package/src/components/MlLayerMagnify/MlLayerMagnify.tsx +201 -201
  199. package/src/components/MlLayerSwipe/MlLayerSwipe.stories.js +20 -20
  200. package/src/components/MlLayerSwipe/MlLayerSwipe.test.js +54 -54
  201. package/src/components/MlLayerSwipe/MlLayerSwipe.tsx +130 -130
  202. package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +194 -194
  203. package/src/components/MlLayerSwitcher/MlLayerSwitcher.stories.js +85 -85
  204. package/src/components/MlLayerSwitcher/components/LayerBox.js +57 -57
  205. package/src/components/MlMarker/MlMarker.stories.js +7 -7
  206. package/src/components/MlMarker/MlMarker.tsx +119 -119
  207. package/src/components/MlMeasureTool/MlMeasureTool.stories.js +64 -64
  208. package/src/components/MlMeasureTool/MlMeasureTool.tsx +38 -38
  209. package/src/components/MlNavigationCompass/MlNavigationCompass.stories.js +45 -45
  210. package/src/components/MlNavigationCompass/MlNavigationCompass.test.js +40 -40
  211. package/src/components/MlNavigationCompass/MlNavigationCompass.tsx +192 -192
  212. package/src/components/MlNavigationTools/MlNavigationTools.stories.js +18 -18
  213. package/src/components/MlNavigationTools/MlNavigationTools.tsx +173 -173
  214. package/src/components/MlOsmLayer/MlOsmLayer.js +49 -49
  215. package/src/components/MlOsmLayer/MlOsmLayer.stories_.js +29 -29
  216. package/src/components/MlOsmLayer/MlOsmLayer.test.js +8 -8
  217. package/src/components/MlScaleReference/MlScaleReference.js +82 -82
  218. package/src/components/MlScaleReference/MlScaleReference.stories.js +27 -27
  219. package/src/components/MlShareMapState/MlShareMapState.js +203 -203
  220. package/src/components/MlShareMapState/MlShareMapState.stories.js +68 -68
  221. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js +201 -201
  222. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.stories.js +35 -35
  223. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.test.js +8 -8
  224. package/src/components/MlThreeJsLayer/MlThreeJsLayer.js +186 -186
  225. package/src/components/MlThreeJsLayer/MlThreeJsLayer.stories.js +21 -21
  226. package/src/components/MlThreeJsLayer/MlThreeJsLayer.test.js +24 -24
  227. package/src/components/MlThreeJsLayer/lib/GLTFLoader.js +3327 -3327
  228. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.stories.js +31 -30
  229. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.test.js +8 -8
  230. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx +146 -146
  231. package/src/components/MlTransitionGeoJsonLayer/util/transitionFunctions.js +207 -207
  232. package/src/components/MlUseMapDebugger/MlUseMapDebugger.js +52 -52
  233. package/src/components/MlUseMapDebugger/MlUseMapDebugger.stories.js +13 -13
  234. package/src/components/MlVectorTileLayer/MlVectorTileLayer.stories.js +27 -27
  235. package/src/components/MlVectorTileLayer/MlVectorTileLayer.test.js +27 -27
  236. package/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx +137 -137
  237. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js +34 -34
  238. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.stories.js +7 -7
  239. package/src/components/MlWmsLayer/MlWmsLayer.stories.js +26 -26
  240. package/src/components/MlWmsLayer/MlWmsLayer.test.js +8 -8
  241. package/src/components/MlWmsLayer/MlWmsLayer.tsx +167 -167
  242. package/src/components/MlWmsLoader/MlWmsLoader.stories.js +27 -27
  243. package/src/components/MlWmsLoader/MlWmsLoader.tsx +254 -254
  244. package/src/contexts/MapComponentsProvider.test.js +229 -229
  245. package/src/contexts/MapContext.tsx +65 -65
  246. package/src/contexts/SimpleDataProvider.js +47 -47
  247. package/src/contexts/SimpleDataProvider.test.js +29 -29
  248. package/src/custom.d.tsx +14 -14
  249. package/src/decorators/MapContextDecorator.js +22 -22
  250. package/src/decorators/MapContextDecoratorHooks.js +34 -0
  251. package/src/decorators/MultiMapContextDecorator.js +63 -63
  252. package/src/decorators/NoNavToolsDecorator.js +17 -17
  253. package/src/decorators/ThemeWrapper.jsx +1 -1
  254. package/src/hooks/assets/pointWG.json +13 -0
  255. package/src/hooks/exportMap/index.ts +30 -0
  256. package/src/hooks/exportMap/lib.ts +187 -0
  257. package/src/hooks/useLayer.test.js +188 -188
  258. package/src/hooks/useLayer.ts +194 -180
  259. package/src/hooks/useLayerEvent.js +49 -0
  260. package/src/hooks/useMap.ts +67 -66
  261. package/src/hooks/useMapState.stories.js +78 -78
  262. package/src/hooks/useMapState.ts +161 -161
  263. package/src/hooks/useSource.ts +84 -0
  264. package/src/hooks/useSources.stories.js +232 -0
  265. package/src/hooks/useWms.js +71 -71
  266. package/src/index.ts +3 -0
  267. package/src/setupTests.js +86 -86
  268. package/src/ui_components/ImageLoader.js +62 -62
  269. package/src/ui_components/Legend.js +34 -34
  270. package/src/ui_components/LoadingOverlay.js +29 -29
  271. package/src/ui_components/LoadingOverlayContext.js +68 -68
  272. package/src/ui_components/Sidebar.js +80 -80
  273. package/src/ui_components/Tooltip.js +9 -9
  274. package/src/ui_components/TopToolbar.js +23 -23
  275. package/src/util/layerRemovalTest.js +111 -111
  276. package/src/util/sourceRemovalTest.js +103 -103
@@ -12,509 +12,509 @@
12
12
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13
13
  */
14
14
  var toGeoJSON = (function () {
15
- var removeSpace = /\s*/g,
16
- trimSpace = /^\s*|\s*$/g,
17
- splitSpace = /\s+/;
18
- // generate a short, numeric hash of a string
19
- function okhash(x) {
20
- if (!x || !x.length) return 0;
21
- for (var i = 0, h = 0; i < x.length; i++) {
22
- h = ((h << 5) - h + x.charCodeAt(i)) | 0;
23
- }
24
- return h;
25
- }
26
- // all Y children of X
27
- function get(x, y) {
28
- return x.getElementsByTagName(y);
29
- }
30
- function attr(x, y) {
31
- return x.getAttribute(y);
32
- }
33
- function attrf(x, y) {
34
- return parseFloat(attr(x, y));
35
- }
36
- // one Y child of X, if any, otherwise null
37
- function get1(x, y) {
38
- var n = get(x, y);
39
- return n.length ? n[0] : null;
40
- }
41
- // https://developer.mozilla.org/en-US/docs/Web/API/Node.normalize
42
- function norm(el) {
43
- if (el.normalize) {
44
- el.normalize();
45
- }
46
- return el;
47
- }
48
- // cast array x into numbers
49
- function numarray(x) {
50
- for (var j = 0, o = []; j < x.length; j++) {
51
- o[j] = parseFloat(x[j]);
52
- }
53
- return o;
54
- }
55
- // get the content of a text node, if any
56
- function nodeVal(x) {
57
- if (x) {
58
- norm(x);
59
- }
60
- return (x && x.textContent) || "";
61
- }
62
- // get the contents of multiple text nodes, if present
63
- function getMulti(x, ys) {
64
- var o = {},
65
- n,
66
- k;
67
- for (k = 0; k < ys.length; k++) {
68
- n = get1(x, ys[k]);
69
- if (n) o[ys[k]] = nodeVal(n);
70
- }
71
- return o;
72
- }
73
- // add properties of Y to X, overwriting if present in both
74
- function extend(x, y) {
75
- for (var k in y) x[k] = y[k];
76
- }
77
- // get one coordinate from a coordinate array, if any
78
- function coord1(v) {
79
- return numarray(v.replace(removeSpace, "").split(","));
80
- }
81
- // get all coordinates from a coordinate array as [[],[]]
82
- function coord(v) {
83
- var coords = v.replace(trimSpace, "").split(splitSpace),
84
- o = [];
85
- for (var i = 0; i < coords.length; i++) {
86
- o.push(coord1(coords[i]));
87
- }
88
- return o;
89
- }
90
- function coordPair(x) {
91
- var ll = [attrf(x, "lon"), attrf(x, "lat")],
92
- ele = get1(x, "ele"),
93
- // handle namespaced attribute in browser
94
- heartRate = get1(x, "gpxtpx:hr") || get1(x, "hr"),
95
- time = get1(x, "time"),
96
- e;
97
- if (ele) {
98
- e = parseFloat(nodeVal(ele));
99
- if (!isNaN(e)) {
100
- ll.push(e);
101
- }
102
- }
103
- return {
104
- coordinates: ll,
105
- time: time ? nodeVal(time) : null,
106
- heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
107
- };
108
- }
15
+ var removeSpace = /\s*/g,
16
+ trimSpace = /^\s*|\s*$/g,
17
+ splitSpace = /\s+/;
18
+ // generate a short, numeric hash of a string
19
+ function okhash(x) {
20
+ if (!x || !x.length) return 0;
21
+ for (var i = 0, h = 0; i < x.length; i++) {
22
+ h = ((h << 5) - h + x.charCodeAt(i)) | 0;
23
+ }
24
+ return h;
25
+ }
26
+ // all Y children of X
27
+ function get(x, y) {
28
+ return x.getElementsByTagName(y);
29
+ }
30
+ function attr(x, y) {
31
+ return x.getAttribute(y);
32
+ }
33
+ function attrf(x, y) {
34
+ return parseFloat(attr(x, y));
35
+ }
36
+ // one Y child of X, if any, otherwise null
37
+ function get1(x, y) {
38
+ var n = get(x, y);
39
+ return n.length ? n[0] : null;
40
+ }
41
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node.normalize
42
+ function norm(el) {
43
+ if (el.normalize) {
44
+ el.normalize();
45
+ }
46
+ return el;
47
+ }
48
+ // cast array x into numbers
49
+ function numarray(x) {
50
+ for (var j = 0, o = []; j < x.length; j++) {
51
+ o[j] = parseFloat(x[j]);
52
+ }
53
+ return o;
54
+ }
55
+ // get the content of a text node, if any
56
+ function nodeVal(x) {
57
+ if (x) {
58
+ norm(x);
59
+ }
60
+ return (x && x.textContent) || "";
61
+ }
62
+ // get the contents of multiple text nodes, if present
63
+ function getMulti(x, ys) {
64
+ var o = {},
65
+ n,
66
+ k;
67
+ for (k = 0; k < ys.length; k++) {
68
+ n = get1(x, ys[k]);
69
+ if (n) o[ys[k]] = nodeVal(n);
70
+ }
71
+ return o;
72
+ }
73
+ // add properties of Y to X, overwriting if present in both
74
+ function extend(x, y) {
75
+ for (var k in y) x[k] = y[k];
76
+ }
77
+ // get one coordinate from a coordinate array, if any
78
+ function coord1(v) {
79
+ return numarray(v.replace(removeSpace, "").split(","));
80
+ }
81
+ // get all coordinates from a coordinate array as [[],[]]
82
+ function coord(v) {
83
+ var coords = v.replace(trimSpace, "").split(splitSpace),
84
+ o = [];
85
+ for (var i = 0; i < coords.length; i++) {
86
+ o.push(coord1(coords[i]));
87
+ }
88
+ return o;
89
+ }
90
+ function coordPair(x) {
91
+ var ll = [attrf(x, "lon"), attrf(x, "lat")],
92
+ ele = get1(x, "ele"),
93
+ // handle namespaced attribute in browser
94
+ heartRate = get1(x, "gpxtpx:hr") || get1(x, "hr"),
95
+ time = get1(x, "time"),
96
+ e;
97
+ if (ele) {
98
+ e = parseFloat(nodeVal(ele));
99
+ if (!isNaN(e)) {
100
+ ll.push(e);
101
+ }
102
+ }
103
+ return {
104
+ coordinates: ll,
105
+ time: time ? nodeVal(time) : null,
106
+ heartRate: heartRate ? parseFloat(nodeVal(heartRate)) : null,
107
+ };
108
+ }
109
109
 
110
- // create a new feature collection parent object
111
- function fc() {
112
- return {
113
- type: "FeatureCollection",
114
- features: [],
115
- };
116
- }
110
+ // create a new feature collection parent object
111
+ function fc() {
112
+ return {
113
+ type: "FeatureCollection",
114
+ features: [],
115
+ };
116
+ }
117
117
 
118
- var serializer;
119
- if (typeof XMLSerializer !== "undefined") {
120
- /* istanbul ignore next */
121
- serializer = new XMLSerializer();
122
- } else {
123
- var isNodeEnv = typeof process === "object" && !process.browser;
124
- var isTitaniumEnv = typeof Titanium === "object";
125
- if (typeof exports === "object" && (isNodeEnv || isTitaniumEnv)) {
126
- serializer = new (require("xmldom").XMLSerializer)();
127
- } else {
128
- throw new Error("Unable to initialize serializer");
129
- }
130
- }
131
- function xml2str(str) {
132
- // IE9 will create a new XMLSerializer but it'll crash immediately.
133
- // This line is ignored because we don't run coverage tests in IE9
134
- /* istanbul ignore next */
135
- if (str.xml !== undefined) return str.xml;
136
- return serializer.serializeToString(str);
137
- }
118
+ var serializer;
119
+ if (typeof XMLSerializer !== "undefined") {
120
+ /* istanbul ignore next */
121
+ serializer = new XMLSerializer();
122
+ } else {
123
+ var isNodeEnv = typeof process === "object" && !process.browser;
124
+ var isTitaniumEnv = typeof Titanium === "object";
125
+ if (typeof exports === "object" && (isNodeEnv || isTitaniumEnv)) {
126
+ serializer = new (require("xmldom").XMLSerializer)();
127
+ } else {
128
+ throw new Error("Unable to initialize serializer");
129
+ }
130
+ }
131
+ function xml2str(str) {
132
+ // IE9 will create a new XMLSerializer but it'll crash immediately.
133
+ // This line is ignored because we don't run coverage tests in IE9
134
+ /* istanbul ignore next */
135
+ if (str.xml !== undefined) return str.xml;
136
+ return serializer.serializeToString(str);
137
+ }
138
138
 
139
- var t = {
140
- kml: function (doc) {
141
- var gj = fc(),
142
- // styleindex keeps track of hashed styles in order to match features
143
- styleIndex = {},
144
- styleByHash = {},
145
- // stylemapindex keeps track of style maps to expose in properties
146
- styleMapIndex = {},
147
- // atomic geospatial types supported by KML - MultiGeometry is
148
- // handled separately
149
- geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"],
150
- // all root placemarks in the file
151
- placemarks = get(doc, "Placemark"),
152
- styles = get(doc, "Style"),
153
- styleMaps = get(doc, "StyleMap");
139
+ var t = {
140
+ kml: function (doc) {
141
+ var gj = fc(),
142
+ // styleindex keeps track of hashed styles in order to match features
143
+ styleIndex = {},
144
+ styleByHash = {},
145
+ // stylemapindex keeps track of style maps to expose in properties
146
+ styleMapIndex = {},
147
+ // atomic geospatial types supported by KML - MultiGeometry is
148
+ // handled separately
149
+ geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"],
150
+ // all root placemarks in the file
151
+ placemarks = get(doc, "Placemark"),
152
+ styles = get(doc, "Style"),
153
+ styleMaps = get(doc, "StyleMap");
154
154
 
155
- for (var k = 0; k < styles.length; k++) {
156
- var hash = okhash(xml2str(styles[k])).toString(16);
157
- styleIndex["#" + attr(styles[k], "id")] = hash;
158
- styleByHash[hash] = styles[k];
159
- }
160
- for (var l = 0; l < styleMaps.length; l++) {
161
- styleIndex["#" + attr(styleMaps[l], "id")] = okhash(xml2str(styleMaps[l])).toString(16);
162
- var pairs = get(styleMaps[l], "Pair");
163
- var pairsMap = {};
164
- for (var m = 0; m < pairs.length; m++) {
165
- pairsMap[nodeVal(get1(pairs[m], "key"))] = nodeVal(get1(pairs[m], "styleUrl"));
166
- }
167
- styleMapIndex["#" + attr(styleMaps[l], "id")] = pairsMap;
168
- }
169
- for (var j = 0; j < placemarks.length; j++) {
170
- gj.features = gj.features.concat(getPlacemark(placemarks[j]));
171
- }
172
- function kmlColor(v) {
173
- var color, opacity;
174
- v = v || "";
175
- if (v.substr(0, 1) === "#") {
176
- v = v.substr(1);
177
- }
178
- if (v.length === 6 || v.length === 3) {
179
- color = v;
180
- }
181
- if (v.length === 8) {
182
- opacity = parseInt(v.substr(0, 2), 16) / 255;
183
- color = "#" + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
184
- }
185
- return [color, isNaN(opacity) ? undefined : opacity];
186
- }
187
- function gxCoord(v) {
188
- return numarray(v.split(" "));
189
- }
190
- function gxCoords(root) {
191
- var elems = get(root, "coord", "gx"),
192
- coords = [],
193
- times = [];
194
- if (elems.length === 0) elems = get(root, "gx:coord");
195
- for (var i = 0; i < elems.length; i++) coords.push(gxCoord(nodeVal(elems[i])));
196
- var timeElems = get(root, "when");
197
- for (var j = 0; j < timeElems.length; j++) times.push(nodeVal(timeElems[j]));
198
- return {
199
- coords: coords,
200
- times: times,
201
- };
202
- }
203
- function getGeometry(root) {
204
- var geomNode,
205
- geomNodes,
206
- i,
207
- j,
208
- k,
209
- geoms = [],
210
- coordTimes = [];
211
- if (get1(root, "MultiGeometry")) {
212
- return getGeometry(get1(root, "MultiGeometry"));
213
- }
214
- if (get1(root, "MultiTrack")) {
215
- return getGeometry(get1(root, "MultiTrack"));
216
- }
217
- if (get1(root, "gx:MultiTrack")) {
218
- return getGeometry(get1(root, "gx:MultiTrack"));
219
- }
220
- for (i = 0; i < geotypes.length; i++) {
221
- geomNodes = get(root, geotypes[i]);
222
- if (geomNodes) {
223
- for (j = 0; j < geomNodes.length; j++) {
224
- geomNode = geomNodes[j];
225
- if (geotypes[i] === "Point") {
226
- geoms.push({
227
- type: "Point",
228
- coordinates: coord1(nodeVal(get1(geomNode, "coordinates"))),
229
- });
230
- } else if (geotypes[i] === "LineString") {
231
- geoms.push({
232
- type: "LineString",
233
- coordinates: coord(nodeVal(get1(geomNode, "coordinates"))),
234
- });
235
- } else if (geotypes[i] === "Polygon") {
236
- var rings = get(geomNode, "LinearRing"),
237
- coords = [];
238
- for (k = 0; k < rings.length; k++) {
239
- coords.push(coord(nodeVal(get1(rings[k], "coordinates"))));
240
- }
241
- geoms.push({
242
- type: "Polygon",
243
- coordinates: coords,
244
- });
245
- } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
246
- var track = gxCoords(geomNode);
247
- geoms.push({
248
- type: "LineString",
249
- coordinates: track.coords,
250
- });
251
- if (track.times.length) coordTimes.push(track.times);
252
- }
253
- }
254
- }
255
- }
256
- return {
257
- geoms: geoms,
258
- coordTimes: coordTimes,
259
- };
260
- }
261
- function getPlacemark(root) {
262
- var geomsAndTimes = getGeometry(root),
263
- i,
264
- properties = {},
265
- name = nodeVal(get1(root, "name")),
266
- address = nodeVal(get1(root, "address")),
267
- styleUrl = nodeVal(get1(root, "styleUrl")),
268
- description = nodeVal(get1(root, "description")),
269
- timeSpan = get1(root, "TimeSpan"),
270
- timeStamp = get1(root, "TimeStamp"),
271
- extendedData = get1(root, "ExtendedData"),
272
- lineStyle = get1(root, "LineStyle"),
273
- polyStyle = get1(root, "PolyStyle"),
274
- visibility = get1(root, "visibility");
155
+ for (var k = 0; k < styles.length; k++) {
156
+ var hash = okhash(xml2str(styles[k])).toString(16);
157
+ styleIndex["#" + attr(styles[k], "id")] = hash;
158
+ styleByHash[hash] = styles[k];
159
+ }
160
+ for (var l = 0; l < styleMaps.length; l++) {
161
+ styleIndex["#" + attr(styleMaps[l], "id")] = okhash(xml2str(styleMaps[l])).toString(16);
162
+ var pairs = get(styleMaps[l], "Pair");
163
+ var pairsMap = {};
164
+ for (var m = 0; m < pairs.length; m++) {
165
+ pairsMap[nodeVal(get1(pairs[m], "key"))] = nodeVal(get1(pairs[m], "styleUrl"));
166
+ }
167
+ styleMapIndex["#" + attr(styleMaps[l], "id")] = pairsMap;
168
+ }
169
+ for (var j = 0; j < placemarks.length; j++) {
170
+ gj.features = gj.features.concat(getPlacemark(placemarks[j]));
171
+ }
172
+ function kmlColor(v) {
173
+ var color, opacity;
174
+ v = v || "";
175
+ if (v.substr(0, 1) === "#") {
176
+ v = v.substr(1);
177
+ }
178
+ if (v.length === 6 || v.length === 3) {
179
+ color = v;
180
+ }
181
+ if (v.length === 8) {
182
+ opacity = parseInt(v.substr(0, 2), 16) / 255;
183
+ color = "#" + v.substr(6, 2) + v.substr(4, 2) + v.substr(2, 2);
184
+ }
185
+ return [color, isNaN(opacity) ? undefined : opacity];
186
+ }
187
+ function gxCoord(v) {
188
+ return numarray(v.split(" "));
189
+ }
190
+ function gxCoords(root) {
191
+ var elems = get(root, "coord", "gx"),
192
+ coords = [],
193
+ times = [];
194
+ if (elems.length === 0) elems = get(root, "gx:coord");
195
+ for (var i = 0; i < elems.length; i++) coords.push(gxCoord(nodeVal(elems[i])));
196
+ var timeElems = get(root, "when");
197
+ for (var j = 0; j < timeElems.length; j++) times.push(nodeVal(timeElems[j]));
198
+ return {
199
+ coords: coords,
200
+ times: times,
201
+ };
202
+ }
203
+ function getGeometry(root) {
204
+ var geomNode,
205
+ geomNodes,
206
+ i,
207
+ j,
208
+ k,
209
+ geoms = [],
210
+ coordTimes = [];
211
+ if (get1(root, "MultiGeometry")) {
212
+ return getGeometry(get1(root, "MultiGeometry"));
213
+ }
214
+ if (get1(root, "MultiTrack")) {
215
+ return getGeometry(get1(root, "MultiTrack"));
216
+ }
217
+ if (get1(root, "gx:MultiTrack")) {
218
+ return getGeometry(get1(root, "gx:MultiTrack"));
219
+ }
220
+ for (i = 0; i < geotypes.length; i++) {
221
+ geomNodes = get(root, geotypes[i]);
222
+ if (geomNodes) {
223
+ for (j = 0; j < geomNodes.length; j++) {
224
+ geomNode = geomNodes[j];
225
+ if (geotypes[i] === "Point") {
226
+ geoms.push({
227
+ type: "Point",
228
+ coordinates: coord1(nodeVal(get1(geomNode, "coordinates"))),
229
+ });
230
+ } else if (geotypes[i] === "LineString") {
231
+ geoms.push({
232
+ type: "LineString",
233
+ coordinates: coord(nodeVal(get1(geomNode, "coordinates"))),
234
+ });
235
+ } else if (geotypes[i] === "Polygon") {
236
+ var rings = get(geomNode, "LinearRing"),
237
+ coords = [];
238
+ for (k = 0; k < rings.length; k++) {
239
+ coords.push(coord(nodeVal(get1(rings[k], "coordinates"))));
240
+ }
241
+ geoms.push({
242
+ type: "Polygon",
243
+ coordinates: coords,
244
+ });
245
+ } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
246
+ var track = gxCoords(geomNode);
247
+ geoms.push({
248
+ type: "LineString",
249
+ coordinates: track.coords,
250
+ });
251
+ if (track.times.length) coordTimes.push(track.times);
252
+ }
253
+ }
254
+ }
255
+ }
256
+ return {
257
+ geoms: geoms,
258
+ coordTimes: coordTimes,
259
+ };
260
+ }
261
+ function getPlacemark(root) {
262
+ var geomsAndTimes = getGeometry(root),
263
+ i,
264
+ properties = {},
265
+ name = nodeVal(get1(root, "name")),
266
+ address = nodeVal(get1(root, "address")),
267
+ styleUrl = nodeVal(get1(root, "styleUrl")),
268
+ description = nodeVal(get1(root, "description")),
269
+ timeSpan = get1(root, "TimeSpan"),
270
+ timeStamp = get1(root, "TimeStamp"),
271
+ extendedData = get1(root, "ExtendedData"),
272
+ lineStyle = get1(root, "LineStyle"),
273
+ polyStyle = get1(root, "PolyStyle"),
274
+ visibility = get1(root, "visibility");
275
275
 
276
- if (!geomsAndTimes.geoms.length) return [];
277
- if (name) properties.name = name;
278
- if (address) properties.address = address;
279
- if (styleUrl) {
280
- if (styleUrl[0] !== "#") {
281
- styleUrl = "#" + styleUrl;
282
- }
276
+ if (!geomsAndTimes.geoms.length) return [];
277
+ if (name) properties.name = name;
278
+ if (address) properties.address = address;
279
+ if (styleUrl) {
280
+ if (styleUrl[0] !== "#") {
281
+ styleUrl = "#" + styleUrl;
282
+ }
283
283
 
284
- properties.styleUrl = styleUrl;
285
- if (styleIndex[styleUrl]) {
286
- properties.styleHash = styleIndex[styleUrl];
287
- }
288
- if (styleMapIndex[styleUrl]) {
289
- properties.styleMapHash = styleMapIndex[styleUrl];
290
- properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
291
- }
292
- // Try to populate the lineStyle or polyStyle since we got the style hash
293
- var style = styleByHash[properties.styleHash];
294
- if (style) {
295
- if (!lineStyle) lineStyle = get1(style, "LineStyle");
296
- if (!polyStyle) polyStyle = get1(style, "PolyStyle");
297
- var iconStyle = get1(style, "IconStyle");
298
- if (iconStyle) {
299
- var icon = get1(iconStyle, "Icon");
300
- if (icon) {
301
- var href = nodeVal(get1(icon, "href"));
302
- if (href) properties.icon = href;
303
- }
304
- }
305
- }
306
- }
307
- if (description) properties.description = description;
308
- if (timeSpan) {
309
- var begin = nodeVal(get1(timeSpan, "begin"));
310
- var end = nodeVal(get1(timeSpan, "end"));
311
- properties.timespan = { begin: begin, end: end };
312
- }
313
- if (timeStamp) {
314
- properties.timestamp = nodeVal(get1(timeStamp, "when"));
315
- }
316
- if (lineStyle) {
317
- var linestyles = kmlColor(nodeVal(get1(lineStyle, "color"))),
318
- color = linestyles[0],
319
- opacity = linestyles[1],
320
- width = parseFloat(nodeVal(get1(lineStyle, "width")));
321
- if (color) properties.stroke = color;
322
- if (!isNaN(opacity)) properties["stroke-opacity"] = opacity;
323
- if (!isNaN(width)) properties["stroke-width"] = width;
324
- }
325
- if (polyStyle) {
326
- var polystyles = kmlColor(nodeVal(get1(polyStyle, "color"))),
327
- pcolor = polystyles[0],
328
- popacity = polystyles[1],
329
- fill = nodeVal(get1(polyStyle, "fill")),
330
- outline = nodeVal(get1(polyStyle, "outline"));
331
- if (pcolor) properties.fill = pcolor;
332
- if (!isNaN(popacity)) properties["fill-opacity"] = popacity;
333
- if (fill) properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
334
- if (outline)
335
- properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
336
- }
337
- if (extendedData) {
338
- var datas = get(extendedData, "Data"),
339
- simpleDatas = get(extendedData, "SimpleData");
284
+ properties.styleUrl = styleUrl;
285
+ if (styleIndex[styleUrl]) {
286
+ properties.styleHash = styleIndex[styleUrl];
287
+ }
288
+ if (styleMapIndex[styleUrl]) {
289
+ properties.styleMapHash = styleMapIndex[styleUrl];
290
+ properties.styleHash = styleIndex[styleMapIndex[styleUrl].normal];
291
+ }
292
+ // Try to populate the lineStyle or polyStyle since we got the style hash
293
+ var style = styleByHash[properties.styleHash];
294
+ if (style) {
295
+ if (!lineStyle) lineStyle = get1(style, "LineStyle");
296
+ if (!polyStyle) polyStyle = get1(style, "PolyStyle");
297
+ var iconStyle = get1(style, "IconStyle");
298
+ if (iconStyle) {
299
+ var icon = get1(iconStyle, "Icon");
300
+ if (icon) {
301
+ var href = nodeVal(get1(icon, "href"));
302
+ if (href) properties.icon = href;
303
+ }
304
+ }
305
+ }
306
+ }
307
+ if (description) properties.description = description;
308
+ if (timeSpan) {
309
+ var begin = nodeVal(get1(timeSpan, "begin"));
310
+ var end = nodeVal(get1(timeSpan, "end"));
311
+ properties.timespan = { begin: begin, end: end };
312
+ }
313
+ if (timeStamp) {
314
+ properties.timestamp = nodeVal(get1(timeStamp, "when"));
315
+ }
316
+ if (lineStyle) {
317
+ var linestyles = kmlColor(nodeVal(get1(lineStyle, "color"))),
318
+ color = linestyles[0],
319
+ opacity = linestyles[1],
320
+ width = parseFloat(nodeVal(get1(lineStyle, "width")));
321
+ if (color) properties.stroke = color;
322
+ if (!isNaN(opacity)) properties["stroke-opacity"] = opacity;
323
+ if (!isNaN(width)) properties["stroke-width"] = width;
324
+ }
325
+ if (polyStyle) {
326
+ var polystyles = kmlColor(nodeVal(get1(polyStyle, "color"))),
327
+ pcolor = polystyles[0],
328
+ popacity = polystyles[1],
329
+ fill = nodeVal(get1(polyStyle, "fill")),
330
+ outline = nodeVal(get1(polyStyle, "outline"));
331
+ if (pcolor) properties.fill = pcolor;
332
+ if (!isNaN(popacity)) properties["fill-opacity"] = popacity;
333
+ if (fill) properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
334
+ if (outline)
335
+ properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
336
+ }
337
+ if (extendedData) {
338
+ var datas = get(extendedData, "Data"),
339
+ simpleDatas = get(extendedData, "SimpleData");
340
340
 
341
- for (i = 0; i < datas.length; i++) {
342
- properties[datas[i].getAttribute("name")] = nodeVal(get1(datas[i], "value"));
343
- }
344
- for (i = 0; i < simpleDatas.length; i++) {
345
- properties[simpleDatas[i].getAttribute("name")] = nodeVal(simpleDatas[i]);
346
- }
347
- }
348
- if (visibility) {
349
- properties.visibility = nodeVal(visibility);
350
- }
351
- if (geomsAndTimes.coordTimes.length) {
352
- properties.coordTimes =
353
- geomsAndTimes.coordTimes.length === 1
354
- ? geomsAndTimes.coordTimes[0]
355
- : geomsAndTimes.coordTimes;
356
- }
357
- var feature = {
358
- type: "Feature",
359
- geometry:
360
- geomsAndTimes.geoms.length === 1
361
- ? geomsAndTimes.geoms[0]
362
- : {
363
- type: "GeometryCollection",
364
- geometries: geomsAndTimes.geoms,
365
- },
366
- properties: properties,
367
- };
368
- if (attr(root, "id")) feature.id = attr(root, "id");
369
- return [feature];
370
- }
371
- return gj;
372
- },
373
- gpx: function (doc) {
374
- var i,
375
- tracks = get(doc, "trk"),
376
- routes = get(doc, "rte"),
377
- waypoints = get(doc, "wpt"),
378
- // a feature collection
379
- gj = fc(),
380
- feature;
381
- for (i = 0; i < tracks.length; i++) {
382
- feature = getTrack(tracks[i]);
383
- if (feature) gj.features.push(feature);
384
- }
385
- for (i = 0; i < routes.length; i++) {
386
- feature = getRoute(routes[i]);
387
- if (feature) gj.features.push(feature);
388
- }
389
- for (i = 0; i < waypoints.length; i++) {
390
- gj.features.push(getPoint(waypoints[i]));
391
- }
392
- function initializeArray(arr, size) {
393
- for (var h = 0; h < size; h++) {
394
- arr.push(null);
395
- }
396
- return arr;
397
- }
398
- function getPoints(node, pointname) {
399
- var pts = get(node, pointname),
400
- line = [],
401
- times = [],
402
- heartRates = [],
403
- l = pts.length;
404
- if (l < 2) return {}; // Invalid line in GeoJSON
405
- for (var i = 0; i < l; i++) {
406
- var c = coordPair(pts[i]);
407
- line.push(c.coordinates);
408
- if (c.time) times.push(c.time);
409
- if (c.heartRate || heartRates.length) {
410
- if (!heartRates.length) initializeArray(heartRates, i);
411
- heartRates.push(c.heartRate || null);
412
- }
413
- }
414
- return {
415
- line: line,
416
- times: times,
417
- heartRates: heartRates,
418
- };
419
- }
420
- function getTrack(node) {
421
- var segments = get(node, "trkseg"),
422
- track = [],
423
- times = [],
424
- heartRates = [],
425
- line;
426
- for (var i = 0; i < segments.length; i++) {
427
- line = getPoints(segments[i], "trkpt");
428
- if (line) {
429
- if (line.line) track.push(line.line);
430
- if (line.times && line.times.length) times.push(line.times);
431
- if (heartRates.length || (line.heartRates && line.heartRates.length)) {
432
- if (!heartRates.length) {
433
- for (var s = 0; s < i; s++) {
434
- heartRates.push(initializeArray([], track[s].length));
435
- }
436
- }
437
- if (line.heartRates && line.heartRates.length) {
438
- heartRates.push(line.heartRates);
439
- } else {
440
- heartRates.push(initializeArray([], line.line.length || 0));
441
- }
442
- }
443
- }
444
- }
445
- if (track.length === 0) return;
446
- var properties = getProperties(node);
447
- extend(properties, getLineStyle(get1(node, "extensions")));
448
- if (times.length) properties.coordTimes = track.length === 1 ? times[0] : times;
449
- if (heartRates.length)
450
- properties.heartRates = track.length === 1 ? heartRates[0] : heartRates;
451
- return {
452
- type: "Feature",
453
- properties: properties,
454
- geometry: {
455
- type: track.length === 1 ? "LineString" : "MultiLineString",
456
- coordinates: track.length === 1 ? track[0] : track,
457
- },
458
- };
459
- }
460
- function getRoute(node) {
461
- var line = getPoints(node, "rtept");
462
- if (!line.line) return;
463
- var prop = getProperties(node);
464
- extend(prop, getLineStyle(get1(node, "extensions")));
465
- var routeObj = {
466
- type: "Feature",
467
- properties: prop,
468
- geometry: {
469
- type: "LineString",
470
- coordinates: line.line,
471
- },
472
- };
473
- return routeObj;
474
- }
475
- function getPoint(node) {
476
- var prop = getProperties(node);
477
- extend(prop, getMulti(node, ["sym"]));
478
- return {
479
- type: "Feature",
480
- properties: prop,
481
- geometry: {
482
- type: "Point",
483
- coordinates: coordPair(node).coordinates,
484
- },
485
- };
486
- }
487
- function getLineStyle(extensions) {
488
- var style = {};
489
- if (extensions) {
490
- var lineStyle = get1(extensions, "line");
491
- if (lineStyle) {
492
- var color = nodeVal(get1(lineStyle, "color")),
493
- opacity = parseFloat(nodeVal(get1(lineStyle, "opacity"))),
494
- width = parseFloat(nodeVal(get1(lineStyle, "width")));
495
- if (color) style.stroke = color;
496
- if (!isNaN(opacity)) style["stroke-opacity"] = opacity;
497
- // GPX width is in mm, convert to px with 96 px per inch
498
- if (!isNaN(width)) style["stroke-width"] = (width * 96) / 25.4;
499
- }
500
- }
501
- return style;
502
- }
503
- function getProperties(node) {
504
- var prop = getMulti(node, ["name", "cmt", "desc", "type", "time", "keywords"]),
505
- links = get(node, "link");
506
- if (links.length) prop.links = [];
507
- for (var i = 0, link; i < links.length; i++) {
508
- link = { href: attr(links[i], "href") };
509
- extend(link, getMulti(links[i], ["text", "type"]));
510
- prop.links.push(link);
511
- }
512
- return prop;
513
- }
514
- return gj;
515
- },
516
- };
517
- return t;
341
+ for (i = 0; i < datas.length; i++) {
342
+ properties[datas[i].getAttribute("name")] = nodeVal(get1(datas[i], "value"));
343
+ }
344
+ for (i = 0; i < simpleDatas.length; i++) {
345
+ properties[simpleDatas[i].getAttribute("name")] = nodeVal(simpleDatas[i]);
346
+ }
347
+ }
348
+ if (visibility) {
349
+ properties.visibility = nodeVal(visibility);
350
+ }
351
+ if (geomsAndTimes.coordTimes.length) {
352
+ properties.coordTimes =
353
+ geomsAndTimes.coordTimes.length === 1
354
+ ? geomsAndTimes.coordTimes[0]
355
+ : geomsAndTimes.coordTimes;
356
+ }
357
+ var feature = {
358
+ type: "Feature",
359
+ geometry:
360
+ geomsAndTimes.geoms.length === 1
361
+ ? geomsAndTimes.geoms[0]
362
+ : {
363
+ type: "GeometryCollection",
364
+ geometries: geomsAndTimes.geoms,
365
+ },
366
+ properties: properties,
367
+ };
368
+ if (attr(root, "id")) feature.id = attr(root, "id");
369
+ return [feature];
370
+ }
371
+ return gj;
372
+ },
373
+ gpx: function (doc) {
374
+ var i,
375
+ tracks = get(doc, "trk"),
376
+ routes = get(doc, "rte"),
377
+ waypoints = get(doc, "wpt"),
378
+ // a feature collection
379
+ gj = fc(),
380
+ feature;
381
+ for (i = 0; i < tracks.length; i++) {
382
+ feature = getTrack(tracks[i]);
383
+ if (feature) gj.features.push(feature);
384
+ }
385
+ for (i = 0; i < routes.length; i++) {
386
+ feature = getRoute(routes[i]);
387
+ if (feature) gj.features.push(feature);
388
+ }
389
+ for (i = 0; i < waypoints.length; i++) {
390
+ gj.features.push(getPoint(waypoints[i]));
391
+ }
392
+ function initializeArray(arr, size) {
393
+ for (var h = 0; h < size; h++) {
394
+ arr.push(null);
395
+ }
396
+ return arr;
397
+ }
398
+ function getPoints(node, pointname) {
399
+ var pts = get(node, pointname),
400
+ line = [],
401
+ times = [],
402
+ heartRates = [],
403
+ l = pts.length;
404
+ if (l < 2) return {}; // Invalid line in GeoJSON
405
+ for (var i = 0; i < l; i++) {
406
+ var c = coordPair(pts[i]);
407
+ line.push(c.coordinates);
408
+ if (c.time) times.push(c.time);
409
+ if (c.heartRate || heartRates.length) {
410
+ if (!heartRates.length) initializeArray(heartRates, i);
411
+ heartRates.push(c.heartRate || null);
412
+ }
413
+ }
414
+ return {
415
+ line: line,
416
+ times: times,
417
+ heartRates: heartRates,
418
+ };
419
+ }
420
+ function getTrack(node) {
421
+ var segments = get(node, "trkseg"),
422
+ track = [],
423
+ times = [],
424
+ heartRates = [],
425
+ line;
426
+ for (var i = 0; i < segments.length; i++) {
427
+ line = getPoints(segments[i], "trkpt");
428
+ if (line) {
429
+ if (line.line) track.push(line.line);
430
+ if (line.times && line.times.length) times.push(line.times);
431
+ if (heartRates.length || (line.heartRates && line.heartRates.length)) {
432
+ if (!heartRates.length) {
433
+ for (var s = 0; s < i; s++) {
434
+ heartRates.push(initializeArray([], track[s].length));
435
+ }
436
+ }
437
+ if (line.heartRates && line.heartRates.length) {
438
+ heartRates.push(line.heartRates);
439
+ } else {
440
+ heartRates.push(initializeArray([], line.line.length || 0));
441
+ }
442
+ }
443
+ }
444
+ }
445
+ if (track.length === 0) return;
446
+ var properties = getProperties(node);
447
+ extend(properties, getLineStyle(get1(node, "extensions")));
448
+ if (times.length) properties.coordTimes = track.length === 1 ? times[0] : times;
449
+ if (heartRates.length)
450
+ properties.heartRates = track.length === 1 ? heartRates[0] : heartRates;
451
+ return {
452
+ type: "Feature",
453
+ properties: properties,
454
+ geometry: {
455
+ type: track.length === 1 ? "LineString" : "MultiLineString",
456
+ coordinates: track.length === 1 ? track[0] : track,
457
+ },
458
+ };
459
+ }
460
+ function getRoute(node) {
461
+ var line = getPoints(node, "rtept");
462
+ if (!line.line) return;
463
+ var prop = getProperties(node);
464
+ extend(prop, getLineStyle(get1(node, "extensions")));
465
+ var routeObj = {
466
+ type: "Feature",
467
+ properties: prop,
468
+ geometry: {
469
+ type: "LineString",
470
+ coordinates: line.line,
471
+ },
472
+ };
473
+ return routeObj;
474
+ }
475
+ function getPoint(node) {
476
+ var prop = getProperties(node);
477
+ extend(prop, getMulti(node, ["sym"]));
478
+ return {
479
+ type: "Feature",
480
+ properties: prop,
481
+ geometry: {
482
+ type: "Point",
483
+ coordinates: coordPair(node).coordinates,
484
+ },
485
+ };
486
+ }
487
+ function getLineStyle(extensions) {
488
+ var style = {};
489
+ if (extensions) {
490
+ var lineStyle = get1(extensions, "line");
491
+ if (lineStyle) {
492
+ var color = nodeVal(get1(lineStyle, "color")),
493
+ opacity = parseFloat(nodeVal(get1(lineStyle, "opacity"))),
494
+ width = parseFloat(nodeVal(get1(lineStyle, "width")));
495
+ if (color) style.stroke = color;
496
+ if (!isNaN(opacity)) style["stroke-opacity"] = opacity;
497
+ // GPX width is in mm, convert to px with 96 px per inch
498
+ if (!isNaN(width)) style["stroke-width"] = (width * 96) / 25.4;
499
+ }
500
+ }
501
+ return style;
502
+ }
503
+ function getProperties(node) {
504
+ var prop = getMulti(node, ["name", "cmt", "desc", "type", "time", "keywords"]),
505
+ links = get(node, "link");
506
+ if (links.length) prop.links = [];
507
+ for (var i = 0, link; i < links.length; i++) {
508
+ link = { href: attr(links[i], "href") };
509
+ extend(link, getMulti(links[i], ["text", "type"]));
510
+ prop.links.push(link);
511
+ }
512
+ return prop;
513
+ }
514
+ return gj;
515
+ },
516
+ };
517
+ return t;
518
518
  })();
519
519
 
520
520
  export default toGeoJSON;