@vaadin/bundles 25.0.0-alpha1 → 25.0.0-alpha12

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 (192) hide show
  1. package/node_modules_ol_ImageCanvas_js.js +76 -83
  2. package/node_modules_ol_ImageCanvas_js.js.map +1 -1
  3. package/node_modules_ol_TileRange_js.js +128 -110
  4. package/node_modules_ol_TileRange_js.js.map +1 -1
  5. package/node_modules_ol_Tile_js.js +279 -0
  6. package/node_modules_ol_Tile_js.js.map +1 -0
  7. package/node_modules_ol_VectorRenderTile_js.js +428 -143
  8. package/node_modules_ol_VectorRenderTile_js.js.map +1 -1
  9. package/node_modules_ol_VectorTile_js.js +405 -119
  10. package/node_modules_ol_VectorTile_js.js.map +1 -1
  11. package/node_modules_ol_control_MousePosition_js.js +327 -0
  12. package/node_modules_ol_control_MousePosition_js.js.map +1 -0
  13. package/node_modules_ol_control_ZoomToExtent_js.js +118 -0
  14. package/node_modules_ol_control_ZoomToExtent_js.js.map +1 -0
  15. package/node_modules_ol_events_SnapEvent_js.js +79 -0
  16. package/node_modules_ol_events_SnapEvent_js.js.map +1 -0
  17. package/node_modules_ol_featureloader_js.js +205 -0
  18. package/node_modules_ol_featureloader_js.js.map +1 -0
  19. package/node_modules_ol_geom_Circle_js.js +300 -0
  20. package/node_modules_ol_geom_Circle_js.js.map +1 -0
  21. package/node_modules_ol_geom_GeometryCollection_js.js +369 -0
  22. package/node_modules_ol_geom_GeometryCollection_js.js.map +1 -0
  23. package/node_modules_ol_geom_MultiPoint_js.js +228 -0
  24. package/node_modules_ol_geom_MultiPoint_js.js.map +1 -0
  25. package/node_modules_ol_geom_flat_center_js.js +47 -0
  26. package/node_modules_ol_geom_flat_center_js.js.map +1 -0
  27. package/node_modules_ol_geom_flat_geodesic_js.js +123 -88
  28. package/node_modules_ol_geom_flat_geodesic_js.js.map +1 -1
  29. package/node_modules_ol_geom_flat_interpolate_js.js +230 -0
  30. package/node_modules_ol_geom_flat_interpolate_js.js.map +1 -0
  31. package/node_modules_ol_geom_flat_length_js-_375a0.js +58 -0
  32. package/node_modules_ol_geom_flat_length_js-_375a0.js.map +1 -0
  33. package/node_modules_ol_geom_flat_length_js-_375a1.js +58 -0
  34. package/node_modules_ol_geom_flat_length_js-_375a1.js.map +1 -0
  35. package/node_modules_ol_geom_flat_length_js-_375a2.js +58 -0
  36. package/node_modules_ol_geom_flat_length_js-_375a2.js.map +1 -0
  37. package/node_modules_ol_geom_flat_length_js-_375a3.js +58 -0
  38. package/node_modules_ol_geom_flat_length_js-_375a3.js.map +1 -0
  39. package/node_modules_ol_geom_flat_length_js-_375a4.js +58 -0
  40. package/node_modules_ol_geom_flat_length_js-_375a4.js.map +1 -0
  41. package/node_modules_ol_geom_flat_linechunk_js.js +76 -0
  42. package/node_modules_ol_geom_flat_linechunk_js.js.map +1 -0
  43. package/node_modules_ol_geom_flat_straightchunk_js.js +68 -0
  44. package/node_modules_ol_geom_flat_straightchunk_js.js.map +1 -0
  45. package/node_modules_ol_geom_flat_textpath_js.js +178 -0
  46. package/node_modules_ol_geom_flat_textpath_js.js.map +1 -0
  47. package/node_modules_ol_interaction_DblClickDragZoom_js.js +285 -0
  48. package/node_modules_ol_interaction_DblClickDragZoom_js.js.map +1 -0
  49. package/node_modules_ol_interaction_DragAndDrop_js.js +351 -0
  50. package/node_modules_ol_interaction_DragAndDrop_js.js.map +1 -0
  51. package/node_modules_ol_interaction_DragRotateAndZoom_js.js +159 -0
  52. package/node_modules_ol_interaction_DragRotateAndZoom_js.js.map +1 -0
  53. package/node_modules_ol_layer_Vector_js-_49290.js +110 -0
  54. package/node_modules_ol_layer_Vector_js-_49290.js.map +1 -0
  55. package/node_modules_ol_layer_Vector_js-_49291.js +110 -0
  56. package/node_modules_ol_layer_Vector_js-_49291.js.map +1 -0
  57. package/node_modules_ol_layer_Vector_js-_49292.js +110 -0
  58. package/node_modules_ol_layer_Vector_js-_49292.js.map +1 -0
  59. package/node_modules_ol_layer_Vector_js-_49293.js +110 -0
  60. package/node_modules_ol_layer_Vector_js-_49293.js.map +1 -0
  61. package/node_modules_ol_loadingstrategy_js.js +95 -0
  62. package/node_modules_ol_loadingstrategy_js.js.map +1 -0
  63. package/node_modules_ol_render_VectorContext_js-_3ad60.js +144 -0
  64. package/node_modules_ol_render_VectorContext_js-_3ad60.js.map +1 -0
  65. package/node_modules_ol_render_VectorContext_js-_3ad61.js +144 -0
  66. package/node_modules_ol_render_VectorContext_js-_3ad61.js.map +1 -0
  67. package/node_modules_ol_render_VectorContext_js-node_modules_ol_render_canvas_hitdetect_js.js +372 -0
  68. package/node_modules_ol_render_VectorContext_js-node_modules_ol_render_canvas_hitdetect_js.js.map +1 -0
  69. package/node_modules_ol_render_canvas_ImageBuilder_js.js +318 -0
  70. package/node_modules_ol_render_canvas_ImageBuilder_js.js.map +1 -0
  71. package/node_modules_ol_render_canvas_Instruction_js.js +66 -0
  72. package/node_modules_ol_render_canvas_Instruction_js.js.map +1 -0
  73. package/node_modules_ol_render_canvas_LineStringBuilder_js.js +187 -0
  74. package/node_modules_ol_render_canvas_LineStringBuilder_js.js.map +1 -0
  75. package/node_modules_ol_render_canvas_PolygonBuilder_js.js +276 -0
  76. package/node_modules_ol_render_canvas_PolygonBuilder_js.js.map +1 -0
  77. package/node_modules_ol_render_canvas_ZIndexContext_js-_fab20.js +156 -0
  78. package/node_modules_ol_render_canvas_ZIndexContext_js-_fab20.js.map +1 -0
  79. package/node_modules_ol_render_canvas_ZIndexContext_js-_fab21.js +156 -0
  80. package/node_modules_ol_render_canvas_ZIndexContext_js-_fab21.js.map +1 -0
  81. package/node_modules_ol_render_js-node_modules_ol_render_VectorContext_js.js +301 -0
  82. package/node_modules_ol_render_js-node_modules_ol_render_VectorContext_js.js.map +1 -0
  83. package/node_modules_ol_renderer_Layer_js.js +219 -0
  84. package/node_modules_ol_renderer_Layer_js.js.map +1 -0
  85. package/node_modules_ol_source_Source_js.js +256 -0
  86. package/node_modules_ol_source_Source_js.js.map +1 -0
  87. package/node_modules_ol_source_VectorEventType_js-node_modules_ol_structs_RBush_js.js +318 -0
  88. package/node_modules_ol_source_VectorEventType_js-node_modules_ol_structs_RBush_js.js.map +1 -0
  89. package/node_modules_ol_source_VectorEventType_js.js +80 -0
  90. package/node_modules_ol_source_VectorEventType_js.js.map +1 -0
  91. package/node_modules_ol_structs_RBush_js.js +242 -0
  92. package/node_modules_ol_structs_RBush_js.js.map +1 -0
  93. package/node_modules_ol_style_js.js +2 -1
  94. package/node_modules_ol_style_js.js.map +1 -1
  95. package/node_modules_rbush_rbush_min_js.js +16 -0
  96. package/node_modules_rbush_rbush_min_js.js.map +1 -0
  97. package/package.json +142 -142
  98. package/vaadin-bundle.json +2059 -2368
  99. package/vaadin.js +46213 -64566
  100. package/vaadin.js.map +1 -1
  101. package/vendors-node_modules_dompurify_dist_purify_es_mjs.js +26 -21
  102. package/vendors-node_modules_dompurify_dist_purify_es_mjs.js.map +1 -1
  103. package/vendors-node_modules_dompurify_dist_purify_js.js +26 -21
  104. package/vendors-node_modules_dompurify_dist_purify_js.js.map +1 -1
  105. package/vendors-node_modules_marked_lib_marked_esm_js.js +2097 -2508
  106. package/vendors-node_modules_marked_lib_marked_esm_js.js.map +1 -1
  107. package/vendors-node_modules_marked_lib_marked_umd_js.js +2164 -2556
  108. package/vendors-node_modules_marked_lib_marked_umd_js.js.map +1 -1
  109. package/vendors-node_modules_ol_Feature_js.js +360 -0
  110. package/vendors-node_modules_ol_Feature_js.js.map +1 -0
  111. package/vendors-node_modules_ol_Geolocation_js.js +352 -293
  112. package/vendors-node_modules_ol_Geolocation_js.js.map +1 -1
  113. package/vendors-node_modules_ol_ImageTile_js.js +494 -0
  114. package/vendors-node_modules_ol_ImageTile_js.js.map +1 -0
  115. package/vendors-node_modules_ol_Overlay_js.js +606 -0
  116. package/vendors-node_modules_ol_Overlay_js.js.map +1 -0
  117. package/vendors-node_modules_ol_control_FullScreen_js.js +417 -0
  118. package/vendors-node_modules_ol_control_FullScreen_js.js.map +1 -0
  119. package/vendors-node_modules_ol_control_OverviewMap_js.js +711 -0
  120. package/vendors-node_modules_ol_control_OverviewMap_js.js.map +1 -0
  121. package/vendors-node_modules_ol_control_ScaleLine_js.js +509 -0
  122. package/vendors-node_modules_ol_control_ScaleLine_js.js.map +1 -0
  123. package/vendors-node_modules_ol_control_ZoomSlider_js.js +418 -0
  124. package/vendors-node_modules_ol_control_ZoomSlider_js.js.map +1 -0
  125. package/vendors-node_modules_ol_control_js.js +490 -0
  126. package/vendors-node_modules_ol_control_js.js.map +1 -0
  127. package/vendors-node_modules_ol_geom_LineString_js.js +574 -0
  128. package/vendors-node_modules_ol_geom_LineString_js.js.map +1 -0
  129. package/vendors-node_modules_ol_geom_MultiLineString_js.js +405 -0
  130. package/vendors-node_modules_ol_geom_MultiLineString_js.js.map +1 -0
  131. package/vendors-node_modules_ol_geom_MultiPolygon_js.js +773 -0
  132. package/vendors-node_modules_ol_geom_MultiPolygon_js.js.map +1 -0
  133. package/vendors-node_modules_ol_geom_js-node_modules_ol_geom_flat_length_js.js +769 -0
  134. package/vendors-node_modules_ol_geom_js-node_modules_ol_geom_flat_length_js.js.map +1 -0
  135. package/vendors-node_modules_ol_index_js.js +526 -675
  136. package/vendors-node_modules_ol_index_js.js.map +1 -1
  137. package/vendors-node_modules_ol_interaction_Draw_js.js +2777 -0
  138. package/vendors-node_modules_ol_interaction_Draw_js.js.map +1 -0
  139. package/vendors-node_modules_ol_interaction_Extent_js.js +586 -0
  140. package/vendors-node_modules_ol_interaction_Extent_js.js.map +1 -0
  141. package/vendors-node_modules_ol_interaction_Link_js.js +489 -0
  142. package/vendors-node_modules_ol_interaction_Link_js.js.map +1 -0
  143. package/vendors-node_modules_ol_interaction_Modify_js.js +1841 -0
  144. package/vendors-node_modules_ol_interaction_Modify_js.js.map +1 -0
  145. package/vendors-node_modules_ol_interaction_Select_js.js +623 -0
  146. package/vendors-node_modules_ol_interaction_Select_js.js.map +1 -0
  147. package/vendors-node_modules_ol_interaction_Snap_js.js +982 -0
  148. package/vendors-node_modules_ol_interaction_Snap_js.js.map +1 -0
  149. package/vendors-node_modules_ol_interaction_Translate_js.js +466 -0
  150. package/vendors-node_modules_ol_interaction_Translate_js.js.map +1 -0
  151. package/vendors-node_modules_ol_interaction_js.js +872 -0
  152. package/vendors-node_modules_ol_interaction_js.js.map +1 -0
  153. package/vendors-node_modules_ol_layer_Graticule_js.js +1374 -989
  154. package/vendors-node_modules_ol_layer_Graticule_js.js.map +1 -1
  155. package/vendors-node_modules_ol_render_Feature_js.js +546 -0
  156. package/vendors-node_modules_ol_render_Feature_js.js.map +1 -0
  157. package/vendors-node_modules_ol_render_canvas_BuilderGroup_js.js +897 -0
  158. package/vendors-node_modules_ol_render_canvas_BuilderGroup_js.js.map +1 -0
  159. package/vendors-node_modules_ol_render_canvas_Builder_js.js +907 -0
  160. package/vendors-node_modules_ol_render_canvas_Builder_js.js.map +1 -0
  161. package/vendors-node_modules_ol_render_canvas_ExecutorGroup_js.js +539 -0
  162. package/vendors-node_modules_ol_render_canvas_ExecutorGroup_js.js.map +1 -0
  163. package/vendors-node_modules_ol_render_canvas_Executor_js.js +1715 -0
  164. package/vendors-node_modules_ol_render_canvas_Executor_js.js.map +1 -0
  165. package/vendors-node_modules_ol_render_canvas_Immediate_js.js +1208 -0
  166. package/vendors-node_modules_ol_render_canvas_Immediate_js.js.map +1 -0
  167. package/vendors-node_modules_ol_render_canvas_TextBuilder_js.js +825 -0
  168. package/vendors-node_modules_ol_render_canvas_TextBuilder_js.js.map +1 -0
  169. package/vendors-node_modules_ol_renderer_canvas_Layer_js.js +654 -0
  170. package/vendors-node_modules_ol_renderer_canvas_Layer_js.js.map +1 -0
  171. package/vendors-node_modules_ol_renderer_canvas_VectorLayer_js.js +1044 -0
  172. package/vendors-node_modules_ol_renderer_canvas_VectorLayer_js.js.map +1 -0
  173. package/vendors-node_modules_ol_renderer_vector_js.js +460 -0
  174. package/vendors-node_modules_ol_renderer_vector_js.js.map +1 -0
  175. package/vendors-node_modules_ol_source_Vector_js.js +2091 -0
  176. package/vendors-node_modules_ol_source_Vector_js.js.map +1 -0
  177. package/node_modules_ol_ImageTile_js.js +0 -177
  178. package/node_modules_ol_ImageTile_js.js.map +0 -1
  179. package/node_modules_ol_render_js.js +0 -131
  180. package/node_modules_ol_render_js.js.map +0 -1
  181. package/node_modules_ol_structs_LRUCache_js.js +0 -275
  182. package/node_modules_ol_structs_LRUCache_js.js.map +0 -1
  183. package/node_modules_ol_tilecoord_js.js +0 -115
  184. package/node_modules_ol_tilecoord_js.js.map +0 -1
  185. package/vendors-node_modules_ol_TileCache_js.js +0 -461
  186. package/vendors-node_modules_ol_TileCache_js.js.map +0 -1
  187. package/vendors-node_modules_ol_Tile_js.js +0 -330
  188. package/vendors-node_modules_ol_Tile_js.js.map +0 -1
  189. package/vendors-node_modules_ol_style_Text_js.js +0 -509
  190. package/vendors-node_modules_ol_style_Text_js.js.map +0 -1
  191. package/vendors-node_modules_rbush_index_js.js +0 -531
  192. package/vendors-node_modules_rbush_index_js.js.map +0 -1
@@ -0,0 +1,2777 @@
1
+ (self["webpackChunk_vaadin_bundles"] = self["webpackChunk_vaadin_bundles"] || []).push([["vendors-node_modules_ol_interaction_Draw_js"],{
2
+
3
+ /***/ "./node_modules/ol/geom/Circle.js":
4
+ /*!****************************************!*\
5
+ !*** ./node_modules/ol/geom/Circle.js ***!
6
+ \****************************************/
7
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
8
+
9
+ __webpack_require__.r(__webpack_exports__);
10
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
11
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
12
+ /* harmony export */ });
13
+ /* harmony import */ var _extent_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../extent.js */ "./node_modules/ol/extent.js");
14
+ /* harmony import */ var _SimpleGeometry_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./SimpleGeometry.js */ "./node_modules/ol/geom/SimpleGeometry.js");
15
+ /* harmony import */ var _flat_deflate_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./flat/deflate.js */ "./node_modules/ol/geom/flat/deflate.js");
16
+ /* harmony import */ var _flat_transform_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./flat/transform.js */ "./node_modules/ol/geom/flat/transform.js");
17
+ /**
18
+ * @module ol/geom/Circle
19
+ */
20
+
21
+
22
+
23
+
24
+
25
+ /**
26
+ * @classdesc
27
+ * Circle geometry.
28
+ *
29
+ * @api
30
+ */
31
+ class Circle extends _SimpleGeometry_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
32
+ /**
33
+ * @param {!import("../coordinate.js").Coordinate} center Center.
34
+ * For internal use, flat coordinates in combination with `layout` and no
35
+ * `radius` are also accepted.
36
+ * @param {number} [radius] Radius in units of the projection.
37
+ * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
38
+ */
39
+ constructor(center, radius, layout) {
40
+ super();
41
+ if (layout !== undefined && radius === undefined) {
42
+ this.setFlatCoordinates(layout, center);
43
+ } else {
44
+ radius = radius ? radius : 0;
45
+ this.setCenterAndRadius(center, radius, layout);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Make a complete copy of the geometry.
51
+ * @return {!Circle} Clone.
52
+ * @api
53
+ * @override
54
+ */
55
+ clone() {
56
+ const circle = new Circle(
57
+ this.flatCoordinates.slice(),
58
+ undefined,
59
+ this.layout,
60
+ );
61
+ circle.applyProperties(this);
62
+ return circle;
63
+ }
64
+
65
+ /**
66
+ * @param {number} x X.
67
+ * @param {number} y Y.
68
+ * @param {import("../coordinate.js").Coordinate} closestPoint Closest point.
69
+ * @param {number} minSquaredDistance Minimum squared distance.
70
+ * @return {number} Minimum squared distance.
71
+ * @override
72
+ */
73
+ closestPointXY(x, y, closestPoint, minSquaredDistance) {
74
+ const flatCoordinates = this.flatCoordinates;
75
+ const dx = x - flatCoordinates[0];
76
+ const dy = y - flatCoordinates[1];
77
+ const squaredDistance = dx * dx + dy * dy;
78
+ if (squaredDistance < minSquaredDistance) {
79
+ if (squaredDistance === 0) {
80
+ for (let i = 0; i < this.stride; ++i) {
81
+ closestPoint[i] = flatCoordinates[i];
82
+ }
83
+ } else {
84
+ const delta = this.getRadius() / Math.sqrt(squaredDistance);
85
+ closestPoint[0] = flatCoordinates[0] + delta * dx;
86
+ closestPoint[1] = flatCoordinates[1] + delta * dy;
87
+ for (let i = 2; i < this.stride; ++i) {
88
+ closestPoint[i] = flatCoordinates[i];
89
+ }
90
+ }
91
+ closestPoint.length = this.stride;
92
+ return squaredDistance;
93
+ }
94
+ return minSquaredDistance;
95
+ }
96
+
97
+ /**
98
+ * @param {number} x X.
99
+ * @param {number} y Y.
100
+ * @return {boolean} Contains (x, y).
101
+ * @override
102
+ */
103
+ containsXY(x, y) {
104
+ const flatCoordinates = this.flatCoordinates;
105
+ const dx = x - flatCoordinates[0];
106
+ const dy = y - flatCoordinates[1];
107
+ return dx * dx + dy * dy <= this.getRadiusSquared_();
108
+ }
109
+
110
+ /**
111
+ * Return the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
112
+ * @return {import("../coordinate.js").Coordinate} Center.
113
+ * @api
114
+ */
115
+ getCenter() {
116
+ return this.flatCoordinates.slice(0, this.stride);
117
+ }
118
+
119
+ /**
120
+ * @param {import("../extent.js").Extent} extent Extent.
121
+ * @protected
122
+ * @return {import("../extent.js").Extent} extent Extent.
123
+ * @override
124
+ */
125
+ computeExtent(extent) {
126
+ const flatCoordinates = this.flatCoordinates;
127
+ const radius = flatCoordinates[this.stride] - flatCoordinates[0];
128
+ return (0,_extent_js__WEBPACK_IMPORTED_MODULE_1__.createOrUpdate)(
129
+ flatCoordinates[0] - radius,
130
+ flatCoordinates[1] - radius,
131
+ flatCoordinates[0] + radius,
132
+ flatCoordinates[1] + radius,
133
+ extent,
134
+ );
135
+ }
136
+
137
+ /**
138
+ * Return the radius of the circle.
139
+ * @return {number} Radius.
140
+ * @api
141
+ */
142
+ getRadius() {
143
+ return Math.sqrt(this.getRadiusSquared_());
144
+ }
145
+
146
+ /**
147
+ * @private
148
+ * @return {number} Radius squared.
149
+ */
150
+ getRadiusSquared_() {
151
+ const dx = this.flatCoordinates[this.stride] - this.flatCoordinates[0];
152
+ const dy = this.flatCoordinates[this.stride + 1] - this.flatCoordinates[1];
153
+ return dx * dx + dy * dy;
154
+ }
155
+
156
+ /**
157
+ * Get the type of this geometry.
158
+ * @return {import("./Geometry.js").Type} Geometry type.
159
+ * @api
160
+ * @override
161
+ */
162
+ getType() {
163
+ return 'Circle';
164
+ }
165
+
166
+ /**
167
+ * Test if the geometry and the passed extent intersect.
168
+ * @param {import("../extent.js").Extent} extent Extent.
169
+ * @return {boolean} `true` if the geometry and the extent intersect.
170
+ * @api
171
+ * @override
172
+ */
173
+ intersectsExtent(extent) {
174
+ const circleExtent = this.getExtent();
175
+ if ((0,_extent_js__WEBPACK_IMPORTED_MODULE_1__.intersects)(extent, circleExtent)) {
176
+ const center = this.getCenter();
177
+
178
+ if (extent[0] <= center[0] && extent[2] >= center[0]) {
179
+ return true;
180
+ }
181
+ if (extent[1] <= center[1] && extent[3] >= center[1]) {
182
+ return true;
183
+ }
184
+
185
+ return (0,_extent_js__WEBPACK_IMPORTED_MODULE_1__.forEachCorner)(extent, this.intersectsCoordinate.bind(this));
186
+ }
187
+ return false;
188
+ }
189
+
190
+ /**
191
+ * Set the center of the circle as {@link module:ol/coordinate~Coordinate coordinate}.
192
+ * @param {import("../coordinate.js").Coordinate} center Center.
193
+ * @api
194
+ */
195
+ setCenter(center) {
196
+ const stride = this.stride;
197
+ const radius = this.flatCoordinates[stride] - this.flatCoordinates[0];
198
+ const flatCoordinates = center.slice();
199
+ flatCoordinates[stride] = flatCoordinates[0] + radius;
200
+ for (let i = 1; i < stride; ++i) {
201
+ flatCoordinates[stride + i] = center[i];
202
+ }
203
+ this.setFlatCoordinates(this.layout, flatCoordinates);
204
+ this.changed();
205
+ }
206
+
207
+ /**
208
+ * Set the center (as {@link module:ol/coordinate~Coordinate coordinate}) and the radius (as
209
+ * number) of the circle.
210
+ * @param {!import("../coordinate.js").Coordinate} center Center.
211
+ * @param {number} radius Radius.
212
+ * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
213
+ * @api
214
+ */
215
+ setCenterAndRadius(center, radius, layout) {
216
+ this.setLayout(layout, center, 0);
217
+ if (!this.flatCoordinates) {
218
+ this.flatCoordinates = [];
219
+ }
220
+ /** @type {Array<number>} */
221
+ const flatCoordinates = this.flatCoordinates;
222
+ let offset = (0,_flat_deflate_js__WEBPACK_IMPORTED_MODULE_2__.deflateCoordinate)(flatCoordinates, 0, center, this.stride);
223
+ flatCoordinates[offset++] = flatCoordinates[0] + radius;
224
+ for (let i = 1, ii = this.stride; i < ii; ++i) {
225
+ flatCoordinates[offset++] = flatCoordinates[i];
226
+ }
227
+ flatCoordinates.length = offset;
228
+ this.changed();
229
+ }
230
+
231
+ /**
232
+ * @override
233
+ */
234
+ getCoordinates() {
235
+ return null;
236
+ }
237
+
238
+ /**
239
+ * @override
240
+ */
241
+ setCoordinates(coordinates, layout) {}
242
+
243
+ /**
244
+ * Set the radius of the circle. The radius is in the units of the projection.
245
+ * @param {number} radius Radius.
246
+ * @api
247
+ */
248
+ setRadius(radius) {
249
+ this.flatCoordinates[this.stride] = this.flatCoordinates[0] + radius;
250
+ this.changed();
251
+ }
252
+
253
+ /**
254
+ * Rotate the geometry around a given coordinate. This modifies the geometry
255
+ * coordinates in place.
256
+ * @param {number} angle Rotation angle in counter-clockwise radians.
257
+ * @param {import("../coordinate.js").Coordinate} anchor The rotation center.
258
+ * @api
259
+ * @override
260
+ */
261
+ rotate(angle, anchor) {
262
+ const center = this.getCenter();
263
+ const stride = this.getStride();
264
+ this.setCenter(
265
+ (0,_flat_transform_js__WEBPACK_IMPORTED_MODULE_3__.rotate)(center, 0, center.length, stride, angle, anchor, center),
266
+ );
267
+ this.changed();
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Transform each coordinate of the circle from one coordinate reference system
273
+ * to another. The geometry is modified in place.
274
+ * If you do not want the geometry modified in place, first clone() it and
275
+ * then use this function on the clone.
276
+ *
277
+ * Internally a circle is currently represented by two points: the center of
278
+ * the circle `[cx, cy]`, and the point to the right of the circle
279
+ * `[cx + r, cy]`. This `transform` function just transforms these two points.
280
+ * So the resulting geometry is also a circle, and that circle does not
281
+ * correspond to the shape that would be obtained by transforming every point
282
+ * of the original circle.
283
+ *
284
+ * @param {import("../proj.js").ProjectionLike} source The current projection. Can be a
285
+ * string identifier or a {@link module:ol/proj/Projection~Projection} object.
286
+ * @param {import("../proj.js").ProjectionLike} destination The desired projection. Can be a
287
+ * string identifier or a {@link module:ol/proj/Projection~Projection} object.
288
+ * @return {Circle} This geometry. Note that original geometry is
289
+ * modified in place.
290
+ * @function
291
+ * @api
292
+ */
293
+ Circle.prototype.transform;
294
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Circle);
295
+
296
+
297
+ /***/ }),
298
+
299
+ /***/ "./node_modules/ol/geom/GeometryCollection.js":
300
+ /*!****************************************************!*\
301
+ !*** ./node_modules/ol/geom/GeometryCollection.js ***!
302
+ \****************************************************/
303
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
304
+
305
+ __webpack_require__.r(__webpack_exports__);
306
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
307
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
308
+ /* harmony export */ });
309
+ /* harmony import */ var _events_EventType_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../events/EventType.js */ "./node_modules/ol/events/EventType.js");
310
+ /* harmony import */ var _events_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../events.js */ "./node_modules/ol/events.js");
311
+ /* harmony import */ var _extent_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../extent.js */ "./node_modules/ol/extent.js");
312
+ /* harmony import */ var _Geometry_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Geometry.js */ "./node_modules/ol/geom/Geometry.js");
313
+ /**
314
+ * @module ol/geom/GeometryCollection
315
+ */
316
+
317
+
318
+
319
+
320
+
321
+ /**
322
+ * @classdesc
323
+ * An array of {@link module:ol/geom/Geometry~Geometry} objects.
324
+ *
325
+ * @api
326
+ */
327
+ class GeometryCollection extends _Geometry_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
328
+ /**
329
+ * @param {Array<Geometry>} geometries Geometries.
330
+ */
331
+ constructor(geometries) {
332
+ super();
333
+
334
+ /**
335
+ * @private
336
+ * @type {Array<Geometry>}
337
+ */
338
+ this.geometries_ = geometries;
339
+
340
+ /**
341
+ * @private
342
+ * @type {Array<import("../events.js").EventsKey>}
343
+ */
344
+ this.changeEventsKeys_ = [];
345
+
346
+ this.listenGeometriesChange_();
347
+ }
348
+
349
+ /**
350
+ * @private
351
+ */
352
+ unlistenGeometriesChange_() {
353
+ this.changeEventsKeys_.forEach(_events_js__WEBPACK_IMPORTED_MODULE_1__.unlistenByKey);
354
+ this.changeEventsKeys_.length = 0;
355
+ }
356
+
357
+ /**
358
+ * @private
359
+ */
360
+ listenGeometriesChange_() {
361
+ const geometries = this.geometries_;
362
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
363
+ this.changeEventsKeys_.push(
364
+ (0,_events_js__WEBPACK_IMPORTED_MODULE_1__.listen)(geometries[i], _events_EventType_js__WEBPACK_IMPORTED_MODULE_2__["default"].CHANGE, this.changed, this),
365
+ );
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Make a complete copy of the geometry.
371
+ * @return {!GeometryCollection} Clone.
372
+ * @api
373
+ * @override
374
+ */
375
+ clone() {
376
+ const geometryCollection = new GeometryCollection(
377
+ cloneGeometries(this.geometries_),
378
+ );
379
+ geometryCollection.applyProperties(this);
380
+ return geometryCollection;
381
+ }
382
+
383
+ /**
384
+ * @param {number} x X.
385
+ * @param {number} y Y.
386
+ * @param {import("../coordinate.js").Coordinate} closestPoint Closest point.
387
+ * @param {number} minSquaredDistance Minimum squared distance.
388
+ * @return {number} Minimum squared distance.
389
+ * @override
390
+ */
391
+ closestPointXY(x, y, closestPoint, minSquaredDistance) {
392
+ if (minSquaredDistance < (0,_extent_js__WEBPACK_IMPORTED_MODULE_3__.closestSquaredDistanceXY)(this.getExtent(), x, y)) {
393
+ return minSquaredDistance;
394
+ }
395
+ const geometries = this.geometries_;
396
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
397
+ minSquaredDistance = geometries[i].closestPointXY(
398
+ x,
399
+ y,
400
+ closestPoint,
401
+ minSquaredDistance,
402
+ );
403
+ }
404
+ return minSquaredDistance;
405
+ }
406
+
407
+ /**
408
+ * @param {number} x X.
409
+ * @param {number} y Y.
410
+ * @return {boolean} Contains (x, y).
411
+ * @override
412
+ */
413
+ containsXY(x, y) {
414
+ const geometries = this.geometries_;
415
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
416
+ if (geometries[i].containsXY(x, y)) {
417
+ return true;
418
+ }
419
+ }
420
+ return false;
421
+ }
422
+
423
+ /**
424
+ * @param {import("../extent.js").Extent} extent Extent.
425
+ * @protected
426
+ * @return {import("../extent.js").Extent} extent Extent.
427
+ * @override
428
+ */
429
+ computeExtent(extent) {
430
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_3__.createOrUpdateEmpty)(extent);
431
+ const geometries = this.geometries_;
432
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
433
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_3__.extend)(extent, geometries[i].getExtent());
434
+ }
435
+ return extent;
436
+ }
437
+
438
+ /**
439
+ * Return the geometries that make up this geometry collection.
440
+ * @return {Array<Geometry>} Geometries.
441
+ * @api
442
+ */
443
+ getGeometries() {
444
+ return cloneGeometries(this.geometries_);
445
+ }
446
+
447
+ /**
448
+ * @return {Array<Geometry>} Geometries.
449
+ */
450
+ getGeometriesArray() {
451
+ return this.geometries_;
452
+ }
453
+
454
+ /**
455
+ * @return {Array<Geometry>} Geometries.
456
+ */
457
+ getGeometriesArrayRecursive() {
458
+ /** @type {Array<Geometry>} */
459
+ let geometriesArray = [];
460
+ const geometries = this.geometries_;
461
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
462
+ if (geometries[i].getType() === this.getType()) {
463
+ geometriesArray = geometriesArray.concat(
464
+ /** @type {GeometryCollection} */ (
465
+ geometries[i]
466
+ ).getGeometriesArrayRecursive(),
467
+ );
468
+ } else {
469
+ geometriesArray.push(geometries[i]);
470
+ }
471
+ }
472
+ return geometriesArray;
473
+ }
474
+
475
+ /**
476
+ * Create a simplified version of this geometry using the Douglas Peucker algorithm.
477
+ * @param {number} squaredTolerance Squared tolerance.
478
+ * @return {GeometryCollection} Simplified GeometryCollection.
479
+ * @override
480
+ */
481
+ getSimplifiedGeometry(squaredTolerance) {
482
+ if (this.simplifiedGeometryRevision !== this.getRevision()) {
483
+ this.simplifiedGeometryMaxMinSquaredTolerance = 0;
484
+ this.simplifiedGeometryRevision = this.getRevision();
485
+ }
486
+ if (
487
+ squaredTolerance < 0 ||
488
+ (this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
489
+ squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)
490
+ ) {
491
+ return this;
492
+ }
493
+
494
+ const simplifiedGeometries = [];
495
+ const geometries = this.geometries_;
496
+ let simplified = false;
497
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
498
+ const geometry = geometries[i];
499
+ const simplifiedGeometry =
500
+ geometry.getSimplifiedGeometry(squaredTolerance);
501
+ simplifiedGeometries.push(simplifiedGeometry);
502
+ if (simplifiedGeometry !== geometry) {
503
+ simplified = true;
504
+ }
505
+ }
506
+ if (simplified) {
507
+ const simplifiedGeometryCollection = new GeometryCollection(
508
+ simplifiedGeometries,
509
+ );
510
+ return simplifiedGeometryCollection;
511
+ }
512
+ this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
513
+ return this;
514
+ }
515
+
516
+ /**
517
+ * Get the type of this geometry.
518
+ * @return {import("./Geometry.js").Type} Geometry type.
519
+ * @api
520
+ * @override
521
+ */
522
+ getType() {
523
+ return 'GeometryCollection';
524
+ }
525
+
526
+ /**
527
+ * Test if the geometry and the passed extent intersect.
528
+ * @param {import("../extent.js").Extent} extent Extent.
529
+ * @return {boolean} `true` if the geometry and the extent intersect.
530
+ * @api
531
+ * @override
532
+ */
533
+ intersectsExtent(extent) {
534
+ const geometries = this.geometries_;
535
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
536
+ if (geometries[i].intersectsExtent(extent)) {
537
+ return true;
538
+ }
539
+ }
540
+ return false;
541
+ }
542
+
543
+ /**
544
+ * @return {boolean} Is empty.
545
+ */
546
+ isEmpty() {
547
+ return this.geometries_.length === 0;
548
+ }
549
+
550
+ /**
551
+ * Rotate the geometry around a given coordinate. This modifies the geometry
552
+ * coordinates in place.
553
+ * @param {number} angle Rotation angle in radians.
554
+ * @param {import("../coordinate.js").Coordinate} anchor The rotation center.
555
+ * @api
556
+ * @override
557
+ */
558
+ rotate(angle, anchor) {
559
+ const geometries = this.geometries_;
560
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
561
+ geometries[i].rotate(angle, anchor);
562
+ }
563
+ this.changed();
564
+ }
565
+
566
+ /**
567
+ * Scale the geometry (with an optional origin). This modifies the geometry
568
+ * coordinates in place.
569
+ * @abstract
570
+ * @param {number} sx The scaling factor in the x-direction.
571
+ * @param {number} [sy] The scaling factor in the y-direction (defaults to sx).
572
+ * @param {import("../coordinate.js").Coordinate} [anchor] The scale origin (defaults to the center
573
+ * of the geometry extent).
574
+ * @api
575
+ * @override
576
+ */
577
+ scale(sx, sy, anchor) {
578
+ if (!anchor) {
579
+ anchor = (0,_extent_js__WEBPACK_IMPORTED_MODULE_3__.getCenter)(this.getExtent());
580
+ }
581
+ const geometries = this.geometries_;
582
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
583
+ geometries[i].scale(sx, sy, anchor);
584
+ }
585
+ this.changed();
586
+ }
587
+
588
+ /**
589
+ * Set the geometries that make up this geometry collection.
590
+ * @param {Array<Geometry>} geometries Geometries.
591
+ * @api
592
+ */
593
+ setGeometries(geometries) {
594
+ this.setGeometriesArray(cloneGeometries(geometries));
595
+ }
596
+
597
+ /**
598
+ * @param {Array<Geometry>} geometries Geometries.
599
+ */
600
+ setGeometriesArray(geometries) {
601
+ this.unlistenGeometriesChange_();
602
+ this.geometries_ = geometries;
603
+ this.listenGeometriesChange_();
604
+ this.changed();
605
+ }
606
+
607
+ /**
608
+ * Apply a transform function to the coordinates of the geometry.
609
+ * The geometry is modified in place.
610
+ * If you do not want the geometry modified in place, first `clone()` it and
611
+ * then use this function on the clone.
612
+ * @param {import("../proj.js").TransformFunction} transformFn Transform function.
613
+ * Called with a flat array of geometry coordinates.
614
+ * @api
615
+ * @override
616
+ */
617
+ applyTransform(transformFn) {
618
+ const geometries = this.geometries_;
619
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
620
+ geometries[i].applyTransform(transformFn);
621
+ }
622
+ this.changed();
623
+ }
624
+
625
+ /**
626
+ * Translate the geometry. This modifies the geometry coordinates in place. If
627
+ * instead you want a new geometry, first `clone()` this geometry.
628
+ * @param {number} deltaX Delta X.
629
+ * @param {number} deltaY Delta Y.
630
+ * @api
631
+ * @override
632
+ */
633
+ translate(deltaX, deltaY) {
634
+ const geometries = this.geometries_;
635
+ for (let i = 0, ii = geometries.length; i < ii; ++i) {
636
+ geometries[i].translate(deltaX, deltaY);
637
+ }
638
+ this.changed();
639
+ }
640
+
641
+ /**
642
+ * Clean up.
643
+ * @override
644
+ */
645
+ disposeInternal() {
646
+ this.unlistenGeometriesChange_();
647
+ super.disposeInternal();
648
+ }
649
+ }
650
+
651
+ /**
652
+ * @param {Array<Geometry>} geometries Geometries.
653
+ * @return {Array<Geometry>} Cloned geometries.
654
+ */
655
+ function cloneGeometries(geometries) {
656
+ return geometries.map((geometry) => geometry.clone());
657
+ }
658
+
659
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (GeometryCollection);
660
+
661
+
662
+ /***/ }),
663
+
664
+ /***/ "./node_modules/ol/interaction/Draw.js":
665
+ /*!*********************************************!*\
666
+ !*** ./node_modules/ol/interaction/Draw.js ***!
667
+ \*********************************************/
668
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
669
+
670
+ __webpack_require__.r(__webpack_exports__);
671
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
672
+ /* harmony export */ "DrawEvent": () => (/* binding */ DrawEvent),
673
+ /* harmony export */ "createBox": () => (/* binding */ createBox),
674
+ /* harmony export */ "createRegularPolygon": () => (/* binding */ createRegularPolygon),
675
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
676
+ /* harmony export */ });
677
+ /* harmony import */ var _Feature_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ../Feature.js */ "./node_modules/ol/Feature.js");
678
+ /* harmony import */ var _MapBrowserEvent_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ../MapBrowserEvent.js */ "./node_modules/ol/MapBrowserEvent.js");
679
+ /* harmony import */ var _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ../MapBrowserEventType.js */ "./node_modules/ol/MapBrowserEventType.js");
680
+ /* harmony import */ var _coordinate_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../coordinate.js */ "./node_modules/ol/coordinate.js");
681
+ /* harmony import */ var _events_Event_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../events/Event.js */ "./node_modules/ol/events/Event.js");
682
+ /* harmony import */ var _events_EventType_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ../events/EventType.js */ "./node_modules/ol/events/EventType.js");
683
+ /* harmony import */ var _events_condition_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ../events/condition.js */ "./node_modules/ol/events/condition.js");
684
+ /* harmony import */ var _extent_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ../extent.js */ "./node_modules/ol/extent.js");
685
+ /* harmony import */ var _functions_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../functions.js */ "./node_modules/ol/functions.js");
686
+ /* harmony import */ var _geom_Circle_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../geom/Circle.js */ "./node_modules/ol/geom/Circle.js");
687
+ /* harmony import */ var _geom_GeometryCollection_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../geom/GeometryCollection.js */ "./node_modules/ol/geom/GeometryCollection.js");
688
+ /* harmony import */ var _geom_LineString_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../geom/LineString.js */ "./node_modules/ol/geom/LineString.js");
689
+ /* harmony import */ var _geom_MultiLineString_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../geom/MultiLineString.js */ "./node_modules/ol/geom/MultiLineString.js");
690
+ /* harmony import */ var _geom_MultiPoint_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ../geom/MultiPoint.js */ "./node_modules/ol/geom/MultiPoint.js");
691
+ /* harmony import */ var _geom_MultiPolygon_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../geom/MultiPolygon.js */ "./node_modules/ol/geom/MultiPolygon.js");
692
+ /* harmony import */ var _geom_Point_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../geom/Point.js */ "./node_modules/ol/geom/Point.js");
693
+ /* harmony import */ var _geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../geom/Polygon.js */ "./node_modules/ol/geom/Polygon.js");
694
+ /* harmony import */ var _geom_SimpleGeometry_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ../geom/SimpleGeometry.js */ "./node_modules/ol/geom/SimpleGeometry.js");
695
+ /* harmony import */ var _layer_Vector_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../layer/Vector.js */ "./node_modules/ol/layer/Vector.js");
696
+ /* harmony import */ var _math_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../math.js */ "./node_modules/ol/math.js");
697
+ /* harmony import */ var _proj_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../proj.js */ "./node_modules/ol/proj.js");
698
+ /* harmony import */ var _source_Vector_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../source/Vector.js */ "./node_modules/ol/source/Vector.js");
699
+ /* harmony import */ var _style_Style_js__WEBPACK_IMPORTED_MODULE_24__ = __webpack_require__(/*! ../style/Style.js */ "./node_modules/ol/style/Style.js");
700
+ /* harmony import */ var _Pointer_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Pointer.js */ "./node_modules/ol/interaction/Pointer.js");
701
+ /* harmony import */ var _Property_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./Property.js */ "./node_modules/ol/interaction/Property.js");
702
+ /**
703
+ * @module ol/interaction/Draw
704
+ */
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+ /**
732
+ * @typedef {Object} Options
733
+ * @property {import("../geom/Geometry.js").Type} type Geometry type of
734
+ * the geometries being drawn with this instance.
735
+ * @property {number} [clickTolerance=6] The maximum distance in pixels between
736
+ * "down" and "up" for a "up" event to be considered a "click" event and
737
+ * actually add a point/vertex to the geometry being drawn. The default of `6`
738
+ * was chosen for the draw interaction to behave correctly on mouse as well as
739
+ * on touch devices.
740
+ * @property {import("../Collection.js").default<Feature>} [features]
741
+ * Destination collection for the drawn features.
742
+ * @property {VectorSource} [source] Destination source for
743
+ * the drawn features.
744
+ * @property {number} [dragVertexDelay=500] Delay in milliseconds after pointerdown
745
+ * before the current vertex can be dragged to its exact position.
746
+ * @property {number} [snapTolerance=12] Pixel distance for snapping to the
747
+ * drawing finish. Must be greater than `0`.
748
+ * @property {boolean} [stopClick=false] Stop click, singleclick, and
749
+ * doubleclick events from firing during drawing.
750
+ * @property {number} [maxPoints] The number of points that can be drawn before
751
+ * a polygon ring or line string is finished. By default there is no
752
+ * restriction.
753
+ * @property {number} [minPoints] The number of points that must be drawn
754
+ * before a polygon ring or line string can be finished. Default is `3` for
755
+ * polygon rings and `2` for line strings.
756
+ * @property {import("../events/condition.js").Condition} [finishCondition] A function
757
+ * that takes a {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
758
+ * boolean to indicate whether the drawing can be finished. Not used when drawing
759
+ * POINT or MULTI_POINT geometries.
760
+ * @property {import("../style/Style.js").StyleLike|import("../style/flat.js").FlatStyleLike} [style]
761
+ * Style for sketch features. The draw interaction can have up to three sketch features, depending on the mode.
762
+ * It will always contain a feature with a `Point` geometry that corresponds to the current cursor position.
763
+ * If the mode is `LineString` or `Polygon`, and there is at least one drawn point, it will also contain a feature with
764
+ * a `LineString` geometry that corresponds to the line between the already drawn points and the current cursor position.
765
+ * If the mode is `Polygon`, and there is at least one drawn point, it will also contain a feature with a `Polygon`
766
+ * geometry that corresponds to the polygon between the already drawn points and the current cursor position
767
+ * (note that this polygon has only two points if only one point is drawn).
768
+ * If the mode is `Circle`, and there is one point drawn, it will also contain a feature with a `Circle` geometry whose
769
+ * center is the drawn point and the radius is determined by the distance between the drawn point and the cursor.
770
+ * @property {GeometryFunction} [geometryFunction]
771
+ * Function that is called when a geometry's coordinates are updated.
772
+ * @property {string} [geometryName] Geometry name to use for features created
773
+ * by the draw interaction.
774
+ * @property {import("../events/condition.js").Condition} [condition] A function that
775
+ * takes a {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
776
+ * boolean to indicate whether that event should be handled.
777
+ * By default {@link module:ol/events/condition.noModifierKeys}, i.e. a click,
778
+ * adds a vertex or deactivates freehand drawing.
779
+ * @property {boolean} [freehand=false] Operate in freehand mode for lines,
780
+ * polygons, and circles. This makes the interaction always operate in freehand
781
+ * mode and takes precedence over any `freehandCondition` option.
782
+ * @property {import("../events/condition.js").Condition} [freehandCondition]
783
+ * Condition that activates freehand drawing for lines and polygons. This
784
+ * function takes a {@link module:ol/MapBrowserEvent~MapBrowserEvent} and
785
+ * returns a boolean to indicate whether that event should be handled. The
786
+ * default is {@link module:ol/events/condition.shiftKeyOnly}, meaning that the
787
+ * Shift key activates freehand drawing.
788
+ * @property {boolean|import("../events/condition.js").Condition} [trace=false] Trace a portion of another geometry.
789
+ * Ignored when in freehand mode.
790
+ * @property {VectorSource} [traceSource] Source for features to trace. If tracing is active and a `traceSource` is
791
+ * not provided, the interaction's `source` will be used. Tracing requires that the interaction is configured with
792
+ * either a `traceSource` or a `source`.
793
+ * @property {boolean} [wrapX=false] Wrap the world horizontally on the sketch
794
+ * overlay.
795
+ * @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout='XY'] Layout of the
796
+ * feature geometries created by the draw interaction.
797
+ */
798
+
799
+ /**
800
+ * Coordinate type when drawing points.
801
+ * @typedef {import("../coordinate.js").Coordinate} PointCoordType
802
+ */
803
+
804
+ /**
805
+ * Coordinate type when drawing lines.
806
+ * @typedef {Array<import("../coordinate.js").Coordinate>} LineCoordType
807
+ */
808
+
809
+ /**
810
+ * Coordinate type when drawing polygons.
811
+ * @typedef {Array<Array<import("../coordinate.js").Coordinate>>} PolyCoordType
812
+ */
813
+
814
+ /**
815
+ * Types used for drawing coordinates.
816
+ * @typedef {PointCoordType|LineCoordType|PolyCoordType} SketchCoordType
817
+ */
818
+
819
+ /**
820
+ * @typedef {Object} TraceState
821
+ * @property {boolean} active Tracing active.
822
+ * @property {import("../pixel.js").Pixel} [startPx] The initially clicked pixel location.
823
+ * @property {Array<TraceTarget>} [targets] Targets available for tracing.
824
+ * @property {number} [targetIndex] The index of the currently traced target. A value of -1 indicates
825
+ * that no trace target is active.
826
+ */
827
+
828
+ /**
829
+ * @typedef {Object} TraceTarget
830
+ * @property {Array<import("../coordinate.js").Coordinate>} coordinates Target coordinates.
831
+ * @property {boolean} ring The target coordinates are a linear ring.
832
+ * @property {number} startIndex The index of first traced coordinate. A fractional index represents an
833
+ * edge intersection. Index values for rings will wrap (may be negative or larger than coordinates length).
834
+ * @property {number} endIndex The index of last traced coordinate. Details from startIndex also apply here.
835
+ */
836
+
837
+ /**
838
+ * Function that takes an array of coordinates and an optional existing geometry
839
+ * and a projection as arguments, and returns a geometry. The optional existing
840
+ * geometry is the geometry that is returned when the function is called without
841
+ * a second argument.
842
+ * @typedef {function(!SketchCoordType, import("../geom/SimpleGeometry.js").default,
843
+ * import("../proj/Projection.js").default):
844
+ * import("../geom/SimpleGeometry.js").default} GeometryFunction
845
+ */
846
+
847
+ /**
848
+ * @typedef {'Point' | 'LineString' | 'Polygon' | 'Circle'} Mode
849
+ * Draw mode. This collapses multi-part geometry types with their single-part
850
+ * cousins.
851
+ */
852
+
853
+ /**
854
+ * @enum {string}
855
+ */
856
+ const DrawEventType = {
857
+ /**
858
+ * Triggered upon feature draw start
859
+ * @event DrawEvent#drawstart
860
+ * @api
861
+ */
862
+ DRAWSTART: 'drawstart',
863
+ /**
864
+ * Triggered upon feature draw end
865
+ * @event DrawEvent#drawend
866
+ * @api
867
+ */
868
+ DRAWEND: 'drawend',
869
+ /**
870
+ * Triggered upon feature draw abortion
871
+ * @event DrawEvent#drawabort
872
+ * @api
873
+ */
874
+ DRAWABORT: 'drawabort',
875
+ };
876
+
877
+ /**
878
+ * @classdesc
879
+ * Events emitted by {@link module:ol/interaction/Draw~Draw} instances are
880
+ * instances of this type.
881
+ */
882
+ class DrawEvent extends _events_Event_js__WEBPACK_IMPORTED_MODULE_1__["default"] {
883
+ /**
884
+ * @param {DrawEventType} type Type.
885
+ * @param {Feature} feature The feature drawn.
886
+ */
887
+ constructor(type, feature) {
888
+ super(type);
889
+
890
+ /**
891
+ * The feature being drawn.
892
+ * @type {Feature}
893
+ * @api
894
+ */
895
+ this.feature = feature;
896
+ }
897
+ }
898
+
899
+ /**
900
+ * @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
901
+ * @param {Array<Feature>} features The candidate features.
902
+ * @return {Array<TraceTarget>} The trace targets.
903
+ */
904
+ function getTraceTargets(coordinate, features) {
905
+ /**
906
+ * @type {Array<TraceTarget>}
907
+ */
908
+ const targets = [];
909
+
910
+ for (let i = 0; i < features.length; ++i) {
911
+ const feature = features[i];
912
+ const geometry = feature.getGeometry();
913
+ appendGeometryTraceTargets(coordinate, geometry, targets);
914
+ }
915
+
916
+ return targets;
917
+ }
918
+
919
+ /**
920
+ * @param {import("../coordinate.js").Coordinate} a One coordinate.
921
+ * @param {import("../coordinate.js").Coordinate} b Another coordinate.
922
+ * @return {number} The squared distance between the two coordinates.
923
+ */
924
+ function getSquaredDistance(a, b) {
925
+ return (0,_math_js__WEBPACK_IMPORTED_MODULE_2__.squaredDistance)(a[0], a[1], b[0], b[1]);
926
+ }
927
+
928
+ /**
929
+ * @param {LineCoordType} coordinates The ring coordinates.
930
+ * @param {number} index The index. May be wrapped.
931
+ * @return {import("../coordinate.js").Coordinate} The coordinate.
932
+ */
933
+ function getCoordinate(coordinates, index) {
934
+ const count = coordinates.length;
935
+ if (index < 0) {
936
+ return coordinates[index + count];
937
+ }
938
+ if (index >= count) {
939
+ return coordinates[index - count];
940
+ }
941
+ return coordinates[index];
942
+ }
943
+
944
+ /**
945
+ * Get the cumulative squared distance along a ring path. The end index index may be "wrapped" and it may
946
+ * be less than the start index to indicate the direction of travel. The start and end index may have
947
+ * a fractional part to indicate a point between two coordinates.
948
+ * @param {LineCoordType} coordinates Ring coordinates.
949
+ * @param {number} startIndex The start index.
950
+ * @param {number} endIndex The end index.
951
+ * @return {number} The cumulative squared distance along the ring path.
952
+ */
953
+ function getCumulativeSquaredDistance(coordinates, startIndex, endIndex) {
954
+ let lowIndex, highIndex;
955
+ if (startIndex < endIndex) {
956
+ lowIndex = startIndex;
957
+ highIndex = endIndex;
958
+ } else {
959
+ lowIndex = endIndex;
960
+ highIndex = startIndex;
961
+ }
962
+ const lowWholeIndex = Math.ceil(lowIndex);
963
+ const highWholeIndex = Math.floor(highIndex);
964
+
965
+ if (lowWholeIndex > highWholeIndex) {
966
+ // both start and end are on the same segment
967
+ const start = interpolateCoordinate(coordinates, lowIndex);
968
+ const end = interpolateCoordinate(coordinates, highIndex);
969
+ return getSquaredDistance(start, end);
970
+ }
971
+
972
+ let sd = 0;
973
+
974
+ if (lowIndex < lowWholeIndex) {
975
+ const start = interpolateCoordinate(coordinates, lowIndex);
976
+ const end = getCoordinate(coordinates, lowWholeIndex);
977
+ sd += getSquaredDistance(start, end);
978
+ }
979
+
980
+ if (highWholeIndex < highIndex) {
981
+ const start = getCoordinate(coordinates, highWholeIndex);
982
+ const end = interpolateCoordinate(coordinates, highIndex);
983
+ sd += getSquaredDistance(start, end);
984
+ }
985
+
986
+ for (let i = lowWholeIndex; i < highWholeIndex - 1; ++i) {
987
+ const start = getCoordinate(coordinates, i);
988
+ const end = getCoordinate(coordinates, i + 1);
989
+ sd += getSquaredDistance(start, end);
990
+ }
991
+
992
+ return sd;
993
+ }
994
+
995
+ /**
996
+ * @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
997
+ * @param {import("../geom/Geometry.js").default} geometry The candidate geometry.
998
+ * @param {Array<TraceTarget>} targets The trace targets.
999
+ */
1000
+ function appendGeometryTraceTargets(coordinate, geometry, targets) {
1001
+ if (geometry instanceof _geom_LineString_js__WEBPACK_IMPORTED_MODULE_3__["default"]) {
1002
+ appendTraceTarget(coordinate, geometry.getCoordinates(), false, targets);
1003
+ return;
1004
+ }
1005
+ if (geometry instanceof _geom_MultiLineString_js__WEBPACK_IMPORTED_MODULE_4__["default"]) {
1006
+ const coordinates = geometry.getCoordinates();
1007
+ for (let i = 0, ii = coordinates.length; i < ii; ++i) {
1008
+ appendTraceTarget(coordinate, coordinates[i], false, targets);
1009
+ }
1010
+ return;
1011
+ }
1012
+ if (geometry instanceof _geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__["default"]) {
1013
+ const coordinates = geometry.getCoordinates();
1014
+ for (let i = 0, ii = coordinates.length; i < ii; ++i) {
1015
+ appendTraceTarget(coordinate, coordinates[i], true, targets);
1016
+ }
1017
+ return;
1018
+ }
1019
+ if (geometry instanceof _geom_MultiPolygon_js__WEBPACK_IMPORTED_MODULE_6__["default"]) {
1020
+ const polys = geometry.getCoordinates();
1021
+ for (let i = 0, ii = polys.length; i < ii; ++i) {
1022
+ const coordinates = polys[i];
1023
+ for (let j = 0, jj = coordinates.length; j < jj; ++j) {
1024
+ appendTraceTarget(coordinate, coordinates[j], true, targets);
1025
+ }
1026
+ }
1027
+ return;
1028
+ }
1029
+ if (geometry instanceof _geom_GeometryCollection_js__WEBPACK_IMPORTED_MODULE_7__["default"]) {
1030
+ const geometries = geometry.getGeometries();
1031
+ for (let i = 0; i < geometries.length; ++i) {
1032
+ appendGeometryTraceTargets(coordinate, geometries[i], targets);
1033
+ }
1034
+ return;
1035
+ }
1036
+ // other types cannot be traced
1037
+ }
1038
+
1039
+ /**
1040
+ * @typedef {Object} TraceTargetUpdateInfo
1041
+ * @property {number} index The new target index.
1042
+ * @property {number} endIndex The new segment end index.
1043
+ */
1044
+
1045
+ /**
1046
+ * @type {TraceTargetUpdateInfo}
1047
+ */
1048
+ const sharedUpdateInfo = {index: -1, endIndex: NaN};
1049
+
1050
+ /**
1051
+ * @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
1052
+ * @param {TraceState} traceState The trace state.
1053
+ * @param {import("../Map.js").default} map The map.
1054
+ * @param {number} snapTolerance The snap tolerance.
1055
+ * @return {TraceTargetUpdateInfo} Information about the new trace target. The returned
1056
+ * object is reused between calls and must not be modified by the caller.
1057
+ */
1058
+ function getTraceTargetUpdate(coordinate, traceState, map, snapTolerance) {
1059
+ const x = coordinate[0];
1060
+ const y = coordinate[1];
1061
+
1062
+ let closestTargetDistance = Infinity;
1063
+
1064
+ let newTargetIndex = -1;
1065
+ let newEndIndex = NaN;
1066
+
1067
+ for (
1068
+ let targetIndex = 0;
1069
+ targetIndex < traceState.targets.length;
1070
+ ++targetIndex
1071
+ ) {
1072
+ const target = traceState.targets[targetIndex];
1073
+ const coordinates = target.coordinates;
1074
+
1075
+ let minSegmentDistance = Infinity;
1076
+ let endIndex;
1077
+ for (
1078
+ let coordinateIndex = 0;
1079
+ coordinateIndex < coordinates.length - 1;
1080
+ ++coordinateIndex
1081
+ ) {
1082
+ const start = coordinates[coordinateIndex];
1083
+ const end = coordinates[coordinateIndex + 1];
1084
+ const rel = getPointSegmentRelationship(x, y, start, end);
1085
+ if (rel.squaredDistance < minSegmentDistance) {
1086
+ minSegmentDistance = rel.squaredDistance;
1087
+ endIndex = coordinateIndex + rel.along;
1088
+ }
1089
+ }
1090
+
1091
+ if (minSegmentDistance < closestTargetDistance) {
1092
+ closestTargetDistance = minSegmentDistance;
1093
+ if (target.ring && traceState.targetIndex === targetIndex) {
1094
+ // same target, maintain the same trace direction
1095
+ if (target.endIndex > target.startIndex) {
1096
+ // forward trace
1097
+ if (endIndex < target.startIndex) {
1098
+ endIndex += coordinates.length;
1099
+ }
1100
+ } else if (target.endIndex < target.startIndex) {
1101
+ // reverse trace
1102
+ if (endIndex > target.startIndex) {
1103
+ endIndex -= coordinates.length;
1104
+ }
1105
+ }
1106
+ }
1107
+ newEndIndex = endIndex;
1108
+ newTargetIndex = targetIndex;
1109
+ }
1110
+ }
1111
+
1112
+ const newTarget = traceState.targets[newTargetIndex];
1113
+ let considerBothDirections = newTarget.ring;
1114
+ if (traceState.targetIndex === newTargetIndex && considerBothDirections) {
1115
+ // only consider switching trace direction if close to the start
1116
+ const newCoordinate = interpolateCoordinate(
1117
+ newTarget.coordinates,
1118
+ newEndIndex,
1119
+ );
1120
+ const pixel = map.getPixelFromCoordinate(newCoordinate);
1121
+ if ((0,_coordinate_js__WEBPACK_IMPORTED_MODULE_8__.distance)(pixel, traceState.startPx) > snapTolerance) {
1122
+ considerBothDirections = false;
1123
+ }
1124
+ }
1125
+
1126
+ if (considerBothDirections) {
1127
+ const coordinates = newTarget.coordinates;
1128
+ const count = coordinates.length;
1129
+ const startIndex = newTarget.startIndex;
1130
+ const endIndex = newEndIndex;
1131
+ if (startIndex < endIndex) {
1132
+ const forwardDistance = getCumulativeSquaredDistance(
1133
+ coordinates,
1134
+ startIndex,
1135
+ endIndex,
1136
+ );
1137
+ const reverseDistance = getCumulativeSquaredDistance(
1138
+ coordinates,
1139
+ startIndex,
1140
+ endIndex - count,
1141
+ );
1142
+ if (reverseDistance < forwardDistance) {
1143
+ newEndIndex -= count;
1144
+ }
1145
+ } else {
1146
+ const reverseDistance = getCumulativeSquaredDistance(
1147
+ coordinates,
1148
+ startIndex,
1149
+ endIndex,
1150
+ );
1151
+ const forwardDistance = getCumulativeSquaredDistance(
1152
+ coordinates,
1153
+ startIndex,
1154
+ endIndex + count,
1155
+ );
1156
+ if (forwardDistance < reverseDistance) {
1157
+ newEndIndex += count;
1158
+ }
1159
+ }
1160
+ }
1161
+
1162
+ sharedUpdateInfo.index = newTargetIndex;
1163
+ sharedUpdateInfo.endIndex = newEndIndex;
1164
+ return sharedUpdateInfo;
1165
+ }
1166
+
1167
+ /**
1168
+ * @param {import("../coordinate.js").Coordinate} coordinate The clicked coordinate.
1169
+ * @param {Array<import("../coordinate.js").Coordinate>} coordinates The geometry component coordinates.
1170
+ * @param {boolean} ring The coordinates represent a linear ring.
1171
+ * @param {Array<TraceTarget>} targets The trace targets.
1172
+ */
1173
+ function appendTraceTarget(coordinate, coordinates, ring, targets) {
1174
+ const x = coordinate[0];
1175
+ const y = coordinate[1];
1176
+ for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
1177
+ const start = coordinates[i];
1178
+ const end = coordinates[i + 1];
1179
+ const rel = getPointSegmentRelationship(x, y, start, end);
1180
+ if (rel.squaredDistance === 0) {
1181
+ const index = i + rel.along;
1182
+ targets.push({
1183
+ coordinates: coordinates,
1184
+ ring: ring,
1185
+ startIndex: index,
1186
+ endIndex: index,
1187
+ });
1188
+ return;
1189
+ }
1190
+ }
1191
+ }
1192
+
1193
+ /**
1194
+ * @typedef {Object} PointSegmentRelationship
1195
+ * @property {number} along The closest point expressed as a fraction along the segment length.
1196
+ * @property {number} squaredDistance The squared distance of the point to the segment.
1197
+ */
1198
+
1199
+ /**
1200
+ * @type {PointSegmentRelationship}
1201
+ */
1202
+ const sharedRel = {along: 0, squaredDistance: 0};
1203
+
1204
+ /**
1205
+ * @param {number} x The point x.
1206
+ * @param {number} y The point y.
1207
+ * @param {import("../coordinate.js").Coordinate} start The segment start.
1208
+ * @param {import("../coordinate.js").Coordinate} end The segment end.
1209
+ * @return {PointSegmentRelationship} The point segment relationship. The returned object is
1210
+ * shared between calls and must not be modified by the caller.
1211
+ */
1212
+ function getPointSegmentRelationship(x, y, start, end) {
1213
+ const x1 = start[0];
1214
+ const y1 = start[1];
1215
+ const x2 = end[0];
1216
+ const y2 = end[1];
1217
+ const dx = x2 - x1;
1218
+ const dy = y2 - y1;
1219
+ let along = 0;
1220
+ let px = x1;
1221
+ let py = y1;
1222
+ if (dx !== 0 || dy !== 0) {
1223
+ along = (0,_math_js__WEBPACK_IMPORTED_MODULE_2__.clamp)(((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy), 0, 1);
1224
+ px += dx * along;
1225
+ py += dy * along;
1226
+ }
1227
+
1228
+ sharedRel.along = along;
1229
+ sharedRel.squaredDistance = (0,_math_js__WEBPACK_IMPORTED_MODULE_2__.toFixed)((0,_math_js__WEBPACK_IMPORTED_MODULE_2__.squaredDistance)(x, y, px, py), 10);
1230
+ return sharedRel;
1231
+ }
1232
+
1233
+ /**
1234
+ * @param {LineCoordType} coordinates The coordinates.
1235
+ * @param {number} index The index. May be fractional and may wrap.
1236
+ * @return {import("../coordinate.js").Coordinate} The interpolated coordinate.
1237
+ */
1238
+ function interpolateCoordinate(coordinates, index) {
1239
+ const count = coordinates.length;
1240
+
1241
+ let startIndex = Math.floor(index);
1242
+ const along = index - startIndex;
1243
+ if (startIndex >= count) {
1244
+ startIndex -= count;
1245
+ } else if (startIndex < 0) {
1246
+ startIndex += count;
1247
+ }
1248
+
1249
+ let endIndex = startIndex + 1;
1250
+ if (endIndex >= count) {
1251
+ endIndex -= count;
1252
+ }
1253
+
1254
+ const start = coordinates[startIndex];
1255
+ const x0 = start[0];
1256
+ const y0 = start[1];
1257
+ const end = coordinates[endIndex];
1258
+ const dx = end[0] - x0;
1259
+ const dy = end[1] - y0;
1260
+
1261
+ return [x0 + dx * along, y0 + dy * along];
1262
+ }
1263
+
1264
+ /***
1265
+ * @template Return
1266
+ * @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
1267
+ * import("../Observable").OnSignature<import("../ObjectEventType").Types|
1268
+ * 'change:active', import("../Object").ObjectEvent, Return> &
1269
+ * import("../Observable").OnSignature<'drawabort'|'drawend'|'drawstart', DrawEvent, Return> &
1270
+ * import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("../ObjectEventType").Types|
1271
+ * 'change:active'|'drawabort'|'drawend'|'drawstart', Return>} DrawOnSignature
1272
+ */
1273
+
1274
+ /**
1275
+ * @classdesc
1276
+ * Interaction for drawing feature geometries.
1277
+ *
1278
+ * @fires DrawEvent
1279
+ * @api
1280
+ */
1281
+ class Draw extends _Pointer_js__WEBPACK_IMPORTED_MODULE_9__["default"] {
1282
+ /**
1283
+ * @param {Options} options Options.
1284
+ */
1285
+ constructor(options) {
1286
+ const pointerOptions = /** @type {import("./Pointer.js").Options} */ (
1287
+ options
1288
+ );
1289
+ if (!pointerOptions.stopDown) {
1290
+ pointerOptions.stopDown = _functions_js__WEBPACK_IMPORTED_MODULE_10__.FALSE;
1291
+ }
1292
+
1293
+ super(pointerOptions);
1294
+
1295
+ /***
1296
+ * @type {DrawOnSignature<import("../events").EventsKey>}
1297
+ */
1298
+ this.on;
1299
+
1300
+ /***
1301
+ * @type {DrawOnSignature<import("../events").EventsKey>}
1302
+ */
1303
+ this.once;
1304
+
1305
+ /***
1306
+ * @type {DrawOnSignature<void>}
1307
+ */
1308
+ this.un;
1309
+
1310
+ /**
1311
+ * @type {boolean}
1312
+ * @private
1313
+ */
1314
+ this.shouldHandle_ = false;
1315
+
1316
+ /**
1317
+ * @type {import("../pixel.js").Pixel}
1318
+ * @private
1319
+ */
1320
+ this.downPx_ = null;
1321
+
1322
+ /**
1323
+ * @type {ReturnType<typeof setTimeout>}
1324
+ * @private
1325
+ */
1326
+ this.downTimeout_;
1327
+
1328
+ /**
1329
+ * @type {number|undefined}
1330
+ * @private
1331
+ */
1332
+ this.lastDragTime_;
1333
+
1334
+ /**
1335
+ * Pointer type of the last pointermove event
1336
+ * @type {string}
1337
+ * @private
1338
+ */
1339
+ this.pointerType_;
1340
+
1341
+ /**
1342
+ * @type {boolean}
1343
+ * @private
1344
+ */
1345
+ this.freehand_ = false;
1346
+
1347
+ /**
1348
+ * Target source for drawn features.
1349
+ * @type {VectorSource|null}
1350
+ * @private
1351
+ */
1352
+ this.source_ = options.source ? options.source : null;
1353
+
1354
+ /**
1355
+ * Target collection for drawn features.
1356
+ * @type {import("../Collection.js").default<Feature>|null}
1357
+ * @private
1358
+ */
1359
+ this.features_ = options.features ? options.features : null;
1360
+
1361
+ /**
1362
+ * Pixel distance for snapping.
1363
+ * @type {number}
1364
+ * @private
1365
+ */
1366
+ this.snapTolerance_ = options.snapTolerance ? options.snapTolerance : 12;
1367
+
1368
+ /**
1369
+ * Geometry type.
1370
+ * @type {import("../geom/Geometry.js").Type}
1371
+ * @private
1372
+ */
1373
+ this.type_ = /** @type {import("../geom/Geometry.js").Type} */ (
1374
+ options.type
1375
+ );
1376
+
1377
+ /**
1378
+ * Drawing mode (derived from geometry type.
1379
+ * @type {Mode}
1380
+ * @private
1381
+ */
1382
+ this.mode_ = getMode(this.type_);
1383
+
1384
+ /**
1385
+ * Stop click, singleclick, and doubleclick events from firing during drawing.
1386
+ * Default is `false`.
1387
+ * @type {boolean}
1388
+ * @private
1389
+ */
1390
+ this.stopClick_ = !!options.stopClick;
1391
+
1392
+ /**
1393
+ * The number of points that must be drawn before a polygon ring or line
1394
+ * string can be finished. The default is 3 for polygon rings and 2 for
1395
+ * line strings.
1396
+ * @type {number}
1397
+ * @private
1398
+ */
1399
+ this.minPoints_ = options.minPoints
1400
+ ? options.minPoints
1401
+ : this.mode_ === 'Polygon'
1402
+ ? 3
1403
+ : 2;
1404
+
1405
+ /**
1406
+ * The number of points that can be drawn before a polygon ring or line string
1407
+ * is finished. The default is no restriction.
1408
+ * @type {number}
1409
+ * @private
1410
+ */
1411
+ this.maxPoints_ =
1412
+ this.mode_ === 'Circle'
1413
+ ? 2
1414
+ : options.maxPoints
1415
+ ? options.maxPoints
1416
+ : Infinity;
1417
+
1418
+ /**
1419
+ * A function to decide if a potential finish coordinate is permissible
1420
+ * @private
1421
+ * @type {import("../events/condition.js").Condition}
1422
+ */
1423
+ this.finishCondition_ = options.finishCondition
1424
+ ? options.finishCondition
1425
+ : _functions_js__WEBPACK_IMPORTED_MODULE_10__.TRUE;
1426
+
1427
+ /**
1428
+ * @private
1429
+ * @type {import("../geom/Geometry.js").GeometryLayout}
1430
+ */
1431
+ this.geometryLayout_ = options.geometryLayout
1432
+ ? options.geometryLayout
1433
+ : 'XY';
1434
+
1435
+ let geometryFunction = options.geometryFunction;
1436
+ if (!geometryFunction) {
1437
+ const mode = this.mode_;
1438
+ if (mode === 'Circle') {
1439
+ /**
1440
+ * @param {!LineCoordType} coordinates The coordinates.
1441
+ * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
1442
+ * @param {import("../proj/Projection.js").default} projection The view projection.
1443
+ * @return {import("../geom/SimpleGeometry.js").default} A geometry.
1444
+ */
1445
+ geometryFunction = (coordinates, geometry, projection) => {
1446
+ const circle = geometry
1447
+ ? /** @type {Circle} */ (geometry)
1448
+ : new _geom_Circle_js__WEBPACK_IMPORTED_MODULE_11__["default"]([NaN, NaN]);
1449
+ const center = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.fromUserCoordinate)(coordinates[0], projection);
1450
+ const squaredLength = (0,_coordinate_js__WEBPACK_IMPORTED_MODULE_8__.squaredDistance)(
1451
+ center,
1452
+ (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.fromUserCoordinate)(coordinates[coordinates.length - 1], projection),
1453
+ );
1454
+ circle.setCenterAndRadius(
1455
+ center,
1456
+ Math.sqrt(squaredLength),
1457
+ this.geometryLayout_,
1458
+ );
1459
+ const userProjection = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.getUserProjection)();
1460
+ if (userProjection) {
1461
+ circle.transform(projection, userProjection);
1462
+ }
1463
+ return circle;
1464
+ };
1465
+ } else {
1466
+ let Constructor;
1467
+ if (mode === 'Point') {
1468
+ Constructor = _geom_Point_js__WEBPACK_IMPORTED_MODULE_12__["default"];
1469
+ } else if (mode === 'LineString') {
1470
+ Constructor = _geom_LineString_js__WEBPACK_IMPORTED_MODULE_3__["default"];
1471
+ } else if (mode === 'Polygon') {
1472
+ Constructor = _geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__["default"];
1473
+ }
1474
+ /**
1475
+ * @param {!LineCoordType} coordinates The coordinates.
1476
+ * @param {import("../geom/SimpleGeometry.js").default|undefined} geometry Optional geometry.
1477
+ * @param {import("../proj/Projection.js").default} projection The view projection.
1478
+ * @return {import("../geom/SimpleGeometry.js").default} A geometry.
1479
+ */
1480
+ geometryFunction = (coordinates, geometry, projection) => {
1481
+ if (geometry) {
1482
+ if (mode === 'Polygon') {
1483
+ if (coordinates[0].length) {
1484
+ // Add a closing coordinate to match the first
1485
+ geometry.setCoordinates(
1486
+ [coordinates[0].concat([coordinates[0][0]])],
1487
+ this.geometryLayout_,
1488
+ );
1489
+ } else {
1490
+ geometry.setCoordinates([], this.geometryLayout_);
1491
+ }
1492
+ } else {
1493
+ geometry.setCoordinates(coordinates, this.geometryLayout_);
1494
+ }
1495
+ } else {
1496
+ geometry = new Constructor(coordinates, this.geometryLayout_);
1497
+ }
1498
+ return geometry;
1499
+ };
1500
+ }
1501
+ }
1502
+
1503
+ /**
1504
+ * @type {GeometryFunction}
1505
+ * @private
1506
+ */
1507
+ this.geometryFunction_ = geometryFunction;
1508
+
1509
+ /**
1510
+ * @type {number}
1511
+ * @private
1512
+ */
1513
+ this.dragVertexDelay_ =
1514
+ options.dragVertexDelay !== undefined ? options.dragVertexDelay : 500;
1515
+
1516
+ /**
1517
+ * Finish coordinate for the feature (first point for polygons, last point for
1518
+ * linestrings).
1519
+ * @type {import("../coordinate.js").Coordinate}
1520
+ * @private
1521
+ */
1522
+ this.finishCoordinate_ = null;
1523
+
1524
+ /**
1525
+ * Sketch feature.
1526
+ * @type {Feature<import('../geom/SimpleGeometry.js').default>}
1527
+ * @private
1528
+ */
1529
+ this.sketchFeature_ = null;
1530
+
1531
+ /**
1532
+ * Sketch point.
1533
+ * @type {Feature<Point>}
1534
+ * @private
1535
+ */
1536
+ this.sketchPoint_ = null;
1537
+
1538
+ /**
1539
+ * Sketch coordinates. Used when drawing a line or polygon.
1540
+ * @type {SketchCoordType}
1541
+ * @private
1542
+ */
1543
+ this.sketchCoords_ = null;
1544
+
1545
+ /**
1546
+ * Sketch line. Used when drawing polygon.
1547
+ * @type {Feature<LineString>}
1548
+ * @private
1549
+ */
1550
+ this.sketchLine_ = null;
1551
+
1552
+ /**
1553
+ * Sketch line coordinates. Used when drawing a polygon or circle.
1554
+ * @type {LineCoordType}
1555
+ * @private
1556
+ */
1557
+ this.sketchLineCoords_ = null;
1558
+
1559
+ /**
1560
+ * Squared tolerance for handling up events. If the squared distance
1561
+ * between a down and up event is greater than this tolerance, up events
1562
+ * will not be handled.
1563
+ * @type {number}
1564
+ * @private
1565
+ */
1566
+ this.squaredClickTolerance_ = options.clickTolerance
1567
+ ? options.clickTolerance * options.clickTolerance
1568
+ : 36;
1569
+
1570
+ /**
1571
+ * Draw overlay where our sketch features are drawn.
1572
+ * @type {VectorLayer}
1573
+ * @private
1574
+ */
1575
+ this.overlay_ = new _layer_Vector_js__WEBPACK_IMPORTED_MODULE_13__["default"]({
1576
+ source: new _source_Vector_js__WEBPACK_IMPORTED_MODULE_14__["default"]({
1577
+ useSpatialIndex: false,
1578
+ wrapX: options.wrapX ? options.wrapX : false,
1579
+ }),
1580
+ style: options.style ? options.style : getDefaultStyleFunction(),
1581
+ updateWhileInteracting: true,
1582
+ });
1583
+
1584
+ /**
1585
+ * Name of the geometry attribute for newly created features.
1586
+ * @type {string|undefined}
1587
+ * @private
1588
+ */
1589
+ this.geometryName_ = options.geometryName;
1590
+
1591
+ /**
1592
+ * @private
1593
+ * @type {import("../events/condition.js").Condition}
1594
+ */
1595
+ this.condition_ = options.condition ? options.condition : _events_condition_js__WEBPACK_IMPORTED_MODULE_15__.noModifierKeys;
1596
+
1597
+ /**
1598
+ * @private
1599
+ * @type {import("../events/condition.js").Condition}
1600
+ */
1601
+ this.freehandCondition_;
1602
+ if (options.freehand) {
1603
+ this.freehandCondition_ = _events_condition_js__WEBPACK_IMPORTED_MODULE_15__.always;
1604
+ } else {
1605
+ this.freehandCondition_ = options.freehandCondition
1606
+ ? options.freehandCondition
1607
+ : _events_condition_js__WEBPACK_IMPORTED_MODULE_15__.shiftKeyOnly;
1608
+ }
1609
+
1610
+ /**
1611
+ * @type {import("../events/condition.js").Condition}
1612
+ * @private
1613
+ */
1614
+ this.traceCondition_;
1615
+ this.setTrace(options.trace || false);
1616
+
1617
+ /**
1618
+ * @type {TraceState}
1619
+ * @private
1620
+ */
1621
+ this.traceState_ = {active: false};
1622
+
1623
+ /**
1624
+ * @type {VectorSource|null}
1625
+ * @private
1626
+ */
1627
+ this.traceSource_ = options.traceSource || options.source || null;
1628
+
1629
+ this.addChangeListener(_Property_js__WEBPACK_IMPORTED_MODULE_16__["default"].ACTIVE, this.updateState_);
1630
+ }
1631
+
1632
+ /**
1633
+ * Toggle tracing mode or set a tracing condition.
1634
+ *
1635
+ * @param {boolean|import("../events/condition.js").Condition} trace A boolean to toggle tracing mode or an event
1636
+ * condition that will be checked when a feature is clicked to determine if tracing should be active.
1637
+ */
1638
+ setTrace(trace) {
1639
+ let condition;
1640
+ if (!trace) {
1641
+ condition = _events_condition_js__WEBPACK_IMPORTED_MODULE_15__.never;
1642
+ } else if (trace === true) {
1643
+ condition = _events_condition_js__WEBPACK_IMPORTED_MODULE_15__.always;
1644
+ } else {
1645
+ condition = trace;
1646
+ }
1647
+ this.traceCondition_ = condition;
1648
+ }
1649
+
1650
+ /**
1651
+ * Remove the interaction from its current map and attach it to the new map.
1652
+ * Subclasses may set up event handlers to get notified about changes to
1653
+ * the map here.
1654
+ * @param {import("../Map.js").default} map Map.
1655
+ * @override
1656
+ */
1657
+ setMap(map) {
1658
+ super.setMap(map);
1659
+ this.updateState_();
1660
+ }
1661
+
1662
+ /**
1663
+ * Get the overlay layer that this interaction renders sketch features to.
1664
+ * @return {VectorLayer} Overlay layer.
1665
+ * @api
1666
+ */
1667
+ getOverlay() {
1668
+ return this.overlay_;
1669
+ }
1670
+
1671
+ /**
1672
+ * Handles the {@link module:ol/MapBrowserEvent~MapBrowserEvent map browser event} and may actually draw or finish the drawing.
1673
+ * @param {import("../MapBrowserEvent.js").default<PointerEvent>} event Map browser event.
1674
+ * @return {boolean} `false` to stop event propagation.
1675
+ * @api
1676
+ * @override
1677
+ */
1678
+ handleEvent(event) {
1679
+ if (event.originalEvent.type === _events_EventType_js__WEBPACK_IMPORTED_MODULE_17__["default"].CONTEXTMENU) {
1680
+ // Avoid context menu for long taps when drawing on mobile
1681
+ event.originalEvent.preventDefault();
1682
+ }
1683
+ this.freehand_ = this.mode_ !== 'Point' && this.freehandCondition_(event);
1684
+ let move = event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERMOVE;
1685
+ let pass = true;
1686
+ if (
1687
+ !this.freehand_ &&
1688
+ this.lastDragTime_ &&
1689
+ event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERDRAG
1690
+ ) {
1691
+ const now = Date.now();
1692
+ if (now - this.lastDragTime_ >= this.dragVertexDelay_) {
1693
+ this.downPx_ = event.pixel;
1694
+ this.shouldHandle_ = !this.freehand_;
1695
+ move = true;
1696
+ } else {
1697
+ this.lastDragTime_ = undefined;
1698
+ }
1699
+ if (this.shouldHandle_ && this.downTimeout_ !== undefined) {
1700
+ clearTimeout(this.downTimeout_);
1701
+ this.downTimeout_ = undefined;
1702
+ }
1703
+ }
1704
+ if (
1705
+ this.freehand_ &&
1706
+ event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERDRAG &&
1707
+ this.sketchFeature_ !== null
1708
+ ) {
1709
+ this.addToDrawing_(event.coordinate);
1710
+ pass = false;
1711
+ } else if (
1712
+ this.freehand_ &&
1713
+ event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERDOWN
1714
+ ) {
1715
+ pass = false;
1716
+ } else if (move && this.getPointerCount() < 2) {
1717
+ pass = event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERMOVE;
1718
+ if (pass && this.freehand_) {
1719
+ this.handlePointerMove_(event);
1720
+ if (this.shouldHandle_) {
1721
+ // Avoid page scrolling when freehand drawing on mobile
1722
+ event.originalEvent.preventDefault();
1723
+ }
1724
+ } else if (
1725
+ event.originalEvent.pointerType === 'mouse' ||
1726
+ (event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERDRAG &&
1727
+ this.downTimeout_ === undefined)
1728
+ ) {
1729
+ this.handlePointerMove_(event);
1730
+ }
1731
+ } else if (event.type === _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].DBLCLICK) {
1732
+ pass = false;
1733
+ }
1734
+
1735
+ return super.handleEvent(event) && pass;
1736
+ }
1737
+
1738
+ /**
1739
+ * Handle pointer down events.
1740
+ * @param {import("../MapBrowserEvent.js").default<PointerEvent>} event Event.
1741
+ * @return {boolean} If the event was consumed.
1742
+ * @override
1743
+ */
1744
+ handleDownEvent(event) {
1745
+ this.shouldHandle_ = !this.freehand_;
1746
+
1747
+ if (this.freehand_) {
1748
+ this.downPx_ = event.pixel;
1749
+ if (!this.finishCoordinate_) {
1750
+ this.startDrawing_(event.coordinate);
1751
+ }
1752
+ return true;
1753
+ }
1754
+
1755
+ if (!this.condition_(event)) {
1756
+ this.lastDragTime_ = undefined;
1757
+ return false;
1758
+ }
1759
+
1760
+ this.lastDragTime_ = Date.now();
1761
+ this.downTimeout_ = setTimeout(() => {
1762
+ this.handlePointerMove_(
1763
+ new _MapBrowserEvent_js__WEBPACK_IMPORTED_MODULE_19__["default"](
1764
+ _MapBrowserEventType_js__WEBPACK_IMPORTED_MODULE_18__["default"].POINTERMOVE,
1765
+ event.map,
1766
+ event.originalEvent,
1767
+ false,
1768
+ event.frameState,
1769
+ ),
1770
+ );
1771
+ }, this.dragVertexDelay_);
1772
+ this.downPx_ = event.pixel;
1773
+ return true;
1774
+ }
1775
+
1776
+ /**
1777
+ * @private
1778
+ */
1779
+ deactivateTrace_() {
1780
+ this.traceState_ = {active: false};
1781
+ }
1782
+
1783
+ /**
1784
+ * Activate or deactivate trace state based on a browser event.
1785
+ * @param {import("../MapBrowserEvent.js").default} event Event.
1786
+ * @private
1787
+ */
1788
+ toggleTraceState_(event) {
1789
+ if (!this.traceSource_ || !this.traceCondition_(event)) {
1790
+ return;
1791
+ }
1792
+
1793
+ if (this.traceState_.active) {
1794
+ this.deactivateTrace_();
1795
+ return;
1796
+ }
1797
+
1798
+ const map = this.getMap();
1799
+ const lowerLeft = map.getCoordinateFromPixel([
1800
+ event.pixel[0] - this.snapTolerance_,
1801
+ event.pixel[1] + this.snapTolerance_,
1802
+ ]);
1803
+ const upperRight = map.getCoordinateFromPixel([
1804
+ event.pixel[0] + this.snapTolerance_,
1805
+ event.pixel[1] - this.snapTolerance_,
1806
+ ]);
1807
+ const extent = (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.boundingExtent)([lowerLeft, upperRight]);
1808
+ const features = this.traceSource_.getFeaturesInExtent(extent);
1809
+ if (features.length === 0) {
1810
+ return;
1811
+ }
1812
+
1813
+ const targets = getTraceTargets(event.coordinate, features);
1814
+ if (targets.length) {
1815
+ this.traceState_ = {
1816
+ active: true,
1817
+ startPx: event.pixel.slice(),
1818
+ targets: targets,
1819
+ targetIndex: -1,
1820
+ };
1821
+ }
1822
+ }
1823
+
1824
+ /**
1825
+ * @param {TraceTarget} target The trace target.
1826
+ * @param {number} endIndex The new end index of the trace.
1827
+ * @private
1828
+ */
1829
+ addOrRemoveTracedCoordinates_(target, endIndex) {
1830
+ // three cases to handle:
1831
+ // 1. traced in the same direction and points need adding
1832
+ // 2. traced in the same direction and points need removing
1833
+ // 3. traced in a new direction
1834
+ const previouslyForward = target.startIndex <= target.endIndex;
1835
+ const currentlyForward = target.startIndex <= endIndex;
1836
+ if (previouslyForward === currentlyForward) {
1837
+ // same direction
1838
+ if (
1839
+ (previouslyForward && endIndex > target.endIndex) ||
1840
+ (!previouslyForward && endIndex < target.endIndex)
1841
+ ) {
1842
+ // case 1 - add new points
1843
+ this.addTracedCoordinates_(target, target.endIndex, endIndex);
1844
+ } else if (
1845
+ (previouslyForward && endIndex < target.endIndex) ||
1846
+ (!previouslyForward && endIndex > target.endIndex)
1847
+ ) {
1848
+ // case 2 - remove old points
1849
+ this.removeTracedCoordinates_(endIndex, target.endIndex);
1850
+ }
1851
+ } else {
1852
+ // case 3 - remove old points, add new points
1853
+ this.removeTracedCoordinates_(target.startIndex, target.endIndex);
1854
+ this.addTracedCoordinates_(target, target.startIndex, endIndex);
1855
+ }
1856
+ }
1857
+
1858
+ /**
1859
+ * @param {number} fromIndex The start index.
1860
+ * @param {number} toIndex The end index.
1861
+ * @private
1862
+ */
1863
+ removeTracedCoordinates_(fromIndex, toIndex) {
1864
+ if (fromIndex === toIndex) {
1865
+ return;
1866
+ }
1867
+
1868
+ let remove = 0;
1869
+ if (fromIndex < toIndex) {
1870
+ const start = Math.ceil(fromIndex);
1871
+ let end = Math.floor(toIndex);
1872
+ if (end === toIndex) {
1873
+ end -= 1;
1874
+ }
1875
+ remove = end - start + 1;
1876
+ } else {
1877
+ const start = Math.floor(fromIndex);
1878
+ let end = Math.ceil(toIndex);
1879
+ if (end === toIndex) {
1880
+ end += 1;
1881
+ }
1882
+ remove = start - end + 1;
1883
+ }
1884
+
1885
+ if (remove > 0) {
1886
+ this.removeLastPoints_(remove);
1887
+ }
1888
+ }
1889
+
1890
+ /**
1891
+ * @param {TraceTarget} target The trace target.
1892
+ * @param {number} fromIndex The start index.
1893
+ * @param {number} toIndex The end index.
1894
+ * @private
1895
+ */
1896
+ addTracedCoordinates_(target, fromIndex, toIndex) {
1897
+ if (fromIndex === toIndex) {
1898
+ return;
1899
+ }
1900
+
1901
+ const coordinates = [];
1902
+ if (fromIndex < toIndex) {
1903
+ // forward trace
1904
+ const start = Math.ceil(fromIndex);
1905
+ let end = Math.floor(toIndex);
1906
+ if (end === toIndex) {
1907
+ // if end is snapped to a vertex, it will be added later
1908
+ end -= 1;
1909
+ }
1910
+ for (let i = start; i <= end; ++i) {
1911
+ coordinates.push(getCoordinate(target.coordinates, i));
1912
+ }
1913
+ } else {
1914
+ // reverse trace
1915
+ const start = Math.floor(fromIndex);
1916
+ let end = Math.ceil(toIndex);
1917
+ if (end === toIndex) {
1918
+ end += 1;
1919
+ }
1920
+ for (let i = start; i >= end; --i) {
1921
+ coordinates.push(getCoordinate(target.coordinates, i));
1922
+ }
1923
+ }
1924
+ if (coordinates.length) {
1925
+ this.appendCoordinates(coordinates);
1926
+ }
1927
+ }
1928
+
1929
+ /**
1930
+ * Update the trace.
1931
+ * @param {import("../MapBrowserEvent.js").default} event Event.
1932
+ * @private
1933
+ */
1934
+ updateTrace_(event) {
1935
+ const traceState = this.traceState_;
1936
+ if (!traceState.active) {
1937
+ return;
1938
+ }
1939
+
1940
+ if (traceState.targetIndex === -1) {
1941
+ // check if we are ready to pick a target
1942
+ if ((0,_coordinate_js__WEBPACK_IMPORTED_MODULE_8__.distance)(traceState.startPx, event.pixel) < this.snapTolerance_) {
1943
+ return;
1944
+ }
1945
+ }
1946
+
1947
+ const updatedTraceTarget = getTraceTargetUpdate(
1948
+ event.coordinate,
1949
+ traceState,
1950
+ this.getMap(),
1951
+ this.snapTolerance_,
1952
+ );
1953
+
1954
+ if (traceState.targetIndex !== updatedTraceTarget.index) {
1955
+ // target changed
1956
+ if (traceState.targetIndex !== -1) {
1957
+ // remove points added during previous trace
1958
+ const oldTarget = traceState.targets[traceState.targetIndex];
1959
+ this.removeTracedCoordinates_(oldTarget.startIndex, oldTarget.endIndex);
1960
+ }
1961
+ // add points for the new target
1962
+ const newTarget = traceState.targets[updatedTraceTarget.index];
1963
+ this.addTracedCoordinates_(
1964
+ newTarget,
1965
+ newTarget.startIndex,
1966
+ updatedTraceTarget.endIndex,
1967
+ );
1968
+ } else {
1969
+ // target stayed the same
1970
+ const target = traceState.targets[traceState.targetIndex];
1971
+ this.addOrRemoveTracedCoordinates_(target, updatedTraceTarget.endIndex);
1972
+ }
1973
+
1974
+ // modify the state with updated info
1975
+ traceState.targetIndex = updatedTraceTarget.index;
1976
+ const target = traceState.targets[traceState.targetIndex];
1977
+ target.endIndex = updatedTraceTarget.endIndex;
1978
+
1979
+ // update event coordinate and pixel to match end point of final segment
1980
+ const coordinate = interpolateCoordinate(
1981
+ target.coordinates,
1982
+ target.endIndex,
1983
+ );
1984
+ const pixel = this.getMap().getPixelFromCoordinate(coordinate);
1985
+ event.coordinate = coordinate;
1986
+ event.pixel = [Math.round(pixel[0]), Math.round(pixel[1])];
1987
+ }
1988
+
1989
+ /**
1990
+ * Handle pointer up events.
1991
+ * @param {import("../MapBrowserEvent.js").default<PointerEvent>} event Event.
1992
+ * @return {boolean} If the event was consumed.
1993
+ * @override
1994
+ */
1995
+ handleUpEvent(event) {
1996
+ let pass = true;
1997
+
1998
+ if (this.getPointerCount() === 0) {
1999
+ if (this.downTimeout_) {
2000
+ clearTimeout(this.downTimeout_);
2001
+ this.downTimeout_ = undefined;
2002
+ }
2003
+
2004
+ this.handlePointerMove_(event);
2005
+ const tracing = this.traceState_.active;
2006
+ this.toggleTraceState_(event);
2007
+
2008
+ if (this.shouldHandle_) {
2009
+ const startingToDraw = !this.finishCoordinate_;
2010
+ if (startingToDraw) {
2011
+ this.startDrawing_(event.coordinate);
2012
+ }
2013
+ if (!startingToDraw && this.freehand_) {
2014
+ this.finishDrawing();
2015
+ } else if (
2016
+ !this.freehand_ &&
2017
+ (!startingToDraw || this.mode_ === 'Point')
2018
+ ) {
2019
+ if (this.atFinish_(event.pixel, tracing)) {
2020
+ if (this.finishCondition_(event)) {
2021
+ this.finishDrawing();
2022
+ }
2023
+ } else {
2024
+ this.addToDrawing_(event.coordinate);
2025
+ }
2026
+ }
2027
+ pass = false;
2028
+ } else if (this.freehand_) {
2029
+ this.abortDrawing();
2030
+ }
2031
+ }
2032
+
2033
+ if (!pass && this.stopClick_) {
2034
+ event.preventDefault();
2035
+ }
2036
+ return pass;
2037
+ }
2038
+
2039
+ /**
2040
+ * Handle move events.
2041
+ * @param {import("../MapBrowserEvent.js").default<PointerEvent>} event A move event.
2042
+ * @private
2043
+ */
2044
+ handlePointerMove_(event) {
2045
+ this.pointerType_ = event.originalEvent.pointerType;
2046
+ if (
2047
+ this.downPx_ &&
2048
+ ((!this.freehand_ && this.shouldHandle_) ||
2049
+ (this.freehand_ && !this.shouldHandle_))
2050
+ ) {
2051
+ const downPx = this.downPx_;
2052
+ const clickPx = event.pixel;
2053
+ const dx = downPx[0] - clickPx[0];
2054
+ const dy = downPx[1] - clickPx[1];
2055
+ const squaredDistance = dx * dx + dy * dy;
2056
+ this.shouldHandle_ = this.freehand_
2057
+ ? squaredDistance > this.squaredClickTolerance_
2058
+ : squaredDistance <= this.squaredClickTolerance_;
2059
+ if (!this.shouldHandle_) {
2060
+ return;
2061
+ }
2062
+ }
2063
+
2064
+ if (!this.finishCoordinate_) {
2065
+ this.createOrUpdateSketchPoint_(event.coordinate.slice());
2066
+ return;
2067
+ }
2068
+
2069
+ this.updateTrace_(event);
2070
+ this.modifyDrawing_(event.coordinate);
2071
+ }
2072
+
2073
+ /**
2074
+ * Determine if an event is within the snapping tolerance of the start coord.
2075
+ * @param {import("../pixel.js").Pixel} pixel Pixel.
2076
+ * @param {boolean} [tracing] Drawing in trace mode (only stop if at the starting point).
2077
+ * @return {boolean} The event is within the snapping tolerance of the start.
2078
+ * @private
2079
+ */
2080
+ atFinish_(pixel, tracing) {
2081
+ let at = false;
2082
+ if (this.sketchFeature_) {
2083
+ let potentiallyDone = false;
2084
+ let potentiallyFinishCoordinates = [this.finishCoordinate_];
2085
+ const mode = this.mode_;
2086
+ if (mode === 'Point') {
2087
+ at = true;
2088
+ } else if (mode === 'Circle') {
2089
+ at = this.sketchCoords_.length === 2;
2090
+ } else if (mode === 'LineString') {
2091
+ potentiallyDone =
2092
+ !tracing && this.sketchCoords_.length > this.minPoints_;
2093
+ } else if (mode === 'Polygon') {
2094
+ const sketchCoords = /** @type {PolyCoordType} */ (this.sketchCoords_);
2095
+ potentiallyDone = sketchCoords[0].length > this.minPoints_;
2096
+ potentiallyFinishCoordinates = [
2097
+ sketchCoords[0][0],
2098
+ sketchCoords[0][sketchCoords[0].length - 2],
2099
+ ];
2100
+ if (tracing) {
2101
+ potentiallyFinishCoordinates = [sketchCoords[0][0]];
2102
+ } else {
2103
+ potentiallyFinishCoordinates = [
2104
+ sketchCoords[0][0],
2105
+ sketchCoords[0][sketchCoords[0].length - 2],
2106
+ ];
2107
+ }
2108
+ }
2109
+ if (potentiallyDone) {
2110
+ const map = this.getMap();
2111
+ for (let i = 0, ii = potentiallyFinishCoordinates.length; i < ii; i++) {
2112
+ const finishCoordinate = potentiallyFinishCoordinates[i];
2113
+ const finishPixel = map.getPixelFromCoordinate(finishCoordinate);
2114
+ const dx = pixel[0] - finishPixel[0];
2115
+ const dy = pixel[1] - finishPixel[1];
2116
+ const snapTolerance = this.freehand_ ? 1 : this.snapTolerance_;
2117
+ at = Math.sqrt(dx * dx + dy * dy) <= snapTolerance;
2118
+ if (at) {
2119
+ this.finishCoordinate_ = finishCoordinate;
2120
+ break;
2121
+ }
2122
+ }
2123
+ }
2124
+ }
2125
+ return at;
2126
+ }
2127
+
2128
+ /**
2129
+ * @param {import("../coordinate").Coordinate} coordinates Coordinate.
2130
+ * @private
2131
+ */
2132
+ createOrUpdateSketchPoint_(coordinates) {
2133
+ if (!this.sketchPoint_) {
2134
+ this.sketchPoint_ = new _Feature_js__WEBPACK_IMPORTED_MODULE_21__["default"](new _geom_Point_js__WEBPACK_IMPORTED_MODULE_12__["default"](coordinates));
2135
+ this.updateSketchFeatures_();
2136
+ } else {
2137
+ const sketchPointGeom = this.sketchPoint_.getGeometry();
2138
+ sketchPointGeom.setCoordinates(coordinates);
2139
+ }
2140
+ }
2141
+
2142
+ /**
2143
+ * @param {import("../geom/Polygon.js").default} geometry Polygon geometry.
2144
+ * @private
2145
+ */
2146
+ createOrUpdateCustomSketchLine_(geometry) {
2147
+ if (!this.sketchLine_) {
2148
+ this.sketchLine_ = new _Feature_js__WEBPACK_IMPORTED_MODULE_21__["default"]();
2149
+ }
2150
+ const ring = geometry.getLinearRing(0);
2151
+ let sketchLineGeom = this.sketchLine_.getGeometry();
2152
+ if (!sketchLineGeom) {
2153
+ sketchLineGeom = new _geom_LineString_js__WEBPACK_IMPORTED_MODULE_3__["default"](
2154
+ ring.getFlatCoordinates(),
2155
+ ring.getLayout(),
2156
+ );
2157
+ this.sketchLine_.setGeometry(sketchLineGeom);
2158
+ } else {
2159
+ sketchLineGeom.setFlatCoordinates(
2160
+ ring.getLayout(),
2161
+ ring.getFlatCoordinates(),
2162
+ );
2163
+ sketchLineGeom.changed();
2164
+ }
2165
+ }
2166
+
2167
+ /**
2168
+ * Start the drawing.
2169
+ * @param {import("../coordinate.js").Coordinate} start Start coordinate.
2170
+ * @private
2171
+ */
2172
+ startDrawing_(start) {
2173
+ const projection = this.getMap().getView().getProjection();
2174
+ const stride = (0,_geom_SimpleGeometry_js__WEBPACK_IMPORTED_MODULE_22__.getStrideForLayout)(this.geometryLayout_);
2175
+ while (start.length < stride) {
2176
+ start.push(0);
2177
+ }
2178
+ this.finishCoordinate_ = start;
2179
+ if (this.mode_ === 'Point') {
2180
+ this.sketchCoords_ = start.slice();
2181
+ } else if (this.mode_ === 'Polygon') {
2182
+ this.sketchCoords_ = [[start.slice(), start.slice()]];
2183
+ this.sketchLineCoords_ = this.sketchCoords_[0];
2184
+ } else {
2185
+ this.sketchCoords_ = [start.slice(), start.slice()];
2186
+ }
2187
+ if (this.sketchLineCoords_) {
2188
+ this.sketchLine_ = new _Feature_js__WEBPACK_IMPORTED_MODULE_21__["default"](new _geom_LineString_js__WEBPACK_IMPORTED_MODULE_3__["default"](this.sketchLineCoords_));
2189
+ }
2190
+ const geometry = this.geometryFunction_(
2191
+ this.sketchCoords_,
2192
+ undefined,
2193
+ projection,
2194
+ );
2195
+ this.sketchFeature_ = new _Feature_js__WEBPACK_IMPORTED_MODULE_21__["default"]();
2196
+ if (this.geometryName_) {
2197
+ this.sketchFeature_.setGeometryName(this.geometryName_);
2198
+ }
2199
+ this.sketchFeature_.setGeometry(geometry);
2200
+ this.updateSketchFeatures_();
2201
+ this.dispatchEvent(
2202
+ new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_),
2203
+ );
2204
+ }
2205
+
2206
+ /**
2207
+ * Modify the drawing.
2208
+ * @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
2209
+ * @private
2210
+ */
2211
+ modifyDrawing_(coordinate) {
2212
+ const map = this.getMap();
2213
+ const geometry = this.sketchFeature_.getGeometry();
2214
+ const projection = map.getView().getProjection();
2215
+ const stride = (0,_geom_SimpleGeometry_js__WEBPACK_IMPORTED_MODULE_22__.getStrideForLayout)(this.geometryLayout_);
2216
+ let coordinates, last;
2217
+ while (coordinate.length < stride) {
2218
+ coordinate.push(0);
2219
+ }
2220
+ if (this.mode_ === 'Point') {
2221
+ last = this.sketchCoords_;
2222
+ } else if (this.mode_ === 'Polygon') {
2223
+ coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
2224
+ last = coordinates[coordinates.length - 1];
2225
+ if (this.atFinish_(map.getPixelFromCoordinate(coordinate))) {
2226
+ // snap to finish
2227
+ coordinate = this.finishCoordinate_.slice();
2228
+ }
2229
+ } else {
2230
+ coordinates = this.sketchCoords_;
2231
+ last = coordinates[coordinates.length - 1];
2232
+ }
2233
+ last[0] = coordinate[0];
2234
+ last[1] = coordinate[1];
2235
+ this.geometryFunction_(
2236
+ /** @type {!LineCoordType} */ (this.sketchCoords_),
2237
+ geometry,
2238
+ projection,
2239
+ );
2240
+ if (this.sketchPoint_) {
2241
+ const sketchPointGeom = this.sketchPoint_.getGeometry();
2242
+ sketchPointGeom.setCoordinates(coordinate);
2243
+ }
2244
+ if (geometry.getType() === 'Polygon' && this.mode_ !== 'Polygon') {
2245
+ this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
2246
+ } else if (this.sketchLineCoords_) {
2247
+ const sketchLineGeom = this.sketchLine_.getGeometry();
2248
+ sketchLineGeom.setCoordinates(this.sketchLineCoords_);
2249
+ }
2250
+ this.updateSketchFeatures_();
2251
+ }
2252
+
2253
+ /**
2254
+ * Add a new coordinate to the drawing.
2255
+ * @param {!PointCoordType} coordinate Coordinate
2256
+ * @return {Feature<import("../geom/SimpleGeometry.js").default>} The sketch feature.
2257
+ * @private
2258
+ */
2259
+ addToDrawing_(coordinate) {
2260
+ const geometry = this.sketchFeature_.getGeometry();
2261
+ const projection = this.getMap().getView().getProjection();
2262
+ let done;
2263
+ let coordinates;
2264
+ const mode = this.mode_;
2265
+ if (mode === 'LineString' || mode === 'Circle') {
2266
+ this.finishCoordinate_ = coordinate.slice();
2267
+ coordinates = /** @type {LineCoordType} */ (this.sketchCoords_);
2268
+ if (coordinates.length >= this.maxPoints_) {
2269
+ if (this.freehand_) {
2270
+ coordinates.pop();
2271
+ } else {
2272
+ done = true;
2273
+ }
2274
+ }
2275
+ coordinates.push(coordinate.slice());
2276
+ this.geometryFunction_(coordinates, geometry, projection);
2277
+ } else if (mode === 'Polygon') {
2278
+ coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
2279
+ if (coordinates.length >= this.maxPoints_) {
2280
+ if (this.freehand_) {
2281
+ coordinates.pop();
2282
+ } else {
2283
+ done = true;
2284
+ }
2285
+ }
2286
+ coordinates.push(coordinate.slice());
2287
+ if (done) {
2288
+ this.finishCoordinate_ = coordinates[0];
2289
+ }
2290
+ this.geometryFunction_(this.sketchCoords_, geometry, projection);
2291
+ }
2292
+ this.createOrUpdateSketchPoint_(coordinate.slice());
2293
+ this.updateSketchFeatures_();
2294
+ if (done) {
2295
+ return this.finishDrawing();
2296
+ }
2297
+ return this.sketchFeature_;
2298
+ }
2299
+
2300
+ /**
2301
+ * @param {number} n The number of points to remove.
2302
+ */
2303
+ removeLastPoints_(n) {
2304
+ if (!this.sketchFeature_) {
2305
+ return;
2306
+ }
2307
+ const geometry = this.sketchFeature_.getGeometry();
2308
+ const projection = this.getMap().getView().getProjection();
2309
+ const mode = this.mode_;
2310
+ for (let i = 0; i < n; ++i) {
2311
+ let coordinates;
2312
+ if (mode === 'LineString' || mode === 'Circle') {
2313
+ coordinates = /** @type {LineCoordType} */ (this.sketchCoords_);
2314
+ coordinates.splice(-2, 1);
2315
+ if (coordinates.length >= 2) {
2316
+ this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
2317
+ const finishCoordinate = this.finishCoordinate_.slice();
2318
+ coordinates[coordinates.length - 1] = finishCoordinate;
2319
+ this.createOrUpdateSketchPoint_(finishCoordinate);
2320
+ }
2321
+ this.geometryFunction_(coordinates, geometry, projection);
2322
+ if (geometry.getType() === 'Polygon' && this.sketchLine_) {
2323
+ this.createOrUpdateCustomSketchLine_(
2324
+ /** @type {Polygon} */ (geometry),
2325
+ );
2326
+ }
2327
+ } else if (mode === 'Polygon') {
2328
+ coordinates = /** @type {PolyCoordType} */ (this.sketchCoords_)[0];
2329
+ coordinates.splice(-2, 1);
2330
+ const sketchLineGeom = this.sketchLine_.getGeometry();
2331
+ if (coordinates.length >= 2) {
2332
+ const finishCoordinate = coordinates[coordinates.length - 2].slice();
2333
+ coordinates[coordinates.length - 1] = finishCoordinate;
2334
+ this.createOrUpdateSketchPoint_(finishCoordinate);
2335
+ }
2336
+ sketchLineGeom.setCoordinates(coordinates);
2337
+ this.geometryFunction_(this.sketchCoords_, geometry, projection);
2338
+ }
2339
+
2340
+ if (coordinates.length === 1) {
2341
+ this.abortDrawing();
2342
+ break;
2343
+ }
2344
+ }
2345
+
2346
+ this.updateSketchFeatures_();
2347
+ }
2348
+
2349
+ /**
2350
+ * Remove last point of the feature currently being drawn. Does not do anything when
2351
+ * drawing POINT or MULTI_POINT geometries.
2352
+ * @api
2353
+ */
2354
+ removeLastPoint() {
2355
+ this.removeLastPoints_(1);
2356
+ }
2357
+
2358
+ /**
2359
+ * Stop drawing and add the sketch feature to the target layer.
2360
+ * The {@link module:ol/interaction/Draw~DrawEventType.DRAWEND} event is
2361
+ * dispatched before inserting the feature.
2362
+ * @return {Feature<import("../geom/SimpleGeometry.js").default>|null} The drawn feature.
2363
+ * @api
2364
+ */
2365
+ finishDrawing() {
2366
+ const sketchFeature = this.abortDrawing_();
2367
+ if (!sketchFeature) {
2368
+ return null;
2369
+ }
2370
+ let coordinates = this.sketchCoords_;
2371
+ const geometry = sketchFeature.getGeometry();
2372
+ const projection = this.getMap().getView().getProjection();
2373
+ if (this.mode_ === 'LineString') {
2374
+ // remove the redundant last point
2375
+ coordinates.pop();
2376
+ this.geometryFunction_(coordinates, geometry, projection);
2377
+ } else if (this.mode_ === 'Polygon') {
2378
+ // remove the redundant last point in ring
2379
+ /** @type {PolyCoordType} */ (coordinates)[0].pop();
2380
+ this.geometryFunction_(coordinates, geometry, projection);
2381
+ coordinates = geometry.getCoordinates();
2382
+ }
2383
+
2384
+ // cast multi-part geometries
2385
+ if (this.type_ === 'MultiPoint') {
2386
+ sketchFeature.setGeometry(
2387
+ new _geom_MultiPoint_js__WEBPACK_IMPORTED_MODULE_23__["default"]([/** @type {PointCoordType} */ (coordinates)]),
2388
+ );
2389
+ } else if (this.type_ === 'MultiLineString') {
2390
+ sketchFeature.setGeometry(
2391
+ new _geom_MultiLineString_js__WEBPACK_IMPORTED_MODULE_4__["default"]([/** @type {LineCoordType} */ (coordinates)]),
2392
+ );
2393
+ } else if (this.type_ === 'MultiPolygon') {
2394
+ sketchFeature.setGeometry(
2395
+ new _geom_MultiPolygon_js__WEBPACK_IMPORTED_MODULE_6__["default"]([/** @type {PolyCoordType} */ (coordinates)]),
2396
+ );
2397
+ }
2398
+
2399
+ // First dispatch event to allow full set up of feature
2400
+ this.dispatchEvent(new DrawEvent(DrawEventType.DRAWEND, sketchFeature));
2401
+
2402
+ // Then insert feature
2403
+ if (this.features_) {
2404
+ this.features_.push(sketchFeature);
2405
+ }
2406
+ if (this.source_) {
2407
+ this.source_.addFeature(sketchFeature);
2408
+ }
2409
+ return sketchFeature;
2410
+ }
2411
+
2412
+ /**
2413
+ * Stop drawing without adding the sketch feature to the target layer.
2414
+ * @return {Feature<import("../geom/SimpleGeometry.js").default>|null} The sketch feature (or null if none).
2415
+ * @private
2416
+ */
2417
+ abortDrawing_() {
2418
+ this.finishCoordinate_ = null;
2419
+ const sketchFeature = this.sketchFeature_;
2420
+ this.sketchFeature_ = null;
2421
+ this.sketchPoint_ = null;
2422
+ this.sketchLine_ = null;
2423
+ this.overlay_.getSource().clear(true);
2424
+ this.deactivateTrace_();
2425
+ return sketchFeature;
2426
+ }
2427
+
2428
+ /**
2429
+ * Stop drawing without adding the sketch feature to the target layer.
2430
+ * @api
2431
+ */
2432
+ abortDrawing() {
2433
+ const sketchFeature = this.abortDrawing_();
2434
+ if (sketchFeature) {
2435
+ this.dispatchEvent(new DrawEvent(DrawEventType.DRAWABORT, sketchFeature));
2436
+ }
2437
+ }
2438
+
2439
+ /**
2440
+ * Append coordinates to the end of the geometry that is currently being drawn.
2441
+ * This can be used when drawing LineStrings or Polygons. Coordinates will
2442
+ * either be appended to the current LineString or the outer ring of the current
2443
+ * Polygon. If no geometry is being drawn, a new one will be created.
2444
+ * @param {!LineCoordType} coordinates Linear coordinates to be appended to
2445
+ * the coordinate array.
2446
+ * @api
2447
+ */
2448
+ appendCoordinates(coordinates) {
2449
+ const mode = this.mode_;
2450
+ const newDrawing = !this.sketchFeature_;
2451
+ if (newDrawing) {
2452
+ this.startDrawing_(coordinates[0]);
2453
+ }
2454
+ /** @type {LineCoordType} */
2455
+ let sketchCoords;
2456
+ if (mode === 'LineString' || mode === 'Circle') {
2457
+ sketchCoords = /** @type {LineCoordType} */ (this.sketchCoords_);
2458
+ } else if (mode === 'Polygon') {
2459
+ sketchCoords =
2460
+ this.sketchCoords_ && this.sketchCoords_.length
2461
+ ? /** @type {PolyCoordType} */ (this.sketchCoords_)[0]
2462
+ : [];
2463
+ } else {
2464
+ return;
2465
+ }
2466
+
2467
+ if (newDrawing) {
2468
+ sketchCoords.shift();
2469
+ }
2470
+
2471
+ // Remove last coordinate from sketch drawing (this coordinate follows cursor position)
2472
+ sketchCoords.pop();
2473
+
2474
+ // Append coordinate list
2475
+ for (let i = 0; i < coordinates.length; i++) {
2476
+ this.addToDrawing_(coordinates[i]);
2477
+ }
2478
+
2479
+ const ending = coordinates[coordinates.length - 1];
2480
+ // Duplicate last coordinate for sketch drawing (cursor position)
2481
+ this.sketchFeature_ = this.addToDrawing_(ending);
2482
+ this.modifyDrawing_(ending);
2483
+ }
2484
+
2485
+ /**
2486
+ * Initiate draw mode by starting from an existing geometry which will
2487
+ * receive new additional points. This only works on features with
2488
+ * `LineString` geometries, where the interaction will extend lines by adding
2489
+ * points to the end of the coordinates array.
2490
+ * This will change the original feature, instead of drawing a copy.
2491
+ *
2492
+ * The function will dispatch a `drawstart` event.
2493
+ *
2494
+ * @param {!Feature<LineString>} feature Feature to be extended.
2495
+ * @api
2496
+ */
2497
+ extend(feature) {
2498
+ const geometry = feature.getGeometry();
2499
+ const lineString = geometry;
2500
+ this.sketchFeature_ = feature;
2501
+ this.sketchCoords_ = lineString.getCoordinates();
2502
+ const last = this.sketchCoords_[this.sketchCoords_.length - 1];
2503
+ this.finishCoordinate_ = last.slice();
2504
+ this.sketchCoords_.push(last.slice());
2505
+ this.sketchPoint_ = new _Feature_js__WEBPACK_IMPORTED_MODULE_21__["default"](new _geom_Point_js__WEBPACK_IMPORTED_MODULE_12__["default"](last));
2506
+ this.updateSketchFeatures_();
2507
+ this.dispatchEvent(
2508
+ new DrawEvent(DrawEventType.DRAWSTART, this.sketchFeature_),
2509
+ );
2510
+ }
2511
+
2512
+ /**
2513
+ * Redraw the sketch features.
2514
+ * @private
2515
+ */
2516
+ updateSketchFeatures_() {
2517
+ const sketchFeatures = [];
2518
+ if (this.sketchFeature_) {
2519
+ sketchFeatures.push(this.sketchFeature_);
2520
+ }
2521
+ if (this.sketchLine_) {
2522
+ sketchFeatures.push(this.sketchLine_);
2523
+ }
2524
+ if (this.sketchPoint_) {
2525
+ sketchFeatures.push(this.sketchPoint_);
2526
+ }
2527
+ const overlaySource = this.overlay_.getSource();
2528
+ overlaySource.clear(true);
2529
+ overlaySource.addFeatures(sketchFeatures);
2530
+ }
2531
+
2532
+ /**
2533
+ * @private
2534
+ */
2535
+ updateState_() {
2536
+ const map = this.getMap();
2537
+ const active = this.getActive();
2538
+ if (!map || !active) {
2539
+ this.abortDrawing();
2540
+ }
2541
+ this.overlay_.setMap(active ? map : null);
2542
+ }
2543
+ }
2544
+
2545
+ /**
2546
+ * @return {import("../style/Style.js").StyleFunction} Styles.
2547
+ */
2548
+ function getDefaultStyleFunction() {
2549
+ const styles = (0,_style_Style_js__WEBPACK_IMPORTED_MODULE_24__.createEditingStyle)();
2550
+ return function (feature, resolution) {
2551
+ return styles[feature.getGeometry().getType()];
2552
+ };
2553
+ }
2554
+
2555
+ /**
2556
+ * Create a `geometryFunction` for `type: 'Circle'` that will create a regular
2557
+ * polygon with a user specified number of sides and start angle instead of a
2558
+ * {@link import("../geom/Circle.js").Circle} geometry.
2559
+ * @param {number} [sides] Number of sides of the regular polygon.
2560
+ * Default is 32.
2561
+ * @param {number} [angle] Angle of the first point in counter-clockwise
2562
+ * radians. 0 means East.
2563
+ * Default is the angle defined by the heading from the center of the
2564
+ * regular polygon to the current pointer position.
2565
+ * @return {GeometryFunction} Function that draws a polygon.
2566
+ * @api
2567
+ */
2568
+ function createRegularPolygon(sides, angle) {
2569
+ return function (coordinates, geometry, projection) {
2570
+ const center = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.fromUserCoordinate)(
2571
+ /** @type {LineCoordType} */ (coordinates)[0],
2572
+ projection,
2573
+ );
2574
+ const end = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.fromUserCoordinate)(
2575
+ /** @type {LineCoordType} */ (coordinates)[coordinates.length - 1],
2576
+ projection,
2577
+ );
2578
+ const radius = Math.sqrt((0,_coordinate_js__WEBPACK_IMPORTED_MODULE_8__.squaredDistance)(center, end));
2579
+ geometry = geometry || (0,_geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__.fromCircle)(new _geom_Circle_js__WEBPACK_IMPORTED_MODULE_11__["default"](center), sides);
2580
+
2581
+ let internalAngle = angle;
2582
+ if (!angle && angle !== 0) {
2583
+ const x = end[0] - center[0];
2584
+ const y = end[1] - center[1];
2585
+ internalAngle = Math.atan2(y, x);
2586
+ }
2587
+ (0,_geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__.makeRegular)(
2588
+ /** @type {Polygon} */ (geometry),
2589
+ center,
2590
+ radius,
2591
+ internalAngle,
2592
+ );
2593
+
2594
+ const userProjection = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.getUserProjection)();
2595
+ if (userProjection) {
2596
+ geometry.transform(projection, userProjection);
2597
+ }
2598
+ return geometry;
2599
+ };
2600
+ }
2601
+
2602
+ /**
2603
+ * Create a `geometryFunction` that will create a box-shaped polygon (aligned
2604
+ * with the coordinate system axes). Use this with the draw interaction and
2605
+ * `type: 'Circle'` to return a box instead of a circle geometry.
2606
+ * @return {GeometryFunction} Function that draws a box-shaped polygon.
2607
+ * @api
2608
+ */
2609
+ function createBox() {
2610
+ return function (coordinates, geometry, projection) {
2611
+ const extent = (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.boundingExtent)(
2612
+ /** @type {LineCoordType} */ ([
2613
+ coordinates[0],
2614
+ coordinates[coordinates.length - 1],
2615
+ ]).map(function (coordinate) {
2616
+ return (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.fromUserCoordinate)(coordinate, projection);
2617
+ }),
2618
+ );
2619
+ const boxCoordinates = [
2620
+ [
2621
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.getBottomLeft)(extent),
2622
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.getBottomRight)(extent),
2623
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.getTopRight)(extent),
2624
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.getTopLeft)(extent),
2625
+ (0,_extent_js__WEBPACK_IMPORTED_MODULE_20__.getBottomLeft)(extent),
2626
+ ],
2627
+ ];
2628
+ if (geometry) {
2629
+ geometry.setCoordinates(boxCoordinates);
2630
+ } else {
2631
+ geometry = new _geom_Polygon_js__WEBPACK_IMPORTED_MODULE_5__["default"](boxCoordinates);
2632
+ }
2633
+ const userProjection = (0,_proj_js__WEBPACK_IMPORTED_MODULE_0__.getUserProjection)();
2634
+ if (userProjection) {
2635
+ geometry.transform(projection, userProjection);
2636
+ }
2637
+ return geometry;
2638
+ };
2639
+ }
2640
+
2641
+ /**
2642
+ * Get the drawing mode. The mode for multi-part geometries is the same as for
2643
+ * their single-part cousins.
2644
+ * @param {import("../geom/Geometry.js").Type} type Geometry type.
2645
+ * @return {Mode} Drawing mode.
2646
+ */
2647
+ function getMode(type) {
2648
+ switch (type) {
2649
+ case 'Point':
2650
+ case 'MultiPoint':
2651
+ return 'Point';
2652
+ case 'LineString':
2653
+ case 'MultiLineString':
2654
+ return 'LineString';
2655
+ case 'Polygon':
2656
+ case 'MultiPolygon':
2657
+ return 'Polygon';
2658
+ case 'Circle':
2659
+ return 'Circle';
2660
+ default:
2661
+ throw new Error('Invalid type: ' + type);
2662
+ }
2663
+ }
2664
+
2665
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Draw);
2666
+
2667
+
2668
+ /***/ }),
2669
+
2670
+ /***/ "./node_modules/ol/layer/Vector.js":
2671
+ /*!*****************************************!*\
2672
+ !*** ./node_modules/ol/layer/Vector.js ***!
2673
+ \*****************************************/
2674
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2675
+
2676
+ __webpack_require__.r(__webpack_exports__);
2677
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2678
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
2679
+ /* harmony export */ });
2680
+ /* harmony import */ var _renderer_canvas_VectorLayer_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../renderer/canvas/VectorLayer.js */ "./node_modules/ol/renderer/canvas/VectorLayer.js");
2681
+ /* harmony import */ var _BaseVector_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./BaseVector.js */ "./node_modules/ol/layer/BaseVector.js");
2682
+ /**
2683
+ * @module ol/layer/Vector
2684
+ */
2685
+
2686
+
2687
+
2688
+ /**
2689
+ * @template {import("../source/Vector.js").default<FeatureType>} [VectorSourceType=import("../source/Vector.js").default<*>]
2690
+ * @template {import('../Feature.js').FeatureLike} [FeatureType=import("./BaseVector.js").ExtractedFeatureType<VectorSourceType>]
2691
+ * @typedef {Object} Options
2692
+ * @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
2693
+ * @property {number} [opacity=1] Opacity (0, 1).
2694
+ * @property {boolean} [visible=true] Visibility.
2695
+ * @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
2696
+ * rendered outside of this extent.
2697
+ * @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
2698
+ * will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
2699
+ * for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
2700
+ * method was used.
2701
+ * @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
2702
+ * visible.
2703
+ * @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
2704
+ * be visible.
2705
+ * @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
2706
+ * visible.
2707
+ * @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
2708
+ * be visible.
2709
+ * @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
2710
+ * features before rendering. By default features are drawn in the order that they are created. Use
2711
+ * `null` to avoid the sort, but get an undefined draw order.
2712
+ * @property {number} [renderBuffer=100] The buffer in pixels around the viewport extent used by the
2713
+ * renderer when getting features from the vector source for the rendering or hit-detection.
2714
+ * Recommended value: the size of the largest symbol, line width or label.
2715
+ * @property {VectorSourceType} [source] Source.
2716
+ * @property {import("../Map.js").default} [map] Sets the layer as overlay on a map. The map will not manage
2717
+ * this layer in its layers collection, and the layer will be rendered on top. This is useful for
2718
+ * temporary layers. The standard way to add a layer to a map and have it managed by the map is to
2719
+ * use [map.addLayer()]{@link import("../Map.js").default#addLayer}.
2720
+ * @property {boolean|string|number} [declutter=false] Declutter images and text. Any truthy value will enable
2721
+ * decluttering. Within a layer, a feature rendered before another has higher priority. All layers with the
2722
+ * same `declutter` value will be decluttered together. The priority is determined by the drawing order of the
2723
+ * layers with the same `declutter` value. Higher in the layer stack means higher priority. To declutter distinct
2724
+ * layers or groups of layers separately, use different truthy values for `declutter`.
2725
+ * @property {import("../style/Style.js").StyleLike|import("../style/flat.js").FlatStyleLike|null} [style] Layer style. When set to `null`, only
2726
+ * features that have their own style will be rendered. See {@link module:ol/style/Style~Style} for the default style
2727
+ * which will be used if this is not set.
2728
+ * @property {import("./Base.js").BackgroundColor} [background] Background color for the layer. If not specified, no background
2729
+ * will be rendered.
2730
+ * @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will
2731
+ * be recreated during animations. This means that no vectors will be shown clipped, but the
2732
+ * setting will have a performance impact for large amounts of vector data. When set to `false`,
2733
+ * batches will be recreated when no animation is active.
2734
+ * @property {boolean} [updateWhileInteracting=false] When set to `true`, feature batches will
2735
+ * be recreated during interactions. See also `updateWhileAnimating`.
2736
+ * @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
2737
+ */
2738
+
2739
+ /**
2740
+ * @classdesc
2741
+ * Vector data is rendered client-side, as vectors. This layer type provides most accurate rendering
2742
+ * even during animations. Points and labels stay upright on rotated views. For very large
2743
+ * amounts of vector data, performance may suffer during pan and zoom animations. In this case,
2744
+ * try {@link module:ol/layer/VectorImage~VectorImageLayer}.
2745
+ *
2746
+ * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
2747
+ * property on the layer object; for example, setting `title: 'My Title'` in the
2748
+ * options means that `title` is observable, and has get/set accessors.
2749
+ *
2750
+ * @template {import("../source/Vector.js").default<FeatureType>} [VectorSourceType=import("../source/Vector.js").default<*>]
2751
+ * @template {import('../Feature.js').FeatureLike} [FeatureType=import("./BaseVector.js").ExtractedFeatureType<VectorSourceType>]
2752
+ * @extends {BaseVectorLayer<FeatureType, VectorSourceType, CanvasVectorLayerRenderer>}
2753
+ * @api
2754
+ */
2755
+ class VectorLayer extends _BaseVector_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
2756
+ /**
2757
+ * @param {Options<VectorSourceType, FeatureType>} [options] Options.
2758
+ */
2759
+ constructor(options) {
2760
+ super(options);
2761
+ }
2762
+
2763
+ /**
2764
+ * @override
2765
+ */
2766
+ createRenderer() {
2767
+ return new _renderer_canvas_VectorLayer_js__WEBPACK_IMPORTED_MODULE_1__["default"](this);
2768
+ }
2769
+ }
2770
+
2771
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (VectorLayer);
2772
+
2773
+
2774
+ /***/ })
2775
+
2776
+ }])
2777
+ //# sourceMappingURL=vendors-node_modules_ol_interaction_Draw_js.js.map