react-spatial 1.5.3 → 1.5.5

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 (282) hide show
  1. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +262 -0
  2. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -0
  3. package/components/BaseLayerSwitcher/index.js +1 -0
  4. package/components/BaseLayerSwitcher/index.js.map +7 -0
  5. package/{src/components → components}/BasicMap/BasicMap.js +80 -170
  6. package/components/BasicMap/BasicMap.js.map +7 -0
  7. package/components/BasicMap/index.js +1 -0
  8. package/components/BasicMap/index.js.map +7 -0
  9. package/{src/components → components}/CanvasSaveButton/CanvasSaveButton.js +133 -278
  10. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -0
  11. package/components/CanvasSaveButton/index.js +1 -0
  12. package/components/CanvasSaveButton/index.js.map +7 -0
  13. package/{src/components → components}/Copyright/Copyright.js +21 -41
  14. package/components/Copyright/Copyright.js.map +7 -0
  15. package/components/Copyright/index.js +1 -0
  16. package/components/Copyright/index.js.map +7 -0
  17. package/components/FeatureExportButton/FeatureExportButton.js +80 -0
  18. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -0
  19. package/components/FeatureExportButton/index.js +1 -0
  20. package/components/FeatureExportButton/index.js.map +7 -0
  21. package/{src/components → components}/FitExtent/FitExtent.js +16 -30
  22. package/components/FitExtent/FitExtent.js.map +7 -0
  23. package/components/FitExtent/index.js +1 -0
  24. package/components/FitExtent/index.js.map +7 -0
  25. package/{src/components → components}/Geolocation/Geolocation.js +60 -110
  26. package/components/Geolocation/Geolocation.js.map +7 -0
  27. package/components/Geolocation/index.js +1 -0
  28. package/components/Geolocation/index.js.map +7 -0
  29. package/{src/components → components}/LayerTree/LayerTree.js +113 -213
  30. package/components/LayerTree/LayerTree.js.map +7 -0
  31. package/components/LayerTree/index.js +1 -0
  32. package/components/LayerTree/index.js.map +7 -0
  33. package/{src/components → components}/MousePosition/MousePosition.js +37 -70
  34. package/components/MousePosition/MousePosition.js.map +7 -0
  35. package/components/MousePosition/index.js +1 -0
  36. package/components/MousePosition/index.js.map +7 -0
  37. package/{src/components → components}/NorthArrow/NorthArrow.js +18 -34
  38. package/components/NorthArrow/NorthArrow.js.map +7 -0
  39. package/components/NorthArrow/index.js +1 -0
  40. package/components/NorthArrow/index.js.map +7 -0
  41. package/{src/components → components}/Overlay/Overlay.js +59 -85
  42. package/components/Overlay/Overlay.js.map +7 -0
  43. package/components/Overlay/index.js +1 -0
  44. package/components/Overlay/index.js.map +7 -0
  45. package/{src/components → components}/Permalink/Permalink.js +64 -147
  46. package/components/Permalink/Permalink.js.map +7 -0
  47. package/components/Permalink/index.js +1 -0
  48. package/components/Permalink/index.js.map +7 -0
  49. package/{src/components → components}/Popup/Popup.js +57 -116
  50. package/components/Popup/Popup.js.map +7 -0
  51. package/components/Popup/index.js +1 -0
  52. package/components/Popup/index.js.map +7 -0
  53. package/{src/components → components}/ResizeHandler/ResizeHandler.js +15 -49
  54. package/components/ResizeHandler/ResizeHandler.js.map +7 -0
  55. package/components/ResizeHandler/index.js +1 -0
  56. package/components/ResizeHandler/index.js.map +7 -0
  57. package/components/RouteSchedule/RouteSchedule.js +268 -0
  58. package/components/RouteSchedule/RouteSchedule.js.map +7 -0
  59. package/components/RouteSchedule/index.js +1 -0
  60. package/components/RouteSchedule/index.js.map +7 -0
  61. package/{src/components → components}/ScaleLine/ScaleLine.js +8 -23
  62. package/components/ScaleLine/ScaleLine.js.map +7 -0
  63. package/components/ScaleLine/index.js +1 -0
  64. package/components/ScaleLine/index.js.map +7 -0
  65. package/{src/components → components}/StopsFinder/StopsFinder.js +74 -103
  66. package/components/StopsFinder/StopsFinder.js.map +7 -0
  67. package/components/StopsFinder/StopsFinderOption.js +44 -0
  68. package/components/StopsFinder/StopsFinderOption.js.map +7 -0
  69. package/components/StopsFinder/index.js +1 -0
  70. package/components/StopsFinder/index.js.map +7 -0
  71. package/{src/components → components}/Zoom/Zoom.js +46 -77
  72. package/components/Zoom/Zoom.js.map +7 -0
  73. package/components/Zoom/index.js +1 -0
  74. package/components/Zoom/index.js.map +7 -0
  75. package/package.json +32 -31
  76. package/{src/propTypes.js → propTypes.js} +30 -16
  77. package/propTypes.js.map +7 -0
  78. package/{src/setupTests.js → setupTests.js} +1 -1
  79. package/setupTests.js.map +7 -0
  80. package/utils/GlobalsForOle.js +94 -0
  81. package/utils/GlobalsForOle.js.map +7 -0
  82. package/utils/KML.js +420 -0
  83. package/utils/KML.js.map +7 -0
  84. package/{src/utils → utils}/KMLFormat.js +29 -32
  85. package/utils/KMLFormat.js.map +7 -0
  86. package/{src/utils → utils}/Styles.js +14 -20
  87. package/utils/Styles.js.map +7 -0
  88. package/{src/utils → utils}/getPolygonPattern.js +6 -34
  89. package/utils/getPolygonPattern.js.map +7 -0
  90. package/{src/utils → utils}/timeUtils.js +5 -22
  91. package/utils/timeUtils.js.map +7 -0
  92. package/.github/workflows/conventional-pr-title.yml +0 -21
  93. package/.github/workflows/main.yml +0 -28
  94. package/.husky/commit-msg +0 -4
  95. package/.husky/post-checkout +0 -4
  96. package/.husky/post-merge +0 -4
  97. package/.husky/post-rebase +0 -4
  98. package/.husky/pre-commit +0 -4
  99. package/.nvmrc +0 -1
  100. package/.whitesource +0 -8
  101. package/CHANGELOG.md +0 -65
  102. package/DEVELOP.md +0 -113
  103. package/__mocks__/mapbox-gl.js +0 -11
  104. package/__mocks__/resize-observer-polyfill.js +0 -9
  105. package/babel.config.js +0 -3
  106. package/commitlint.config.js +0 -1
  107. package/data/topic1.js +0 -119
  108. package/data/topic2.js +0 -28
  109. package/doc/README.md +0 -21
  110. package/doc/doc-config.json +0 -4
  111. package/pull_request_template.md +0 -16
  112. package/renovate.json +0 -4
  113. package/scripts/read-pkg-json.js +0 -17
  114. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -322
  115. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -69
  116. package/src/components/BaseLayerSwitcher/README.md +0 -61
  117. package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +0 -88
  118. package/src/components/BaseLayerSwitcher/index.js +0 -1
  119. package/src/components/BasicMap/BasicMap.test.js +0 -281
  120. package/src/components/BasicMap/README.md +0 -18
  121. package/src/components/BasicMap/index.js +0 -1
  122. package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -148
  123. package/src/components/CanvasSaveButton/README.md +0 -76
  124. package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +0 -76
  125. package/src/components/CanvasSaveButton/index.js +0 -1
  126. package/src/components/Copyright/Copyright.test.js +0 -134
  127. package/src/components/Copyright/README.md +0 -36
  128. package/src/components/Copyright/index.js +0 -1
  129. package/src/components/FeatureExportButton/FeatureExportButton.js +0 -118
  130. package/src/components/FeatureExportButton/FeatureExportButton.test.js +0 -417
  131. package/src/components/FeatureExportButton/README.md +0 -76
  132. package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +0 -67
  133. package/src/components/FeatureExportButton/index.js +0 -1
  134. package/src/components/FitExtent/FitExtent.test.js +0 -48
  135. package/src/components/FitExtent/README.md +0 -34
  136. package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +0 -13
  137. package/src/components/FitExtent/index.js +0 -1
  138. package/src/components/Geolocation/Geolocation.test.js +0 -267
  139. package/src/components/Geolocation/README.md +0 -25
  140. package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +0 -92
  141. package/src/components/Geolocation/index.js +0 -1
  142. package/src/components/LayerTree/LayerTree.test.js +0 -337
  143. package/src/components/LayerTree/README.md +0 -92
  144. package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +0 -1746
  145. package/src/components/LayerTree/index.js +0 -1
  146. package/src/components/MousePosition/MousePosition.test.js +0 -132
  147. package/src/components/MousePosition/README.md +0 -50
  148. package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +0 -76
  149. package/src/components/MousePosition/index.js +0 -1
  150. package/src/components/NorthArrow/NorthArrow.test.js +0 -104
  151. package/src/components/NorthArrow/README.md +0 -59
  152. package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +0 -117
  153. package/src/components/NorthArrow/index.js +0 -1
  154. package/src/components/Overlay/Overlay.test.js +0 -149
  155. package/src/components/Overlay/README.md +0 -59
  156. package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +0 -9
  157. package/src/components/Overlay/index.js +0 -1
  158. package/src/components/Permalink/Permalink.test.js +0 -285
  159. package/src/components/Permalink/README.md +0 -105
  160. package/src/components/Permalink/index.js +0 -1
  161. package/src/components/Popup/Popup.test.js +0 -307
  162. package/src/components/Popup/README.md +0 -93
  163. package/src/components/Popup/__snapshots__/Popup.test.js.snap +0 -180
  164. package/src/components/Popup/index.js +0 -1
  165. package/src/components/README.md +0 -41
  166. package/src/components/ResizeHandler/ResizeHandler.test.js +0 -344
  167. package/src/components/ResizeHandler/index.js +0 -1
  168. package/src/components/RouteSchedule/README.md +0 -118
  169. package/src/components/RouteSchedule/RouteSchedule.js +0 -370
  170. package/src/components/RouteSchedule/RouteSchedule.test.js +0 -113
  171. package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +0 -248
  172. package/src/components/RouteSchedule/index.js +0 -1
  173. package/src/components/ScaleLine/README.md +0 -29
  174. package/src/components/ScaleLine/ScaleLine.test.js +0 -30
  175. package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +0 -7
  176. package/src/components/ScaleLine/index.js +0 -1
  177. package/src/components/StopsFinder/README.md +0 -50
  178. package/src/components/StopsFinder/StopsFinder.test.js +0 -17
  179. package/src/components/StopsFinder/StopsFinderOption.js +0 -61
  180. package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +0 -133
  181. package/src/components/StopsFinder/index.js +0 -1
  182. package/src/components/Zoom/README.md +0 -25
  183. package/src/components/Zoom/Zoom.test.js +0 -141
  184. package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +0 -201
  185. package/src/components/Zoom/index.js +0 -1
  186. package/src/styleguidist/ComponentsList.js +0 -52
  187. package/src/styleguidist/StyleGuide.js +0 -277
  188. package/src/styleguidist/styleguidist.css +0 -38
  189. package/src/utils/GlobalsForOle.js +0 -99
  190. package/src/utils/KML.js +0 -594
  191. package/src/utils/KML.test.js +0 -337
  192. package/src/utils/KMLFormat.test.js +0 -50
  193. package/src/utils/__snapshots__/KML.test.js.snap.KML-readFeatures()-and-writeFeatures()-should-read-and-write-lineDash-and-fillPattern-style-for-polygon.canvas-image.png +0 -0
  194. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
  195. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-3-(diagonal-line-from-bottom-left-tot-top-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  196. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-4-(diagonal-line-from-top-left-to-bottom-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
  197. package/src/utils/getPolygonPattern.test.js +0 -61
  198. package/src/utils/timeUtils.test.js +0 -30
  199. package/styleguide.config.js +0 -251
  200. /package/{src/components → components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
  201. /package/{src/components → components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
  202. /package/{src/components → components}/BasicMap/BasicMap.md.scss +0 -0
  203. /package/{src/components → components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
  204. /package/{src/components → components}/Copyright/Copyright.md.scss +0 -0
  205. /package/{src/components → components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
  206. /package/{src/components → components}/FitExtent/FitExtent.md.scss +0 -0
  207. /package/{src/components → components}/Geolocation/Geolocation.md.scss +0 -0
  208. /package/{src/components → components}/Geolocation/Geolocation.scss +0 -0
  209. /package/{src/components → components}/LayerTree/LayerTree.md.scss +0 -0
  210. /package/{src/components → components}/LayerTree/LayerTree.scss +0 -0
  211. /package/{src/components → components}/MousePosition/MousePosition.md.scss +0 -0
  212. /package/{src/components → components}/NorthArrow/NorthArrow.scss +0 -0
  213. /package/{src/components → components}/Overlay/Overlay.md.scss +0 -0
  214. /package/{src/components → components}/Overlay/Overlay.scss +0 -0
  215. /package/{src/components → components}/Permalink/Permalink.md.scss +0 -0
  216. /package/{src/components → components}/Popup/Popup.md.scss +0 -0
  217. /package/{src/components → components}/Popup/Popup.scss +0 -0
  218. /package/{src/components → components}/RouteSchedule/RouteSchedule.md.scss +0 -0
  219. /package/{src/components → components}/RouteSchedule/RouteSchedule.scss +0 -0
  220. /package/{src/components → components}/ScaleLine/ScaleLine.scss +0 -0
  221. /package/{src/components → components}/Zoom/Zoom.md.scss +0 -0
  222. /package/{src/components → components}/Zoom/Zoom.scss +0 -0
  223. /package/{src/images → images}/RouteSchedule/firstStation.png +0 -0
  224. /package/{src/images → images}/RouteSchedule/lastStation.png +0 -0
  225. /package/{src/images → images}/RouteSchedule/line.png +0 -0
  226. /package/{src/images → images}/RouteSchedule/station.png +0 -0
  227. /package/{src/images → images}/baselayer/baselayer.basebright.png +0 -0
  228. /package/{src/images → images}/baselayer/baselayer.osm.png +0 -0
  229. /package/{src/images → images}/baselayer/baselayer.travic.png +0 -0
  230. /package/{src/images → images}/baselayer/open.topo.map.png +0 -0
  231. /package/{src/images → images}/baselayer/osm.baselayer.hot.png +0 -0
  232. /package/{src/images → images}/baselayer/osm.baselayer.png +0 -0
  233. /package/{src/images → images}/favicon.png +0 -0
  234. /package/{src/images → images}/geops_logo.png +0 -0
  235. /package/{src/images → images}/geops_logo.svg +0 -0
  236. /package/{src/images → images}/geops_qr.png +0 -0
  237. /package/{src/images → images}/mots/bus_poi-blue-01.svg +0 -0
  238. /package/{src/images → images}/mots/bus_poi-grey-01.svg +0 -0
  239. /package/{src/images → images}/mots/bus_round-blue-01.svg +0 -0
  240. /package/{src/images → images}/mots/bus_round-grey-01.svg +0 -0
  241. /package/{src/images → images}/mots/bus_square-blue-01.svg +0 -0
  242. /package/{src/images → images}/mots/bus_square-grey-01.svg +0 -0
  243. /package/{src/images → images}/mots/cable_car_poi-blue-01.svg +0 -0
  244. /package/{src/images → images}/mots/cable_car_poi-grey-01.svg +0 -0
  245. /package/{src/images → images}/mots/cable_car_round-blue-01.svg +0 -0
  246. /package/{src/images → images}/mots/cable_car_round-grey-01.svg +0 -0
  247. /package/{src/images → images}/mots/cable_car_square-blue-01.svg +0 -0
  248. /package/{src/images → images}/mots/cable_car_square-grey-01.svg +0 -0
  249. /package/{src/images → images}/mots/ferry_poi-blue-01.svg +0 -0
  250. /package/{src/images → images}/mots/ferry_poi-grey-01.svg +0 -0
  251. /package/{src/images → images}/mots/ferry_round-blue-01.svg +0 -0
  252. /package/{src/images → images}/mots/ferry_round-grey-01.svg +0 -0
  253. /package/{src/images → images}/mots/ferry_square-blue-01.svg +0 -0
  254. /package/{src/images → images}/mots/ferry_square-grey-01.svg +0 -0
  255. /package/{src/images → images}/mots/funicular_round-blue-01.svg +0 -0
  256. /package/{src/images → images}/mots/funicular_round-grey-01.svg +0 -0
  257. /package/{src/images → images}/mots/funicular_square-blue-01.svg +0 -0
  258. /package/{src/images → images}/mots/gondola_round-blue-01.svg +0 -0
  259. /package/{src/images → images}/mots/rail_poi-blue-01.svg +0 -0
  260. /package/{src/images → images}/mots/rail_poi-grey-01.svg +0 -0
  261. /package/{src/images → images}/mots/rail_round-blue-01.svg +0 -0
  262. /package/{src/images → images}/mots/rail_round-grey-01.svg +0 -0
  263. /package/{src/images → images}/mots/rail_square-blue-01.svg +0 -0
  264. /package/{src/images → images}/mots/rail_square-grey-01.svg +0 -0
  265. /package/{src/images → images}/mots/subway_round blue-01.svg +0 -0
  266. /package/{src/images → images}/mots/subway_round-blue-01.svg +0 -0
  267. /package/{src/images → images}/mots/tram_poi-blue-01.svg +0 -0
  268. /package/{src/images → images}/mots/tram_poi-grey-01.svg +0 -0
  269. /package/{src/images → images}/mots/tram_round-blue-01.svg +0 -0
  270. /package/{src/images → images}/mots/tram_round-grey-01.svg +0 -0
  271. /package/{src/images → images}/mots/tram_square-blue-01.svg +0 -0
  272. /package/{src/images → images}/mots/tram_square-grey-01.svg +0 -0
  273. /package/{src/images → images}/northArrow.svg +0 -0
  274. /package/{src/images → images}/northArrow.url.svg +0 -0
  275. /package/{src/images → images}/northArrowCircle.svg +0 -0
  276. /package/{src/images → images}/northArrowCircle.url.svg +0 -0
  277. /package/{src/themes → themes}/README.md +0 -0
  278. /package/{src/themes → themes}/default/components.scss +0 -0
  279. /package/{src/themes → themes}/default/examples.scss +0 -0
  280. /package/{src/themes → themes}/default/index.scss +0 -0
  281. /package/{src/themes → themes}/default/mixins.scss +0 -0
  282. /package/{src/themes → themes}/default/variables.scss +0 -0
package/utils/KML.js ADDED
@@ -0,0 +1,420 @@
1
+ import KML from "ol/format/KML";
2
+ import { Feature } from "ol";
3
+ import Point from "ol/geom/Point";
4
+ import MultiPoint from "ol/geom/MultiPoint";
5
+ import GeometryCollection from "ol/geom/GeometryCollection";
6
+ import { Style, Text, Icon, Circle, Fill, Stroke } from "ol/style";
7
+ import { asString } from "ol/color";
8
+ import { parse } from "ol/xml";
9
+ import { kmlStyle } from "./Styles";
10
+ import getPolygonPattern from "./getPolygonPattern";
11
+ const applyTextStyleForIcon = (olIcon, olText) => {
12
+ const size = olIcon.getSize() || [48, 48];
13
+ const scale = olIcon.getScale() || 1;
14
+ const anchor = olIcon.getAnchor() || [
15
+ size[0] * scale / 2,
16
+ size[1] * scale / 2
17
+ ];
18
+ const offset = [
19
+ scale * (size[0] - anchor[0]) + 5,
20
+ scale * (size[1] / 2 - anchor[1])
21
+ ];
22
+ olText.setOffsetX(offset[0]);
23
+ olText.setOffsetY(offset[1]);
24
+ olText.setTextAlign("left");
25
+ };
26
+ const getVertexCoord = (geom, start = true, index = 0) => {
27
+ const coords = geom.getCoordinates();
28
+ const len = coords.length - 1;
29
+ return start ? coords[index] : coords[len - index];
30
+ };
31
+ const getLineIcon = (feature, icon, color, start = true) => {
32
+ const geom = feature.getGeometry();
33
+ const coordA = getVertexCoord(geom, start, 1);
34
+ const coordB = getVertexCoord(geom, start);
35
+ const dx = start ? coordA[0] - coordB[0] : coordB[0] - coordA[0];
36
+ const dy = start ? coordA[1] - coordB[1] : coordB[1] - coordA[1];
37
+ const rotation = Math.atan2(dy, dx);
38
+ return new Style({
39
+ geometry: (feat) => {
40
+ const ge = feat.getGeometry();
41
+ return new Point(getVertexCoord(ge, start));
42
+ },
43
+ image: new Icon({
44
+ src: icon.url,
45
+ color,
46
+ rotation: -rotation,
47
+ rotateWithView: true,
48
+ scale: icon.scale,
49
+ imgSize: icon.size
50
+ // ie 11
51
+ }),
52
+ zIndex: icon.zIndex
53
+ });
54
+ };
55
+ const sanitizeFeature = (feature) => {
56
+ const geom = feature.getGeometry();
57
+ let styles = feature.getStyleFunction();
58
+ if (feature.get("maxZoom")) {
59
+ feature.set("maxZoom", parseFloat(feature.get("maxZoom"), 10));
60
+ }
61
+ if (feature.get("minZoom")) {
62
+ feature.set("minZoom", parseFloat(feature.get("minZoom"), 10));
63
+ }
64
+ const tmpStyles = styles(feature);
65
+ const style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone();
66
+ let stroke = style.getStroke();
67
+ if (stroke && feature.get("lineDash")) {
68
+ stroke.setLineDash(
69
+ feature.get("lineDash").split(",").map((l) => {
70
+ return parseInt(l, 10);
71
+ })
72
+ );
73
+ }
74
+ if (stroke && stroke.getWidth() === 0) {
75
+ stroke = void 0;
76
+ }
77
+ if (feature.get("zIndex")) {
78
+ style.setZIndex(parseInt(feature.get("zIndex"), 10));
79
+ }
80
+ if (style && (geom instanceof Point || geom instanceof MultiPoint)) {
81
+ let image = style.getImage();
82
+ let text = null;
83
+ let fill = style.getFill();
84
+ if (feature.get("name") && style.getText() && style.getText().getScale() !== 0) {
85
+ if (image && image.getScale() === 0) {
86
+ image = new Circle({
87
+ radius: 1,
88
+ fill: new Fill({ color: [0, 0, 0, 0] }),
89
+ stroke: new Stroke({ color: [0, 0, 0, 0] })
90
+ });
91
+ }
92
+ let name = feature.get("name");
93
+ if (/\u200B/g.test(name)) {
94
+ name = name.replace(/\u200B/g, "");
95
+ feature.set("name", name);
96
+ }
97
+ text = new Text({
98
+ font: feature.get("textFont") || "normal 16px Helvetica",
99
+ text: feature.get("name"),
100
+ fill: style.getText().getFill(),
101
+ // rotation unsupported by KML, taken instead from custom field.
102
+ rotation: feature.get("textRotation") || 0,
103
+ // since ol 6.3.1 : https://github.com/openlayers/openlayers/pull/10613/files#diff-1883da8b57e690db7ea0c35ce53c880aR925
104
+ // a default textstroke is added to mimic google earth.
105
+ // it was not the case before, the stroke was always null. So to keep
106
+ // the same behavior we don't copy the stroke style.
107
+ // TODO : maybe we should use this functionnality in the futur.
108
+ // stroke: style.getText().getStroke(),
109
+ scale: style.getText().getScale()
110
+ });
111
+ if (feature.get("textStrokeColor") && feature.get("textStrokeWidth")) {
112
+ text.setStroke(
113
+ new Stroke({
114
+ color: feature.get("textStrokeColor"),
115
+ width: parseFloat(feature.get("textStrokeWidth"))
116
+ })
117
+ );
118
+ }
119
+ if (feature.get("textAlign")) {
120
+ text.setTextAlign(feature.get("textAlign"));
121
+ }
122
+ if (feature.get("textOffsetX")) {
123
+ text.setOffsetX(parseFloat(feature.get("textOffsetX")));
124
+ }
125
+ if (feature.get("textOffsetY")) {
126
+ text.setOffsetY(parseFloat(feature.get("textOffsetY")));
127
+ }
128
+ if (feature.get("textBackgroundFillColor")) {
129
+ text.setBackgroundFill(
130
+ new Fill({
131
+ color: feature.get("textBackgroundFillColor")
132
+ })
133
+ );
134
+ }
135
+ if (feature.get("textPadding")) {
136
+ text.setPadding(
137
+ feature.get("textPadding").split(",").map((n) => {
138
+ return parseFloat(n);
139
+ })
140
+ );
141
+ }
142
+ if (image instanceof Icon) {
143
+ applyTextStyleForIcon(image, text);
144
+ }
145
+ }
146
+ if (image instanceof Icon) {
147
+ image.setRotation(parseFloat(feature.get("iconRotation")) || 0);
148
+ }
149
+ fill = void 0;
150
+ stroke = void 0;
151
+ styles = (feat, resolution) => {
152
+ if (feat.get("pictureOptions")) {
153
+ let pictureOptions = feat.get("pictureOptions");
154
+ if (typeof pictureOptions === "string") {
155
+ pictureOptions = JSON.parse(pictureOptions);
156
+ }
157
+ feat.set("pictureOptions", pictureOptions);
158
+ if (pictureOptions.resolution) {
159
+ image.setScale(
160
+ pictureOptions.resolution / resolution * pictureOptions.defaultScale || 1
161
+ );
162
+ }
163
+ }
164
+ return new Style({
165
+ fill,
166
+ stroke,
167
+ image,
168
+ text,
169
+ zIndex: style.getZIndex()
170
+ });
171
+ };
172
+ }
173
+ if (!(geom instanceof Point || geom instanceof MultiPoint || geom instanceof GeometryCollection)) {
174
+ styles = [
175
+ new Style({
176
+ fill: style.getFill(),
177
+ stroke,
178
+ image: null,
179
+ text: null,
180
+ zIndex: style.getZIndex()
181
+ })
182
+ ];
183
+ let fillPattern = feature.get("fillPattern");
184
+ if (fillPattern) {
185
+ fillPattern = JSON.parse(fillPattern);
186
+ feature.set("fillPattern", fillPattern);
187
+ if (!style.getFill()) {
188
+ styles[0].setFill(new Fill());
189
+ }
190
+ const patternOrColor = fillPattern.empty ? [0, 0, 0, 0] : getPolygonPattern(fillPattern.id, fillPattern.color);
191
+ styles[0].getFill().setColor(patternOrColor);
192
+ }
193
+ if (feature.get("lineStartIcon")) {
194
+ styles.push(
195
+ getLineIcon(
196
+ feature,
197
+ JSON.parse(feature.get("lineStartIcon")),
198
+ stroke.getColor()
199
+ )
200
+ );
201
+ }
202
+ if (feature.get("lineEndIcon")) {
203
+ styles.push(
204
+ getLineIcon(
205
+ feature,
206
+ JSON.parse(feature.get("lineEndIcon")),
207
+ stroke.getColor(),
208
+ false
209
+ )
210
+ );
211
+ }
212
+ }
213
+ feature.setStyle(styles);
214
+ };
215
+ const readFeatures = (kmlString, featureProjection) => {
216
+ const features = new KML().readFeatures(kmlString, {
217
+ featureProjection
218
+ });
219
+ features.forEach((feature) => {
220
+ sanitizeFeature(feature);
221
+ });
222
+ return features;
223
+ };
224
+ const writeFeatures = (layer, featureProjection, mapResolution) => {
225
+ let featString;
226
+ const { olLayer } = layer;
227
+ const exportFeatures = [];
228
+ olLayer.getSource().forEachFeature((feature) => {
229
+ if (feature.getGeometry().getType() === "Circle") {
230
+ return;
231
+ }
232
+ const clone = feature.clone();
233
+ clone.setId(feature.getId());
234
+ clone.getGeometry().setProperties(feature.getGeometry().getProperties());
235
+ clone.getGeometry().transform(featureProjection, "EPSG:4326");
236
+ Object.keys(feature.getProperties()).forEach((key) => {
237
+ if (!/^(geometry|name|description)$/.test(key)) {
238
+ clone.unset(key, true);
239
+ }
240
+ });
241
+ let styles;
242
+ if (feature.getStyleFunction()) {
243
+ styles = feature.getStyleFunction()(feature, mapResolution);
244
+ } else if (olLayer && olLayer.getStyleFunction()) {
245
+ styles = olLayer.getStyleFunction()(feature, mapResolution);
246
+ }
247
+ const mainStyle = styles[0] || styles;
248
+ const newStyle = {
249
+ fill: mainStyle.getFill(),
250
+ stroke: mainStyle.getStroke(),
251
+ text: mainStyle.getText(),
252
+ image: mainStyle.getImage(),
253
+ zIndex: mainStyle.getZIndex()
254
+ };
255
+ if (newStyle.zIndex) {
256
+ clone.set("zIndex", newStyle.zIndex);
257
+ }
258
+ if (newStyle.text && /^\s|\s$/g.test(newStyle.text.getText())) {
259
+ newStyle.text.setText(`\u200B${newStyle.text.getText()}\u200B`);
260
+ }
261
+ if (newStyle.text && newStyle.text.getRotation()) {
262
+ clone.set("textRotation", newStyle.text.getRotation());
263
+ }
264
+ if (newStyle.text && newStyle.text.getFont()) {
265
+ clone.set("textFont", newStyle.text.getFont());
266
+ }
267
+ if (newStyle.text && newStyle.text.getTextAlign()) {
268
+ clone.set("textAlign", newStyle.text.getTextAlign());
269
+ }
270
+ if (newStyle.text && newStyle.text.getOffsetX()) {
271
+ clone.set("textOffsetX", newStyle.text.getOffsetX());
272
+ }
273
+ if (newStyle.text && newStyle.text.getOffsetY()) {
274
+ clone.set("textOffsetY", newStyle.text.getOffsetY());
275
+ }
276
+ if (newStyle.text && newStyle.text.getStroke()) {
277
+ if (newStyle.text.getStroke().getColor()) {
278
+ clone.set(
279
+ "textStrokeColor",
280
+ asString(newStyle.text.getStroke().getColor())
281
+ );
282
+ }
283
+ if (newStyle.text.getStroke().getWidth()) {
284
+ clone.set("textStrokeWidth", newStyle.text.getStroke().getWidth());
285
+ }
286
+ }
287
+ if (newStyle.text && newStyle.text.getBackgroundFill()) {
288
+ clone.set(
289
+ "textBackgroundFillColor",
290
+ asString(newStyle.text.getBackgroundFill().getColor())
291
+ );
292
+ }
293
+ if (newStyle.text && newStyle.text.getPadding()) {
294
+ clone.set("textPadding", newStyle.text.getPadding().join());
295
+ }
296
+ if (newStyle.stroke && newStyle.stroke.getLineDash()) {
297
+ clone.set("lineDash", newStyle.stroke.getLineDash().join(","));
298
+ }
299
+ if (newStyle.image instanceof Circle) {
300
+ newStyle.image = null;
301
+ }
302
+ if (newStyle.image) {
303
+ const imgSource = newStyle.image.getSrc();
304
+ if (!/(http(s?)):\/\//gi.test(imgSource)) {
305
+ console.log(
306
+ "Local image source not supported for KML export.Should use remote web server"
307
+ );
308
+ }
309
+ if (newStyle.image.getRotation()) {
310
+ clone.set("iconRotation", newStyle.image.getRotation());
311
+ }
312
+ if (feature.get("pictureOptions")) {
313
+ clone.set(
314
+ "pictureOptions",
315
+ JSON.stringify(feature.get("pictureOptions"))
316
+ );
317
+ }
318
+ }
319
+ if (feature.get("fillPattern")) {
320
+ clone.set("fillPattern", JSON.stringify(feature.get("fillPattern")));
321
+ newStyle.fill = null;
322
+ }
323
+ if (feature.get("maxZoom")) {
324
+ clone.set("maxZoom", parseFloat(feature.get("maxZoom"), 10));
325
+ }
326
+ if (feature.get("minZoom")) {
327
+ clone.set("minZoom", parseFloat(feature.get("minZoom"), 10));
328
+ }
329
+ if (newStyle.text && !newStyle.image) {
330
+ newStyle.image = new Icon({
331
+ src: "noimage",
332
+ scale: 0
333
+ });
334
+ }
335
+ const extraLineStyles = Array.isArray(styles) && styles.slice(1) || [];
336
+ extraLineStyles.forEach((extraLineStyle) => {
337
+ if (extraLineStyle && extraLineStyle.getImage() instanceof Icon && extraLineStyle.getGeometry()) {
338
+ const coord = extraLineStyle.getGeometry()(feature).getCoordinates();
339
+ const startCoord = feature.getGeometry().getFirstCoordinate();
340
+ if (coord[0] === startCoord[0] && coord[1] === startCoord[1]) {
341
+ clone.set(
342
+ "lineStartIcon",
343
+ JSON.stringify({
344
+ url: extraLineStyle.getImage().getSrc(),
345
+ scale: extraLineStyle.getImage().getScale(),
346
+ size: extraLineStyle.getImage().getSize(),
347
+ zIndex: extraLineStyle.getZIndex()
348
+ })
349
+ );
350
+ } else {
351
+ clone.set(
352
+ "lineEndIcon",
353
+ JSON.stringify({
354
+ url: extraLineStyle.getImage().getSrc(),
355
+ scale: extraLineStyle.getImage().getScale(),
356
+ size: extraLineStyle.getImage().getSize(),
357
+ zIndex: extraLineStyle.getZIndex()
358
+ })
359
+ );
360
+ }
361
+ }
362
+ });
363
+ const olStyle = new Style(newStyle);
364
+ clone.setStyle(olStyle);
365
+ if (!(clone.getGeometry() instanceof Point && olStyle.getText() && !olStyle.getText().getText())) {
366
+ exportFeatures.push(clone);
367
+ }
368
+ });
369
+ if (exportFeatures.length > 0) {
370
+ if (exportFeatures.length === 1) {
371
+ exportFeatures.push(new Feature());
372
+ }
373
+ featString = new KML({
374
+ extractStyles: true,
375
+ defaultStyle: [kmlStyle]
376
+ }).writeFeatures(exportFeatures);
377
+ featString = featString.replace(
378
+ /<Icon>\s*<href>noimage<\/href>\s*<\/Icon>/g,
379
+ ""
380
+ );
381
+ featString = featString.replace(/<Placemark\/>/g, "");
382
+ if (layer.name) {
383
+ featString = featString.replace(
384
+ /<Document>/,
385
+ `<Document><name>${layer.name}</name>`
386
+ );
387
+ }
388
+ }
389
+ return featString;
390
+ };
391
+ const removeDocumentCamera = (kmlString) => {
392
+ const kmlDoc = parse(kmlString);
393
+ const oldCameraNode = kmlDoc.getElementsByTagName("Camera")[0];
394
+ if (oldCameraNode) {
395
+ oldCameraNode.remove();
396
+ }
397
+ return new XMLSerializer().serializeToString(kmlDoc);
398
+ };
399
+ const writeDocumentCamera = (kmlString, cameraAttributes) => {
400
+ const kmlDoc = parse(removeDocumentCamera(kmlString));
401
+ if (cameraAttributes) {
402
+ const cameraNode = kmlDoc.createElement("Camera");
403
+ Object.keys(cameraAttributes).forEach((key) => {
404
+ const cameraAttribute = kmlDoc.createElement(
405
+ `${key.charAt(0).toUpperCase() + key.slice(1)}`
406
+ );
407
+ cameraAttribute.innerHTML = cameraAttributes[key];
408
+ cameraNode.appendChild(cameraAttribute);
409
+ });
410
+ const documentNode = kmlDoc.getElementsByTagName("Document")[0];
411
+ documentNode.appendChild(cameraNode);
412
+ }
413
+ return new XMLSerializer().serializeToString(kmlDoc);
414
+ };
415
+ export default {
416
+ readFeatures,
417
+ writeFeatures,
418
+ writeDocumentCamera,
419
+ removeDocumentCamera
420
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/KML.js"],
4
+ "sourcesContent": ["import KML from 'ol/format/KML';\nimport { Feature } from 'ol';\nimport Point from 'ol/geom/Point';\nimport MultiPoint from 'ol/geom/MultiPoint';\nimport GeometryCollection from 'ol/geom/GeometryCollection';\nimport { Style, Text, Icon, Circle, Fill, Stroke } from 'ol/style';\nimport { asString } from 'ol/color';\nimport { parse } from 'ol/xml';\nimport { kmlStyle } from './Styles';\nimport getPolygonPattern from './getPolygonPattern';\n\nconst applyTextStyleForIcon = (olIcon, olText) => {\n const size = olIcon.getSize() || [48, 48];\n const scale = olIcon.getScale() || 1;\n const anchor = olIcon.getAnchor() || [\n (size[0] * scale) / 2,\n (size[1] * scale) / 2,\n ];\n const offset = [\n scale * (size[0] - anchor[0]) + 5,\n scale * (size[1] / 2 - anchor[1]),\n ];\n olText.setOffsetX(offset[0]);\n olText.setOffsetY(offset[1]);\n olText.setTextAlign('left');\n};\n\nconst getVertexCoord = (geom, start = true, index = 0) => {\n const coords = geom.getCoordinates();\n const len = coords.length - 1;\n return start ? coords[index] : coords[len - index];\n};\n\nconst getLineIcon = (feature, icon, color, start = true) => {\n const geom = feature.getGeometry();\n const coordA = getVertexCoord(geom, start, 1);\n const coordB = getVertexCoord(geom, start);\n const dx = start ? coordA[0] - coordB[0] : coordB[0] - coordA[0];\n const dy = start ? coordA[1] - coordB[1] : coordB[1] - coordA[1];\n const rotation = Math.atan2(dy, dx);\n\n return new Style({\n geometry: (feat) => {\n const ge = feat.getGeometry();\n return new Point(getVertexCoord(ge, start));\n },\n image: new Icon({\n src: icon.url,\n color,\n rotation: -rotation,\n rotateWithView: true,\n scale: icon.scale,\n imgSize: icon.size, // ie 11\n }),\n zIndex: icon.zIndex,\n });\n};\n\n// Clean the unneeded feature's style and properties created by the KML parser.\nconst sanitizeFeature = (feature) => {\n const geom = feature.getGeometry();\n let styles = feature.getStyleFunction();\n\n // Store maxZoom in properties\n if (feature.get('maxZoom')) {\n feature.set('maxZoom', parseFloat(feature.get('maxZoom'), 10));\n }\n\n // Store minZoom in properties\n if (feature.get('minZoom')) {\n feature.set('minZoom', parseFloat(feature.get('minZoom'), 10));\n }\n\n // The use of clone is part of the scale fix line 156\n const tmpStyles = styles(feature);\n const style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone();\n\n let stroke = style.getStroke();\n if (stroke && feature.get('lineDash')) {\n stroke.setLineDash(\n feature\n .get('lineDash')\n .split(',')\n .map((l) => {\n return parseInt(l, 10);\n }),\n );\n }\n\n // The canvas draws a stroke width=1 by default if width=0, so we\n // remove the stroke style in that case.\n if (stroke && stroke.getWidth() === 0) {\n stroke = undefined;\n }\n\n if (feature.get('zIndex')) {\n style.setZIndex(parseInt(feature.get('zIndex'), 10));\n }\n\n // if the feature is a Point and we are offline, we use default vector\n // style.\n // if the feature is a Point and has a name with a text style, we\n // create a correct text style.\n // TODO Handle GeometryCollection displaying name on the first Point\n // geometry.\n if (style && (geom instanceof Point || geom instanceof MultiPoint)) {\n let image = style.getImage();\n let text = null;\n let fill = style.getFill();\n\n // If the feature has name we display it on the map as Google does\n if (\n feature.get('name') &&\n style.getText() &&\n style.getText().getScale() !== 0\n ) {\n if (image && image.getScale() === 0) {\n // transparentCircle is used to allow selection\n image = new Circle({\n radius: 1,\n fill: new Fill({ color: [0, 0, 0, 0] }),\n stroke: new Stroke({ color: [0, 0, 0, 0] }),\n });\n }\n\n // We replace empty white spaces used to keep normal spaces before and after the name.\n let name = feature.get('name');\n if (/\\u200B/g.test(name)) {\n name = name.replace(/\\u200B/g, '');\n feature.set('name', name);\n }\n\n text = new Text({\n font: feature.get('textFont') || 'normal 16px Helvetica',\n text: feature.get('name'),\n fill: style.getText().getFill(),\n // rotation unsupported by KML, taken instead from custom field.\n rotation: feature.get('textRotation') || 0,\n // since ol 6.3.1 : https://github.com/openlayers/openlayers/pull/10613/files#diff-1883da8b57e690db7ea0c35ce53c880aR925\n // a default textstroke is added to mimic google earth.\n // it was not the case before, the stroke was always null. So to keep\n // the same behavior we don't copy the stroke style.\n // TODO : maybe we should use this functionnality in the futur.\n // stroke: style.getText().getStroke(),\n scale: style.getText().getScale(),\n });\n\n if (feature.get('textStrokeColor') && feature.get('textStrokeWidth')) {\n text.setStroke(\n new Stroke({\n color: feature.get('textStrokeColor'),\n width: parseFloat(feature.get('textStrokeWidth')),\n }),\n );\n }\n\n if (feature.get('textAlign')) {\n text.setTextAlign(feature.get('textAlign'));\n }\n\n if (feature.get('textOffsetX')) {\n text.setOffsetX(parseFloat(feature.get('textOffsetX')));\n }\n\n if (feature.get('textOffsetY')) {\n text.setOffsetY(parseFloat(feature.get('textOffsetY')));\n }\n\n if (feature.get('textBackgroundFillColor')) {\n text.setBackgroundFill(\n new Fill({\n color: feature.get('textBackgroundFillColor'),\n }),\n );\n }\n\n if (feature.get('textPadding')) {\n text.setPadding(\n feature\n .get('textPadding')\n .split(',')\n .map((n) => {\n return parseFloat(n);\n }),\n );\n }\n\n if (image instanceof Icon) {\n applyTextStyleForIcon(image, text);\n }\n }\n\n if (image instanceof Icon) {\n /* Apply icon rotation if defined (by default only written as\n * <heading> tag, which is not read as rotation value by the ol KML module)\n */\n image.setRotation(parseFloat(feature.get('iconRotation')) || 0);\n }\n\n fill = undefined;\n stroke = undefined;\n\n styles = (feat, resolution) => {\n /* Options to be used for picture scaling with map, should have at least\n * a resolution attribute (this is the map resolution at the zoom level when\n * the picture is created), can take an optional constant for further scale\n * adjustment.\n * e.g. { resolution: 0.123, defaultScale: 1 / 6 }\n */\n\n if (feat.get('pictureOptions')) {\n let pictureOptions = feat.get('pictureOptions');\n if (typeof pictureOptions === 'string') {\n pictureOptions = JSON.parse(pictureOptions);\n }\n feat.set('pictureOptions', pictureOptions);\n if (pictureOptions.resolution) {\n image.setScale(\n (pictureOptions.resolution / resolution) *\n pictureOptions.defaultScale || 1,\n );\n }\n }\n\n return new Style({\n fill,\n stroke,\n image,\n text,\n zIndex: style.getZIndex(),\n });\n };\n }\n\n // Remove image and text styles for polygons and lines\n if (\n !(\n geom instanceof Point ||\n geom instanceof MultiPoint ||\n geom instanceof GeometryCollection\n )\n ) {\n styles = [\n new Style({\n fill: style.getFill(),\n stroke,\n image: null,\n text: null,\n zIndex: style.getZIndex(),\n }),\n ];\n\n // Parse the fillPattern json string and store parsed object\n let fillPattern = feature.get('fillPattern');\n if (fillPattern) {\n fillPattern = JSON.parse(fillPattern);\n feature.set('fillPattern', fillPattern);\n\n /* We set the fill pattern for polygons */\n if (!style.getFill()) {\n styles[0].setFill(new Fill());\n }\n const patternOrColor = fillPattern.empty\n ? [0, 0, 0, 0]\n : getPolygonPattern(fillPattern.id, fillPattern.color);\n styles[0].getFill().setColor(patternOrColor);\n }\n\n // Add line's icons styles\n if (feature.get('lineStartIcon')) {\n styles.push(\n getLineIcon(\n feature,\n JSON.parse(feature.get('lineStartIcon')),\n stroke.getColor(),\n ),\n );\n }\n\n if (feature.get('lineEndIcon')) {\n styles.push(\n getLineIcon(\n feature,\n JSON.parse(feature.get('lineEndIcon')),\n stroke.getColor(),\n false,\n ),\n );\n }\n }\n feature.setStyle(styles);\n};\n\n/**\n * Read a KML string.\n * @param {String} kmlString A string representing a KML file.\n * @param {<ol.Projection|String>} featureProjection The projection used by the map.\n */\nconst readFeatures = (kmlString, featureProjection) => {\n const features = new KML().readFeatures(kmlString, {\n featureProjection,\n });\n features.forEach((feature) => {\n sanitizeFeature(feature);\n });\n return features;\n};\n\n/**\n * Create a KML string.\n * @param {VectorLayer} layer A react-spatial VectorLayer.\n * @param {<ol.Projection|String>} featureProjection The current projection used by the features.\n */\nconst writeFeatures = (layer, featureProjection, mapResolution) => {\n let featString;\n const { olLayer } = layer;\n const exportFeatures = [];\n\n olLayer.getSource().forEachFeature((feature) => {\n // We silently ignore Circle elements as they are\n // not supported in kml.\n if (feature.getGeometry().getType() === 'Circle') {\n return;\n }\n\n const clone = feature.clone();\n clone.setId(feature.getId());\n clone.getGeometry().setProperties(feature.getGeometry().getProperties());\n clone.getGeometry().transform(featureProjection, 'EPSG:4326');\n\n // We remove all ExtendedData not related to style.\n Object.keys(feature.getProperties()).forEach((key) => {\n if (!/^(geometry|name|description)$/.test(key)) {\n clone.unset(key, true);\n }\n });\n\n let styles;\n\n if (feature.getStyleFunction()) {\n styles = feature.getStyleFunction()(feature, mapResolution);\n } else if (olLayer && olLayer.getStyleFunction()) {\n styles = olLayer.getStyleFunction()(feature, mapResolution);\n }\n\n const mainStyle = styles[0] || styles;\n\n const newStyle = {\n fill: mainStyle.getFill(),\n stroke: mainStyle.getStroke(),\n text: mainStyle.getText(),\n image: mainStyle.getImage(),\n zIndex: mainStyle.getZIndex(),\n };\n\n if (newStyle.zIndex) {\n clone.set('zIndex', newStyle.zIndex);\n }\n\n // If we see spaces at the beginning or at the end we add a empty\n // white space at the beginning and at the end.\n if (newStyle.text && /^\\s|\\s$/g.test(newStyle.text.getText())) {\n newStyle.text.setText(`\\u200B${newStyle.text.getText()}\\u200B`);\n }\n\n // Set custom properties to be converted in extendedData in KML.\n if (newStyle.text && newStyle.text.getRotation()) {\n clone.set('textRotation', newStyle.text.getRotation());\n }\n\n if (newStyle.text && newStyle.text.getFont()) {\n clone.set('textFont', newStyle.text.getFont());\n }\n\n if (newStyle.text && newStyle.text.getTextAlign()) {\n clone.set('textAlign', newStyle.text.getTextAlign());\n }\n\n if (newStyle.text && newStyle.text.getOffsetX()) {\n clone.set('textOffsetX', newStyle.text.getOffsetX());\n }\n\n if (newStyle.text && newStyle.text.getOffsetY()) {\n clone.set('textOffsetY', newStyle.text.getOffsetY());\n }\n\n if (newStyle.text && newStyle.text.getStroke()) {\n if (newStyle.text.getStroke().getColor()) {\n clone.set(\n 'textStrokeColor',\n asString(newStyle.text.getStroke().getColor()),\n );\n }\n\n if (newStyle.text.getStroke().getWidth()) {\n clone.set('textStrokeWidth', newStyle.text.getStroke().getWidth());\n }\n }\n\n if (newStyle.text && newStyle.text.getBackgroundFill()) {\n clone.set(\n 'textBackgroundFillColor',\n asString(newStyle.text.getBackgroundFill().getColor()),\n );\n }\n\n if (newStyle.text && newStyle.text.getPadding()) {\n clone.set('textPadding', newStyle.text.getPadding().join());\n }\n\n if (newStyle.stroke && newStyle.stroke.getLineDash()) {\n clone.set('lineDash', newStyle.stroke.getLineDash().join(','));\n }\n\n if (newStyle.image instanceof Circle) {\n newStyle.image = null;\n }\n\n if (newStyle.image) {\n const imgSource = newStyle.image.getSrc();\n if (!/(http(s?)):\\/\\//gi.test(imgSource)) {\n // eslint-disable-next-line no-console\n console.log(\n 'Local image source not supported for KML export.' +\n 'Should use remote web server',\n );\n }\n\n if (newStyle.image.getRotation()) {\n // We set the icon rotation as extended data\n clone.set('iconRotation', newStyle.image.getRotation());\n }\n\n // Set map resolution to use for icon-to-map proportional scaling\n if (feature.get('pictureOptions')) {\n clone.set(\n 'pictureOptions',\n JSON.stringify(feature.get('pictureOptions')),\n );\n }\n }\n\n // In case a fill pattern should be applied (use fillPattern attribute to store pattern id, color etc)\n if (feature.get('fillPattern')) {\n clone.set('fillPattern', JSON.stringify(feature.get('fillPattern')));\n newStyle.fill = null;\n }\n\n // maxZoom: maximum zoom level at which the feature is displayed\n if (feature.get('maxZoom')) {\n clone.set('maxZoom', parseFloat(feature.get('maxZoom'), 10));\n }\n\n // minZoom: minimum zoom level at which the feature is displayed\n if (feature.get('minZoom')) {\n clone.set('minZoom', parseFloat(feature.get('minZoom'), 10));\n }\n\n // If only text is displayed we must specify an\n // image style with scale=0\n if (newStyle.text && !newStyle.image) {\n newStyle.image = new Icon({\n src: 'noimage',\n scale: 0,\n });\n }\n\n // In case we use line's icon .\n const extraLineStyles = (Array.isArray(styles) && styles.slice(1)) || [];\n extraLineStyles.forEach((extraLineStyle) => {\n if (\n extraLineStyle &&\n extraLineStyle.getImage() instanceof Icon &&\n extraLineStyle.getGeometry()\n ) {\n const coord = extraLineStyle.getGeometry()(feature).getCoordinates();\n const startCoord = feature.getGeometry().getFirstCoordinate();\n if (coord[0] === startCoord[0] && coord[1] === startCoord[1]) {\n clone.set(\n 'lineStartIcon',\n JSON.stringify({\n url: extraLineStyle.getImage().getSrc(),\n scale: extraLineStyle.getImage().getScale(),\n size: extraLineStyle.getImage().getSize(),\n zIndex: extraLineStyle.getZIndex(),\n }),\n );\n } else {\n clone.set(\n 'lineEndIcon',\n JSON.stringify({\n url: extraLineStyle.getImage().getSrc(),\n scale: extraLineStyle.getImage().getScale(),\n size: extraLineStyle.getImage().getSize(),\n zIndex: extraLineStyle.getZIndex(),\n }),\n );\n }\n }\n });\n\n const olStyle = new Style(newStyle);\n clone.setStyle(olStyle);\n\n if (\n !(\n clone.getGeometry() instanceof Point &&\n olStyle.getText() &&\n !olStyle.getText().getText()\n )\n ) {\n exportFeatures.push(clone);\n }\n });\n\n if (exportFeatures.length > 0) {\n if (exportFeatures.length === 1) {\n // force the add of a <Document> node\n exportFeatures.push(new Feature());\n }\n\n featString = new KML({\n extractStyles: true,\n defaultStyle: [kmlStyle],\n }).writeFeatures(exportFeatures);\n\n // Remove no image hack\n featString = featString.replace(\n /<Icon>\\s*<href>noimage<\\/href>\\s*<\\/Icon>/g,\n '',\n );\n\n // Remove empty placemark added to have\n // <Document> tag\n featString = featString.replace(/<Placemark\\/>/g, '');\n\n // Add KML document name\n if (layer.name) {\n featString = featString.replace(\n /<Document>/,\n `<Document><name>${layer.name}</name>`,\n );\n }\n }\n\n return featString;\n};\n\n/**\n * Removes the <Camera> tag from a KML string. Returns the KML string with removed <Camera> tag.\n * @param {String} kmlString A string representing a KML file.\n */\nconst removeDocumentCamera = (kmlString) => {\n const kmlDoc = parse(kmlString);\n // Remove old Camera node\n const oldCameraNode = kmlDoc.getElementsByTagName('Camera')[0];\n if (oldCameraNode) {\n oldCameraNode.remove();\n }\n return new XMLSerializer().serializeToString(kmlDoc);\n};\n\n/**\n * Write the <Camera> tag into a KML string. Returns the KML string with added <Camera> tag.\n * @param {String} kmlString A string representing a KML file.\n * @param {Object} cameraAttributes Object containing the camera tags (longitude, latitude, altitude, heading, tilt, altitudeMode, roll)\n * as keys with corresponding values. See https://developers.google.com/kml/documentation/kmlreference#camera\n */\nconst writeDocumentCamera = (kmlString, cameraAttributes) => {\n const kmlDoc = parse(removeDocumentCamera(kmlString));\n\n if (cameraAttributes) {\n // Create Camera node with child attributes if the cameraAttributes object is defined\n const cameraNode = kmlDoc.createElement('Camera');\n Object.keys(cameraAttributes).forEach((key) => {\n const cameraAttribute = kmlDoc.createElement(\n `${key.charAt(0).toUpperCase() + key.slice(1)}`,\n );\n cameraAttribute.innerHTML = cameraAttributes[key];\n cameraNode.appendChild(cameraAttribute);\n });\n const documentNode = kmlDoc.getElementsByTagName('Document')[0];\n documentNode.appendChild(cameraNode);\n }\n\n return new XMLSerializer().serializeToString(kmlDoc);\n};\n\nexport default {\n readFe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
  makeStructureNS,
7
- makeObjectPropertySetter,
8
- } from 'ol/xml';
9
- import { extend, includes } from 'ol/array';
10
- import { readDecimal, readString } from 'ol/format/xsd';
11
-
7
+ makeObjectPropertySetter
8
+ } from "ol/xml";
9
+ import { extend, includes } from "ol/array";
10
+ import { readDecimal, readString } from "ol/format/xsd";
12
11
  const NAMESPACE_URIS = [
13
12
  null,
14
- 'http://earth.google.com/kml/2.0',
15
- 'http://earth.google.com/kml/2.1',
16
- 'http://earth.google.com/kml/2.2',
17
- 'http://www.opengis.net/kml/2.2',
13
+ "http://earth.google.com/kml/2.0",
14
+ "http://earth.google.com/kml/2.1",
15
+ "http://earth.google.com/kml/2.2",
16
+ "http://www.opengis.net/kml/2.2"
18
17
  ];
19
-
20
18
  const CAMERA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
21
19
  Altitude: makeObjectPropertySetter(readDecimal),
22
20
  Longitude: makeObjectPropertySetter(readDecimal),
@@ -24,9 +22,8 @@ const CAMERA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
24
22
  Tilt: makeObjectPropertySetter(readDecimal),
25
23
  AltitudeMode: makeObjectPropertySetter(readString),
26
24
  Heading: makeObjectPropertySetter(readDecimal),
27
- Roll: makeObjectPropertySetter(readDecimal),
25
+ Roll: makeObjectPropertySetter(readDecimal)
28
26
  });
29
-
30
27
  class KML extends OLKML {
31
28
  /**
32
29
  * Read the cameras of the KML.
@@ -37,34 +34,44 @@ class KML extends OLKML {
37
34
  */
38
35
  readCamera(source) {
39
36
  const cameras = [];
40
- if (typeof source === 'string') {
37
+ if (typeof source === "string") {
41
38
  const doc = parse(source);
42
39
  extend(cameras, this.readCameraFromDocument(doc));
43
40
  } else if (isDocument(source)) {
44
41
  extend(
45
42
  cameras,
46
- this.readCameraFromDocument(/** @type {Document} */ (source)),
43
+ this.readCameraFromDocument(
44
+ /** @type {Document} */
45
+ source
46
+ )
47
47
  );
48
48
  } else {
49
- extend(cameras, this.readCameraFromNode(/** @type {Element} */ (source)));
49
+ extend(cameras, this.readCameraFromNode(
50
+ /** @type {Element} */
51
+ source
52
+ ));
50
53
  }
51
54
  return cameras;
52
55
  }
53
-
54
56
  /**
55
57
  * @param {Document} doc Document.
56
58
  * @return {Array<Object>} Cameras.
57
59
  */
58
60
  readCameraFromDocument(doc) {
59
61
  const cameras = [];
60
- for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
62
+ for (let n = (
63
+ /** @type {Node} */
64
+ doc.firstChild
65
+ ); n; n = n.nextSibling) {
61
66
  if (n.nodeType === Node.ELEMENT_NODE) {
62
- extend(cameras, this.readCameraFromNode(/** @type {Element} */ (n)));
67
+ extend(cameras, this.readCameraFromNode(
68
+ /** @type {Element} */
69
+ n
70
+ ));
63
71
  }
64
72
  }
65
73
  return cameras;
66
74
  }
67
-
68
75
  /**
69
76
  * @param {Element} node Node.
70
77
  * @return {Array<Object>} Cameras.
@@ -73,28 +80,18 @@ class KML extends OLKML {
73
80
  readCameraFromNode(node) {
74
81
  const cameras = [];
75
82
  for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
76
- if (
77
- includes(NAMESPACE_URIS, n.namespaceURI) &&
78
- n.localName === 'Camera'
79
- ) {
83
+ if (includes(NAMESPACE_URIS, n.namespaceURI) && n.localName === "Camera") {
80
84
  const obj = pushParseAndPop({}, CAMERA_PARSERS, n, []);
81
85
  cameras.push(obj);
82
86
  }
83
87
  }
84
88
  for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
85
89
  const { localName } = n;
86
- if (
87
- includes(NAMESPACE_URIS, n.namespaceURI) &&
88
- (localName === 'Document' ||
89
- localName === 'Folder' ||
90
- localName === 'Placemark' ||
91
- localName === 'kml')
92
- ) {
90
+ if (includes(NAMESPACE_URIS, n.namespaceURI) && (localName === "Document" || localName === "Folder" || localName === "Placemark" || localName === "kml")) {
93
91
  extend(cameras, this.readCameraFromNode(n));
94
92
  }
95
93
  }
96
94
  return cameras;
97
95
  }
98
96
  }
99
-
100
97
  export default KML;
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/KMLFormat.js"],
4
+ "sourcesContent": ["import OLKML from 'ol/format/KML';\nimport {\n parse,\n pushParseAndPop,\n isDocument,\n makeStructureNS,\n makeObjectPropertySetter,\n} from 'ol/xml';\nimport { extend, includes } from 'ol/array';\nimport { readDecimal, readString } from 'ol/format/xsd';\n\nconst NAMESPACE_URIS = [\n null,\n 'http://earth.google.com/kml/2.0',\n 'http://earth.google.com/kml/2.1',\n 'http://earth.google.com/kml/2.2',\n 'http://www.opengis.net/kml/2.2',\n];\n\nconst CAMERA_PARSERS = makeStructureNS(NAMESPACE_URIS, {\n Altitude: makeObjectPropertySetter(readDecimal),\n Longitude: makeObjectPropertySetter(readDecimal),\n Latitude: makeObjectPropertySetter(readDecimal),\n Tilt: makeObjectPropertySetter(readDecimal),\n AltitudeMode: makeObjectPropertySetter(readString),\n Heading: makeObjectPropertySetter(readDecimal),\n Roll: makeObjectPropertySetter(readDecimal),\n});\n\nclass KML extends OLKML {\n /**\n * Read the cameras of the KML.\n *\n * @param {Document|Element|string} source Source.\n * @return {Array<Object>} Cameras.\n * @api\n */\n readCamera(source) {\n const cameras = [];\n if (typeof source === 'string') {\n const doc = parse(source);\n extend(cameras, this.readCameraFromDocument(doc));\n } else if (isDocument(source)) {\n extend(\n cameras,\n this.readCameraFromDocument(/** @type {Document} */ (source)),\n );\n } else {\n extend(cameras, this.readCameraFromNode(/** @type {Element} */ (source)));\n }\n return cameras;\n }\n\n /**\n * @param {Document} doc Document.\n * @return {Array<Object>} Cameras.\n */\n readCameraFromDocument(doc) {\n const cameras = [];\n for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {\n if (n.nodeType === Node.ELEMENT_NODE) {\n extend(cameras, this.readCameraFromNode(/** @type {Element} */ (n)));\n }\n }\n return cameras;\n }\n\n /**\n * @param {Element} node Node.\n * @return {Array<Object>} Cameras.\n * @api\n */\n readCameraFromNode(node) {\n const cameras = [];\n for (let n = node.firstElementChild; n; n = n.nextElementSibling) {\n if (\n includes(NAMESPACE_URIS, n.namespaceURI) &&\n n.localName === 'Camera'\n ) {\n const obj = pushParseAndPop({}, CAMERA_PARSERS, n, []);\n cameras.push(obj);\n }\n }\n for (let n = node.firstElementChild; n; n = n.nextElementSibling) {\n const { localName } = n;\n if (\n includes(NAMESPACE_URIS, n.namespaceURI) &&\n (localName === 'Document' ||\n localName === 'Folder' ||\n localName === 'Placemark' ||\n localName === 'kml')\n ) {\n extend(cameras, this.readCameraFromNode(n));\n }\n }\n return cameras;\n }\n}\n\nexport default KML;\n"],
5
+ "mappings": "AAAA,OAAO,WAAW;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,QAAQ,gBAAgB;AACjC,SAAS,aAAa,kBAAkB;AAExC,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,iBAAiB,gBAAgB,gBAAgB;AAAA,EACrD,UAAU,yBAAyB,WAAW;AAAA,EAC9C,WAAW,yBAAyB,WAAW;AAAA,EAC/C,UAAU,yBAAyB,WAAW;AAAA,EAC9C,MAAM,yBAAyB,WAAW;AAAA,EAC1C,cAAc,yBAAyB,UAAU;AAAA,EACjD,SAAS,yBAAyB,WAAW;AAAA,EAC7C,MAAM,yBAAyB,WAAW;AAC5C,CAAC;AAED,MAAM,YAAY,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtB,WAAW,QAAQ;AACjB,UAAM,UAAU,CAAC;AACjB,QAAI,OAAO,WAAW,UAAU;AAC9B,YAAM,MAAM,MAAM,MAAM;AACxB,aAAO,SAAS,KAAK,uBAAuB,GAAG,CAAC;AAAA,IAClD,WAAW,WAAW,MAAM,GAAG;AAC7B;AAAA,QACE;AAAA,QACA,KAAK;AAAA;AAAA,UAAgD;AAAA,QAAO;AAA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