react-spatial 1.5.2 → 1.5.3

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 (295) hide show
  1. package/.github/workflows/conventional-pr-title.yml +21 -0
  2. package/.github/workflows/main.yml +28 -0
  3. package/.husky/commit-msg +4 -0
  4. package/.husky/post-checkout +4 -0
  5. package/.husky/post-merge +4 -0
  6. package/.husky/post-rebase +4 -0
  7. package/.husky/pre-commit +4 -0
  8. package/.nvmrc +1 -0
  9. package/.whitesource +8 -0
  10. package/CHANGELOG.md +65 -0
  11. package/DEVELOP.md +113 -0
  12. package/__mocks__/mapbox-gl.js +11 -0
  13. package/__mocks__/resize-observer-polyfill.js +9 -0
  14. package/babel.config.js +3 -0
  15. package/commitlint.config.js +1 -0
  16. package/data/topic1.js +119 -0
  17. package/data/topic2.js +28 -0
  18. package/doc/README.md +21 -0
  19. package/doc/doc-config.json +4 -0
  20. package/package.json +4 -3
  21. package/pull_request_template.md +16 -0
  22. package/renovate.json +4 -0
  23. package/scripts/read-pkg-json.js +17 -0
  24. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +322 -0
  25. package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +69 -0
  26. package/src/components/BaseLayerSwitcher/README.md +61 -0
  27. package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +88 -0
  28. package/src/components/BaseLayerSwitcher/index.js +1 -0
  29. package/src/components/BasicMap/BasicMap.js +413 -0
  30. package/src/components/BasicMap/BasicMap.test.js +281 -0
  31. package/src/components/BasicMap/README.md +18 -0
  32. package/src/components/BasicMap/index.js +1 -0
  33. package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.js +320 -93
  34. package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +148 -0
  35. package/src/components/CanvasSaveButton/README.md +76 -0
  36. package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +76 -0
  37. package/src/components/CanvasSaveButton/index.js +1 -0
  38. package/src/components/Copyright/Copyright.js +89 -0
  39. package/src/components/Copyright/Copyright.test.js +134 -0
  40. package/src/components/Copyright/README.md +36 -0
  41. package/src/components/Copyright/index.js +1 -0
  42. package/src/components/FeatureExportButton/FeatureExportButton.js +118 -0
  43. package/src/components/FeatureExportButton/FeatureExportButton.test.js +417 -0
  44. package/src/components/FeatureExportButton/README.md +76 -0
  45. package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +67 -0
  46. package/src/components/FeatureExportButton/index.js +1 -0
  47. package/src/components/FitExtent/FitExtent.js +62 -0
  48. package/src/components/FitExtent/FitExtent.test.js +48 -0
  49. package/src/components/FitExtent/README.md +34 -0
  50. package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +13 -0
  51. package/src/components/FitExtent/index.js +1 -0
  52. package/{components → src/components}/Geolocation/Geolocation.js +144 -61
  53. package/src/components/Geolocation/Geolocation.test.js +267 -0
  54. package/src/components/Geolocation/README.md +25 -0
  55. package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +92 -0
  56. package/src/components/Geolocation/index.js +1 -0
  57. package/src/components/LayerTree/LayerTree.js +487 -0
  58. package/src/components/LayerTree/LayerTree.test.js +337 -0
  59. package/src/components/LayerTree/README.md +92 -0
  60. package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +1746 -0
  61. package/src/components/LayerTree/index.js +1 -0
  62. package/src/components/MousePosition/MousePosition.js +175 -0
  63. package/src/components/MousePosition/MousePosition.test.js +132 -0
  64. package/src/components/MousePosition/README.md +50 -0
  65. package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +76 -0
  66. package/src/components/MousePosition/index.js +1 -0
  67. package/src/components/NorthArrow/NorthArrow.js +75 -0
  68. package/src/components/NorthArrow/NorthArrow.test.js +104 -0
  69. package/src/components/NorthArrow/README.md +59 -0
  70. package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +117 -0
  71. package/src/components/NorthArrow/index.js +1 -0
  72. package/src/components/Overlay/Overlay.js +176 -0
  73. package/src/components/Overlay/Overlay.test.js +149 -0
  74. package/src/components/Overlay/README.md +59 -0
  75. package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +9 -0
  76. package/src/components/Overlay/index.js +1 -0
  77. package/src/components/Permalink/Permalink.js +326 -0
  78. package/src/components/Permalink/Permalink.test.js +285 -0
  79. package/src/components/Permalink/README.md +105 -0
  80. package/src/components/Permalink/index.js +1 -0
  81. package/{components → src/components}/Popup/Popup.js +165 -55
  82. package/src/components/Popup/Popup.test.js +307 -0
  83. package/src/components/Popup/README.md +93 -0
  84. package/src/components/Popup/__snapshots__/Popup.test.js.snap +180 -0
  85. package/src/components/Popup/index.js +1 -0
  86. package/src/components/README.md +41 -0
  87. package/{components → src/components}/ResizeHandler/ResizeHandler.js +50 -15
  88. package/src/components/ResizeHandler/ResizeHandler.test.js +344 -0
  89. package/src/components/ResizeHandler/index.js +1 -0
  90. package/src/components/RouteSchedule/README.md +118 -0
  91. package/src/components/RouteSchedule/RouteSchedule.js +370 -0
  92. package/src/components/RouteSchedule/RouteSchedule.test.js +113 -0
  93. package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +248 -0
  94. package/src/components/RouteSchedule/index.js +1 -0
  95. package/src/components/ScaleLine/README.md +29 -0
  96. package/src/components/ScaleLine/ScaleLine.js +50 -0
  97. package/src/components/ScaleLine/ScaleLine.test.js +30 -0
  98. package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +7 -0
  99. package/src/components/ScaleLine/index.js +1 -0
  100. package/src/components/StopsFinder/README.md +50 -0
  101. package/src/components/StopsFinder/StopsFinder.js +284 -0
  102. package/src/components/StopsFinder/StopsFinder.test.js +17 -0
  103. package/src/components/StopsFinder/StopsFinderOption.js +61 -0
  104. package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +133 -0
  105. package/src/components/StopsFinder/index.js +1 -0
  106. package/src/components/Zoom/README.md +25 -0
  107. package/src/components/Zoom/Zoom.js +180 -0
  108. package/src/components/Zoom/Zoom.test.js +141 -0
  109. package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +201 -0
  110. package/src/components/Zoom/index.js +1 -0
  111. package/{propTypes.js → src/propTypes.js} +16 -12
  112. package/{setupTests.js → src/setupTests.js} +1 -1
  113. package/src/styleguidist/ComponentsList.js +52 -0
  114. package/src/styleguidist/StyleGuide.js +277 -0
  115. package/src/styleguidist/styleguidist.css +38 -0
  116. package/src/utils/GlobalsForOle.js +99 -0
  117. package/src/utils/KML.js +594 -0
  118. package/src/utils/KML.test.js +337 -0
  119. package/src/utils/KMLFormat.js +100 -0
  120. package/src/utils/KMLFormat.test.js +50 -0
  121. package/{utils → src/utils}/Styles.js +20 -14
  122. 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
  123. package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
  124. 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
  125. 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
  126. package/{utils → src/utils}/getPolygonPattern.js +34 -6
  127. package/src/utils/getPolygonPattern.test.js +61 -0
  128. package/src/utils/timeUtils.js +52 -0
  129. package/src/utils/timeUtils.test.js +30 -0
  130. package/styleguide.config.js +251 -0
  131. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -231
  132. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +0 -7
  133. package/components/BaseLayerSwitcher/index.js +0 -1
  134. package/components/BaseLayerSwitcher/index.js.map +0 -7
  135. package/components/BasicMap/BasicMap.js +0 -278
  136. package/components/BasicMap/BasicMap.js.map +0 -7
  137. package/components/BasicMap/index.js +0 -1
  138. package/components/BasicMap/index.js.map +0 -7
  139. package/components/CanvasSaveButton/CanvasSaveButton.js.map +0 -7
  140. package/components/CanvasSaveButton/index.js +0 -1
  141. package/components/CanvasSaveButton/index.js.map +0 -7
  142. package/components/Copyright/Copyright.js +0 -55
  143. package/components/Copyright/Copyright.js.map +0 -7
  144. package/components/Copyright/index.js +0 -1
  145. package/components/Copyright/index.js.map +0 -7
  146. package/components/FeatureExportButton/FeatureExportButton.js +0 -62
  147. package/components/FeatureExportButton/FeatureExportButton.js.map +0 -7
  148. package/components/FeatureExportButton/index.js +0 -1
  149. package/components/FeatureExportButton/index.js.map +0 -7
  150. package/components/FitExtent/FitExtent.js +0 -32
  151. package/components/FitExtent/FitExtent.js.map +0 -7
  152. package/components/FitExtent/index.js +0 -1
  153. package/components/FitExtent/index.js.map +0 -7
  154. package/components/Geolocation/Geolocation.js.map +0 -7
  155. package/components/Geolocation/index.js +0 -1
  156. package/components/Geolocation/index.js.map +0 -7
  157. package/components/LayerTree/LayerTree.js +0 -278
  158. package/components/LayerTree/LayerTree.js.map +0 -7
  159. package/components/LayerTree/index.js +0 -1
  160. package/components/LayerTree/index.js.map +0 -7
  161. package/components/MousePosition/MousePosition.js +0 -110
  162. package/components/MousePosition/MousePosition.js.map +0 -7
  163. package/components/MousePosition/index.js +0 -1
  164. package/components/MousePosition/index.js.map +0 -7
  165. package/components/NorthArrow/NorthArrow.js +0 -43
  166. package/components/NorthArrow/NorthArrow.js.map +0 -7
  167. package/components/NorthArrow/index.js +0 -1
  168. package/components/NorthArrow/index.js.map +0 -7
  169. package/components/Overlay/Overlay.js +0 -122
  170. package/components/Overlay/Overlay.js.map +0 -7
  171. package/components/Overlay/index.js +0 -1
  172. package/components/Overlay/index.js.map +0 -7
  173. package/components/Permalink/Permalink.js +0 -206
  174. package/components/Permalink/Permalink.js.map +0 -7
  175. package/components/Permalink/index.js +0 -1
  176. package/components/Permalink/index.js.map +0 -7
  177. package/components/Popup/Popup.js.map +0 -7
  178. package/components/Popup/index.js +0 -1
  179. package/components/Popup/index.js.map +0 -7
  180. package/components/ResizeHandler/ResizeHandler.js.map +0 -7
  181. package/components/ResizeHandler/index.js +0 -1
  182. package/components/ResizeHandler/index.js.map +0 -7
  183. package/components/RouteSchedule/RouteSchedule.js +0 -220
  184. package/components/RouteSchedule/RouteSchedule.js.map +0 -7
  185. package/components/RouteSchedule/index.js +0 -1
  186. package/components/RouteSchedule/index.js.map +0 -7
  187. package/components/ScaleLine/ScaleLine.js +0 -32
  188. package/components/ScaleLine/ScaleLine.js.map +0 -7
  189. package/components/ScaleLine/index.js +0 -1
  190. package/components/ScaleLine/index.js.map +0 -7
  191. package/components/StopsFinder/StopsFinder.js +0 -210
  192. package/components/StopsFinder/StopsFinder.js.map +0 -7
  193. package/components/StopsFinder/StopsFinderOption.js +0 -51
  194. package/components/StopsFinder/StopsFinderOption.js.map +0 -7
  195. package/components/StopsFinder/index.js +0 -1
  196. package/components/StopsFinder/index.js.map +0 -7
  197. package/components/Zoom/Zoom.js +0 -130
  198. package/components/Zoom/Zoom.js.map +0 -7
  199. package/components/Zoom/index.js +0 -1
  200. package/components/Zoom/index.js.map +0 -7
  201. package/propTypes.js.map +0 -7
  202. package/setupTests.js.map +0 -7
  203. package/utils/GlobalsForOle.js +0 -94
  204. package/utils/GlobalsForOle.js.map +0 -7
  205. package/utils/KML.js +0 -412
  206. package/utils/KML.js.map +0 -7
  207. package/utils/KMLFormat.js +0 -69
  208. package/utils/KMLFormat.js.map +0 -7
  209. package/utils/Styles.js.map +0 -7
  210. package/utils/getPolygonPattern.js.map +0 -7
  211. package/utils/timeUtils.js +0 -31
  212. package/utils/timeUtils.js.map +0 -7
  213. /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
  214. /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
  215. /package/{components → src/components}/BasicMap/BasicMap.md.scss +0 -0
  216. /package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
  217. /package/{components → src/components}/Copyright/Copyright.md.scss +0 -0
  218. /package/{components → src/components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
  219. /package/{components → src/components}/FitExtent/FitExtent.md.scss +0 -0
  220. /package/{components → src/components}/Geolocation/Geolocation.md.scss +0 -0
  221. /package/{components → src/components}/Geolocation/Geolocation.scss +0 -0
  222. /package/{components → src/components}/LayerTree/LayerTree.md.scss +0 -0
  223. /package/{components → src/components}/LayerTree/LayerTree.scss +0 -0
  224. /package/{components → src/components}/MousePosition/MousePosition.md.scss +0 -0
  225. /package/{components → src/components}/NorthArrow/NorthArrow.scss +0 -0
  226. /package/{components → src/components}/Overlay/Overlay.md.scss +0 -0
  227. /package/{components → src/components}/Overlay/Overlay.scss +0 -0
  228. /package/{components → src/components}/Permalink/Permalink.md.scss +0 -0
  229. /package/{components → src/components}/Popup/Popup.md.scss +0 -0
  230. /package/{components → src/components}/Popup/Popup.scss +0 -0
  231. /package/{components → src/components}/RouteSchedule/RouteSchedule.md.scss +0 -0
  232. /package/{components → src/components}/RouteSchedule/RouteSchedule.scss +0 -0
  233. /package/{components → src/components}/ScaleLine/ScaleLine.scss +0 -0
  234. /package/{components → src/components}/Zoom/Zoom.md.scss +0 -0
  235. /package/{components → src/components}/Zoom/Zoom.scss +0 -0
  236. /package/{images → src/images}/RouteSchedule/firstStation.png +0 -0
  237. /package/{images → src/images}/RouteSchedule/lastStation.png +0 -0
  238. /package/{images → src/images}/RouteSchedule/line.png +0 -0
  239. /package/{images → src/images}/RouteSchedule/station.png +0 -0
  240. /package/{images → src/images}/baselayer/baselayer.basebright.png +0 -0
  241. /package/{images → src/images}/baselayer/baselayer.osm.png +0 -0
  242. /package/{images → src/images}/baselayer/baselayer.travic.png +0 -0
  243. /package/{images → src/images}/baselayer/open.topo.map.png +0 -0
  244. /package/{images → src/images}/baselayer/osm.baselayer.hot.png +0 -0
  245. /package/{images → src/images}/baselayer/osm.baselayer.png +0 -0
  246. /package/{images → src/images}/favicon.png +0 -0
  247. /package/{images → src/images}/geops_logo.png +0 -0
  248. /package/{images → src/images}/geops_logo.svg +0 -0
  249. /package/{images → src/images}/geops_qr.png +0 -0
  250. /package/{images → src/images}/mots/bus_poi-blue-01.svg +0 -0
  251. /package/{images → src/images}/mots/bus_poi-grey-01.svg +0 -0
  252. /package/{images → src/images}/mots/bus_round-blue-01.svg +0 -0
  253. /package/{images → src/images}/mots/bus_round-grey-01.svg +0 -0
  254. /package/{images → src/images}/mots/bus_square-blue-01.svg +0 -0
  255. /package/{images → src/images}/mots/bus_square-grey-01.svg +0 -0
  256. /package/{images → src/images}/mots/cable_car_poi-blue-01.svg +0 -0
  257. /package/{images → src/images}/mots/cable_car_poi-grey-01.svg +0 -0
  258. /package/{images → src/images}/mots/cable_car_round-blue-01.svg +0 -0
  259. /package/{images → src/images}/mots/cable_car_round-grey-01.svg +0 -0
  260. /package/{images → src/images}/mots/cable_car_square-blue-01.svg +0 -0
  261. /package/{images → src/images}/mots/cable_car_square-grey-01.svg +0 -0
  262. /package/{images → src/images}/mots/ferry_poi-blue-01.svg +0 -0
  263. /package/{images → src/images}/mots/ferry_poi-grey-01.svg +0 -0
  264. /package/{images → src/images}/mots/ferry_round-blue-01.svg +0 -0
  265. /package/{images → src/images}/mots/ferry_round-grey-01.svg +0 -0
  266. /package/{images → src/images}/mots/ferry_square-blue-01.svg +0 -0
  267. /package/{images → src/images}/mots/ferry_square-grey-01.svg +0 -0
  268. /package/{images → src/images}/mots/funicular_round-blue-01.svg +0 -0
  269. /package/{images → src/images}/mots/funicular_round-grey-01.svg +0 -0
  270. /package/{images → src/images}/mots/funicular_square-blue-01.svg +0 -0
  271. /package/{images → src/images}/mots/gondola_round-blue-01.svg +0 -0
  272. /package/{images → src/images}/mots/rail_poi-blue-01.svg +0 -0
  273. /package/{images → src/images}/mots/rail_poi-grey-01.svg +0 -0
  274. /package/{images → src/images}/mots/rail_round-blue-01.svg +0 -0
  275. /package/{images → src/images}/mots/rail_round-grey-01.svg +0 -0
  276. /package/{images → src/images}/mots/rail_square-blue-01.svg +0 -0
  277. /package/{images → src/images}/mots/rail_square-grey-01.svg +0 -0
  278. /package/{images → src/images}/mots/subway_round blue-01.svg +0 -0
  279. /package/{images → src/images}/mots/subway_round-blue-01.svg +0 -0
  280. /package/{images → src/images}/mots/tram_poi-blue-01.svg +0 -0
  281. /package/{images → src/images}/mots/tram_poi-grey-01.svg +0 -0
  282. /package/{images → src/images}/mots/tram_round-blue-01.svg +0 -0
  283. /package/{images → src/images}/mots/tram_round-grey-01.svg +0 -0
  284. /package/{images → src/images}/mots/tram_square-blue-01.svg +0 -0
  285. /package/{images → src/images}/mots/tram_square-grey-01.svg +0 -0
  286. /package/{images → src/images}/northArrow.svg +0 -0
  287. /package/{images → src/images}/northArrow.url.svg +0 -0
  288. /package/{images → src/images}/northArrowCircle.svg +0 -0
  289. /package/{images → src/images}/northArrowCircle.url.svg +0 -0
  290. /package/{themes → src/themes}/README.md +0 -0
  291. /package/{themes → src/themes}/default/components.scss +0 -0
  292. /package/{themes → src/themes}/default/examples.scss +0 -0
  293. /package/{themes → src/themes}/default/index.scss +0 -0
  294. /package/{themes → src/themes}/default/mixins.scss +0 -0
  295. /package/{themes → src/themes}/default/variables.scss +0 -0
@@ -0,0 +1,337 @@
1
+ import VectorLayer from 'ol/layer/Vector';
2
+ import VectorSource from 'ol/source/Vector';
3
+ import { Style } from 'ol/style';
4
+ import { get } from 'ol/proj';
5
+ import beautify from 'xml-beautifier';
6
+ import KML from './KML';
7
+
8
+ const xmlns =
9
+ 'xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 https://developers.google.com/kml/schema/kml22gx.xsd"';
10
+
11
+ const expectWriteResult = (feats, str) => {
12
+ expect(
13
+ beautify(
14
+ KML.writeFeatures(
15
+ {
16
+ name: 'lala',
17
+ olLayer: new VectorLayer({
18
+ source: new VectorSource({
19
+ features: feats,
20
+ }),
21
+ }),
22
+ },
23
+ get('EPSG:4326'),
24
+ ),
25
+ ),
26
+ ).toEqual(beautify(str));
27
+ };
28
+
29
+ describe('KML', () => {
30
+ describe('readFeatures() and writeFeatures()', () => {
31
+ test('should read/write LineStyle and ExtendedData (linesDash, lineStartIcon and lineEndIcon).', () => {
32
+ const str = `
33
+ <kml ${xmlns}>
34
+ <Document>
35
+ <name>lala</name>
36
+ <Placemark>
37
+ <Style>
38
+ <LineStyle>
39
+ <color>ff056600</color>
40
+ <width>1</width>
41
+ </LineStyle>
42
+ </Style>
43
+ <ExtendedData>
44
+ <Data name="lineDash"><value>40,40</value></Data>
45
+ <Data name="lineEndIcon"><value>{"url":"fooarrowend.png","scale":0.35,"size":[36,58],"zIndex":1}</value></Data>
46
+ <Data name="lineStartIcon"><value>{"url":"fooarrowstart.png","scale":0.35,"size":[36,58],"zIndex":1}</value></Data>
47
+ </ExtendedData>
48
+ <LineString><coordinates>0,1,0 3,5,0 40,25,0</coordinates></LineString>
49
+ </Placemark>
50
+ </Document>
51
+ </kml>
52
+ `;
53
+ const feats = KML.readFeatures(str);
54
+ const styles = feats[0].getStyle();
55
+ expect(feats.length).toBe(1);
56
+ expect(styles.length).toBe(3);
57
+
58
+ // line stroke
59
+ const strokeStyle = styles[0].getStroke();
60
+ expect(strokeStyle.getColor()).toEqual([0, 102, 5, 1]);
61
+ expect(strokeStyle.getLineDash()).toEqual([40, 40]);
62
+
63
+ // line start icon
64
+ const lineStartStyle = styles[1];
65
+ expect(lineStartStyle.getImage().getRotation()).toEqual(
66
+ -0.9272952180016122,
67
+ );
68
+ expect(lineStartStyle.getImage().getColor()).toEqual([0, 102, 5, 1]);
69
+ expect(lineStartStyle.getImage().getRotateWithView()).toBe(true);
70
+ expect(lineStartStyle.getGeometry()(feats[0]).getCoordinates()).toEqual([
71
+ 0, 1, 0,
72
+ ]);
73
+ expect(lineStartStyle.getZIndex()).toEqual(1);
74
+
75
+ // line end icon
76
+ const lineEndStyle = styles[2];
77
+ expect(lineEndStyle.getImage().getRotation()).toEqual(
78
+ -0.49555167348582857,
79
+ );
80
+ expect(lineEndStyle.getImage().getRotateWithView()).toBe(true);
81
+ expect(lineEndStyle.getImage().getColor()).toEqual([0, 102, 5, 1]);
82
+ expect(lineEndStyle.getGeometry()(feats[0]).getCoordinates()).toEqual([
83
+ 40, 25, 0,
84
+ ]);
85
+ expect(lineEndStyle.getZIndex()).toEqual(1);
86
+
87
+ expectWriteResult(feats, str);
88
+ });
89
+
90
+ test('should read/write TextStyle and ExtendedData.', () => {
91
+ const str = `
92
+ <kml ${xmlns}>
93
+ <Document>
94
+ <name>lala</name>
95
+ <Placemark>
96
+ <name> bar </name>
97
+ <Style>
98
+ <IconStyle>
99
+ <scale>0</scale>
100
+ </IconStyle>
101
+ <LabelStyle>
102
+ <color>ff7e3420</color>
103
+ <scale>2</scale>
104
+ </LabelStyle>
105
+ </Style>
106
+ <ExtendedData>
107
+ <Data name="textAlign">
108
+ <value>right</value>
109
+ </Data>
110
+ <Data name="textBackgroundFillColor">
111
+ <value>rgba(255,255,255,0.01)</value>
112
+ </Data>
113
+ <Data name="textFont">
114
+ <value>bold 16px arial</value>
115
+ </Data>
116
+ <Data name="textOffsetX">
117
+ <value>-90</value>
118
+ </Data>
119
+ <Data name="textOffsetY">
120
+ <value>30</value>
121
+ </Data>
122
+ <Data name="textPadding">
123
+ <value>5,6,7,8</value>
124
+ </Data>
125
+ <Data name="textRotation">
126
+ <value>2.303834612632515</value>
127
+ </Data>
128
+ <Data name="textStrokeColor">
129
+ <value>rgba(100,255,255,0.2)</value>
130
+ </Data>
131
+ <Data name="textStrokeWidth">
132
+ <value>3</value>
133
+ </Data>
134
+ </ExtendedData>
135
+ <Point>
136
+ <coordinates>0,0,0</coordinates>
137
+ </Point>
138
+ </Placemark>
139
+ </Document>
140
+ </kml>
141
+ `;
142
+ const feats = KML.readFeatures(str);
143
+ const style = feats[0].getStyleFunction()(feats[0], 1);
144
+ expect(feats.length).toBe(1);
145
+ expect(style instanceof Style).toBe(true);
146
+
147
+ // Text
148
+ const styleText = style.getText();
149
+ expect(styleText.getText()).toBe('bar'); // spaces are trimmed.
150
+ expect(styleText.getFont()).toEqual('bold 16px arial');
151
+ expect(styleText.getFill()).toEqual({ color_: [32, 52, 126, 1] });
152
+ expect(styleText.getStroke()).toEqual({
153
+ color_: 'rgba(100,255,255,0.2)',
154
+ width_: 3,
155
+ lineCap_: undefined,
156
+ lineDashOffset_: undefined,
157
+ lineDash_: null,
158
+ lineJoin_: undefined,
159
+ miterLimit_: undefined,
160
+ });
161
+ expect(styleText.getScale()).toEqual(2);
162
+ expect(styleText.getRotation()).toEqual('2.303834612632515');
163
+ expect(styleText.getPadding()).toEqual([5, 6, 7, 8]);
164
+ expect(styleText.getBackgroundFill()).toEqual({
165
+ color_: 'rgba(255,255,255,0.01)',
166
+ });
167
+ expect(styleText.getTextAlign()).toEqual('right');
168
+ expect(styleText.getOffsetX()).toEqual(-90);
169
+ expect(styleText.getOffsetY()).toEqual(30);
170
+ expectWriteResult(feats, str);
171
+ });
172
+
173
+ test('should read and write lineDash and fillPattern style for polygon', () => {
174
+ const str = `
175
+ <kml ${xmlns}>
176
+ <Document>
177
+ <name>lala</name>
178
+ <Placemark>
179
+ <description></description>
180
+ <Style>
181
+ <LineStyle>
182
+ <color>ff0000eb</color>
183
+ <width>2</width>
184
+ </LineStyle>
185
+ <PolyStyle>
186
+ <fill>0</fill>
187
+ </PolyStyle>
188
+ </Style>
189
+ <ExtendedData>
190
+ <Data name="fillPattern">
191
+ <value>{"id":3,"color":[235,0,0,1]}</value>
192
+ </Data>
193
+ <Data name="lineDash">
194
+ <value>1,1</value>
195
+ </Data>
196
+ </ExtendedData>
197
+ <Polygon>
198
+ <outerBoundaryIs>
199
+ <LinearRing>
200
+ <coordinates>8.521,47.381,0 8.529,47.375,0 8.531,47.382,0 8.521,47.381,0</coordinates>
201
+ </LinearRing>
202
+ </outerBoundaryIs>
203
+ </Polygon>
204
+ </Placemark>
205
+ </Document>
206
+ </kml>
207
+ `;
208
+ const feats = KML.readFeatures(str);
209
+ const styles = feats[0].getStyle();
210
+ expect(feats.length).toBe(1);
211
+ expect(styles.length).toBe(1);
212
+
213
+ // Polygon
214
+ const feature = feats[0];
215
+ const outlineStyle = styles[0].getStroke();
216
+ expect(outlineStyle.getColor()).toEqual([235, 0, 0, 1]);
217
+ expect(outlineStyle.getWidth()).toEqual(2);
218
+ const fillStyle = styles[0].getFill();
219
+ expect(feature.get('fillPattern')).toEqual({
220
+ id: 3,
221
+ color: [235, 0, 0, 1],
222
+ });
223
+ const color = fillStyle.getColor();
224
+ expect(color.id).toBe(3);
225
+ expect(color.color).toEqual([235, 0, 0, 1]);
226
+ expectWriteResult(feats, str);
227
+ });
228
+
229
+ test('should add zIndex and rotation to icon style and pictureOptions to feature properties.', () => {
230
+ const str = `
231
+ <kml ${xmlns}>
232
+ <Document>
233
+ <name>lala</name>
234
+ <Placemark>
235
+ <description></description>
236
+ <Style>
237
+ <IconStyle>
238
+ <scale>
239
+ 2
240
+ </scale>
241
+ <heading>
242
+ 1.5707963267948966
243
+ </heading>
244
+ <Icon>
245
+ <href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
246
+ <gx:w>64</gx:w>
247
+ <gx:h>64</gx:h>
248
+ </Icon>
249
+ <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
250
+ </IconStyle>
251
+ </Style>
252
+ <ExtendedData>
253
+ <Data name="iconRotation">
254
+ <value>1.5707963267948966</value>
255
+ </Data>
256
+ <Data name="maxZoom">
257
+ <value>18.5</value>
258
+ </Data>
259
+ <Data name="minZoom">
260
+ <value>15</value>
261
+ </Data>
262
+ <Data name="pictureOptions">
263
+ <value>{"resolution":4,"defaultScale":0.5}</value>
264
+ </Data>
265
+ <Data name="zIndex">
266
+ <value>1</value>
267
+ </Data>
268
+ </ExtendedData>
269
+ <Point>
270
+ <coordinates>0,0,0</coordinates>
271
+ </Point>
272
+ </Placemark>
273
+ </Document>
274
+ </kml>
275
+ `;
276
+ const feats = KML.readFeatures(str);
277
+ const style = feats[0].getStyleFunction()(feats[0], 1);
278
+ expect(style.getZIndex()).toBe(1);
279
+ expect(style.getImage().getRotation()).toBe(1.5707963267948966);
280
+ expect(feats[0].get('pictureOptions')).toEqual({
281
+ resolution: 4,
282
+ defaultScale: 0.5,
283
+ });
284
+ expect(feats[0].get('maxZoom')).toEqual(18.5);
285
+ expect(feats[0].get('minZoom')).toEqual(15);
286
+ expectWriteResult(feats, str);
287
+ });
288
+ });
289
+
290
+ describe('writeDocumentCamera()', () => {
291
+ const str = `
292
+ <kml ${xmlns}>
293
+ <Document>
294
+ <name>
295
+ CamTest
296
+ </name>
297
+ </Document>
298
+ </kml>`;
299
+
300
+ const strWithCam = `<kml ${xmlns}>
301
+ <Document>
302
+ <name>
303
+ CamTest
304
+ </name>
305
+ <Camera xmlns="">
306
+ <Heading>
307
+ 270
308
+ </Heading>
309
+ <Altitude>
310
+ 300
311
+ </Altitude>
312
+ <Longitude>
313
+ 5.8
314
+ </Longitude>
315
+ <Latitude>
316
+ 41.6
317
+ </Latitude>
318
+ </Camera>
319
+ </Document>
320
+ </kml>`;
321
+
322
+ test('should insert the correct <Camera> tag.', () => {
323
+ const kmlWithKamera = KML.writeDocumentCamera(str, {
324
+ heading: 270,
325
+ altitude: 300,
326
+ longitude: 5.8,
327
+ latitude: 41.6,
328
+ });
329
+ expect(beautify(kmlWithKamera)).toEqual(beautify(strWithCam));
330
+ });
331
+
332
+ test('should remove the present <Camera> tag when called without cameraAttributes.', () => {
333
+ const kmlWithoutKamera = KML.writeDocumentCamera(strWithCam);
334
+ expect(beautify(kmlWithoutKamera)).toEqual(beautify(str));
335
+ });
336
+ });
337
+ });
@@ -0,0 +1,100 @@
1
+ import OLKML from 'ol/format/KML';
2
+ import {
3
+ parse,
4
+ pushParseAndPop,
5
+ isDocument,
6
+ makeStructureNS,
7
+ makeObjectPropertySetter,
8
+ } from 'ol/xml';
9
+ import { extend, includes } from 'ol/array';
10
+ import { readDecimal, readString } from 'ol/format/xsd';
11
+
12
+ const NAMESPACE_URIS = [
13
+ 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',
18
+ ];
19
+
20
+ const CAMERA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
21
+ Altitude: makeObjectPropertySetter(readDecimal),
22
+ Longitude: makeObjectPropertySetter(readDecimal),
23
+ Latitude: makeObjectPropertySetter(readDecimal),
24
+ Tilt: makeObjectPropertySetter(readDecimal),
25
+ AltitudeMode: makeObjectPropertySetter(readString),
26
+ Heading: makeObjectPropertySetter(readDecimal),
27
+ Roll: makeObjectPropertySetter(readDecimal),
28
+ });
29
+
30
+ class KML extends OLKML {
31
+ /**
32
+ * Read the cameras of the KML.
33
+ *
34
+ * @param {Document|Element|string} source Source.
35
+ * @return {Array<Object>} Cameras.
36
+ * @api
37
+ */
38
+ readCamera(source) {
39
+ const cameras = [];
40
+ if (typeof source === 'string') {
41
+ const doc = parse(source);
42
+ extend(cameras, this.readCameraFromDocument(doc));
43
+ } else if (isDocument(source)) {
44
+ extend(
45
+ cameras,
46
+ this.readCameraFromDocument(/** @type {Document} */ (source)),
47
+ );
48
+ } else {
49
+ extend(cameras, this.readCameraFromNode(/** @type {Element} */ (source)));
50
+ }
51
+ return cameras;
52
+ }
53
+
54
+ /**
55
+ * @param {Document} doc Document.
56
+ * @return {Array<Object>} Cameras.
57
+ */
58
+ readCameraFromDocument(doc) {
59
+ const cameras = [];
60
+ for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
61
+ if (n.nodeType === Node.ELEMENT_NODE) {
62
+ extend(cameras, this.readCameraFromNode(/** @type {Element} */ (n)));
63
+ }
64
+ }
65
+ return cameras;
66
+ }
67
+
68
+ /**
69
+ * @param {Element} node Node.
70
+ * @return {Array<Object>} Cameras.
71
+ * @api
72
+ */
73
+ readCameraFromNode(node) {
74
+ const cameras = [];
75
+ for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
76
+ if (
77
+ includes(NAMESPACE_URIS, n.namespaceURI) &&
78
+ n.localName === 'Camera'
79
+ ) {
80
+ const obj = pushParseAndPop({}, CAMERA_PARSERS, n, []);
81
+ cameras.push(obj);
82
+ }
83
+ }
84
+ for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
85
+ const { localName } = n;
86
+ if (
87
+ includes(NAMESPACE_URIS, n.namespaceURI) &&
88
+ (localName === 'Document' ||
89
+ localName === 'Folder' ||
90
+ localName === 'Placemark' ||
91
+ localName === 'kml')
92
+ ) {
93
+ extend(cameras, this.readCameraFromNode(n));
94
+ }
95
+ }
96
+ return cameras;
97
+ }
98
+ }
99
+
100
+ export default KML;
@@ -0,0 +1,50 @@
1
+ import KML from './KMLFormat';
2
+
3
+ const xmlns =
4
+ 'xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 https://developers.google.com/kml/schema/kml22gx.xsd"';
5
+
6
+ describe('KML', () => {
7
+ test('should read <Camera> tags correctly.', () => {
8
+ const str = `
9
+ <kml ${xmlns}>
10
+ <Document>
11
+ <name>lala</name>
12
+ <Camera>
13
+ <Heading>
14
+ 270
15
+ </Heading>
16
+ <Altitude>
17
+ 300
18
+ </Altitude>
19
+ <Longitude>
20
+ 5.8
21
+ </Longitude>
22
+ <Latitude>
23
+ 41.6
24
+ </Latitude>
25
+ </Camera>
26
+ <Placemark>
27
+ <Camera>
28
+ <Heading>
29
+ 180
30
+ </Heading>
31
+ <AltitudeMode>
32
+ clampToGround
33
+ </AltitudeMode>
34
+ </Camera>
35
+ </Placemark>
36
+ </Document>
37
+ </kml>
38
+ `;
39
+ const format = new KML();
40
+ const cameras = format.readCamera(str);
41
+
42
+ expect(cameras.length).toEqual(2);
43
+ expect(cameras[0].Heading).toEqual(270);
44
+ expect(cameras[0].Altitude).toEqual(300);
45
+ expect(cameras[0].Longitude).toEqual(5.8);
46
+ expect(cameras[0].Latitude).toEqual(41.6);
47
+ expect(cameras[1].Heading).toEqual(180);
48
+ expect(cameras[1].AltitudeMode).toEqual('clampToGround');
49
+ });
50
+ });
@@ -1,46 +1,52 @@
1
- import { Fill, Stroke, Circle, Style, Text } from "ol/style";
1
+ import { Fill, Stroke, Circle, Style, Text } from 'ol/style';
2
+
3
+ // Default style for Ol
2
4
  const fill = new Fill({
3
- color: "rgba(255,255,255,0.4)"
5
+ color: 'rgba(255,255,255,0.4)',
4
6
  });
5
7
  const stroke = new Stroke({
6
- color: "#3399CC",
7
- width: 1.25
8
+ color: '#3399CC',
9
+ width: 1.25,
8
10
  });
9
11
  const dfltOlStyle = new Style({
10
12
  image: new Circle({
11
13
  fill,
12
14
  stroke,
13
- radius: 5
15
+ radius: 5,
14
16
  }),
15
17
  fill,
16
- stroke
18
+ stroke,
17
19
  });
20
+
21
+ // Default style for KML layer
18
22
  const kmlFill = new Fill({
19
- color: [255, 0, 0, 0.7]
23
+ color: [255, 0, 0, 0.7],
20
24
  });
21
25
  const kmlStroke = new Stroke({
22
26
  color: [255, 0, 0, 1],
23
- width: 1.5
27
+ width: 1.5,
24
28
  });
25
29
  const kmlcircle = new Circle({
26
30
  radius: 7,
27
31
  fill: kmlFill,
28
- stroke: kmlStroke
32
+ stroke: kmlStroke,
29
33
  });
30
34
  const kmlStyle = new Style({
31
35
  fill: kmlFill,
32
36
  stroke: kmlStroke,
33
37
  image: kmlcircle,
34
38
  text: new Text({
35
- font: "normal 16px Helvetica",
39
+ font: 'normal 16px Helvetica',
36
40
  fill: kmlFill,
37
41
  stroke: new Stroke({
38
42
  color: [255, 255, 255, 1],
39
- width: 3
40
- })
41
- })
43
+ width: 3,
44
+ }),
45
+ }),
42
46
  });
47
+
43
48
  export { kmlStyle };
49
+
44
50
  export default {
45
- default: dfltOlStyle
51
+ default: dfltOlStyle,
46
52
  };
@@ -1,19 +1,26 @@
1
- import { DEVICE_PIXEL_RATIO } from "ol/has";
1
+ import { DEVICE_PIXEL_RATIO } from 'ol/has';
2
+
2
3
  const getPolygonPattern = (patternId = 1, color = [235, 0, 0, 1]) => {
3
4
  if (patternId === 1) {
4
5
  return color;
5
6
  }
6
- const canvasElement = document.createElement("canvas");
7
+
8
+ const canvasElement = document.createElement('canvas');
7
9
  const pixelRatio = DEVICE_PIXEL_RATIO;
10
+
8
11
  canvasElement.width = 20 * pixelRatio;
9
12
  canvasElement.height = 20 * pixelRatio;
13
+
10
14
  let pattern = {};
11
- const ctx = canvasElement.getContext("2d");
15
+ const ctx = canvasElement.getContext('2d');
12
16
  ctx.strokeStyle = `rgba(${color.toString()})`;
13
17
  ctx.fillStyle = `rgba(${color.toString()})`;
14
18
  ctx.lineWidth = 3;
19
+
15
20
  switch (patternId) {
16
21
  case 2:
22
+ /* Hatched pattern */
23
+ /* Ascending line */
17
24
  ctx.beginPath();
18
25
  ctx.moveTo(0, canvasElement.height);
19
26
  ctx.lineTo(0, canvasElement.height - ctx.lineWidth / 2);
@@ -24,6 +31,8 @@ const getPolygonPattern = (patternId = 1, color = [235, 0, 0, 1]) => {
24
31
  ctx.lineTo(ctx.lineWidth / 2, canvasElement.height);
25
32
  ctx.fill();
26
33
  ctx.closePath();
34
+
35
+ /* Descending line */
27
36
  ctx.beginPath();
28
37
  ctx.moveTo(0, 0);
29
38
  ctx.lineTo(0, ctx.lineWidth / 2);
@@ -34,16 +43,21 @@ const getPolygonPattern = (patternId = 1, color = [235, 0, 0, 1]) => {
34
43
  ctx.lineTo(0, 0);
35
44
  ctx.fill();
36
45
  ctx.closePath();
37
- pattern = ctx.createPattern(canvasElement, "repeat");
46
+
47
+ pattern = ctx.createPattern(canvasElement, 'repeat');
38
48
  pattern.canvas = canvasElement;
39
49
  break;
40
50
  case 3:
51
+ /* Shade ascending pattern */
52
+ /* Corner triangle */
41
53
  ctx.beginPath();
42
54
  ctx.moveTo(0, 0);
43
55
  ctx.lineTo(0, ctx.lineWidth / 2);
44
56
  ctx.lineTo(ctx.lineWidth / 2, 0);
45
57
  ctx.fill();
46
58
  ctx.closePath();
59
+
60
+ /* Ascending line */
47
61
  ctx.beginPath();
48
62
  ctx.moveTo(0, canvasElement.height);
49
63
  ctx.lineTo(0, canvasElement.height - ctx.lineWidth / 2);
@@ -54,22 +68,29 @@ const getPolygonPattern = (patternId = 1, color = [235, 0, 0, 1]) => {
54
68
  ctx.lineTo(ctx.lineWidth / 2, canvasElement.height);
55
69
  ctx.fill();
56
70
  ctx.closePath();
71
+
72
+ /* Corner triangle */
57
73
  ctx.beginPath();
58
74
  ctx.moveTo(canvasElement.width, canvasElement.height);
59
75
  ctx.lineTo(canvasElement.width, canvasElement.height - ctx.lineWidth / 2);
60
76
  ctx.lineTo(canvasElement.width - ctx.lineWidth / 2, canvasElement.height);
61
77
  ctx.fill();
62
78
  ctx.closePath();
63
- pattern = ctx.createPattern(canvasElement, "repeat");
79
+
80
+ pattern = ctx.createPattern(canvasElement, 'repeat');
64
81
  pattern.canvas = canvasElement;
65
82
  break;
66
83
  case 4:
84
+ /* Shade descending pattern */
85
+ /* Corner triangle */
67
86
  ctx.beginPath();
68
87
  ctx.moveTo(canvasElement.width, 0);
69
88
  ctx.lineTo(canvasElement.width, ctx.lineWidth / 2);
70
89
  ctx.lineTo(canvasElement.width - ctx.lineWidth / 2, 0);
71
90
  ctx.fill();
72
91
  ctx.closePath();
92
+
93
+ /* Descending line */
73
94
  ctx.beginPath();
74
95
  ctx.moveTo(0, 0);
75
96
  ctx.lineTo(0, ctx.lineWidth / 2);
@@ -80,22 +101,29 @@ const getPolygonPattern = (patternId = 1, color = [235, 0, 0, 1]) => {
80
101
  ctx.lineTo(0, 0);
81
102
  ctx.fill();
82
103
  ctx.closePath();
104
+
105
+ /* Corner triangle */
83
106
  ctx.beginPath();
84
107
  ctx.moveTo(0, canvasElement.height);
85
108
  ctx.lineTo(0, canvasElement.height - ctx.lineWidth / 2);
86
109
  ctx.lineTo(ctx.lineWidth / 2, canvasElement.height);
87
110
  ctx.fill();
88
111
  ctx.closePath();
89
- pattern = ctx.createPattern(canvasElement, "repeat");
112
+
113
+ pattern = ctx.createPattern(canvasElement, 'repeat');
90
114
  pattern.canvas = canvasElement;
91
115
  break;
92
116
  default:
93
117
  }
118
+
94
119
  if (patternId === 0) {
95
120
  pattern.empty = true;
96
121
  }
122
+
97
123
  pattern.id = patternId;
98
124
  pattern.color = color;
125
+
99
126
  return pattern;
100
127
  };
128
+
101
129
  export default getPolygonPattern;