react-spatial 1.2.2 → 1.2.3-beta.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 (186) hide show
  1. package/LayerService.js +128 -184
  2. package/LayerService.js.map +7 -1
  3. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
  4. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
  5. package/components/BaseLayerSwitcher/index.js +1 -3
  6. package/components/BaseLayerSwitcher/index.js.map +7 -1
  7. package/components/BasicMap/BasicMap.js +147 -285
  8. package/components/BasicMap/BasicMap.js.map +7 -1
  9. package/components/BasicMap/index.js +1 -3
  10. package/components/BasicMap/index.js.map +7 -1
  11. package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
  12. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
  13. package/components/CanvasSaveButton/index.js +1 -3
  14. package/components/CanvasSaveButton/index.js.map +7 -1
  15. package/components/Copyright/Copyright.js +29 -70
  16. package/components/Copyright/Copyright.js.map +7 -1
  17. package/components/Copyright/index.js +1 -3
  18. package/components/Copyright/index.js.map +7 -1
  19. package/components/FeatureExportButton/FeatureExportButton.js +40 -106
  20. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
  21. package/components/FeatureExportButton/index.js +1 -3
  22. package/components/FeatureExportButton/index.js.map +7 -1
  23. package/components/FilterButton/FilterButton.js +41 -106
  24. package/components/FilterButton/FilterButton.js.map +7 -1
  25. package/components/FilterButton/index.js +1 -3
  26. package/components/FilterButton/index.js.map +7 -1
  27. package/components/FitExtent/FitExtent.js +17 -50
  28. package/components/FitExtent/FitExtent.js.map +7 -1
  29. package/components/FitExtent/index.js +1 -3
  30. package/components/FitExtent/index.js.map +7 -1
  31. package/components/FollowButton/FollowButton.js +41 -111
  32. package/components/FollowButton/FollowButton.js.map +7 -1
  33. package/components/FollowButton/index.js +1 -3
  34. package/components/FollowButton/index.js.map +7 -1
  35. package/components/Geolocation/Geolocation.js +104 -213
  36. package/components/Geolocation/Geolocation.js.map +7 -1
  37. package/components/Geolocation/index.js +1 -3
  38. package/components/Geolocation/index.js.map +7 -1
  39. package/components/LayerTree/LayerTree.js +204 -410
  40. package/components/LayerTree/LayerTree.js.map +7 -1
  41. package/components/LayerTree/index.js +1 -3
  42. package/components/LayerTree/index.js.map +7 -1
  43. package/components/MousePosition/MousePosition.js +61 -130
  44. package/components/MousePosition/MousePosition.js.map +7 -1
  45. package/components/MousePosition/index.js +1 -3
  46. package/components/MousePosition/index.js.map +7 -1
  47. package/components/NorthArrow/NorthArrow.js +22 -62
  48. package/components/NorthArrow/NorthArrow.js.map +7 -1
  49. package/components/NorthArrow/index.js +1 -3
  50. package/components/NorthArrow/index.js.map +7 -1
  51. package/components/Overlay/Overlay.js +83 -130
  52. package/components/Overlay/Overlay.js.map +7 -1
  53. package/components/Overlay/index.js +1 -3
  54. package/components/Overlay/index.js.map +7 -1
  55. package/components/Permalink/Permalink.js +150 -244
  56. package/components/Permalink/Permalink.js.map +7 -1
  57. package/components/Permalink/index.js +1 -3
  58. package/components/Permalink/index.js.map +7 -1
  59. package/components/Popup/Popup.js +106 -233
  60. package/components/Popup/Popup.js.map +7 -1
  61. package/components/Popup/index.js +1 -3
  62. package/components/Popup/index.js.map +7 -1
  63. package/components/ResizeHandler/ResizeHandler.js +58 -113
  64. package/components/ResizeHandler/ResizeHandler.js.map +7 -1
  65. package/components/ResizeHandler/index.js +1 -3
  66. package/components/ResizeHandler/index.js.map +7 -1
  67. package/components/RouteSchedule/RouteSchedule.js +150 -283
  68. package/components/RouteSchedule/RouteSchedule.js.map +7 -1
  69. package/components/RouteSchedule/index.js +1 -3
  70. package/components/RouteSchedule/index.js.map +7 -1
  71. package/components/ScaleLine/ScaleLine.js +21 -45
  72. package/components/ScaleLine/ScaleLine.js.map +7 -1
  73. package/components/ScaleLine/index.js +1 -3
  74. package/components/ScaleLine/index.js.map +7 -1
  75. package/components/Search/Search.js +122 -186
  76. package/components/Search/Search.js.map +7 -1
  77. package/components/Search/SearchService.js +45 -69
  78. package/components/Search/SearchService.js.map +7 -1
  79. package/components/Search/engines/Engine.js +18 -25
  80. package/components/Search/engines/Engine.js.map +7 -1
  81. package/components/Search/engines/StopFinder.js +21 -38
  82. package/components/Search/engines/StopFinder.js.map +7 -1
  83. package/components/Search/index.js +3 -6
  84. package/components/Search/index.js.map +7 -1
  85. package/components/StopsFinder/StopsFinder.js +123 -174
  86. package/components/StopsFinder/StopsFinder.js.map +7 -1
  87. package/components/StopsFinder/StopsFinderOption.js +37 -54
  88. package/components/StopsFinder/StopsFinderOption.js.map +7 -1
  89. package/components/StopsFinder/index.js +1 -3
  90. package/components/StopsFinder/index.js.map +7 -1
  91. package/components/TrackerControl/TrackerControl.js +73 -128
  92. package/components/TrackerControl/TrackerControl.js.map +7 -1
  93. package/components/TrackerControl/index.js +1 -3
  94. package/components/TrackerControl/index.js.map +7 -1
  95. package/components/Zoom/Zoom.js +69 -112
  96. package/components/Zoom/Zoom.js.map +7 -1
  97. package/components/Zoom/index.js +1 -3
  98. package/components/Zoom/index.js.map +7 -1
  99. package/package.json +10 -5
  100. package/propTypes.js +17 -23
  101. package/propTypes.js.map +7 -1
  102. package/setupTests.js +2 -4
  103. package/setupTests.js.map +7 -1
  104. package/themes/README.md +26 -0
  105. package/themes/default/components.scss +0 -1
  106. package/themes/default/examples.scss +0 -1
  107. package/utils/GlobalsForOle.js +63 -64
  108. package/utils/GlobalsForOle.js.map +7 -1
  109. package/utils/KML.js +178 -364
  110. package/utils/KML.js.map +7 -1
  111. package/utils/KMLFormat.js +37 -73
  112. package/utils/KMLFormat.js.map +7 -1
  113. package/utils/Styles.js +24 -32
  114. package/utils/Styles.js.map +7 -1
  115. package/utils/getPolygonPattern.js +11 -44
  116. package/utils/getPolygonPattern.js.map +7 -1
  117. package/utils/timeUtils.js +16 -35
  118. package/utils/timeUtils.js.map +7 -1
  119. package/LayerService.test.js +0 -160
  120. package/LayerService.test.js.map +0 -1
  121. package/Projections.js +0 -16
  122. package/Projections.js.map +0 -1
  123. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
  124. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
  125. package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
  126. package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
  127. package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
  128. package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
  129. package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
  130. package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
  131. package/components/BaseLayerToggler/index.js +0 -3
  132. package/components/BaseLayerToggler/index.js.map +0 -1
  133. package/components/BasicMap/BasicMap.test.js +0 -288
  134. package/components/BasicMap/BasicMap.test.js.map +0 -1
  135. package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
  136. package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
  137. package/components/Copyright/Copyright.test.js +0 -133
  138. package/components/Copyright/Copyright.test.js.map +0 -1
  139. package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
  140. package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
  141. package/components/FilterButton/FilterButton.test.js +0 -48
  142. package/components/FilterButton/FilterButton.test.js.map +0 -1
  143. package/components/FitExtent/FitExtent.test.js +0 -44
  144. package/components/FitExtent/FitExtent.test.js.map +0 -1
  145. package/components/FollowButton/FollowButton.test.js +0 -57
  146. package/components/FollowButton/FollowButton.test.js.map +0 -1
  147. package/components/Geolocation/Geolocation.test.js +0 -263
  148. package/components/Geolocation/Geolocation.test.js.map +0 -1
  149. package/components/LayerTree/LayerTree.test.js +0 -323
  150. package/components/LayerTree/LayerTree.test.js.map +0 -1
  151. package/components/MousePosition/MousePosition.test.js +0 -125
  152. package/components/MousePosition/MousePosition.test.js.map +0 -1
  153. package/components/NorthArrow/NorthArrow.test.js +0 -106
  154. package/components/NorthArrow/NorthArrow.test.js.map +0 -1
  155. package/components/Overlay/Overlay.test.js +0 -145
  156. package/components/Overlay/Overlay.test.js.map +0 -1
  157. package/components/Permalink/Permalink.test.js +0 -267
  158. package/components/Permalink/Permalink.test.js.map +0 -1
  159. package/components/Popup/Popup.test.js +0 -291
  160. package/components/Popup/Popup.test.js.map +0 -1
  161. package/components/ResizeHandler/ResizeHandler.test.js +0 -410
  162. package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
  163. package/components/RouteSchedule/RouteSchedule.test.js +0 -102
  164. package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
  165. package/components/ScaleLine/ScaleLine.test.js +0 -32
  166. package/components/ScaleLine/ScaleLine.test.js.map +0 -1
  167. package/components/Search/Search.test.js +0 -15
  168. package/components/Search/Search.test.js.map +0 -1
  169. package/components/StopsFinder/StopsFinder.test.js +0 -19
  170. package/components/StopsFinder/StopsFinder.test.js.map +0 -1
  171. package/components/TrackerControl/TrackerControl.test.js +0 -17
  172. package/components/TrackerControl/TrackerControl.test.js.map +0 -1
  173. package/components/Zoom/Zoom.test.js +0 -150
  174. package/components/Zoom/Zoom.test.js.map +0 -1
  175. package/styleguidist/ComponentsList.js +0 -52
  176. package/styleguidist/ComponentsList.js.map +0 -1
  177. package/styleguidist/StyleGuide.js +0 -253
  178. package/styleguidist/StyleGuide.js.map +0 -1
  179. package/utils/KML.test.js +0 -163
  180. package/utils/KML.test.js.map +0 -1
  181. package/utils/KMLFormat.test.js +0 -22
  182. package/utils/KMLFormat.test.js.map +0 -1
  183. package/utils/getPolygonPattern.test.js +0 -66
  184. package/utils/getPolygonPattern.test.js.map +0 -1
  185. package/utils/timeUtils.test.js +0 -32
  186. package/utils/timeUtils.test.js.map +0 -1
package/utils/KML.js CHANGED
@@ -1,289 +1,201 @@
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
-
12
- var applyTextStyleForIcon = function (olIcon, olText) {
13
- var size = olIcon.getSize() || [48, 48];
14
- var scale = olIcon.getScale() || 1;
15
- var anchor = olIcon.getAnchor() || [
16
- (size[0] * scale) / 2,
17
- (size[1] * scale) / 2 ];
18
- var offset = [
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
19
  scale * (size[0] - anchor[0]) + 5,
20
- scale * (size[1] / 2 - anchor[1]) ];
20
+ scale * (size[1] / 2 - anchor[1])
21
+ ];
21
22
  olText.setOffsetX(offset[0]);
22
23
  olText.setOffsetY(offset[1]);
23
- olText.setTextAlign('left');
24
+ olText.setTextAlign("left");
24
25
  };
25
-
26
- var getVertexCoord = function (geom, start, index) {
27
- if ( start === void 0 ) start = true;
28
- if ( index === void 0 ) index = 0;
29
-
30
- var coords = geom.getCoordinates();
31
- var len = coords.length - 1;
26
+ const getVertexCoord = (geom, start = true, index = 0) => {
27
+ const coords = geom.getCoordinates();
28
+ const len = coords.length - 1;
32
29
  return start ? coords[index] : coords[len - index];
33
30
  };
34
-
35
- var getLineIcon = function (feature, icon, color, start) {
36
- if ( start === void 0 ) start = true;
37
-
38
- var geom = feature.getGeometry();
39
- var coordA = getVertexCoord(geom, start, 1);
40
- var coordB = getVertexCoord(geom, start);
41
- var dx = start ? coordA[0] - coordB[0] : coordB[0] - coordA[0];
42
- var dy = start ? coordA[1] - coordB[1] : coordB[1] - coordA[1];
43
- var rotation = Math.atan2(dy, dx);
44
-
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);
45
38
  return new Style({
46
- geometry: function (feat) {
47
- var ge = feat.getGeometry();
39
+ geometry: (feat) => {
40
+ const ge = feat.getGeometry();
48
41
  return new Point(getVertexCoord(ge, start));
49
42
  },
50
43
  image: new Icon({
51
44
  src: icon.url,
52
- color: color,
45
+ color,
53
46
  rotation: -rotation,
54
47
  rotateWithView: true,
55
48
  scale: icon.scale,
56
- imgSize: icon.size, // ie 11
49
+ imgSize: icon.size
57
50
  }),
58
- zIndex: icon.zIndex,
51
+ zIndex: icon.zIndex
59
52
  });
60
53
  };
61
-
62
- // Clean the unneeded feature's style and properties created by the KML parser.
63
- var sanitizeFeature = function (feature) {
64
- var geom = feature.getGeometry();
65
- var styles = feature.getStyleFunction();
66
-
67
- // Store maxZoom in properties
68
- if (feature.get('maxZoom')) {
69
- feature.set('maxZoom', parseFloat(feature.get('maxZoom'), 10));
54
+ const sanitizeFeature = (feature) => {
55
+ const geom = feature.getGeometry();
56
+ let styles = feature.getStyleFunction();
57
+ if (feature.get("maxZoom")) {
58
+ feature.set("maxZoom", parseFloat(feature.get("maxZoom"), 10));
70
59
  }
71
-
72
- // Store minZoom in properties
73
- if (feature.get('minZoom')) {
74
- feature.set('minZoom', parseFloat(feature.get('minZoom'), 10));
60
+ if (feature.get("minZoom")) {
61
+ feature.set("minZoom", parseFloat(feature.get("minZoom"), 10));
75
62
  }
76
-
77
- // The use of clone is part of the scale fix line 156
78
- var tmpStyles = styles(feature);
79
- var style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone();
80
-
81
- var stroke = style.getStroke();
82
- if (stroke && feature.get('lineDash')) {
63
+ const tmpStyles = styles(feature);
64
+ const style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone();
65
+ let stroke = style.getStroke();
66
+ if (stroke && feature.get("lineDash")) {
83
67
  stroke.setLineDash(
84
- feature
85
- .get('lineDash')
86
- .split(',')
87
- .map(function (l) {
88
- return parseInt(l, 10);
89
- })
68
+ feature.get("lineDash").split(",").map((l) => {
69
+ return parseInt(l, 10);
70
+ })
90
71
  );
91
72
  }
92
-
93
- // The canvas draws a stroke width=1 by default if width=0, so we
94
- // remove the stroke style in that case.
95
73
  if (stroke && stroke.getWidth() === 0) {
96
- stroke = undefined;
74
+ stroke = void 0;
97
75
  }
98
-
99
- if (feature.get('zIndex')) {
100
- style.setZIndex(parseInt(feature.get('zIndex'), 10));
76
+ if (feature.get("zIndex")) {
77
+ style.setZIndex(parseInt(feature.get("zIndex"), 10));
101
78
  }
102
-
103
- // if the feature is a Point and we are offline, we use default vector
104
- // style.
105
- // if the feature is a Point and has a name with a text style, we
106
- // create a correct text style.
107
- // TODO Handle GeometryCollection displaying name on the first Point
108
- // geometry.
109
79
  if (style && (geom instanceof Point || geom instanceof MultiPoint)) {
110
- var image = style.getImage();
111
- var text = null;
112
- var fill = style.getFill();
113
-
114
- // If the feature has name we display it on the map as Google does
115
- if (
116
- feature.get('name') &&
117
- style.getText() &&
118
- style.getText().getScale() !== 0
119
- ) {
80
+ let image = style.getImage();
81
+ let text = null;
82
+ let fill = style.getFill();
83
+ if (feature.get("name") && style.getText() && style.getText().getScale() !== 0) {
120
84
  if (image && image.getScale() === 0) {
121
- // transparentCircle is used to allow selection
122
85
  image = new Circle({
123
86
  radius: 1,
124
87
  fill: new Fill({ color: [0, 0, 0, 0] }),
125
- stroke: new Stroke({ color: [0, 0, 0, 0] }),
88
+ stroke: new Stroke({ color: [0, 0, 0, 0] })
126
89
  });
127
90
  }
128
-
129
- // We replace empty white spaces used to keep normal spaces before and after the name.
130
- var name = feature.get('name');
91
+ let name = feature.get("name");
131
92
  if (/\u200B/g.test(name)) {
132
- name = name.replace(/\u200B/g, '');
133
- feature.set('name', name);
93
+ name = name.replace(/\u200B/g, "");
94
+ feature.set("name", name);
134
95
  }
135
-
136
96
  text = new Text({
137
- font: feature.get('textFont') || 'normal 16px Helvetica',
138
- text: feature.get('name'),
97
+ font: feature.get("textFont") || "normal 16px Helvetica",
98
+ text: feature.get("name"),
139
99
  fill: style.getText().getFill(),
140
- // rotation unsupported by KML, taken instead from custom field.
141
- rotation: feature.get('textRotation') || 0,
142
- // since ol 6.3.1 : https://github.com/openlayers/openlayers/pull/10613/files#diff-1883da8b57e690db7ea0c35ce53c880aR925
143
- // a default textstroke is added to mimic google earth.
144
- // it was not the case before, the stroke was always null. So to keep
145
- // the same behavior we don't copy the stroke style.
146
- // TODO : maybe we should use this functionnality in the futur.
147
- // stroke: style.getText().getStroke(),
148
- scale: style.getText().getScale(),
100
+ rotation: feature.get("textRotation") || 0,
101
+ scale: style.getText().getScale()
149
102
  });
150
-
151
- if (feature.get('textStrokeColor') && feature.get('textStrokeWidth')) {
103
+ if (feature.get("textStrokeColor") && feature.get("textStrokeWidth")) {
152
104
  text.setStroke(
153
105
  new Stroke({
154
- color: feature.get('textStrokeColor'),
155
- width: parseFloat(feature.get('textStrokeWidth')),
106
+ color: feature.get("textStrokeColor"),
107
+ width: parseFloat(feature.get("textStrokeWidth"))
156
108
  })
157
109
  );
158
110
  }
159
-
160
- if (feature.get('textAlign')) {
161
- text.setTextAlign(feature.get('textAlign'));
111
+ if (feature.get("textAlign")) {
112
+ text.setTextAlign(feature.get("textAlign"));
162
113
  }
163
-
164
- if (feature.get('textOffsetX')) {
165
- text.setOffsetX(parseFloat(feature.get('textOffsetX')));
114
+ if (feature.get("textOffsetX")) {
115
+ text.setOffsetX(parseFloat(feature.get("textOffsetX")));
166
116
  }
167
-
168
- if (feature.get('textOffsetY')) {
169
- text.setOffsetY(parseFloat(feature.get('textOffsetY')));
117
+ if (feature.get("textOffsetY")) {
118
+ text.setOffsetY(parseFloat(feature.get("textOffsetY")));
170
119
  }
171
-
172
- if (feature.get('textBackgroundFillColor')) {
120
+ if (feature.get("textBackgroundFillColor")) {
173
121
  text.setBackgroundFill(
174
122
  new Fill({
175
- color: feature.get('textBackgroundFillColor'),
123
+ color: feature.get("textBackgroundFillColor")
176
124
  })
177
125
  );
178
126
  }
179
-
180
- if (feature.get('textPadding')) {
127
+ if (feature.get("textPadding")) {
181
128
  text.setPadding(
182
- feature
183
- .get('textPadding')
184
- .split(',')
185
- .map(function (n) {
186
- return parseFloat(n);
187
- })
129
+ feature.get("textPadding").split(",").map((n) => {
130
+ return parseFloat(n);
131
+ })
188
132
  );
189
133
  }
190
-
191
134
  if (image instanceof Icon) {
192
135
  applyTextStyleForIcon(image, text);
193
136
  }
194
137
  }
195
-
196
138
  if (image instanceof Icon) {
197
- /* Apply icon rotation if defined (by default only written as
198
- * <heading> tag, which is not read as rotation value by the ol KML module)
199
- */
200
- image.setRotation(parseFloat(feature.get('iconRotation')) || 0);
139
+ image.setRotation(parseFloat(feature.get("iconRotation")) || 0);
201
140
  }
202
-
203
- fill = undefined;
204
- stroke = undefined;
205
-
206
- styles = function (feat, resolution) {
207
- /* Options to be used for picture scaling with map, should have at least
208
- * a resolution attribute (this is the map resolution at the zoom level when
209
- * the picture is created), can take an optional constant for further scale
210
- * adjustment.
211
- * e.g. { resolution: 0.123, defaultScale: 1 / 6 }
212
- */
213
-
214
- if (feat.get('pictureOptions')) {
215
- var pictureOptions = feat.get('pictureOptions');
216
- if (typeof pictureOptions === 'string') {
141
+ fill = void 0;
142
+ stroke = void 0;
143
+ styles = (feat, resolution) => {
144
+ if (feat.get("pictureOptions")) {
145
+ let pictureOptions = feat.get("pictureOptions");
146
+ if (typeof pictureOptions === "string") {
217
147
  pictureOptions = JSON.parse(pictureOptions);
218
148
  }
219
- feat.set('pictureOptions', pictureOptions);
149
+ feat.set("pictureOptions", pictureOptions);
220
150
  if (pictureOptions.resolution) {
221
151
  image.setScale(
222
- (pictureOptions.resolution / resolution) *
223
- pictureOptions.defaultScale || 1
152
+ pictureOptions.resolution / resolution * pictureOptions.defaultScale || 1
224
153
  );
225
154
  }
226
155
  }
227
-
228
156
  return new Style({
229
- fill: fill,
230
- stroke: stroke,
231
- image: image,
232
- text: text,
233
- zIndex: style.getZIndex(),
157
+ fill,
158
+ stroke,
159
+ image,
160
+ text,
161
+ zIndex: style.getZIndex()
234
162
  });
235
163
  };
236
164
  }
237
-
238
- // Remove image and text styles for polygons and lines
239
- if (
240
- !(
241
- geom instanceof Point ||
242
- geom instanceof MultiPoint ||
243
- geom instanceof GeometryCollection
244
- )
245
- ) {
165
+ if (!(geom instanceof Point || geom instanceof MultiPoint || geom instanceof GeometryCollection)) {
246
166
  styles = [
247
167
  new Style({
248
168
  fill: style.getFill(),
249
- stroke: stroke,
169
+ stroke,
250
170
  image: null,
251
171
  text: null,
252
- zIndex: style.getZIndex(),
253
- }) ];
254
-
255
- // Parse the fillPattern json string and store parsed object
256
- var fillPattern = feature.get('fillPattern');
172
+ zIndex: style.getZIndex()
173
+ })
174
+ ];
175
+ let fillPattern = feature.get("fillPattern");
257
176
  if (fillPattern) {
258
177
  fillPattern = JSON.parse(fillPattern);
259
- feature.set('fillPattern', fillPattern);
260
-
261
- /* We set the fill pattern for polygons */
178
+ feature.set("fillPattern", fillPattern);
262
179
  if (!style.getFill()) {
263
180
  styles[0].setFill(new Fill());
264
181
  }
265
- var patternOrColor = fillPattern.empty
266
- ? [0, 0, 0, 0]
267
- : getPolygonPattern(fillPattern.id, fillPattern.color);
182
+ const patternOrColor = fillPattern.empty ? [0, 0, 0, 0] : getPolygonPattern(fillPattern.id, fillPattern.color);
268
183
  styles[0].getFill().setColor(patternOrColor);
269
184
  }
270
-
271
- // Add line's icons styles
272
- if (feature.get('lineStartIcon')) {
185
+ if (feature.get("lineStartIcon")) {
273
186
  styles.push(
274
187
  getLineIcon(
275
188
  feature,
276
- JSON.parse(feature.get('lineStartIcon')),
189
+ JSON.parse(feature.get("lineStartIcon")),
277
190
  stroke.getColor()
278
191
  )
279
192
  );
280
193
  }
281
-
282
- if (feature.get('lineEndIcon')) {
194
+ if (feature.get("lineEndIcon")) {
283
195
  styles.push(
284
196
  getLineIcon(
285
197
  feature,
286
- JSON.parse(feature.get('lineEndIcon')),
198
+ JSON.parse(feature.get("lineEndIcon")),
287
199
  stroke.getColor(),
288
200
  false
289
201
  )
@@ -292,307 +204,209 @@ var sanitizeFeature = function (feature) {
292
204
  }
293
205
  feature.setStyle(styles);
294
206
  };
295
-
296
- /**
297
- * Read a KML string.
298
- * @param {String} kmlString A string representing a KML file.
299
- * @param {<ol.Projection|String>} featureProjection The projection used by the map.
300
- */
301
- var readFeatures = function (kmlString, featureProjection) {
302
- var features = new KML().readFeatures(kmlString, {
303
- featureProjection: featureProjection,
207
+ const readFeatures = (kmlString, featureProjection) => {
208
+ const features = new KML().readFeatures(kmlString, {
209
+ featureProjection
304
210
  });
305
- features.forEach(function (feature) {
211
+ features.forEach((feature) => {
306
212
  sanitizeFeature(feature);
307
213
  });
308
214
  return features;
309
215
  };
310
-
311
- /**
312
- * Create a KML string.
313
- * @param {VectorLayer} layer A react-spatial VectorLayer.
314
- * @param {<ol.Projection|String>} featureProjection The current projection used by the features.
315
- */
316
- var writeFeatures = function (layer, featureProjection, mapResolution) {
317
- var featString;
318
- var olLayer = layer.olLayer;
319
- var exportFeatures = [];
320
-
321
- olLayer.getSource().forEachFeature(function (feature) {
322
- // We silently ignore Circle elements as they are
323
- // not supported in kml.
324
- if (feature.getGeometry().getType() === 'Circle') {
216
+ const writeFeatures = (layer, featureProjection, mapResolution) => {
217
+ let featString;
218
+ const { olLayer } = layer;
219
+ const exportFeatures = [];
220
+ olLayer.getSource().forEachFeature((feature) => {
221
+ if (feature.getGeometry().getType() === "Circle") {
325
222
  return;
326
223
  }
327
-
328
- var clone = feature.clone();
224
+ const clone = feature.clone();
329
225
  clone.setId(feature.getId());
330
226
  clone.getGeometry().setProperties(feature.getGeometry().getProperties());
331
- clone.getGeometry().transform(featureProjection, 'EPSG:4326');
332
-
333
- // We remove all ExtendedData not related to style.
334
- Object.keys(feature.getProperties()).forEach(function (key) {
227
+ clone.getGeometry().transform(featureProjection, "EPSG:4326");
228
+ Object.keys(feature.getProperties()).forEach((key) => {
335
229
  if (!/^(geometry|name|description)$/.test(key)) {
336
230
  clone.unset(key, true);
337
231
  }
338
232
  });
339
-
340
- var styles;
341
-
233
+ let styles;
342
234
  if (feature.getStyleFunction()) {
343
235
  styles = feature.getStyleFunction()(feature, mapResolution);
344
236
  } else if (olLayer && olLayer.getStyleFunction()) {
345
237
  styles = olLayer.getStyleFunction()(feature, mapResolution);
346
238
  }
347
-
348
- var mainStyle = styles[0] || styles;
349
-
350
- var newStyle = {
239
+ const mainStyle = styles[0] || styles;
240
+ const newStyle = {
351
241
  fill: mainStyle.getFill(),
352
242
  stroke: mainStyle.getStroke(),
353
243
  text: mainStyle.getText(),
354
244
  image: mainStyle.getImage(),
355
- zIndex: mainStyle.getZIndex(),
245
+ zIndex: mainStyle.getZIndex()
356
246
  };
357
-
358
247
  if (newStyle.zIndex) {
359
- clone.set('zIndex', newStyle.zIndex);
248
+ clone.set("zIndex", newStyle.zIndex);
360
249
  }
361
-
362
- // If we see spaces at the beginning or at the end we add a empty
363
- // white space at the beginning and at the end.
364
250
  if (newStyle.text && /^\s|\s$/g.test(newStyle.text.getText())) {
365
- newStyle.text.setText(("​" + (newStyle.text.getText()) + "​"));
251
+ newStyle.text.setText(`\u200B${newStyle.text.getText()}\u200B`);
366
252
  }
367
-
368
- // Set custom properties to be converted in extendedData in KML.
369
253
  if (newStyle.text && newStyle.text.getRotation()) {
370
- clone.set('textRotation', newStyle.text.getRotation());
254
+ clone.set("textRotation", newStyle.text.getRotation());
371
255
  }
372
-
373
256
  if (newStyle.text && newStyle.text.getFont()) {
374
- clone.set('textFont', newStyle.text.getFont());
257
+ clone.set("textFont", newStyle.text.getFont());
375
258
  }
376
-
377
259
  if (newStyle.text && newStyle.text.getTextAlign()) {
378
- clone.set('textAlign', newStyle.text.getTextAlign());
260
+ clone.set("textAlign", newStyle.text.getTextAlign());
379
261
  }
380
-
381
262
  if (newStyle.text && newStyle.text.getOffsetX()) {
382
- clone.set('textOffsetX', newStyle.text.getOffsetX());
263
+ clone.set("textOffsetX", newStyle.text.getOffsetX());
383
264
  }
384
-
385
265
  if (newStyle.text && newStyle.text.getOffsetY()) {
386
- clone.set('textOffsetY', newStyle.text.getOffsetY());
266
+ clone.set("textOffsetY", newStyle.text.getOffsetY());
387
267
  }
388
-
389
268
  if (newStyle.text && newStyle.text.getStroke()) {
390
269
  if (newStyle.text.getStroke().getColor()) {
391
270
  clone.set(
392
- 'textStrokeColor',
271
+ "textStrokeColor",
393
272
  asString(newStyle.text.getStroke().getColor())
394
273
  );
395
274
  }
396
-
397
275
  if (newStyle.text.getStroke().getWidth()) {
398
- clone.set('textStrokeWidth', newStyle.text.getStroke().getWidth());
276
+ clone.set("textStrokeWidth", newStyle.text.getStroke().getWidth());
399
277
  }
400
278
  }
401
-
402
279
  if (newStyle.text && newStyle.text.getBackgroundFill()) {
403
280
  clone.set(
404
- 'textBackgroundFillColor',
281
+ "textBackgroundFillColor",
405
282
  asString(newStyle.text.getBackgroundFill().getColor())
406
283
  );
407
284
  }
408
-
409
285
  if (newStyle.text && newStyle.text.getPadding()) {
410
- clone.set('textPadding', newStyle.text.getPadding().join());
286
+ clone.set("textPadding", newStyle.text.getPadding().join());
411
287
  }
412
-
413
288
  if (newStyle.stroke && newStyle.stroke.getLineDash()) {
414
- clone.set('lineDash', newStyle.stroke.getLineDash().join(','));
289
+ clone.set("lineDash", newStyle.stroke.getLineDash().join(","));
415
290
  }
416
-
417
291
  if (newStyle.image instanceof Circle) {
418
292
  newStyle.image = null;
419
293
  }
420
-
421
294
  if (newStyle.image) {
422
- var imgSource = newStyle.image.getSrc();
295
+ const imgSource = newStyle.image.getSrc();
423
296
  if (!/(http(s?)):\/\//gi.test(imgSource)) {
424
- // eslint-disable-next-line no-console
425
297
  console.log(
426
- 'Local image source not supported for KML export.' +
427
- 'Should use remote web server'
298
+ "Local image source not supported for KML export.Should use remote web server"
428
299
  );
429
300
  }
430
-
431
301
  if (newStyle.image.getRotation()) {
432
- // We set the icon rotation as extended data
433
- clone.set('iconRotation', newStyle.image.getRotation());
302
+ clone.set("iconRotation", newStyle.image.getRotation());
434
303
  }
435
-
436
- // Set map resolution to use for icon-to-map proportional scaling
437
- if (feature.get('pictureOptions')) {
304
+ if (feature.get("pictureOptions")) {
438
305
  clone.set(
439
- 'pictureOptions',
440
- JSON.stringify(feature.get('pictureOptions'))
306
+ "pictureOptions",
307
+ JSON.stringify(feature.get("pictureOptions"))
441
308
  );
442
309
  }
443
310
  }
444
-
445
- // In case a fill pattern should be applied (use fillPattern attribute to store pattern id, color etc)
446
- if (feature.get('fillPattern')) {
447
- clone.set('fillPattern', JSON.stringify(feature.get('fillPattern')));
311
+ if (feature.get("fillPattern")) {
312
+ clone.set("fillPattern", JSON.stringify(feature.get("fillPattern")));
448
313
  newStyle.fill = null;
449
314
  }
450
-
451
- // maxZoom: maximum zoom level at which the feature is displayed
452
- if (feature.get('maxZoom')) {
453
- clone.set('maxZoom', parseFloat(feature.get('maxZoom'), 10));
315
+ if (feature.get("maxZoom")) {
316
+ clone.set("maxZoom", parseFloat(feature.get("maxZoom"), 10));
454
317
  }
455
-
456
- // minZoom: minimum zoom level at which the feature is displayed
457
- if (feature.get('minZoom')) {
458
- clone.set('minZoom', parseFloat(feature.get('minZoom'), 10));
318
+ if (feature.get("minZoom")) {
319
+ clone.set("minZoom", parseFloat(feature.get("minZoom"), 10));
459
320
  }
460
-
461
- // If only text is displayed we must specify an
462
- // image style with scale=0
463
321
  if (newStyle.text && !newStyle.image) {
464
322
  newStyle.image = new Icon({
465
- src: 'noimage',
466
- scale: 0,
323
+ src: "noimage",
324
+ scale: 0
467
325
  });
468
326
  }
469
-
470
- // In case we use line's icon .
471
- var extraLineStyles = (Array.isArray(styles) && styles.slice(1)) || [];
472
- extraLineStyles.forEach(function (extraLineStyle) {
473
- if (
474
- extraLineStyle &&
475
- extraLineStyle.getImage() instanceof Icon &&
476
- extraLineStyle.getGeometry()
477
- ) {
478
- var coord = extraLineStyle.getGeometry()(feature).getCoordinates();
479
- var startCoord = feature.getGeometry().getFirstCoordinate();
327
+ const extraLineStyles = Array.isArray(styles) && styles.slice(1) || [];
328
+ extraLineStyles.forEach((extraLineStyle) => {
329
+ if (extraLineStyle && extraLineStyle.getImage() instanceof Icon && extraLineStyle.getGeometry()) {
330
+ const coord = extraLineStyle.getGeometry()(feature).getCoordinates();
331
+ const startCoord = feature.getGeometry().getFirstCoordinate();
480
332
  if (coord[0] === startCoord[0] && coord[1] === startCoord[1]) {
481
333
  clone.set(
482
- 'lineStartIcon',
334
+ "lineStartIcon",
483
335
  JSON.stringify({
484
336
  url: extraLineStyle.getImage().getSrc(),
485
337
  scale: extraLineStyle.getImage().getScale(),
486
338
  size: extraLineStyle.getImage().getSize(),
487
- zIndex: extraLineStyle.getZIndex(),
339
+ zIndex: extraLineStyle.getZIndex()
488
340
  })
489
341
  );
490
342
  } else {
491
343
  clone.set(
492
- 'lineEndIcon',
344
+ "lineEndIcon",
493
345
  JSON.stringify({
494
346
  url: extraLineStyle.getImage().getSrc(),
495
347
  scale: extraLineStyle.getImage().getScale(),
496
348
  size: extraLineStyle.getImage().getSize(),
497
- zIndex: extraLineStyle.getZIndex(),
349
+ zIndex: extraLineStyle.getZIndex()
498
350
  })
499
351
  );
500
352
  }
501
353
  }
502
354
  });
503
-
504
- var olStyle = new Style(newStyle);
355
+ const olStyle = new Style(newStyle);
505
356
  clone.setStyle(olStyle);
506
-
507
- if (
508
- !(
509
- clone.getGeometry() instanceof Point &&
510
- olStyle.getText() &&
511
- !olStyle.getText().getText()
512
- )
513
- ) {
357
+ if (!(clone.getGeometry() instanceof Point && olStyle.getText() && !olStyle.getText().getText())) {
514
358
  exportFeatures.push(clone);
515
359
  }
516
360
  });
517
-
518
361
  if (exportFeatures.length > 0) {
519
362
  if (exportFeatures.length === 1) {
520
- // force the add of a <Document> node
521
363
  exportFeatures.push(new Feature());
522
364
  }
523
-
524
365
  featString = new KML({
525
366
  extractStyles: true,
526
- defaultStyle: [kmlStyle],
367
+ defaultStyle: [kmlStyle]
527
368
  }).writeFeatures(exportFeatures);
528
-
529
- // Remove no image hack
530
369
  featString = featString.replace(
531
370
  /<Icon>\s*<href>noimage<\/href>\s*<\/Icon>/g,
532
- ''
371
+ ""
533
372
  );
534
-
535
- // Remove empty placemark added to have
536
- // <Document> tag
537
- featString = featString.replace(/<Placemark\/>/g, '');
538
-
539
- // Add KML document name
373
+ featString = featString.replace(/<Placemark\/>/g, "");
540
374
  if (layer.name) {
541
375
  featString = featString.replace(
542
376
  /<Document>/,
543
- ("<Document><name>" + (layer.name) + "</name>")
377
+ `<Document><name>${layer.name}</name>`
544
378
  );
545
379
  }
546
380
  }
547
-
548
381
  return featString;
549
382
  };
550
-
551
- /**
552
- * Removes the <Camera> tag from a KML string. Returns the KML string with removed <Camera> tag.
553
- * @param {String} kmlString A string representing a KML file.
554
- */
555
- var removeDocumentCamera = function (kmlString) {
556
- var kmlDoc = parse(kmlString);
557
- // Remove old Camera node
558
- var oldCameraNode = kmlDoc.getElementsByTagName('Camera')[0];
383
+ const removeDocumentCamera = (kmlString) => {
384
+ const kmlDoc = parse(kmlString);
385
+ const oldCameraNode = kmlDoc.getElementsByTagName("Camera")[0];
559
386
  if (oldCameraNode) {
560
387
  oldCameraNode.remove();
561
388
  }
562
389
  return new XMLSerializer().serializeToString(kmlDoc);
563
390
  };
564
-
565
- /**
566
- * Write the <Camera> tag into a KML string. Returns the KML string with added <Camera> tag.
567
- * @param {String} kmlString A string representing a KML file.
568
- * @param {Object} cameraAttributes Object containing the camera tags (longitude, latitude, altitude, heading, tilt, altitudeMode, roll)
569
- * as keys with corresponding values. See https://developers.google.com/kml/documentation/kmlreference#camera
570
- */
571
- var writeDocumentCamera = function (kmlString, cameraAttributes) {
572
- var kmlDoc = parse(removeDocumentCamera(kmlString));
573
-
391
+ const writeDocumentCamera = (kmlString, cameraAttributes) => {
392
+ const kmlDoc = parse(removeDocumentCamera(kmlString));
574
393
  if (cameraAttributes) {
575
- // Create Camera node with child attributes if the cameraAttributes object is defined
576
- var cameraNode = kmlDoc.createElement('Camera');
577
- Object.keys(cameraAttributes).forEach(function (key) {
578
- var cameraAttribute = kmlDoc.createElement(
579
- ("" + (key.charAt(0).toUpperCase() + key.slice(1)))
394
+ const cameraNode = kmlDoc.createElement("Camera");
395
+ Object.keys(cameraAttributes).forEach((key) => {
396
+ const cameraAttribute = kmlDoc.createElement(
397
+ `${key.charAt(0).toUpperCase() + key.slice(1)}`
580
398
  );
581
399
  cameraAttribute.innerHTML = cameraAttributes[key];
582
400
  cameraNode.appendChild(cameraAttribute);
583
401
  });
584
- var documentNode = kmlDoc.getElementsByTagName('Document')[0];
402
+ const documentNode = kmlDoc.getElementsByTagName("Document")[0];
585
403
  documentNode.appendChild(cameraNode);
586
404
  }
587
-
588
405
  return new XMLSerializer().serializeToString(kmlDoc);
589
406
  };
590
-
591
407
  export default {
592
- readFeatures: readFeatures,
593
- writeFeatures: writeFeatures,
594
- writeDocumentCamera: writeDocumentCamera,
595
- removeDocumentCamera: removeDocumentCamera,
408
+ readFeatures,
409
+ writeFeatures,
410
+ writeDocumentCamera,
411
+ removeDocumentCamera
596
412
  };
597
-
598
- //# sourceMappingURL=KML.js.map