mapping-component-package-jp 0.0.2

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 (50) hide show
  1. package/README.md +70 -0
  2. package/dist/index.d.ts +264 -0
  3. package/dist/index.js +54 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +54 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +48 -0
  8. package/public/favicon.ico +0 -0
  9. package/public/index.html +43 -0
  10. package/public/logo192.png +0 -0
  11. package/public/logo512.png +0 -0
  12. package/public/manifest.json +25 -0
  13. package/public/robots.txt +3 -0
  14. package/rollup.config.js +48 -0
  15. package/src/components/FabControl.tsx +63 -0
  16. package/src/components/GoogleSearchBar.tsx +182 -0
  17. package/src/components/Icons.tsx +20 -0
  18. package/src/components/JPMapComponent.tsx +96 -0
  19. package/src/components/SpeedDialTool.tsx +97 -0
  20. package/src/components/index.ts +22 -0
  21. package/src/hooks/useMapManager.ts +48 -0
  22. package/src/interfaces/AgnifyMapComponentProps.ts +18 -0
  23. package/src/interfaces/CustomMapOptions.ts +14 -0
  24. package/src/interfaces/Data/EnterpriseRegion.ts +12 -0
  25. package/src/interfaces/Data/Farm.ts +10 -0
  26. package/src/interfaces/Data/Field.ts +19 -0
  27. package/src/interfaces/Data/LocationData.ts +9 -0
  28. package/src/interfaces/Data/MapLocationFeature.ts +8 -0
  29. package/src/interfaces/Data/NDVI.ts +14 -0
  30. package/src/interfaces/GoogleMapsOptions.ts +39 -0
  31. package/src/interfaces/Message.ts +13 -0
  32. package/src/interfaces/Mode.ts +54 -0
  33. package/src/interfaces/Properties.ts +16 -0
  34. package/src/js/fieldEncapsulation/iql.field.js +8 -0
  35. package/src/js/fieldEncapsulation/iql.fieldupload.js +158 -0
  36. package/src/js/fieldEncapsulation/iql.fieldvalidator.js +574 -0
  37. package/src/js/mapEncapsulation/circle.functions.js +30 -0
  38. package/src/js/mapEncapsulation/field.geolocation.js +19 -0
  39. package/src/js/mapEncapsulation/map.common.js +96 -0
  40. package/src/js/mapEncapsulation/mapOverlayManager.d.ts +64 -0
  41. package/src/js/mapEncapsulation/mapOverlayManager.js +2753 -0
  42. package/src/js/mapEncapsulation/shapes/circle.full.js +789 -0
  43. package/src/js/mapEncapsulation/shapes/circle.sector.js +1099 -0
  44. package/src/js/mapEncapsulation/shapes/circle.segment.js +1109 -0
  45. package/src/js/mapEncapsulation/shapes/polygon.customedit.js +393 -0
  46. package/src/js/mapEncapsulation/shapes/polyline.customedit.js +478 -0
  47. package/src/utils/commonUtils.ts +5 -0
  48. package/src/utils/iconUtils.js +52 -0
  49. package/src/utils/mapUtils.ts +88 -0
  50. package/tsconfig.json +20 -0
@@ -0,0 +1,478 @@
1
+ export class IQLPolylineCustomEdit {
2
+
3
+ constructor() {
4
+ }
5
+
6
+ delete(map, currentPolylineCustomEdit) {
7
+
8
+ currentPolylineCustomEdit.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 currentPolylineCustomEdit;
20
+
21
+ }
22
+
23
+ getEncodedPath(map, currentPolylineCustomEdit) {
24
+ return google.maps.geometry.encoding.encodePath(currentPolylineCustomEdit.getPath());
25
+ }
26
+
27
+ verify(map, rmarker, pmarker, dirmarkers, dpolylines, currentPolylineCustomEdit, offsetX, offsetY, eventHandlers) {
28
+
29
+ var verifyResult = {success: false};//, errmsg: '', dirmarkers: dirmarkers, dpolyline: dpolyline};//, cpce: null, dirmarkers: null, dpolyline: null};
30
+
31
+ var directionsService = new google.maps.DirectionsService();
32
+ //var directionsDisplay = new google.maps.DirectionsRenderer();
33
+
34
+ var rplstart = currentPolylineCustomEdit.getPath().getAt(0); //road
35
+ var rplend = currentPolylineCustomEdit.getPath().getAt(currentPolylineCustomEdit.getPath().getLength()-1); //field
36
+
37
+ var dbounds = new google.maps.LatLngBounds();
38
+
39
+ var cpcePath = currentPolylineCustomEdit.getPath();
40
+ cpcePath.forEach(function(c,ci) {
41
+ dbounds.extend(cpcePath.getAt(ci));
42
+ });
43
+ dbounds.extend(rplend);
44
+ var iqlpos = new google.maps.LatLng(-25.765255, 28.271339);
45
+ calcRoute(rplstart, iqlpos, rplend, rmarker, pmarker, dirmarkers, dpolylines, currentPolylineCustomEdit, offsetX, offsetY, eventHandlers);
46
+
47
+
48
+ function calcRoute(start, end, fpos, rmarker, pmarker, dirmarkers, dpolylines, currentPolylineCustomEdit, offsetX, offsetY, eventHandlers) {
49
+
50
+ var request = {
51
+ origin: start,
52
+ destination: end,
53
+ travelMode: google.maps.TravelMode.DRIVING
54
+ };
55
+
56
+ directionsService.route(request, function(response, status) {
57
+ if (status == google.maps.DirectionsStatus.OK) {
58
+ renderRoute(response, start, fpos, rmarker, pmarker, dirmarkers, dpolylines, currentPolylineCustomEdit, offsetX, offsetY, eventHandlers);
59
+ } else {
60
+ verifyResult.success = false;
61
+ eventHandlers["TriggerRouteRendered"](verifyResult);
62
+ }
63
+ });
64
+ }
65
+
66
+ function renderRoute(response, start, fpos, rmarker, pmarker, dirmarkers, dpolylines, currentPolylineCustomEdit, offsetX, offsetY, eventHandlers) {
67
+ /*
68
+ var dpolyline = new google.maps.Polyline({
69
+ path: [],
70
+ strokeColor: '#0000ff',
71
+ strokeWeight: 5,
72
+ strokeOpacity: 0.5,
73
+ zIndex: 10006
74
+ });
75
+ dpolylines.push(dpolyline);
76
+ var asvg = '<svg version="1.1" id="Capa_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">';
77
+ asvg += '<g transform="scale(0.4 0.4)">';
78
+ asvg += '<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"/>';
79
+ asvg += '<text x="16" y="28" style="font: bold 28px sans-serif;fill: #ffffff;">A</text>';
80
+ asvg += '</g>';
81
+ asvg += '</svg>';
82
+
83
+ var bsvg = '<svg version="1.1" id="Capa_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">';
84
+ bsvg += '<g transform="scale(0.4 0.4)">';
85
+ bsvg += '<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"/>';
86
+ bsvg += '<text x="16" y="28" style="font: bold 28px sans-serif;fill: #ffffff;">B</text>';
87
+ bsvg += '</g>';
88
+ bsvg += '</svg>';
89
+
90
+
91
+ var route = response.routes[0];
92
+ var path = response.routes[0].overview_path;
93
+ var legs = response.routes[0].legs;
94
+
95
+ //rmarker.setMap(null);
96
+ //pmarker.setMap(null);
97
+
98
+ currentPolylineCustomEdit.getPath().forEach(function (vertex, index) {
99
+ if (vertex.marker) {
100
+ vertex.marker.setMap(null);
101
+ vertex.marker = undefined;
102
+ }
103
+ if (vertex.ghostMarker) {
104
+ vertex.ghostMarker.setMap(null);
105
+ vertex.ghostMarker = undefined;
106
+ }
107
+ });
108
+
109
+
110
+ //dirmarkers = [];
111
+
112
+ var amarker = new google.maps.Marker({
113
+ position: fpos,
114
+ icon: {
115
+ url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(asvg),
116
+ anchor: new google.maps.Point(30, 60)
117
+ },
118
+ //map: map,
119
+ zIndex: 10007
120
+ });
121
+ dirmarkers.push(amarker);
122
+
123
+ var tempPath = [];
124
+ cpcePath.forEach(function(cp) {
125
+ tempPath.push([cp.lat(),cp.lng()]);
126
+ });
127
+ tempPath.reverse();
128
+ tempPath.forEach(function(tp) {
129
+ dpolyline.getPath().push(new google.maps.LatLng(tp[0],tp[1]));
130
+ });
131
+
132
+ for (var i = 0; i < legs.length; i++) {
133
+ if(i == legs.length-1) {
134
+ var bmarker = new google.maps.Marker({
135
+ position: legs[i].end_location,
136
+ icon: {
137
+ url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(bsvg),
138
+ anchor: new google.maps.Point(30, 60)
139
+ },
140
+ //map: map,
141
+ zIndex: 10007
142
+ });
143
+ dirmarkers.push(bmarker);
144
+ }
145
+ var steps = legs[i].steps;
146
+ for (var j = 0; j < steps.length; j++) {
147
+ var nextSegment = steps[j].path;
148
+
149
+ for (var k = 0; k < nextSegment.length; k++) {
150
+ dpolyline.getPath().push(nextSegment[k]);
151
+ dbounds.extend(nextSegment[k]);
152
+ }
153
+ }
154
+ }
155
+ amarker.setMap(map);
156
+ dpolyline.setMap(map);
157
+ bmarker.setMap(map);
158
+
159
+ var boundsChangedListener = google.maps.event.addListenerOnce(map, 'bounds_changed', function () {
160
+ var zoomChangedListener = google.maps.event.addListenerOnce(map, 'zoom_changed', function () {
161
+ offsetCenter(map.getCenter(), offsetX, offsetY);
162
+ });
163
+ map.setZoom(map.getZoom()-1);
164
+ });
165
+
166
+
167
+ map.fitBounds(dbounds);
168
+ */
169
+
170
+ verifyResult.success = true;
171
+
172
+ eventHandlers["TriggerRouteRendered"](verifyResult);
173
+
174
+
175
+ }
176
+
177
+ function offsetCenter(latlng, offsetX, offsetY) {
178
+
179
+ // latlng is the apparent centre-point
180
+ // offsetx is the distance you want that point to move to the right, in pixels
181
+ // offsety is the distance you want that point to move upwards, in pixels
182
+ // offset can be negative
183
+ // offsetx and offsety are both optional
184
+
185
+ var zoom = map.getZoom();
186
+ //var scale = Math.pow(2, map.getZoom());
187
+ var scale = 1 << zoom;
188
+ var worldCoordinateCenter = map.getProjection().fromLatLngToPoint(latlng);
189
+ var pixelOffset = new google.maps.Point((offsetX/scale) || 0,(offsetY/scale) || 0);
190
+
191
+ var worldCoordinateNewCenter = new google.maps.Point(
192
+ worldCoordinateCenter.x - pixelOffset.x,
193
+ worldCoordinateCenter.y + pixelOffset.y
194
+ );
195
+
196
+ var newCenter = map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);
197
+
198
+ map.setCenter(newCenter);
199
+
200
+ }
201
+
202
+ }
203
+
204
+ edit(map, polyline, sm, em, str, eventHandlers, currentPolylineCustomEdit, isMobile) {
205
+
206
+ 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">'
207
+ 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" />';
208
+ 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" />';
209
+ svgpi += '</svg>';
210
+
211
+ var pointIcon = {
212
+ url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgpi),
213
+ anchor: new google.maps.Point(24, 24)
214
+ };
215
+ /*
216
+ var pointIcon = {
217
+ path: 'M4 4m-4,0a4,4,0 0,1 8,0a 4,4 0 0,1 -8,0z',
218
+ fillColor: '#ffffff',
219
+ fillOpacity: 1,
220
+ anchor: new google.maps.Point(4, 4),
221
+ strokeWeight: 1,
222
+ strokeOpacity: 1,
223
+ strokeColor: '#303030',
224
+ scale: 1
225
+ };
226
+ */
227
+
228
+ 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">'
229
+ 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" />';
230
+ 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" />';
231
+ svgmpi += '</svg>';
232
+
233
+ var midPointIcon = {
234
+ url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgmpi),
235
+ anchor: new google.maps.Point(24, 24)
236
+ };
237
+
238
+ var handleIcon = {
239
+ path: 'M0,0 32,0 16,27.7z',
240
+ fillColor: '#ffffff',
241
+ fillOpacity: 1,
242
+ anchor: new google.maps.Point(16, 28),
243
+ strokeWeight: 1,
244
+ strokeOpacity: 1,
245
+ strokeColor: '#303030',
246
+ scale: 1,
247
+ id: 'handleIcon'
248
+ };
249
+
250
+ var ghostPath = new google.maps.Polyline({
251
+ map: polyline.getMap(),
252
+ strokeColor: '#ffa500',//polyline.strokeColor,
253
+ strokeOpacity: 1,
254
+ strokeWeight: 3// polyline.strokeWeight
255
+ });
256
+
257
+ function at(index){
258
+ return polyline.getPath().getAt(index);
259
+ }
260
+
261
+ /*
262
+ function vertexGhostMouseOver() {
263
+ this.setIcon(imgGhostVertexOver);
264
+ }
265
+
266
+ function vertexGhostMouseOut() {
267
+ this.setIcon(imgGhostVertex);
268
+ }
269
+ */
270
+ function vertexGhostDrag() {
271
+ if (ghostPath.getPath().getLength() === 0) {
272
+ ghostPath.setPath([
273
+ this.marker.getPosition(),
274
+ this.getPosition(),
275
+ at(this.marker.editIndex + 1)
276
+ ]);
277
+ }
278
+ ghostPath.getPath().setAt(1, this.getPosition());
279
+ }
280
+
281
+ function moveGhostMarkers(marker) {
282
+ var vertex = at(marker.editIndex),
283
+ previous = at(marker.editIndex - 1),
284
+ next = at(marker.editIndex + 1),
285
+ position = marker.getPosition();
286
+
287
+ if (vertex && vertex.ghostMarker) {
288
+ if (!google.maps.geometry) {
289
+ vertex.ghostMarker.setPosition(
290
+ new google.maps.LatLng(
291
+ vertex.lat() + 0.5 * (next.lat() - vertex.lat()),
292
+ vertex.lng() + 0.5 * (next.lng() - vertex.lng())
293
+ )
294
+ );
295
+ } else {
296
+ vertex.ghostMarker.setPosition(
297
+ google.maps.geometry.spherical.interpolate(
298
+ vertex, next, 0.5
299
+ )
300
+ );
301
+ }
302
+ }
303
+ if (previous && previous.ghostMarker) {
304
+ if (!google.maps.geometry) {
305
+ previous.ghostMarker.setPosition(
306
+ new google.maps.LatLng(
307
+ previous.lat() + 0.5 * (position.lat() - previous.lat()),
308
+ previous.lng() + 0.5 * (position.lng() - previous.lng())
309
+ )
310
+ );
311
+ } else {
312
+ previous.ghostMarker.setPosition(
313
+ google.maps.geometry.spherical.interpolate(
314
+ previous, position, 0.5
315
+ )
316
+ );
317
+ }
318
+ }
319
+ }
320
+
321
+ function vertexGhostDragEnd() {
322
+ var position = this.getPosition();
323
+ var index = this.marker.editIndex + 1;
324
+
325
+ var vertex;
326
+
327
+ ghostPath.getPath().forEach(function() {
328
+ ghostPath.getPath().pop();
329
+ });
330
+
331
+ polyline.getPath().insertAt(index, position);
332
+
333
+ vertex = createMarkerVertex(at(index));
334
+ vertex.editIndex = index;
335
+
336
+
337
+ moveGhostMarkers(this.marker);
338
+
339
+ createGhostMarkerVertex(at(index));
340
+
341
+ polyline.getPath().forEach(function (vertex, index) {
342
+ if (vertex.marker) {
343
+ vertex.marker.editIndex = index;
344
+ }
345
+ });
346
+
347
+ google.maps.event.trigger(polyline, 'insert_at', index, position);
348
+ eventHandlers["TriggerRoadAccessChanged"](polyline);
349
+ }
350
+
351
+ function createGhostMarkerVertex(point) {
352
+ if (point.marker.editIndex < polyline.getPath().getLength() - 1) {
353
+ var next = at(point.marker.editIndex + 1),
354
+ position, vertex;
355
+
356
+ if (!google.maps.geometry) {
357
+ position = new google.maps.LatLng(
358
+ point.lat() + 0.5 * (next.lat() - point.lat()),
359
+ point.lng() + 0.5 * (next.lng() - point.lng())
360
+ );
361
+ } else {
362
+ position = google.maps.geometry.spherical.interpolate(
363
+ point, next, 0.5
364
+ );
365
+ }
366
+
367
+ vertex = point.ghostMarker;
368
+
369
+ if (!vertex){
370
+ vertex = new google.maps.Marker({
371
+ map: polyline.getMap(),
372
+ icon: midPointIcon,//imgGhostVertex,
373
+ draggable: true,
374
+ raiseOnDrag: false
375
+ });
376
+
377
+ //google.maps.event.addListener(vertex, "mouseover", vertexGhostMouseOver);
378
+ //google.maps.event.addListener(vertex, "mouseout", vertexGhostMouseOut);
379
+ google.maps.event.addListener(vertex, "drag", vertexGhostDrag);
380
+ google.maps.event.addListener(vertex, "dragend", vertexGhostDragEnd);
381
+
382
+ point.ghostMarker = vertex;
383
+ vertex.marker = point.marker;
384
+ }
385
+
386
+ vertex.setPosition(position);
387
+
388
+ return vertex;
389
+ }
390
+ return null;
391
+ }
392
+
393
+ function vertexDrag() {
394
+ var vertex = this.getPosition();
395
+
396
+ if(this.editIndex == polyline.getPath().getLength() - 1) {
397
+ str.updateMarkerLocation_(vertex);
398
+ vertex = this.getPosition();
399
+ }
400
+ vertex.marker = this;
401
+
402
+ vertex.ghostMarker = at(this.editIndex).ghostMarker;
403
+ polyline.getPath().setAt(this.editIndex, vertex);
404
+ moveGhostMarkers(this);
405
+
406
+ }
407
+
408
+ function vertexDragEnd(){
409
+ var vertex = this.getPosition();
410
+ vertex.marker = this;
411
+
412
+ if(this.editIndex == polyline.getPath().getLength() - 1) {
413
+ str.updateMarkerLocation_(vertex);
414
+ vertex = this.getPosition();
415
+ }
416
+
417
+ google.maps.event.trigger(
418
+ polyline,
419
+ 'update_at',
420
+ this.editIndex,
421
+ vertex
422
+ );
423
+ eventHandlers["TriggerRoadAccessChanged"](polyline);
424
+ }
425
+
426
+ function createMarkerVertex(point) {
427
+
428
+ var vertex = point.marker;
429
+
430
+ if (!vertex){
431
+ if (polyline.getPath().getAt(0) == point) {
432
+ vertex = sm;
433
+ } else if (polyline.getPath().getAt(polyline.getPath().getLength()-1) == point) {
434
+ vertex = em;
435
+ } else {
436
+ vertex = new google.maps.Marker({
437
+ position: point,
438
+ map: polyline.getMap(),
439
+ icon: pointIcon,//handleIcon,//imgVertex,
440
+ draggable: true,
441
+ raiseOnDrag: false
442
+ });
443
+ }
444
+ google.maps.event.addListener(vertex, "drag", vertexDrag);
445
+ google.maps.event.addListener(vertex, "dragend", vertexDragEnd);
446
+
447
+ //google.maps.event.addListener(vertex, "rightclick", vertexRightClick);
448
+
449
+ point.marker = vertex;
450
+ }
451
+
452
+ vertex.setPosition(point);
453
+
454
+ return vertex;
455
+ }
456
+
457
+ function PolylineCustomEditWidget(map, polyline, sm, em, str, eventHandlers, currentPolylineCustomEdit, isMobile) {
458
+
459
+ polyline.setMap(map);
460
+
461
+ polyline.getPath().forEach(function (vertex, index) {
462
+ createMarkerVertex(vertex).editIndex = index;
463
+ createGhostMarkerVertex(vertex);
464
+
465
+ });
466
+
467
+ currentPolylineCustomEdit = polyline;
468
+
469
+ return currentPolylineCustomEdit;
470
+ }
471
+
472
+ PolylineCustomEditWidget.prototype = new google.maps.MVCObject();
473
+
474
+ return new PolylineCustomEditWidget(map, polyline, sm, em, str, eventHandlers, currentPolylineCustomEdit, isMobile);
475
+
476
+ };
477
+ }
478
+
@@ -0,0 +1,5 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+
3
+ export const generateUniqueId = (prefix: string = 'map'): string => {
4
+ return `${prefix}-${uuidv4()}`;
5
+ };
@@ -0,0 +1,52 @@
1
+ export function createSvgIcon(options) {
2
+ const { iconName = "pinIcon", fillColor = '#f1a81e', width = 30, height = 41, strokeColor = '#000000', strokeWidth = 1 } = options;
3
+ const svgNamespace = "http://www.w3.org/2000/svg";
4
+
5
+ const svgIcon = document.createElementNS(svgNamespace, "svg");
6
+ svgIcon.setAttribute("viewBox", "0 0 57.64 83.57");
7
+ svgIcon.setAttribute("width", width);
8
+ svgIcon.setAttribute("height", height);
9
+ svgIcon.style.opacity = 0.8;
10
+ svgIcon.style.zIndex = 11000;
11
+
12
+ const defs = document.createElementNS(svgNamespace, "defs");
13
+
14
+ const clipPath = document.createElementNS(svgNamespace, "clipPath");
15
+ clipPath.setAttribute("id", `clippath-${iconName}`);
16
+ const rect = document.createElementNS(svgNamespace, "rect");
17
+ rect.setAttribute("width", "57.64");
18
+ rect.setAttribute("height", "83.57");
19
+ defs.appendChild(clipPath);
20
+ clipPath.appendChild(rect);
21
+
22
+ const style = document.createElementNS(svgNamespace, "style");
23
+ style.textContent = `
24
+ .cls-1 { clip-path: url(#clippath-${iconName}); }
25
+ .cls-2 { fill: none; stroke: ${strokeColor}; stroke-width: ${strokeWidth}; }
26
+ .cls-3 { fill: ${fillColor}; }
27
+ `;
28
+ defs.appendChild(style);
29
+ svgIcon.appendChild(defs);
30
+
31
+ const g = document.createElementNS(svgNamespace, "g");
32
+ g.setAttribute("class", "cls-1");
33
+
34
+ const pathData = {
35
+ 'pinIcon': 'M16.01,31.23c-.07,7.22,5.73,12.51,11.98,12.86,3.84.22,7.17-1.04,9.9-3.73,2.36-2.32,3.64-5.2,3.77-8.49.31-7.8-5.87-13.21-12.29-13.47-7.66-.3-13.54,6.01-13.37,12.83M28.82.1c.43,0,.87-.03,1.3,0,.98.07,1.97.16,2.95.27,1.85.21,3.65.69,5.4,1.31,1.89.66,3.68,1.52,5.38,2.57,1.49.91,2.88,1.95,4.18,3.12,1.68,1.51,3.21,3.15,4.45,5.04.84,1.29,1.65,2.62,2.35,4,1.05,2.06,1.76,4.25,2.2,6.52.25,1.25.41,2.53.5,3.81.1,1.31.15,2.64.07,3.95-.15,2.38-.58,4.72-1.32,6.99-.64,1.97-1.49,3.87-2.54,5.67-1.07,1.83-2.08,3.7-3.13,5.54-.82,1.44-1.67,2.87-2.49,4.31-.8,1.39-1.58,2.78-2.37,4.17-.83,1.45-1.68,2.89-2.51,4.33-.68,1.18-1.34,2.37-2.02,3.55-1.3,2.26-2.61,4.52-3.91,6.79-1.02,1.77-2.02,3.55-3.04,5.32-.92,1.6-1.79,3.24-2.79,4.79-1.33,2.04-4.29,1.81-5.44-.18-1.33-2.3-2.67-4.6-3.99-6.91-1.42-2.46-2.82-4.93-4.23-7.39-1.18-2.06-2.36-4.12-3.54-6.18-1.36-2.37-2.74-4.73-4.1-7.1-1.29-2.25-2.57-4.5-3.83-6.76-1.21-2.17-2.46-4.32-3.6-6.53-1-1.93-1.66-4.01-2.09-6.14-.31-1.54-.58-3.09-.58-4.67,0-.48-.08-.96-.06-1.43.07-1.28.16-2.57.28-3.85.18-1.93.66-3.8,1.3-5.62.75-2.13,1.72-4.16,2.94-6.06,1.27-1.98,2.75-3.79,4.45-5.41,1.55-1.47,3.26-2.75,5.1-3.85,1.63-.98,3.36-1.77,5.14-2.42,1.61-.59,3.28-1.02,4.97-1.26,1.53-.22,3.09-.28,4.63-.41v.1'
36
+ };
37
+
38
+ const fillPath = document.createElementNS(svgNamespace, "path");
39
+ fillPath.setAttribute("class", "cls-3");
40
+ fillPath.setAttribute("d", pathData[iconName] || '');
41
+
42
+ const outlinePath = document.createElementNS(svgNamespace, "path");
43
+ outlinePath.setAttribute("class", "cls-2");
44
+ outlinePath.setAttribute("d", pathData[iconName] || '');
45
+
46
+ g.appendChild(fillPath);
47
+ g.appendChild(outlinePath);
48
+
49
+ svgIcon.appendChild(g);
50
+
51
+ return svgIcon;
52
+ }
@@ -0,0 +1,88 @@
1
+ import { Field } from "../interfaces/Data/Field";
2
+
3
+ export class ClearHTML {
4
+ static clearString(str: string): string {
5
+ return str
6
+ .replace(/&/g, "&amp;")
7
+ .replace(/>/g, "&gt;")
8
+ .replace(/</g, "&lt;")
9
+ .replace(/"/g, "&quot;");
10
+ }
11
+ }
12
+
13
+ export function formatFieldContent(location: Field): string {
14
+ let content = `${location.FarmName} - ${location.LocationName}<br>${location.Area} ha${location.IsIrrigated ? ', irrigated' : ''}`;
15
+
16
+ if (location.CropPlanted) {
17
+ content += `<br>${location.CropPlanted}`;
18
+ if (location.CultivarPlanted) {
19
+ content += ` (${location.CultivarPlanted})`;
20
+ }
21
+ if (location.PlantingDate) {
22
+ content += `<br>Planted: ${location.PlantingDate.replace(/-/g, "/")}`;
23
+ }
24
+ }
25
+ return content;
26
+ }
27
+
28
+ let tooltipElement: HTMLDivElement | null = null;
29
+
30
+ export const showTooltip = (
31
+ event: google.maps.KmlMouseEvent,
32
+ content: string,
33
+ map: google.maps.Map
34
+ ): void => {
35
+ if (!tooltipElement && event.latLng) {
36
+ const overlay = new google.maps.OverlayView();
37
+ overlay.setMap(map);
38
+ overlay.draw = () => {};
39
+
40
+ const point = overlay.getProjection().fromLatLngToDivPixel(event.latLng);
41
+
42
+ tooltipElement = document.createElement('div');
43
+ tooltipElement.style.cssText = `
44
+ position: fixed;
45
+ background: rgba(0, 0, 0, 0.75);
46
+ color: #ffffff;
47
+ border-radius: 4px;
48
+ padding: 8px 12px;
49
+ font-size: 12px;
50
+ z-index: 1000;
51
+ pointer-events: none;
52
+ white-space: nowrap;
53
+ `;
54
+ tooltipElement.innerHTML = content;
55
+
56
+ if (point) {
57
+ tooltipElement.style.top = `${point.y + 10}px`;
58
+ tooltipElement.style.left = `${point.x + 10}px`;
59
+ }
60
+
61
+ document.body.appendChild(tooltipElement);
62
+ }
63
+ };
64
+
65
+ export const moveTooltip = (
66
+ event: google.maps.KmlMouseEvent,
67
+ map: google.maps.Map,
68
+ offset = { x: 10, y: 10 }
69
+ ): void => {
70
+ if (tooltipElement && event.latLng) {
71
+ const overlay = new google.maps.OverlayView();
72
+ overlay.setMap(map);
73
+ overlay.draw = () => {};
74
+
75
+ const point = overlay.getProjection().fromLatLngToDivPixel(event.latLng);
76
+ if (point) {
77
+ tooltipElement!.style.top = `${point.y + offset.y}px`;
78
+ tooltipElement!.style.left = `${point.x + offset.x}px`;
79
+ }
80
+ }
81
+ };
82
+
83
+ export const hideTooltip = (): void => {
84
+ if (tooltipElement) {
85
+ document.body.removeChild(tooltipElement);
86
+ tooltipElement = null;
87
+ }
88
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "esModuleInterop": true,
8
+ "allowSyntheticDefaultImports": true,
9
+ "strict": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "noFallthroughCasesInSwitch": true,
12
+ "module": "ESNext",
13
+ "moduleResolution": "Node",
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "noEmit": true,
17
+ "jsx": "react-jsx"
18
+ },
19
+ "include": ["src"]
20
+ }