mapping-component-package-jp 0.0.57 → 0.1.4

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.
@@ -1,393 +1,479 @@
1
- export class IQLPolygonCustomEdit {
2
-
3
- constructor() {
4
- }
5
-
6
- delete(map, currentPolygonCustomEdit) {
7
-
8
- currentPolygonCustomEdit.getPath().forEach(function (vertex, index) {
9
- if (vertex.marker) {
10
- vertex.marker.setMap(null);
11
- vertex.marker = undefined;
12
- }
13
- if (vertex.ghostMarker) {
14
- vertex.ghostMarker.setMap(null);
15
- vertex.ghostMarker = undefined;
16
- }
17
- });
18
-
19
- return currentPolygonCustomEdit;
20
-
21
- }
22
-
23
- edit(map, polygon, currentPolygonCustomEdit, isMobile) {
24
-
25
- if(isMobile) {
26
- var svgpi = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48" width="48" height="48">'
27
- svgpi += '<path fill="rgba(255,255,255,0.01)" d="M 0, 24 a 24,24 0 1,0 48,0 a 24,24 0 1,0 -48,0" />';
28
- svgpi += '<path fill="rgba(255,255,255,1)" stroke="#303030" stroke-width="1" d="M24 24 m-4,0 a 4,4,0 0,1 8,0 a 4,4 0 0,1 -8,0z" />';
29
- svgpi += '</svg>';
30
-
31
- var pointIcon = {
32
- url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgpi),
33
- anchor: new google.maps.Point(24, 24)
34
- };
35
-
36
- var svgmpi = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48" width="48" height="48">'
37
- svgmpi += '<path fill="rgba(255,255,255,0.01)" d="M 0, 24 a 24,24 0 1,0 48,0 a 24,24 0 1,0 -48,0" />';
38
- svgmpi += '<path fill="rgba(255,255,255,0.4)" stroke="#303030" stroke-width="0.3" stroke-opacity="0.01" d="M24 24 m-4,0 a 4,4,0 0,1 8,0 a 4,4 0 0,1 -8,0z" />';
39
- svgmpi += '</svg>';
40
-
41
- var midPointIcon = {
42
- url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgmpi),
43
- anchor: new google.maps.Point(24, 24)
44
- };
45
-
46
- var svgup = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 52" style="enable-background:new 0 0 52 52;" xml:space="preserve">';
47
- svgup += '<g transform="scale(0.4 0.4)">';
48
- svgup += '<path style="fill:#f1a81e;" d="M38.853,5.324L38.853,5.324c-7.098-7.098-18.607-7.098-25.706,0h0 C6.751,11.72,6.031,23.763,11.459,31L26,52l14.541-21C45.969,23.763,45.249,11.72,38.853,5.324z"/>';
49
- svgup += '<g transform="translate(13.2 5.9) scale(0.8 0.8)">';
50
- svgup += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 15.78125 0.0546875 C 15.710938 0.0859375 14.742188 1.03125 13.625 2.148438 C 11.136719 4.644531 11.257812 4.351562 12.300781 5.386719 C 12.957031 6.050781 13.011719 6.09375 13.25 6.09375 C 13.480469 6.09375 13.542969 6.050781 14.0625 5.53125 L 14.625 4.96875 L 14.625 8.019531 C 14.625 11.261719 14.636719 11.398438 14.925781 11.554688 C 15.09375 11.648438 16.90625 11.648438 17.074219 11.554688 C 17.363281 11.398438 17.375 11.261719 17.375 8.019531 L 17.375 4.96875 L 17.9375 5.53125 C 18.457031 6.050781 18.519531 6.09375 18.75 6.09375 C 18.988281 6.09375 19.042969 6.050781 19.699219 5.386719 C 20.742188 4.351562 20.867188 4.648438 18.34375 2.125 C 16.210938 -0.0078125 16.105469 -0.0859375 15.78125 0.0546875 Z M 15.78125 0.0546875 "/>';
51
- svgup += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 4.21875 11.617188 C 4.148438 11.648438 3.179688 12.59375 2.0625 13.710938 C 0.0703125 15.710938 0.03125 15.75 0.03125 16 C 0.03125 16.25 0.0703125 16.289062 2.113281 18.324219 C 4.648438 20.867188 4.351562 20.742188 5.386719 19.699219 C 6.050781 19.042969 6.09375 18.988281 6.09375 18.75 C 6.09375 18.519531 6.050781 18.457031 5.53125 17.9375 L 4.96875 17.375 L 8.019531 17.375 C 11.261719 17.375 11.398438 17.363281 11.554688 17.074219 C 11.648438 16.90625 11.648438 15.09375 11.554688 14.925781 C 11.398438 14.636719 11.261719 14.625 8.019531 14.625 L 4.96875 14.625 L 5.53125 14.0625 C 6.050781 13.542969 6.09375 13.480469 6.09375 13.25 C 6.09375 13.011719 6.050781 12.957031 5.40625 12.3125 C 4.699219 11.613281 4.5 11.492188 4.21875 11.617188 Z M 4.21875 11.617188 "/>';
52
- svgup += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 27.34375 11.617188 C 27.273438 11.648438 26.925781 11.976562 26.5625 12.335938 C 25.949219 12.957031 25.90625 13.011719 25.90625 13.25 C 25.90625 13.480469 25.949219 13.542969 26.46875 14.0625 L 27.03125 14.625 L 23.980469 14.625 C 20.738281 14.625 20.601562 14.636719 20.445312 14.925781 C 20.351562 15.09375 20.351562 16.90625 20.445312 17.074219 C 20.601562 17.363281 20.738281 17.375 23.980469 17.375 L 27.03125 17.375 L 26.46875 17.9375 C 25.949219 18.457031 25.90625 18.519531 25.90625 18.75 C 25.90625 18.988281 25.949219 19.042969 26.613281 19.699219 C 27.648438 20.742188 27.351562 20.867188 29.886719 18.324219 C 31.929688 16.289062 31.96875 16.25 31.96875 16 C 31.96875 15.75 31.929688 15.710938 29.90625 13.6875 C 27.773438 11.554688 27.675781 11.476562 27.34375 11.617188 Z M 27.34375 11.617188 "/>';
53
- svgup += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 14.917969 20.445312 C 14.636719 20.605469 14.625 20.757812 14.625 23.980469 L 14.625 27.03125 L 14.0625 26.46875 C 13.542969 25.949219 13.480469 25.90625 13.25 25.90625 C 13.011719 25.90625 12.957031 25.949219 12.300781 26.613281 C 11.257812 27.648438 11.132812 27.351562 13.675781 29.886719 C 15.710938 31.929688 15.75 31.96875 16 31.96875 C 16.25 31.96875 16.289062 31.929688 18.324219 29.886719 C 20.867188 27.351562 20.742188 27.648438 19.699219 26.613281 C 19.042969 25.949219 18.988281 25.90625 18.75 25.90625 C 18.519531 25.90625 18.457031 25.949219 17.9375 26.46875 L 17.375 27.03125 L 17.375 23.980469 C 17.375 20.738281 17.363281 20.601562 17.074219 20.445312 C 16.90625 20.355469 15.070312 20.355469 14.917969 20.445312 Z M 14.917969 20.445312 "/>';
54
- svgup += '</g>';
55
- svgup += '</g>';
56
- svgup += '</svg>';
57
-
58
- var handleIconUp = {
59
- url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgup),
60
- anchor: new google.maps.Point(30, 60)
61
- };
62
-
63
- var svgdown = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 52" style="enable-background:new 0 0 52 52;" xml:space="preserve">';
64
- svgdown += '<g transform="scale(0.4 0.4) rotate(180 26 26)">';
65
- svgdown += '<path style="fill:#f1a81e;" d="M38.853,5.324L38.853,5.324c-7.098-7.098-18.607-7.098-25.706,0h0 C6.751,11.72,6.031,23.763,11.459,31L26,52l14.541-21C45.969,23.763,45.249,11.72,38.853,5.324z"/>';
66
- svgdown += '<g transform="translate(13.2 5.9) scale(0.8 0.8)">';
67
- svgdown += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 15.78125 0.0546875 C 15.710938 0.0859375 14.742188 1.03125 13.625 2.148438 C 11.136719 4.644531 11.257812 4.351562 12.300781 5.386719 C 12.957031 6.050781 13.011719 6.09375 13.25 6.09375 C 13.480469 6.09375 13.542969 6.050781 14.0625 5.53125 L 14.625 4.96875 L 14.625 8.019531 C 14.625 11.261719 14.636719 11.398438 14.925781 11.554688 C 15.09375 11.648438 16.90625 11.648438 17.074219 11.554688 C 17.363281 11.398438 17.375 11.261719 17.375 8.019531 L 17.375 4.96875 L 17.9375 5.53125 C 18.457031 6.050781 18.519531 6.09375 18.75 6.09375 C 18.988281 6.09375 19.042969 6.050781 19.699219 5.386719 C 20.742188 4.351562 20.867188 4.648438 18.34375 2.125 C 16.210938 -0.0078125 16.105469 -0.0859375 15.78125 0.0546875 Z M 15.78125 0.0546875 "/>';
68
- svgdown += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 4.21875 11.617188 C 4.148438 11.648438 3.179688 12.59375 2.0625 13.710938 C 0.0703125 15.710938 0.03125 15.75 0.03125 16 C 0.03125 16.25 0.0703125 16.289062 2.113281 18.324219 C 4.648438 20.867188 4.351562 20.742188 5.386719 19.699219 C 6.050781 19.042969 6.09375 18.988281 6.09375 18.75 C 6.09375 18.519531 6.050781 18.457031 5.53125 17.9375 L 4.96875 17.375 L 8.019531 17.375 C 11.261719 17.375 11.398438 17.363281 11.554688 17.074219 C 11.648438 16.90625 11.648438 15.09375 11.554688 14.925781 C 11.398438 14.636719 11.261719 14.625 8.019531 14.625 L 4.96875 14.625 L 5.53125 14.0625 C 6.050781 13.542969 6.09375 13.480469 6.09375 13.25 C 6.09375 13.011719 6.050781 12.957031 5.40625 12.3125 C 4.699219 11.613281 4.5 11.492188 4.21875 11.617188 Z M 4.21875 11.617188 "/>';
69
- svgdown += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 27.34375 11.617188 C 27.273438 11.648438 26.925781 11.976562 26.5625 12.335938 C 25.949219 12.957031 25.90625 13.011719 25.90625 13.25 C 25.90625 13.480469 25.949219 13.542969 26.46875 14.0625 L 27.03125 14.625 L 23.980469 14.625 C 20.738281 14.625 20.601562 14.636719 20.445312 14.925781 C 20.351562 15.09375 20.351562 16.90625 20.445312 17.074219 C 20.601562 17.363281 20.738281 17.375 23.980469 17.375 L 27.03125 17.375 L 26.46875 17.9375 C 25.949219 18.457031 25.90625 18.519531 25.90625 18.75 C 25.90625 18.988281 25.949219 19.042969 26.613281 19.699219 C 27.648438 20.742188 27.351562 20.867188 29.886719 18.324219 C 31.929688 16.289062 31.96875 16.25 31.96875 16 C 31.96875 15.75 31.929688 15.710938 29.90625 13.6875 C 27.773438 11.554688 27.675781 11.476562 27.34375 11.617188 Z M 27.34375 11.617188 "/>';
70
- svgdown += '<path style=" stroke:none;fill-rule:nonzero;fill:rgb(255,255,255);fill-opacity:1;" d="M 14.917969 20.445312 C 14.636719 20.605469 14.625 20.757812 14.625 23.980469 L 14.625 27.03125 L 14.0625 26.46875 C 13.542969 25.949219 13.480469 25.90625 13.25 25.90625 C 13.011719 25.90625 12.957031 25.949219 12.300781 26.613281 C 11.257812 27.648438 11.132812 27.351562 13.675781 29.886719 C 15.710938 31.929688 15.75 31.96875 16 31.96875 C 16.25 31.96875 16.289062 31.929688 18.324219 29.886719 C 20.867188 27.351562 20.742188 27.648438 19.699219 26.613281 C 19.042969 25.949219 18.988281 25.90625 18.75 25.90625 C 18.519531 25.90625 18.457031 25.949219 17.9375 26.46875 L 17.375 27.03125 L 17.375 23.980469 C 17.375 20.738281 17.363281 20.601562 17.074219 20.445312 C 16.90625 20.355469 15.070312 20.355469 14.917969 20.445312 Z M 14.917969 20.445312 "/>';
71
- svgdown += '</g>';
72
- svgdown += '</g>';
73
- svgdown += '</svg>';
74
-
75
- var handleIconDown = {
76
- url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgdown),
77
- anchor: new google.maps.Point(30, 0)
78
- };
79
-
80
- } else {
81
-
82
- var pointIcon = {
83
- path: 'M4 4m-4,0a4,4,0 0,1 8,0a 4,4 0 0,1 -8,0z',
84
- fillColor: '#ffffff',
85
- fillOpacity: 1,
86
- anchor: new google.maps.Point(4, 4),
87
- strokeWeight: 1,
88
- strokeOpacity: 1,
89
- strokeColor: '#303030',
90
- scale: 1
91
- };
92
-
93
- var midPointIcon = {
94
- path: 'M4 4m-4,0a4,4,0 0,1 8,0a 4,4 0 0,1 -8,0z',
95
- fillColor: '#ffffff',
96
- fillOpacity: 0.4,
97
- anchor: new google.maps.Point(4, 4),
98
- strokeWeight: 0.3,
99
- strokeOpacity: 0.01,
100
- strokeColor: '#303030',
101
- scale: 1
102
- };
103
- }
104
-
105
- var ghostPath = new google.maps.Polyline({
106
- map: map,
107
- strokeColor: '#ffa500',
108
- strokeOpacity: 1,
109
- strokeWeight: 3
110
- });
111
-
112
- function at(index){
113
- return polygon.getPath().getAt(index);
114
- }
115
-
116
- function vertexGhostDragStart() {
117
-
118
- var polygonBounds = new google.maps.LatLngBounds();
119
- polygon.getPath().forEach(function (vertex, index) {
120
- vertex.marker.setIcon(pointIcon);
121
- polygonBounds.extend(vertex);
122
- });
123
- if(isMobile) {
124
- var polygonBoundsCenter = polygonBounds.getCenter();
125
- if(this.position.lat() >= polygonBoundsCenter.lat()) {
126
- this.setIcon(handleIconUp);
127
- } else {
128
- this.setIcon(handleIconDown);
129
- }
130
- }
131
- }
132
-
133
- function vertexGhostDrag() {
134
- if (ghostPath.getPath().getLength() === 0) {
135
- if(this.marker.editIndex < polygon.getPath().getLength() - 1) {
136
- ghostPath.setPath([
137
- this.marker.getPosition(),
138
- this.getPosition(),
139
- at(this.marker.editIndex + 1)
140
- ]);
141
- } else if(this.marker.editIndex == polygon.getPath().getLength() - 1) {
142
- ghostPath.setPath([
143
- this.marker.getPosition(),
144
- this.getPosition(),
145
- at(0)
146
- ]);
147
- }
148
- }
149
- ghostPath.getPath().setAt(1, this.getPosition());
150
- }
151
-
152
- function moveGhostMarkers(marker) {
153
-
154
- var vertex = at(marker.editIndex);
155
- var previous, next, position;
156
-
157
- if(marker.editIndex === 0) {
158
- previous = at(polygon.getPath().getLength()-1);
159
- } else {
160
- previous = at(marker.editIndex - 1);
161
- }
162
- if(marker.editIndex == polygon.getPath().getLength()-1) {
163
- next = at(0);
164
- } else {
165
- next = at(marker.editIndex + 1);
166
- }
167
- position = marker.getPosition();
168
-
169
- if (vertex && vertex.ghostMarker) {
170
- if (!google.maps.geometry) {
171
- vertex.ghostMarker.setPosition(new google.maps.LatLng(vertex.lat() + 0.5 * (next.lat() - vertex.lat()), vertex.lng() + 0.5 * (next.lng() - vertex.lng())));
172
- } else {
173
- vertex.ghostMarker.setPosition(google.maps.geometry.spherical.interpolate(vertex, next, 0.5));
174
- }
175
- }
176
- if (previous && previous.ghostMarker) {
177
- if (!google.maps.geometry) {
178
- previous.ghostMarker.setPosition(new google.maps.LatLng(previous.lat() + 0.5 * (position.lat() - previous.lat()), previous.lng() + 0.5 * (position.lng() - previous.lng())));
179
- } else {
180
- previous.ghostMarker.setPosition(google.maps.geometry.spherical.interpolate(previous, position, 0.5));
181
- }
182
- }
183
- }
184
-
185
- function vertexGhostDragEnd() {
186
-
187
- this.setIcon(midPointIcon);
188
-
189
- var position = this.getPosition(),
190
- index = this.marker.editIndex + 1,
191
- vertex;
192
-
193
- ghostPath.getPath().forEach(function() {
194
- ghostPath.getPath().pop();
195
- });
196
-
197
- polygon.getPath().insertAt(index, position);
198
-
199
- vertex = createMarkerVertex(at(index), pointIcon);
200
- vertex.editIndex = index;
201
-
202
- moveGhostMarkers(this.marker);
203
-
204
- createGhostMarkerVertex(at(index));
205
-
206
- polygon.getPath().forEach(function (vertex, index) {
207
- if (vertex.marker) {
208
- vertex.marker.editIndex = index;
209
- }
210
- });
211
-
212
- google.maps.event.trigger(polygon, 'insert_at', index, position);
213
- }
214
-
215
- function createGhostMarkerVertex(point) {
216
-
217
- if (point.marker.editIndex < polygon.getPath().getLength() - 1) {
218
- var next = at(point.marker.editIndex + 1),
219
- position, vertex;
220
-
221
- if (!google.maps.geometry) {
222
- position = new google.maps.LatLng(point.lat() + 0.5 * (next.lat() - point.lat()), point.lng() + 0.5 * (next.lng() - point.lng()));
223
- } else {
224
- position = google.maps.geometry.spherical.interpolate(point, next, 0.5);
225
- }
226
-
227
- vertex = point.ghostMarker;
228
-
229
- if (!vertex){
230
- vertex = new google.maps.Marker({
231
- map: map,
232
- icon: midPointIcon,
233
- draggable: true,
234
- raiseOnDrag: false
235
- });
236
-
237
- google.maps.event.addListener(vertex, "dragstart", vertexGhostDragStart);
238
- google.maps.event.addListener(vertex, "drag", vertexGhostDrag);
239
- google.maps.event.addListener(vertex, "dragend", vertexGhostDragEnd);
240
-
241
- point.ghostMarker = vertex;
242
- vertex.marker = point.marker;
243
- }
244
-
245
- vertex.setPosition(position);
246
- return vertex;
247
-
248
- } else if (point.marker.editIndex == polygon.getPath().getLength() - 1) {
249
- var next = at(0),
250
- position, vertex;
251
-
252
- if (!google.maps.geometry) {
253
- position = new google.maps.LatLng(point.lat() + 0.5 * (next.lat() - point.lat()), point.lng() + 0.5 * (next.lng() - point.lng()));
254
- } else {
255
- position = google.maps.geometry.spherical.interpolate(point, next, 0.5);
256
- }
257
-
258
- vertex = point.ghostMarker;
259
-
260
- if (!vertex){
261
- vertex = new google.maps.Marker({
262
- map: map,
263
- icon: midPointIcon,
264
- draggable: true,
265
- raiseOnDrag: false
266
- });
267
-
268
- google.maps.event.addListener(vertex, "dragstart", vertexGhostDragStart);
269
- google.maps.event.addListener(vertex, "drag", vertexGhostDrag);
270
- google.maps.event.addListener(vertex, "dragend", vertexGhostDragEnd);
271
-
272
- point.ghostMarker = vertex;
273
- vertex.marker = point.marker;
274
- }
275
-
276
- vertex.setPosition(position);
277
- return vertex;
278
-
279
- }
280
- return null;
281
- }
282
-
283
- function vertexDragStart() {
284
- var polygonBounds = new google.maps.LatLngBounds();
285
- polygon.getPath().forEach(function (vertex, index) {
286
- vertex.marker.setIcon(pointIcon);
287
- polygonBounds.extend(vertex);
288
- });
289
- if(isMobile) {
290
- var polygonBoundsCenter = polygonBounds.getCenter();
291
- if(this.position.lat() >= polygonBoundsCenter.lat()) {
292
- this.setIcon(handleIconUp);
293
- } else {
294
- this.setIcon(handleIconDown);
295
- }
296
- }
297
- }
298
-
299
- function vertexDrag() {
300
- var vertex = this.getPosition();
301
- vertex.marker = this;
302
- vertex.ghostMarker = at(this.editIndex).ghostMarker;
303
- polygon.getPath().setAt(this.editIndex, vertex);
304
- moveGhostMarkers(this);
305
- }
306
-
307
- function vertexDragEnd() {
308
- google.maps.event.trigger(polygon, 'update_at', this.editIndex, this.getPosition());
309
- }
310
-
311
- function vertexRightClick() {
312
- var vertex = at(this.editIndex),
313
- previous = at(this.editIndex - 1);
314
-
315
- if (vertex.ghostMarker) {
316
- vertex.ghostMarker.setMap(null);
317
- }
318
-
319
- polygon.getPath().removeAt(this.editIndex);
320
-
321
- if (previous) {
322
- if (this.editIndex < polygon.getPath().getLength()) {
323
- moveGhostMarkers(previous.marker);
324
- } else {
325
- previous.ghostMarker.setMap(null);
326
- previous.ghostMarker = undefined;
327
- }
328
- }
329
-
330
- this.setMap(null);
331
- polygon.getPath().forEach(function (vertex, index) {
332
- if (vertex.marker) {
333
- vertex.marker.editIndex = index;
334
- }
335
- });
336
-
337
- if (polygon.getPath().getLength() === 1) {
338
- polygon.getPath().pop().marker.setMap(null);
339
- }
340
-
341
- google.maps.event.trigger(polygon, 'remove_at', this.editIndex, vertex);
342
- }
343
-
344
- function createMarkerVertex(point, icon) {
345
-
346
- var vertex = point.marker;
347
-
348
- if (!vertex){
349
-
350
- vertex = new google.maps.Marker({
351
- position: point,
352
- map: map,
353
- icon: icon,
354
- draggable: true,
355
- raiseOnDrag: false
356
- });
357
-
358
- google.maps.event.addListener(vertex, "dragstart", vertexDragStart);
359
- google.maps.event.addListener(vertex, "drag", vertexDrag);
360
- google.maps.event.addListener(vertex, "dragend", vertexDragEnd);
361
-
362
- point.marker = vertex;
363
- }
364
-
365
- vertex.setPosition(point);
366
-
367
- return vertex;
368
- }
369
-
370
- function PolygonCustomEditWidget(map, polygon, currentPolygonCustomEdit, isMobile) {
371
-
372
- polygon.setMap(map);
373
-
374
- polygon.getPath().forEach(function (vertex, index) {
375
- var mIcon = pointIcon;
376
- if(isMobile && index === 1) {
377
- mIcon = handleIconUp;
378
- }
379
- createMarkerVertex(vertex, mIcon).editIndex = index;
380
- createGhostMarkerVertex(vertex);
381
- });
382
-
383
- currentPolygonCustomEdit = polygon;
384
-
385
- return currentPolygonCustomEdit;
386
- }
387
-
388
- PolygonCustomEditWidget.prototype = new google.maps.MVCObject();
389
-
390
- return new PolygonCustomEditWidget(map, polygon, currentPolygonCustomEdit, isMobile);
391
-
392
- };
393
- }
1
+ const handles = []
2
+
3
+ export class IQLPolygonCustomEdit {
4
+ constructor() {}
5
+
6
+ delete(map, currentPolygonCustomEdit) {
7
+ //console.log('polygon-custom-edit, delete, currentPolygonCustomEdit', currentPolygonCustomEdit);
8
+
9
+ if (!currentPolygonCustomEdit) return null
10
+ const path = currentPolygonCustomEdit.getPath()
11
+ //console.log('currentPolygonCustomEdit.delete, path', path);
12
+ const len = path.getLength()
13
+ //console.log('currentPolygonCustomEdit.delete, len', len);
14
+
15
+ for (let i = 0; i < len; i++) {
16
+ const handle = handles[i]
17
+ if (!handle) continue
18
+
19
+ if (handle.ghostMarker) {
20
+ google.maps.event.clearInstanceListeners(handle.ghostMarker)
21
+ handle.ghostMarker.setMap(null)
22
+ delete handle.ghostMarker.marker
23
+ delete handle.ghostMarker
24
+ }
25
+
26
+ if (handle.marker) {
27
+ google.maps.event.clearInstanceListeners(handle.marker)
28
+ handle.marker.setMap(null)
29
+ handle.marker = null
30
+ }
31
+ }
32
+
33
+ handles.length = 0
34
+
35
+ return currentPolygonCustomEdit
36
+ }
37
+
38
+ edit(map, polygon, currentPolygonCustomEdit, isMobile) {
39
+ let pointIcon
40
+ let midPointIcon
41
+ let handleIconUp
42
+ let handleIconDown
43
+
44
+ if (isMobile) {
45
+ const svgpi =
46
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48" height="48">' +
47
+ '<path fill="rgba(255,255,255,0.01)" d="M 0, 24 a 24,24 0 1,0 48,0 a 24,24 0 1,0 -48,0" />' +
48
+ '<path fill="rgba(255,255,255,1)" stroke="#303030" stroke-width="1" d="M24 24 m-4,0 a 4,4,0 0,1 8,0 a 4,4 0 0,1 -8,0z" />' +
49
+ "</svg>"
50
+
51
+ pointIcon = {
52
+ url: "data:image/svg+xml;charset=UTF-8;base64," + btoa(svgpi),
53
+ anchor: new google.maps.Point(24, 24)
54
+ }
55
+
56
+ const svgmpi =
57
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48" height="48">' +
58
+ '<path fill="rgba(255,255,255,0.01)" d="M 0, 24 a 24,24 0 1,0 48,0 a 24,24 0 1,0 -48,0" />' +
59
+ '<path fill="rgba(255,255,255,0.4)" stroke="#303030" stroke-width="0.3" stroke-opacity="0.01" d="M24 24 m-4,0 a 4,4,0 0,1 8,0 a 4,4 0 0,1 -8,0z" />' +
60
+ "</svg>"
61
+
62
+ midPointIcon = {
63
+ url: "data:image/svg+xml;charset=UTF-8;base64," + btoa(svgmpi),
64
+ anchor: new google.maps.Point(24, 24)
65
+ }
66
+
67
+ const svgup =
68
+ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">' +
69
+ '<g transform="scale(0.4 0.4)">' +
70
+ '<path style="fill:#f1a81e;" d="M38.853,5.324L38.853,5.324c-7.098-7.098-18.607-7.098-25.706,0h0 C6.751,11.72,6.031,23.763,11.459,31L26,52l14.541-21C45.969,23.763,45.249,11.72,38.853,5.324z"/>' +
71
+ '<g transform="translate(13.2 5.9) scale(0.8 0.8)">' +
72
+ // (paths trimmed for brevity—same as your JS)
73
+ "</g></g></svg>"
74
+
75
+ handleIconUp = {
76
+ url: "data:image/svg+xml;charset=UTF-8;base64," + btoa(svgup),
77
+ anchor: new google.maps.Point(30, 60)
78
+ }
79
+
80
+ const svgdown =
81
+ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">' +
82
+ '<g transform="scale(0.4 0.4) rotate(180 26 26)">' +
83
+ '<path style="fill:#f1a81e;" d="M38.853,5.324L38.853,5.324c-7.098-7.098-18.607-7.098-25.706,0h0 C6.751,11.72,6.031,23.763,11.459,31L26,52l14.541-21C45.969,23.763,45.249,11.72,38.853,5.324z"/>' +
84
+ '<g transform="translate(13.2 5.9) scale(0.8 0.8)">' +
85
+ // (paths trimmed for brevity—same as your JS)
86
+ "</g></g></svg>"
87
+
88
+ handleIconDown = {
89
+ url: "data:image/svg+xml;charset=UTF-8;base64," + btoa(svgdown),
90
+ anchor: new google.maps.Point(30, 0)
91
+ }
92
+ } else {
93
+ pointIcon = {
94
+ path: "M4 4m-4,0a4,4,0 0,1 8,0a 4,4 0 0,1 -8,0z",
95
+ fillColor: "#ffffff",
96
+ fillOpacity: 1,
97
+ anchor: new google.maps.Point(4, 4),
98
+ strokeWeight: 1,
99
+ strokeOpacity: 1,
100
+ strokeColor: "#303030",
101
+ scale: 1
102
+ }
103
+
104
+ midPointIcon = {
105
+ path: "M4 4m-4,0a4,4,0 0,1 8,0a 4,4 0 0,1 -8,0z",
106
+ fillColor: "#ffffff",
107
+ fillOpacity: 0.4,
108
+ anchor: new google.maps.Point(4, 4),
109
+ strokeWeight: 0.3,
110
+ strokeOpacity: 0.01,
111
+ strokeColor: "#303030",
112
+ scale: 1
113
+ }
114
+ }
115
+
116
+ const ghostPath = new google.maps.Polyline({
117
+ map,
118
+ strokeColor: "#ffff00",
119
+ strokeOpacity: 0.6,
120
+ strokeWeight: 2,
121
+ clickable: false,
122
+ zIndex: 10100
123
+ })
124
+
125
+ const vertexGhostDragStart = function() {
126
+ for (let i = 0; i < handles.length; i++) {
127
+ const m = handles[i]?.marker
128
+ if (m) m.setIcon(pointIcon)
129
+ }
130
+
131
+ const path = polygon.getPath()
132
+ const bounds = new google.maps.LatLngBounds()
133
+ for (let i = 0, len = path.getLength(); i < len; i++) {
134
+ bounds.extend(path.getAt(i))
135
+ }
136
+
137
+ if (isMobile && handleIconUp && handleIconDown) {
138
+ const center = bounds.getCenter()
139
+ const pos = this.getPosition()
140
+ if (!pos) return
141
+ this.setIcon(pos.lat() >= center.lat() ? handleIconUp : handleIconDown)
142
+ }
143
+ }
144
+
145
+ const vertexGhostDrag = function() {
146
+ const idx = this.marker.editIndex
147
+ const path = polygon.getPath()
148
+ const lastIndex = path.getLength() - 1
149
+
150
+ const from = this.marker.getPosition()
151
+ const current = this.getPosition()
152
+ const third = idx < lastIndex ? path.getAt(idx + 1) : path.getAt(0)
153
+
154
+ if (ghostPath.getPath().getLength() === 0) {
155
+ ghostPath.setPath([from, current, third])
156
+ } else {
157
+ ghostPath.getPath().setAt(1, current)
158
+ }
159
+ }
160
+
161
+ const vertexGhostDragEnd = function() {
162
+ const linked = this.marker
163
+ if (!linked) return
164
+ const pos = this.getPosition()
165
+ if (!pos) return
166
+
167
+ const path = polygon.getPath()
168
+ const len = path.getLength()
169
+ if (len < 1) return
170
+
171
+ const i = linked.editIndex
172
+ const insertIdx = i === len - 1 ? 0 : i + 1
173
+
174
+ // Capture the original handle that owns this ghost BEFORE mutating handles
175
+ const originalHandle = handles[i]
176
+
177
+ // 1) Remove the dragged ghost instance itself
178
+ google.maps.event.clearInstanceListeners(this)
179
+ this.setMap(null)
180
+
181
+ // 2) Insert the new vertex at the ghost position
182
+ path.insertAt(insertIdx, pos)
183
+
184
+ // 3) Create the new vertex marker and splice into handles
185
+ const newVertexMarker = new google.maps.Marker({
186
+ map,
187
+ icon: pointIcon,
188
+ draggable: true,
189
+ raiseOnDrag: false,
190
+ position: pos
191
+ })
192
+ google.maps.event.addListener(
193
+ newVertexMarker,
194
+ "dragstart",
195
+ vertexDragStart
196
+ )
197
+ google.maps.event.addListener(newVertexMarker, "drag", vertexDrag)
198
+ google.maps.event.addListener(newVertexMarker, "dragend", vertexDragEnd)
199
+
200
+ handles.splice(insertIdx, 0, {
201
+ marker: newVertexMarker,
202
+ ghostMarker: undefined
203
+ })
204
+
205
+ // 4) Update editIndex for all markers from insertIdx onward
206
+ for (let k = insertIdx; k < handles.length; k++) {
207
+ const m = handles[k]?.marker
208
+ if (m) m.editIndex = k
209
+ }
210
+
211
+ // 5) Clean up the original handle's ghost (the one on edge i→i+1),
212
+ // but ONLY if it’s not the same instance as the dragged ghost
213
+ const gh = originalHandle?.ghostMarker
214
+ if (gh && gh !== this) {
215
+ google.maps.event.clearInstanceListeners(gh)
216
+ gh.setMap(null)
217
+ delete gh.marker
218
+ delete originalHandle.ghostMarker
219
+ } else if (originalHandle) {
220
+ // Ensure the property is gone to force recreation
221
+ delete originalHandle?.ghostMarker
222
+ }
223
+
224
+ // 6) Recreate ONLY the two ghosts adjacent to the new vertex
225
+ const prevIndex = insertIdx === 0 ? path.getLength() - 1 : insertIdx - 1
226
+ createGhostMarkerVertex(prevIndex) // between previous vertex and new vertex
227
+ createGhostMarkerVertex(insertIdx) // between new vertex and next vertex
228
+
229
+ // 7) Clear the visual helper polyline
230
+ while (ghostPath.getPath().getLength() > 0) ghostPath.getPath().pop()
231
+
232
+ // 8) Notify consumers
233
+ google.maps.event.trigger(polygon, "insert_at", insertIdx, pos)
234
+ }
235
+
236
+ const vertexDragStart = function() {
237
+ for (let i = 0; i < handles.length; i++) {
238
+ const m = handles[i]?.marker
239
+ if (m) m.setIcon(pointIcon)
240
+ }
241
+
242
+ const path = polygon.getPath()
243
+ const bounds = new google.maps.LatLngBounds()
244
+ for (let i = 0, len = path.getLength(); i < len; i++) {
245
+ bounds.extend(path.getAt(i))
246
+ }
247
+
248
+ if (isMobile && handleIconUp && handleIconDown) {
249
+ const center = bounds.getCenter()
250
+ const pos = this.getPosition()
251
+ if (!pos) return
252
+ this.setIcon(pos.lat() >= center.lat() ? handleIconUp : handleIconDown)
253
+ }
254
+ }
255
+
256
+ const vertexDrag = function() {
257
+ const idx = this.editIndex
258
+ const pos = this.getPosition()
259
+ polygon.getPath().setAt(idx, pos)
260
+
261
+ const path = polygon.getPath()
262
+ const prevIdx = idx === 0 ? path.getLength() - 1 : idx - 1
263
+
264
+ createGhostMarkerVertex(prevIdx)
265
+ createGhostMarkerVertex(idx)
266
+ }
267
+
268
+ const vertexDragEnd = function() {
269
+ google.maps.event.trigger(
270
+ polygon,
271
+ "update_at",
272
+ this.editIndex,
273
+ this.getPosition()
274
+ )
275
+ }
276
+
277
+ const vertexRightClick = function() {
278
+ const path = polygon.getPath()
279
+ const len = path.getLength()
280
+ if (len === 0) return
281
+
282
+ const i = this.editIndex
283
+ const prevIdx = i === 0 ? len - 1 : i - 1
284
+
285
+ const gm = handles[i]?.ghostMarker
286
+ if (gm) {
287
+ google.maps.event.clearInstanceListeners(gm)
288
+ gm.setMap(null)
289
+ delete gm.marker // clear back-reference
290
+ delete handles[i].ghostMarker
291
+ }
292
+
293
+ const removedLL = path.getAt(i)
294
+ path.removeAt(i)
295
+ google.maps.event.clearInstanceListeners(this)
296
+ this.setMap(null)
297
+
298
+ handles.splice(i, 1)
299
+
300
+ const newLen = path.getLength()
301
+
302
+ if (newLen >= 2) {
303
+ let adjPrevIdx = prevIdx
304
+ if (prevIdx > i) adjPrevIdx = prevIdx - 1
305
+
306
+ const prevLL = path.getAt(adjPrevIdx)
307
+ const newNextIdx = adjPrevIdx === newLen - 1 ? 0 : adjPrevIdx + 1
308
+ const nextLL = path.getAt(newNextIdx)
309
+
310
+ const prevHandle = handles[adjPrevIdx]
311
+ if (prevHandle?.ghostMarker && prevLL && nextLL) {
312
+ const midPos = google.maps.geometry
313
+ ? google.maps.geometry.spherical.interpolate(prevLL, nextLL, 0.5)
314
+ : new google.maps.LatLng(
315
+ prevLL.lat() + 0.5 * (nextLL.lat() - prevLL.lat()),
316
+ prevLL.lng() + 0.5 * (nextLL.lng() - prevLL.lng())
317
+ )
318
+ prevHandle.ghostMarker.setPosition(midPos)
319
+ }
320
+ } else {
321
+ if (newLen === 1) {
322
+ const onlyHandle = handles[0]
323
+
324
+ if (onlyHandle?.ghostMarker) {
325
+ google.maps.event.clearInstanceListeners(onlyHandle.ghostMarker)
326
+ onlyHandle.ghostMarker.setMap(null)
327
+ delete onlyHandle.ghostMarker.marker
328
+ delete onlyHandle.ghostMarker
329
+ }
330
+
331
+ if (onlyHandle?.marker) {
332
+ google.maps.event.clearInstanceListeners(onlyHandle.marker)
333
+ onlyHandle.marker.setMap(null)
334
+ onlyHandle.marker = null
335
+ }
336
+ path.removeAt(0)
337
+ }
338
+ }
339
+
340
+ for (let idx = 0; idx < handles.length; idx++) {
341
+ const m = handles[idx]?.marker
342
+ if (m) m.editIndex = idx
343
+ }
344
+
345
+ google.maps.event.trigger(polygon, "remove_at", i, removedLL)
346
+ }
347
+
348
+ const createMarkerVertex = (index, icon) => {
349
+ const ll = polygon.getPath().getAt(index)
350
+
351
+ let vm = handles[index]?.marker
352
+ if (!vm) {
353
+ vm = new google.maps.Marker({
354
+ position: ll,
355
+ map,
356
+ icon,
357
+ draggable: true,
358
+ raiseOnDrag: false
359
+ })
360
+
361
+ google.maps.event.addListener(vm, "dragstart", vertexDragStart)
362
+ google.maps.event.addListener(vm, "drag", vertexDrag)
363
+ google.maps.event.addListener(vm, "dragend", vertexDragEnd)
364
+ //google.maps.event.addListener(vm, 'rightclick', vertexRightClick); // if you want delete
365
+
366
+ vm.editIndex = index
367
+ handles[index] = { marker: vm } // create the VertexHandle
368
+ } else {
369
+ vm.setPosition(ll)
370
+ vm.editIndex = index
371
+ }
372
+
373
+ return vm
374
+ }
375
+
376
+ const createGhostMarkerVertex = index => {
377
+ const path = polygon.getPath()
378
+ const pathLen = path.getLength()
379
+ if (pathLen < 2) return null
380
+
381
+ const currLL = path.getAt(index)
382
+ const nextIndex = index < pathLen - 1 ? index + 1 : 0
383
+ const nextLL = path.getAt(nextIndex)
384
+ const midPos = !google.maps.geometry
385
+ ? new google.maps.LatLng(
386
+ currLL.lat() + 0.5 * (nextLL.lat() - currLL.lat()),
387
+ currLL.lng() + 0.5 * (nextLL.lng() - currLL.lng())
388
+ )
389
+ : google.maps.geometry.spherical.interpolate(currLL, nextLL, 0.5)
390
+
391
+ const vertexMarker = handles[index]?.marker
392
+ if (!vertexMarker) return null
393
+
394
+ let gm = handles[index]?.ghostMarker
395
+
396
+ // Recreate if missing OR removed from map (e.g., after dragend cleanup)
397
+ if (!gm || gm.getMap() === null) {
398
+ gm = new google.maps.Marker({
399
+ map,
400
+ icon: midPointIcon,
401
+ draggable: true,
402
+ raiseOnDrag: false
403
+ })
404
+ gm.marker = vertexMarker
405
+ google.maps.event.addListener(gm, "dragstart", vertexGhostDragStart)
406
+ google.maps.event.addListener(gm, "drag", vertexGhostDrag)
407
+ google.maps.event.addListener(gm, "dragend", vertexGhostDragEnd)
408
+ handles[index].ghostMarker = gm
409
+ } else {
410
+ // keep the back-reference correct
411
+ gm.marker = vertexMarker
412
+ }
413
+
414
+ gm.setPosition(midPos)
415
+ return gm
416
+ }
417
+
418
+
419
+ const syncMarkersToPolygonPath = () => {
420
+ const path = polygon.getPath()
421
+ for (let i = 0; i < path.getLength(); i++) {
422
+ const ll = path.getAt(i)
423
+ const vh = handles[i]
424
+ if (!vh) continue
425
+
426
+ const m = vh.marker
427
+ if (m) {
428
+ m.setPosition(ll)
429
+ m.editIndex = i
430
+ }
431
+
432
+ createGhostMarkerVertex(i)
433
+ }
434
+ }
435
+
436
+ const setVertexAndGhostMarkersDraggable = draggable => {
437
+ for (let i = 0; i < handles.length; i++) {
438
+ const vh = handles[i]
439
+ vh?.marker?.setDraggable(draggable)
440
+ vh?.ghostMarker?.setDraggable(draggable)
441
+ }
442
+ }
443
+
444
+ google.maps.event.addListener(polygon, "dragstart", () => {
445
+ setVertexAndGhostMarkersDraggable(false)
446
+ })
447
+
448
+ google.maps.event.addListener(polygon, "drag", () => {
449
+ syncMarkersToPolygonPath()
450
+ })
451
+
452
+ google.maps.event.addListener(polygon, "dragend", () => {
453
+ syncMarkersToPolygonPath()
454
+ setVertexAndGhostMarkersDraggable(true)
455
+ })
456
+
457
+ function PolygonCustomEditWidget(map, polygon, currentPolygonCustomEdit, isMobile) {
458
+
459
+ polygon.setMap(map)
460
+
461
+ polygon.getPath().forEach((_vertexLL, index) => {
462
+ const iconForThisVertex = isMobile && handleIconUp && index === 1 ? handleIconUp : pointIcon
463
+ const vm = createMarkerVertex(index, iconForThisVertex)
464
+ vm.editIndex = index
465
+
466
+ createGhostMarkerVertex(index);
467
+ });
468
+
469
+ currentPolygonCustomEdit = polygon;
470
+
471
+ return currentPolygonCustomEdit;
472
+ }
473
+
474
+ PolygonCustomEditWidget.prototype = new google.maps.MVCObject();
475
+
476
+ return new PolygonCustomEditWidget(map, polygon, currentPolygonCustomEdit, isMobile);
477
+
478
+ }
479
+ }