@syncfusion/ej2-maps 19.4.53 → 19.4.56-105067

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 (84) hide show
  1. package/.eslintrc.json +18 -3
  2. package/.github/PULL_REQUEST_TEMPLATE/Bug.md +72 -72
  3. package/.github/PULL_REQUEST_TEMPLATE/Feature.md +49 -49
  4. package/CHANGELOG.md +441 -422
  5. package/README.md +73 -73
  6. package/dist/ej2-maps.umd.min.js +1 -10
  7. package/dist/ej2-maps.umd.min.js.map +1 -1
  8. package/dist/es6/ej2-maps.es2015.js +1220 -653
  9. package/dist/es6/ej2-maps.es2015.js.map +1 -1
  10. package/dist/es6/ej2-maps.es5.js +1258 -692
  11. package/dist/es6/ej2-maps.es5.js.map +1 -1
  12. package/dist/global/ej2-maps.min.js +1 -10
  13. package/dist/global/ej2-maps.min.js.map +1 -1
  14. package/dist/global/index.d.ts +0 -9
  15. package/dist/ts/maps/layers/bing-map.ts +50 -0
  16. package/dist/ts/maps/layers/bubble.ts +290 -0
  17. package/dist/ts/maps/layers/color-mapping.ts +226 -0
  18. package/dist/ts/maps/layers/data-label.ts +418 -0
  19. package/dist/ts/maps/layers/layer-panel.ts +1480 -0
  20. package/dist/ts/maps/layers/legend.ts +2236 -0
  21. package/dist/ts/maps/layers/marker.ts +453 -0
  22. package/dist/ts/maps/layers/navigation-selected-line.ts +167 -0
  23. package/dist/ts/maps/maps.ts +2886 -0
  24. package/dist/ts/maps/model/base.ts +1843 -0
  25. package/dist/ts/maps/model/constants.ts +200 -0
  26. package/dist/ts/maps/model/export-image.ts +178 -0
  27. package/dist/ts/maps/model/export-pdf.ts +170 -0
  28. package/dist/ts/maps/model/interface.ts +823 -0
  29. package/dist/ts/maps/model/print.ts +104 -0
  30. package/dist/ts/maps/model/theme.ts +554 -0
  31. package/dist/ts/maps/user-interaction/annotation.ts +127 -0
  32. package/dist/ts/maps/user-interaction/highlight.ts +233 -0
  33. package/dist/ts/maps/user-interaction/selection.ts +321 -0
  34. package/dist/ts/maps/user-interaction/tooltip.ts +387 -0
  35. package/dist/ts/maps/user-interaction/zoom.ts +1767 -0
  36. package/dist/ts/maps/utils/enum.ts +368 -0
  37. package/dist/ts/maps/utils/helper.ts +3421 -0
  38. package/helper/e2e/index.js +3 -3
  39. package/helper/e2e/maps-helper.js +13 -13
  40. package/license +9 -9
  41. package/package.json +85 -85
  42. package/src/maps/layers/bing-map.d.ts +4 -0
  43. package/src/maps/layers/bing-map.js +16 -3
  44. package/src/maps/layers/bubble.d.ts +1 -2
  45. package/src/maps/layers/bubble.js +7 -12
  46. package/src/maps/layers/data-label.d.ts +1 -4
  47. package/src/maps/layers/data-label.js +32 -35
  48. package/src/maps/layers/layer-panel.d.ts +18 -1
  49. package/src/maps/layers/layer-panel.js +226 -72
  50. package/src/maps/layers/legend.d.ts +5 -2
  51. package/src/maps/layers/legend.js +170 -61
  52. package/src/maps/layers/marker.d.ts +2 -4
  53. package/src/maps/layers/marker.js +49 -48
  54. package/src/maps/layers/navigation-selected-line.d.ts +1 -2
  55. package/src/maps/layers/navigation-selected-line.js +7 -13
  56. package/src/maps/maps-model.d.ts +259 -251
  57. package/src/maps/maps.d.ts +25 -3
  58. package/src/maps/maps.js +179 -106
  59. package/src/maps/model/base-model.d.ts +1025 -1021
  60. package/src/maps/model/base.d.ts +5 -1
  61. package/src/maps/model/base.js +24 -24
  62. package/src/maps/model/constants.d.ts +6 -0
  63. package/src/maps/model/constants.js +6 -0
  64. package/src/maps/model/export-image.d.ts +2 -4
  65. package/src/maps/model/export-image.js +34 -33
  66. package/src/maps/model/export-pdf.d.ts +4 -6
  67. package/src/maps/model/export-pdf.js +31 -32
  68. package/src/maps/model/interface.d.ts +34 -26
  69. package/src/maps/model/print.d.ts +2 -5
  70. package/src/maps/model/print.js +32 -18
  71. package/src/maps/model/theme.js +7 -4
  72. package/src/maps/user-interaction/annotation.d.ts +1 -2
  73. package/src/maps/user-interaction/annotation.js +3 -4
  74. package/src/maps/user-interaction/highlight.d.ts +1 -2
  75. package/src/maps/user-interaction/highlight.js +11 -10
  76. package/src/maps/user-interaction/selection.d.ts +1 -2
  77. package/src/maps/user-interaction/selection.js +42 -19
  78. package/src/maps/user-interaction/tooltip.d.ts +3 -5
  79. package/src/maps/user-interaction/tooltip.js +27 -14
  80. package/src/maps/user-interaction/zoom.d.ts +3 -8
  81. package/src/maps/user-interaction/zoom.js +282 -162
  82. package/src/maps/utils/enum.d.ts +5 -1
  83. package/src/maps/utils/helper.d.ts +9 -1
  84. package/src/maps/utils/helper.js +82 -33
@@ -0,0 +1,2236 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable max-len */
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
4
+ import { Maps } from '../../index';
5
+ import {
6
+ LayerSettings, ColorMappingSettings, BorderModel, LegendPosition, FontModel, LegendSettingsModel,
7
+ click, ILegendRenderingEventArgs, legendRendering,
8
+ MarkerSettingsModel, MarkerSettings, LegendShape, LabelPosition, LabelIntersectAction
9
+ } from '../index';
10
+ import { LegendArrangement, LegendMode } from '../index';
11
+ import {
12
+ Rect, measureText, CircleOption, PathOption, textTrim, drawBalloon,
13
+ removeClass, querySelector, getTemplateFunction, maintainStyleClass, getValueFromObject
14
+ } from '../utils/helper';
15
+ import { RectOption, Size, TextOption, Point, renderTextElement, drawSymbol, checkPropertyPath, getElement } from '../utils/helper';
16
+ import { isNullOrUndefined, Browser, EventHandler, remove, extend } from '@syncfusion/ej2-base';
17
+ import { SvgRenderer } from '@syncfusion/ej2-svg-base';
18
+ import { LayerSettingsModel, HighlightSettingsModel, SelectionSettingsModel } from '../model/base-model';
19
+ import { ShapeSettings } from '../model/base';
20
+ /**
21
+ * Legend module is used to render legend for the maps
22
+ */
23
+ export class Legend {
24
+ /**
25
+ * @private
26
+ */
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ public legendCollection: any[];
29
+ /**
30
+ * @private
31
+ */
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ public legendRenderingCollections: any[];
34
+ private translate: Point;
35
+ /**
36
+ * @private
37
+ */
38
+ public legendBorderRect: Rect = new Rect(0, 0, 0, 0);
39
+ /**
40
+ * @private
41
+ */
42
+ public initialMapAreaRect: Rect = new Rect(0, 0, 0, 0);
43
+ /**
44
+ * @private
45
+ */
46
+ public legendTotalRect: Rect = new Rect(0, 0, 0, 0);
47
+ private maps: Maps;
48
+ /**
49
+ * @private
50
+ */
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ public totalPages: any[] = [];
53
+ private page: number = 0;
54
+ /**
55
+ * @private
56
+ */
57
+ public currentPage: number = 0;
58
+ private legendItemRect: Rect = new Rect(0, 0, 0, 0);
59
+ private heightIncrement: number = 0;
60
+ private widthIncrement: number = 0;
61
+ private textMaxWidth: number = 0;
62
+ /**
63
+ * @private
64
+ */
65
+ public legendGroup: Element;
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ private shapeHighlightCollection: any[] = [];
68
+ /**
69
+ * @private
70
+ */
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ public legendHighlightCollection: any[] = [];
73
+ /**
74
+ * @private
75
+ */
76
+ public shapePreviousColor: string[] = [];
77
+ /**
78
+ * @private
79
+ */
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ public selectedNonLegendShapes: any[] = [];
82
+ /**
83
+ * @private
84
+ */
85
+ public shapeToggled: boolean = true;
86
+ private legendLinearGradient: Element;
87
+ private currentLayer: LayerSettings;
88
+ private defsElement: Element;
89
+ /**
90
+ * @private
91
+ */
92
+ public legendElement: Element[] = null;
93
+ /**
94
+ * @private
95
+ */
96
+ public oldShapeElement: Element;
97
+ constructor(maps: Maps) {
98
+ this.maps = maps;
99
+ this.addEventListener();
100
+ }
101
+ /**
102
+ * To calculate legend bounds and draw the legend shape and text.
103
+ *
104
+ * @returns {void}
105
+ */
106
+ public renderLegend(): void {
107
+ this.legendRenderingCollections = [];
108
+ this.legendCollection = [];
109
+ this.totalPages = [];
110
+ this.widthIncrement = 0;
111
+ this.heightIncrement = 0;
112
+ this.defsElement = this.maps.renderer.createDefs();
113
+ this.maps.svgObject.appendChild(this.defsElement);
114
+ this.initialMapAreaRect = this.maps.mapAreaRect;
115
+ this.calculateLegendBounds();
116
+ this.drawLegend();
117
+ }
118
+
119
+ public calculateLegendBounds(): void {
120
+ const map: Maps = this.maps;
121
+ const legend: LegendSettingsModel = <LegendSettingsModel>map.legendSettings;
122
+ this.legendCollection = [];
123
+ const spacing: number = 10;
124
+ const leftPadding: number = 10; const topPadding: number = map.mapAreaRect.y;
125
+ this.legendRenderingCollections = [];
126
+ Array.prototype.forEach.call(map.layersCollection, (layer: LayerSettings, layerIndex: number) => {
127
+ if (!isNullOrUndefined(layer.shapeData)) {
128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
+ const layerData: any[] = layer.shapeData['features'];
130
+ const dataPath: string = layer.shapeDataPath;
131
+ const propertyPath: string | string[] = layer.shapePropertyPath;
132
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
+ let dataSource: any[] = layer.dataSource as any[];
134
+ let colorValuePath: string;
135
+ let colorMapping: ColorMappingSettings[];
136
+ if (legend.type === 'Layers' && layer.visible) {
137
+ colorValuePath = layer.shapeSettings.colorValuePath;
138
+ colorMapping = <ColorMappingSettings[]>layer.shapeSettings.colorMapping;
139
+ this.getLegends(layerIndex, layerData, colorMapping, dataSource, dataPath, colorValuePath, propertyPath);
140
+ } else if (legend.type === 'Bubbles') {
141
+ for (const bubble of layer.bubbleSettings) {
142
+ if (bubble.visible) {
143
+ colorValuePath = bubble.colorValuePath;
144
+ colorMapping = <ColorMappingSettings[]>bubble.colorMapping;
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
+ dataSource = bubble.dataSource as any[];
147
+ this.getLegends(layerIndex, layerData, colorMapping, dataSource, dataPath, colorValuePath, propertyPath);
148
+ }
149
+ }
150
+ }
151
+ }
152
+ if (legend.type === 'Markers') {
153
+ this.getMarkersLegendCollections(layerIndex, layer.markerSettings);
154
+ }
155
+ });
156
+ if (this.legendCollection.length > 0) {
157
+ for (let i: number = 0; i < this.legendCollection.length; i++) {
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ const legendItem: any = this.legendCollection[i];
160
+ const eventArgs: ILegendRenderingEventArgs = {
161
+ name: legendRendering, cancel: false, fill: legendItem['fill'], shape: legend.shape,
162
+ shapeBorder: legend.shapeBorder,
163
+ text: typeof legendItem['text'] === 'number' ? legendItem['text'].toString() : legendItem['text']
164
+ };
165
+ map.trigger('legendRendering', eventArgs);
166
+ legendItem['fill'] = eventArgs.fill;
167
+ legendItem['shape'] = eventArgs.shape;
168
+ legendItem['shapeBorder'] = eventArgs.shapeBorder;
169
+ legendItem['text'] = eventArgs.text;
170
+ if (eventArgs.cancel) {
171
+ this.legendCollection.splice(i, 1);
172
+ i--;
173
+ }
174
+ }
175
+ }
176
+ const defaultSize: number = 25;
177
+ const legendTitle: string = map.legendSettings.title.text;
178
+ const titleTextStyle: FontModel = map.legendSettings.titleStyle;
179
+ if (this.legendCollection.length > 0) {
180
+ const legendMode: LegendMode = legend.mode;
181
+ let shapeX: number = 0; let shapeY: number = 0;
182
+ let textX: number = 0; let textY: number = 0;
183
+ const shapePadding: number = legend.shapePadding;
184
+ const textPadding: number = 10;
185
+ const shapeHeight: number = legend.shapeHeight; const shapeWidth: number = legend.shapeWidth;
186
+ let shapeLocation: Point[] = []; let textLocation: Rect[] = [];
187
+ let legendRectCollection: Rect[] = [];
188
+ let location: Point;
189
+ const position: LegendPosition = legend.position;
190
+ const labelAction: LabelIntersectAction = legend.labelDisplayMode;
191
+ const arrangement: LegendArrangement = (legend.orientation === 'None') ? ((position === 'Top' || position === 'Bottom')
192
+ ? 'Horizontal' : 'Vertical') : legend.orientation;
193
+ let legendWidth: number = (legend.width.length > 1) ? (legend.width.indexOf('%') > -1) ? (map.availableSize.width / 100)
194
+ * parseInt(legend.width, 10) : parseInt(legend.width, 10) : null;
195
+ let legendHeight: number = (legend.height.length > 1) ? (legend.height.indexOf('%') > -1) ? (map.availableSize.height / 100) *
196
+ parseInt(legend.height, 10) : parseInt(legend.height, 10) : null;
197
+ let legendItemStartX: number; let legendItemStartY: number;
198
+ let startX: number = 0; let startY: number = 0;
199
+ const legendtitleSize: Size = measureText(legendTitle, titleTextStyle);
200
+ if (legendMode === 'Interactive') {
201
+ const itemTextStyle: FontModel = legend.textStyle;
202
+ const legendLength: number = this.legendCollection.length;
203
+ const rectWidth: number = (arrangement === 'Horizontal') ? (isNullOrUndefined(legendWidth)) ? (map.mapAreaRect.width / legendLength) :
204
+ (legendWidth / legendLength) : (isNullOrUndefined(legendWidth)) ? defaultSize : legendWidth;
205
+ const rectHeight: number = (arrangement === 'Horizontal') ? (isNullOrUndefined(legendHeight)) ? defaultSize : legendHeight :
206
+ (isNullOrUndefined(legendHeight)) ? (map.mapAreaRect.height / legendLength) : (legendHeight / legendLength);
207
+ startX = 0; startY = legendtitleSize.height + spacing;
208
+ const position: LabelPosition = legend.labelPosition;
209
+ let textX: number = 0; let textY: number = 0; const textPadding: number = 10;
210
+ let itemStartX: number = 0; let itemStartY: number = 0;
211
+ let maxTextHeight: number = 0; let maxTextWidth: number = 0;
212
+ for (let i: number = 0; i < this.legendCollection.length; i++) {
213
+ startX = (arrangement === 'Horizontal') ? (startX + rectWidth) : startX;
214
+ startY = (arrangement === 'Horizontal') ? startY : (startY + rectHeight);
215
+ let legendText: string = this.legendCollection[i]['text'];
216
+ let itemTextSize: Size = new Size(0, 0);
217
+ if (labelAction === 'None') {
218
+ itemTextSize = measureText(legendText, itemTextStyle);
219
+ } else if (labelAction === 'Trim') {
220
+ legendText = textTrim((arrangement === 'Horizontal' ? rectWidth : rectHeight), legendText, itemTextStyle);
221
+ itemTextSize = measureText(legendText, itemTextStyle);
222
+ } else {
223
+ legendText = '';
224
+ }
225
+ maxTextHeight = Math.max(maxTextHeight, itemTextSize.height);
226
+ maxTextWidth = Math.max(maxTextWidth, itemTextSize.width);
227
+ if (itemTextSize.width > 0 && itemTextSize.height > 0) {
228
+ if (arrangement === 'Horizontal') {
229
+ textX = startX + (rectWidth / 2);
230
+ textY = (position === 'After') ? (startY + rectHeight + (itemTextSize.height / 2)) + textPadding :
231
+ (startY - textPadding);
232
+ } else {
233
+ textX = (position === 'After') ? startX - (itemTextSize.width / 2) - textPadding
234
+ : (startX + rectWidth + itemTextSize.width / 2) + textPadding;
235
+ textY = startY + (rectHeight / 2) + (itemTextSize.height / 4);
236
+ }
237
+ }
238
+ if (i === 0) {
239
+ itemStartX = (arrangement === 'Horizontal') ? startX : (position === 'After') ?
240
+ textX - (itemTextSize.width / 2) : startX;
241
+ itemStartY = (arrangement === 'Horizontal') ? (position === 'After') ? startY :
242
+ textY - (itemTextSize.height / 2) : startY;
243
+ if (this.legendCollection.length === 1) {
244
+ legendWidth = (arrangement === 'Horizontal') ? Math.abs((startX + rectWidth) - itemStartX) :
245
+ (rectWidth + maxTextWidth + textPadding);
246
+ legendHeight = (arrangement === 'Horizontal') ? (rectHeight + (maxTextHeight / 2) + textPadding) :
247
+ Math.abs((startY + rectHeight) - itemStartY);
248
+ }
249
+ } else if (i === this.legendCollection.length - 1) {
250
+ legendWidth = (arrangement === 'Horizontal') ? Math.abs((startX + rectWidth) - itemStartX) :
251
+ (rectWidth + maxTextWidth + textPadding);
252
+ legendHeight = (arrangement === 'Horizontal') ? (rectHeight + (maxTextHeight / 2) + textPadding) :
253
+ Math.abs((startY + rectHeight) - itemStartY);
254
+ }
255
+ this.legendRenderingCollections.push({
256
+ fill: this.legendCollection[i]['fill'], x: startX, y: startY,
257
+ width: rectWidth, height: rectHeight,
258
+ text: legendText, textX: textX, textY: textY,
259
+ textWidth: itemTextSize.width, textHeight: itemTextSize.height,
260
+ shapeBorder: this.legendCollection[i]['shapeBorder']
261
+ });
262
+ }
263
+ if (this.legendCollection.length === 1) {
264
+ legendHeight = rectHeight;
265
+ legendWidth = rectWidth;
266
+ }
267
+ this.legendItemRect = { x: itemStartX, y: itemStartY, width: legendWidth, height: legendHeight };
268
+ } else {
269
+ legendWidth = (isNullOrUndefined(legendWidth)) ? map.mapAreaRect.width : legendWidth;
270
+ legendHeight = (isNullOrUndefined(legendHeight)) ? map.mapAreaRect.height : legendHeight;
271
+ let j: number = 0;
272
+ this.page = 0;
273
+ for (let i: number = 0; i < this.legendCollection.length; i++) {
274
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
275
+ const legendItem: any = this.legendCollection[i];
276
+ if (isNullOrUndefined(this.totalPages[this.page])) {
277
+ this.totalPages[this.page] = { Page: (this.page + 1), Collection: [] };
278
+ }
279
+ const legendTextSize: Size = measureText(legendItem['text'], legend.textStyle);
280
+ this.textMaxWidth = Math.max(this.textMaxWidth, legendTextSize.width);
281
+ if (i === 0) {
282
+ startX = shapeX = (leftPadding + (shapeWidth / 2));
283
+ startY = shapeY = topPadding + legendtitleSize.height + (shapeHeight > legendTextSize.height ? shapeHeight / 2
284
+ : (legendTextSize.height / 4));
285
+ } else {
286
+ const maxSize: number = (legendTextSize.height > shapeHeight) ? legendTextSize.height : shapeHeight;
287
+ if (arrangement === 'Horizontal') {
288
+ const prvePositionX: number = (textLocation[j - 1].x + textLocation[j - 1].width) + textPadding + shapeWidth;
289
+ if ((prvePositionX + shapePadding + legendTextSize.width) > legendWidth) {
290
+ const nextPositionY: number = (textLocation[j - 1].y > (shapeLocation[j - 1].y + (shapeHeight / 2)) ?
291
+ textLocation[j - 1].y : (shapeLocation[j - 1].y + (shapeHeight / 2))) + topPadding;
292
+ if ((nextPositionY + maxSize) > legendHeight) {
293
+ this.getPageChanged();
294
+ j = 0;
295
+ shapeLocation = [];
296
+ textLocation = [];
297
+ legendRectCollection = [];
298
+ shapeX = startX;
299
+ shapeY = startY;
300
+ } else {
301
+ shapeX = (shapeLocation[0].x);
302
+ shapeY = (nextPositionY + (maxSize / 2));
303
+ }
304
+ } else {
305
+ shapeX = (prvePositionX - (shapeWidth / 2));
306
+ shapeY = (shapeLocation[j - 1]).y;
307
+ }
308
+ } else {
309
+ const prevPositionY: number = textLocation[j - 1].y > shapeLocation[j - 1].y + (shapeHeight / 2) ?
310
+ textLocation[j - 1].y : shapeLocation[j - 1].y + (shapeHeight / 2);
311
+ if ((prevPositionY + topPadding + maxSize) > legendHeight) {
312
+ const nextPositionX: number = (textLocation[j - 1].x + this.textMaxWidth + textPadding);
313
+ if ((nextPositionX + shapePadding + legendTextSize.width) > legendWidth) {
314
+ shapeX = startX;
315
+ shapeY = startY;
316
+ legendRectCollection = [];
317
+ textLocation = [];
318
+ shapeLocation = [];
319
+ this.getPageChanged();
320
+ j = 0;
321
+ } else {
322
+ shapeX = nextPositionX + (shapeWidth / 2);
323
+ shapeY = (shapeLocation[0].y);
324
+ }
325
+ } else {
326
+ let padding: number = 10;
327
+ shapeX = shapeLocation[j - 1].x;
328
+ shapeY = prevPositionY + padding + (shapeHeight / 2);
329
+ }
330
+ }
331
+ }
332
+ textX = shapeX + (shapeWidth / 2) + shapePadding;
333
+ textY = shapeY + (legendTextSize.height / 4);
334
+ shapeLocation.push({ x: shapeX, y: shapeY });
335
+ textLocation.push({ x: textX, y: textY, width: legendTextSize.width, height: (legendTextSize.height / 2) });
336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
+ (<any[]>this.totalPages[this.page]['Collection']).push({
338
+ DisplayText: legendItem['text'],
339
+ ImageSrc: legendItem['imageSrc'],
340
+ Shape: { x: shapeX, y: shapeY },
341
+ Text: { x: textX, y: textY },
342
+ Fill: legendItem['fill'],
343
+ legendShape: legendItem['shape'],
344
+ shapeBorder: legendItem['shapeBorder'],
345
+ idIndex: i,
346
+ Rect: {
347
+ x: shapeLocation[j].x - (shapeWidth / 2),
348
+ y: (shapeLocation[j].y - (shapeHeight / 2)) < (textY - legendTextSize.height) ?
349
+ (shapeLocation[j].y - (shapeHeight / 2)) : (textY - legendTextSize.height),
350
+ width: Math.abs((shapeLocation[j].x - (shapeWidth / 2)) - (textX + legendTextSize.width)),
351
+ height: ((shapeHeight > legendTextSize.height) ? shapeHeight : legendTextSize.height)
352
+ }
353
+ });
354
+ j++;
355
+ }
356
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
357
+ const collection: any[] = (<any[]>this.totalPages[0]['Collection']);
358
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
359
+ Array.prototype.forEach.call(collection, (legendObj: any, index: number) => {
360
+ const legendRect: Rect = new Rect(
361
+ legendObj['Rect']['x'], legendObj['Rect']['y'],
362
+ legendObj['Rect']['width'], legendObj['Rect']['height']
363
+ );
364
+ if (index === 0) {
365
+ legendItemStartX = legendRect.x;
366
+ legendItemStartY = legendRect.y;
367
+ }
368
+ this.widthIncrement = Math.max(this.widthIncrement, Math.abs(legendItemStartX - (legendRect.x + legendRect.width)));
369
+ this.heightIncrement = Math.max(this.heightIncrement, Math.abs(legendItemStartY - (legendRect.y + legendRect.height)));
370
+ });
371
+ legendWidth = ((this.widthIncrement < legendWidth) ? this.widthIncrement : legendWidth);
372
+ legendHeight = ((this.heightIncrement < legendHeight) ? this.heightIncrement : legendHeight);
373
+ this.legendItemRect = {
374
+ x: collection[0]['Rect']['x'], y: collection[0]['Rect']['y'],
375
+ width: legendWidth, height: legendHeight
376
+ };
377
+ }
378
+ }
379
+ }
380
+ /**
381
+ * Get the legend collections
382
+ *
383
+ * @param {number} layerIndex - Specifies the layer index
384
+ * @param {object[]} layerData - Specifies the layer data
385
+ * @param {ColorMappingSettings[]} colorMapping - Specifies the color mapping
386
+ * @param {object[]} dataSource - Specifies the data source
387
+ * @param {string} dataPath - Specifies the data path
388
+ * @param {string} colorValuePath - Specifies the color value path
389
+ * @param {string | string[]} propertyPath - Specifies the property path
390
+ * @returns {void}
391
+ */
392
+ private getLegends(
393
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
394
+ layerIndex: number, layerData: any[], colorMapping: ColorMappingSettings[], dataSource: any[],
395
+ dataPath: string, colorValuePath: string, propertyPath: string | string[]
396
+ ): void {
397
+ this.getRangeLegendCollection(layerIndex, layerData, colorMapping, dataSource, dataPath, colorValuePath, propertyPath);
398
+ this.getEqualLegendCollection(layerIndex, layerData, colorMapping, dataSource, dataPath, colorValuePath, propertyPath);
399
+ this.getDataLegendCollection(layerIndex, layerData, colorMapping, dataSource, dataPath, colorValuePath, propertyPath);
400
+ }
401
+ private getPageChanged(): void {
402
+ this.page++;
403
+ if (isNullOrUndefined(this.totalPages[this.page])) {
404
+ this.totalPages[this.page] = { Page: (this.page + 1), Collection: [] };
405
+ }
406
+ }
407
+
408
+ private legendTextTrim(maxWidth: number, text: string, font: FontModel, legendRectSize: number): string {
409
+ let label: string = text;
410
+ let size: number = measureText(text, font).width;
411
+ const legendWithoutTextSize : number = legendRectSize - size;
412
+ if (legendRectSize > maxWidth) {
413
+ const textLength: number = text.length;
414
+ for (let i: number = textLength - 1; i >= 0; --i) {
415
+ label = text.substring(0, i) + '...';
416
+ size = measureText(label, font).width;
417
+ const totalSize : number = legendWithoutTextSize + size;
418
+ if (totalSize <= maxWidth || label.length < 4) {
419
+ if (label.length < 4) {
420
+ label = ' ';
421
+ }
422
+ return label;
423
+ }
424
+ }
425
+ }
426
+ return label;
427
+ }
428
+
429
+ // eslint-disable-next-line valid-jsdoc
430
+ /**
431
+ * To draw the legend shape and text.
432
+ */
433
+ public drawLegend(): void {
434
+ const map: Maps = this.maps;
435
+ const legend: LegendSettingsModel = <LegendSettingsModel>map.legendSettings;
436
+ const render: SvgRenderer = map.renderer;
437
+ let textOptions: TextOption;
438
+ const textFont: FontModel = {
439
+ size: legend.textStyle.size,
440
+ color: legend.textStyle.color,
441
+ fontFamily: legend.textStyle.fontFamily,
442
+ fontWeight: legend.textStyle.fontWeight,
443
+ fontStyle: legend.textStyle.fontStyle,
444
+ opacity: legend.textStyle.opacity
445
+ };
446
+ this.legendGroup = render.createGroup({ id: map.element.id + '_Legend_Group' });
447
+ if (legend.mode === 'Interactive') {
448
+ for (let i: number = 0; i < this.legendRenderingCollections.length; i++) {
449
+ const itemId: string = map.element.id + '_Legend_Index_' + i;
450
+ const textId: string = map.element.id + '_Legend_Index_' + i + '_Text';
451
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
452
+ const item: any = this.legendRenderingCollections[i];
453
+ const bounds: Rect = new Rect(item['x'], item['y'], item['width'], item['height']);
454
+ if (i === 0) {
455
+ this.renderLegendBorder();
456
+ }
457
+ const textLocation: Point = new Point(item['textX'], item['textY']);
458
+ textFont.color = (textFont.color !== null) ? textFont.color : this.maps.themeStyle.legendTextColor;
459
+ const rectOptions: RectOption = new RectOption(itemId, item['fill'], item['shapeBorder'], legend.opacity, bounds);
460
+ textOptions = new TextOption(textId, textLocation.x, textLocation.y, 'middle', item['text'], '', '');
461
+ textFont.fontFamily = !isNullOrUndefined(textFont.fontFamily) ? textFont.fontFamily : this.maps.themeStyle.fontFamily;
462
+ textFont.size = map.themeStyle.legendFontSize || textFont.size;
463
+ renderTextElement(textOptions, textFont, textFont.color, this.legendGroup);
464
+ this.legendGroup.appendChild(render.drawRectangle(rectOptions));
465
+ this.legendToggle();
466
+ }
467
+ } else {
468
+ this.drawLegendItem(this.currentPage);
469
+ }
470
+ }
471
+ /**
472
+ * @param {string} page - Specifies the legend page.
473
+ * @returns {void}
474
+ * @private
475
+ */
476
+ public drawLegendItem(page: number): void {
477
+ const map: Maps = this.maps;
478
+ const legend: LegendSettingsModel = <LegendSettingsModel>map.legendSettings; const spacing: number = 10;
479
+ const shapeSize: Size = new Size(legend.shapeWidth, legend.shapeHeight);
480
+ let textOptions: TextOption; let renderOptions: CircleOption | PathOption | RectOption;
481
+ const render: SvgRenderer = map.renderer;
482
+ let legendShape: LegendShape = legend.shape;
483
+ if (page >= 0 && page < this.totalPages.length) {
484
+ if (querySelector(this.legendGroup.id, this.maps.element.id)) {
485
+ remove(querySelector(this.legendGroup.id, this.maps.element.id));
486
+ }
487
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
488
+ for (let i: number = 0; i < (<any[]>this.totalPages[page]['Collection']).length; i++) {
489
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
490
+ const collection: any = <any[]>this.totalPages[page]['Collection'][i];
491
+ const shapeBorder: BorderModel = collection['shapeBorder'];
492
+ let legendElement: Element = render.createGroup({ id: map.element.id + '_Legend_Index_' + collection['idIndex'] });
493
+ let legendText: string = collection['DisplayText'];
494
+ const pagingArrowPadding: number = 4;
495
+ const shape: LegendShape = <LegendShape>((legend.type === 'Markers') ? ((isNullOrUndefined(collection['ImageSrc'])) ?
496
+ legend.shape : 'Image') : collection['legendShape']);
497
+ const strokeColor: string = (legend.shape === 'HorizontalLine' || legend.shape === 'VerticalLine'
498
+ || legend.shape === 'Cross') ? isNullOrUndefined(legend.fill) ? '#000000' : legend.fill : shapeBorder.color;
499
+ const strokeWidth: number = (legend.shape === 'HorizontalLine' || legend.shape === 'VerticalLine'
500
+ || legend.shape === 'Cross') ? (shapeBorder.width === 0) ?
501
+ 1 : shapeBorder.width : shapeBorder.width;
502
+ const shapeId: string = map.element.id + '_Legend_Shape_Index_' + collection['idIndex'];
503
+ const textId: string = map.element.id + '_Legend_Text_Index_' + collection['idIndex'];
504
+ const shapeLocation: Point = new Point(collection['Shape']['x'], (collection['Shape']['y'] - pagingArrowPadding));
505
+ const textLocation: Point = new Point(collection['Text']['x'], (collection['Text']['y'] - pagingArrowPadding));
506
+ const imageUrl: string = ((isNullOrUndefined(collection['ImageSrc'])) ? legend.shape : collection['ImageSrc']);
507
+ const renderOptions: PathOption = new PathOption(
508
+ shapeId, collection['Fill'], strokeWidth, strokeColor, legend.opacity,
509
+ isNullOrUndefined(shapeBorder.opacity) ? legend.opacity : shapeBorder.opacity, ''
510
+ );
511
+ const legendTextStyle: FontModel = {
512
+ fontFamily: legend.textStyle.fontFamily, fontStyle: legend.textStyle.fontStyle,
513
+ fontWeight: legend.textStyle.fontWeight, size: legend.textStyle.size, color: legend.textStyle.color, opacity: legend.textStyle.opacity
514
+ };
515
+ legendTextStyle.color = (legendTextStyle.color !== null) ? legendTextStyle.color :
516
+ this.maps.themeStyle.legendTextColor;
517
+ legendTextStyle.fontFamily = !isNullOrUndefined(legendTextStyle.fontFamily) ? legendTextStyle.fontFamily : this.maps.themeStyle.fontFamily;
518
+ legendTextStyle.size = map.themeStyle.legendFontSize || legendTextStyle.size;
519
+ if (i === 0) {
520
+ this.renderLegendBorder();
521
+ }
522
+ if (legend.type === 'Markers' && legend.useMarkerShape) {
523
+ const legendShapeData: object = this.legendCollection[collection['idIndex']].data[0];
524
+ const marker: MarkerSettingsModel = map.layers[legendShapeData['layerIndex']].markerSettings[legendShapeData['markerIndex']];
525
+ legendShape = !isNullOrUndefined(marker.dataSource[legendShapeData['dataIndex']][marker['shapeValuePath']]) && marker.dataSource[legendShapeData['dataIndex']][marker['shapeValuePath']] !== '' ? marker.dataSource[legendShapeData['dataIndex']][marker['shapeValuePath']] : marker.shape;
526
+ }
527
+ if (legendShape === "Balloon") {
528
+ legendElement.appendChild(drawBalloon(map, renderOptions, shapeSize, { x: shapeLocation.x, y: (shapeLocation.y + 5)}, 'Legend'));
529
+ }
530
+ else {
531
+ legendElement.appendChild(drawSymbol(shapeLocation, legendShape, shapeSize, collection['ImageSrc'], renderOptions));
532
+ }
533
+ const legendRectSize : number = collection['Rect']['x'] + collection['Rect']['width'];
534
+ if (legendRectSize > this.legendBorderRect.width) {
535
+ const trimmedText: string = this.legendTextTrim(this.legendBorderRect.width, legendText, legendTextStyle, legendRectSize);
536
+ legendText = trimmedText;
537
+ }
538
+ textOptions = new TextOption(textId, textLocation.x, textLocation.y, 'start', legendText, '', '');
539
+ renderTextElement(textOptions, legendTextStyle, legendTextStyle.color, legendElement);
540
+ this.legendGroup.appendChild(legendElement);
541
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
542
+ if (i === ((<any[]>this.totalPages[page]['Collection']).length - 1)) {
543
+ let pagingGroup: Element; const width: number = spacing; const height: number = (spacing / 2);
544
+ if (this.page !== 0) {
545
+ const pagingText: string = (page + 1) + '/' + this.totalPages.length;
546
+ const pagingFont: FontModel = legend.textStyle;
547
+ const pagingTextSize: Size = measureText(pagingText, pagingFont);
548
+ const leftPageX: number = (this.legendItemRect.x + this.legendItemRect.width) - pagingTextSize.width -
549
+ (width * 2) - (spacing * 2) + (pagingArrowPadding / 2);
550
+ const rightPageX: number = (this.legendItemRect.x + this.legendItemRect.width);
551
+ const pageTextX: number = rightPageX - width - (pagingTextSize.width / 2) - (spacing / 2) - pagingArrowPadding;
552
+ const locY: number = (this.legendItemRect.y + this.legendItemRect.height) + (height / 2) + spacing;
553
+ pagingGroup = render.createGroup({ id: map.element.id + '_Legend_Paging_Group' });
554
+ const leftPageElement: Element = render.createGroup({ id: map.element.id + '_Legend_Left_Paging_Group' });
555
+ const rightPageElement: Element = render.createGroup({ id: map.element.id + '_Legend_Right_Paging_Group' });
556
+ const rightPath: string = ' M ' + rightPageX + ' ' + locY + ' L ' + (rightPageX - width) + ' ' + (locY - height) +
557
+ ' L ' + (rightPageX - width) + ' ' + (locY + height) + ' z ';
558
+ const leftPath: string = ' M ' + leftPageX + ' ' + locY + ' L ' + (leftPageX + width) + ' ' + (locY - height) +
559
+ ' L ' + (leftPageX + width) + ' ' + (locY + height) + ' z ';
560
+ const leftPageOptions: PathOption = new PathOption(
561
+ map.element.id + '_Left_Page', '#a6a6a6', 0, '#a6a6a6', ((page + 1) === 1 ? 0.5 : 1), 1, '', leftPath
562
+ );
563
+ leftPageElement.appendChild(render.drawPath(leftPageOptions));
564
+ const leftRectPageOptions: RectOption = new RectOption(
565
+ map.element.id + '_Left_Page_Rect', 'transparent', {}, 1,
566
+ new Rect(leftPageX - (width / 2), (locY - (height * 2)), width * 2, spacing * 2), null, null, '', ''
567
+ );
568
+ let pathEle: Element = render.drawRectangle(leftRectPageOptions);
569
+ pathEle.setAttribute('tabindex', ((page + 1) === 1 ? -1 : map.tabIndex + 1).toString());
570
+ leftPageElement.appendChild(pathEle);
571
+ this.wireEvents(leftPageElement);
572
+ const rightPageOptions: PathOption = new PathOption(
573
+ map.element.id + '_Right_Page', '#a6a6a6', 0, '#a6a6a6', ((page + 1) === this.totalPages.length ? 0.5 : 1), 1, '', rightPath
574
+ );
575
+ rightPageElement.appendChild(render.drawPath(rightPageOptions));
576
+ const rightRectPageOptions: RectOption = new RectOption(
577
+ map.element.id + '_Right_Page_Rect', 'transparent', {}, 1,
578
+ new Rect(rightPageX - spacing - (width / 2), (locY - (height * 2)), width * 2, spacing * 2), null, null, '', ''
579
+ );
580
+ pathEle = render.drawRectangle(rightRectPageOptions);
581
+ pathEle.setAttribute('tabindex', ((page + 1) === this.totalPages.length ? -1 : map.tabIndex + 2).toString());
582
+ rightPageElement.appendChild(pathEle);
583
+ this.wireEvents(rightPageElement);
584
+ pagingGroup.appendChild(leftPageElement);
585
+ pagingGroup.appendChild(rightPageElement);
586
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
587
+ const pageTextOptions: any = {
588
+ 'id': map.element.id + '_Paging_Text',
589
+ 'x': pageTextX,
590
+ 'y': locY + (pagingTextSize.height / 4),
591
+ 'fill': '#a6a6a6',
592
+ 'font-size': '14px',
593
+ 'font-style': pagingFont.fontStyle,
594
+ 'font-family': pagingFont.fontFamily,
595
+ 'font-weight': pagingFont.fontWeight,
596
+ 'text-anchor': 'middle',
597
+ 'transform': '',
598
+ 'opacity': 1,
599
+ 'dominant-baseline': ''
600
+ };
601
+ let pagingTextElement: HTMLElement = <HTMLElement>render.createText(pageTextOptions, pagingText);
602
+ pagingTextElement.setAttribute('style', 'user-select: none;')
603
+ pagingGroup.appendChild(pagingTextElement);
604
+ this.legendGroup.appendChild(pagingGroup);
605
+ }
606
+ this.legendToggle();
607
+ }
608
+ }
609
+ }
610
+ }
611
+
612
+ public legendHighLightAndSelection(targetElement: Element, value: string): void {
613
+ let shapeIndex: number;
614
+ let layerIndex: number;
615
+ let dataIndex: number;
616
+ let pointIndex: number;
617
+ const legend: LegendSettingsModel = this.maps.legendSettings;
618
+ const textEle: Element = legend.mode === 'Default' ? document.getElementById(targetElement.id.replace('Shape', 'Text')) :
619
+ document.getElementById(targetElement.id + '_Text');
620
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
621
+ const collection: any[] = this.maps.legendModule.legendCollection;
622
+ let length: number;
623
+ const multiSelectEnable: boolean = !isNullOrUndefined(collection[0]['data'][0]['layerIndex']) ? this.maps.layers[collection[0]['data'][0]['layerIndex']].selectionSettings.enableMultiSelect : false;
624
+ let selectLength: number = 0;
625
+ let interactProcess: boolean = true;
626
+ const idIndex: number = parseFloat(targetElement.id.charAt(targetElement.id.length - 1));
627
+ this.updateLegendElement();
628
+ const toggleLegendCheck: number = this.maps.toggledLegendId.indexOf(idIndex);
629
+ if (this.maps.legendSettings.toggleLegendSettings.enable && value === 'highlight' && toggleLegendCheck !== -1) {
630
+ const collectionIndex: number = this.getIndexofLegend(this.legendHighlightCollection, targetElement);
631
+ if (collectionIndex !== -1) {
632
+ this.legendHighlightCollection.splice(collectionIndex, 1);
633
+ }
634
+ this.removeLegendHighlightCollection();
635
+ return null;
636
+ }
637
+ if (value === 'selection') {
638
+ this.shapeHighlightCollection = [];
639
+ if (!this.maps.shapeSelections && !multiSelectEnable) {
640
+ this.removeAllSelections();
641
+ this.maps.shapeSelections = true;
642
+ }
643
+ if (this.maps.legendSelectionCollection.length > 0 && (!multiSelectEnable ? this.maps.shapeSelections : true)) {
644
+ for (let k: number = 0; k < this.maps.legendSelectionCollection.length; k++) {
645
+ if (targetElement === this.maps.legendSelectionCollection[k]['legendElement']) {
646
+ this.maps.legendSelectionCollection[k]['legendElement'] = targetElement;
647
+ interactProcess = false;
648
+ this.removeLegendSelectionCollection(this.maps.legendSelectionCollection[k]['legendElement']);
649
+
650
+ this.maps.selectedLegendElementId.splice(this.maps.selectedLegendElementId.indexOf(idIndex), 1);
651
+ this.maps.legendSelectionCollection.splice(k, 1);
652
+ this.maps.legendSelection = this.maps.legendSelectionCollection.length > 0 ? false : true;
653
+ break;
654
+ } else if (!multiSelectEnable) {
655
+ if (this.maps.legendSelectionCollection.length > 1) {
656
+ for (let z : number = 0; z < this.maps.legendSelectionCollection.length; z++) {
657
+ this.removeLegendSelectionCollection(this.maps.legendSelectionCollection[z]['legendElement']);
658
+ }
659
+ this.maps.legendSelectionCollection = [];
660
+ } else {
661
+ this.removeLegendSelectionCollection(this.maps.legendSelectionCollection[k]['legendElement']);
662
+ this.maps.legendSelectionCollection.splice(k, 1);
663
+ }
664
+ }
665
+ }
666
+ }
667
+ } else {
668
+ if (this.maps.legendSelectionCollection.length > 0) {
669
+ for (let k: number = 0; k < this.maps.legendSelectionCollection.length; k++) {
670
+ if ((targetElement.id.indexOf('_Legend_Shape') > -1 || targetElement.id.indexOf('_Legend_Index')) &&
671
+ targetElement === this.maps.legendSelectionCollection[k]['legendElement']) {
672
+ interactProcess = false;
673
+ break;
674
+ } else {
675
+ this.removeLegendHighlightCollection();
676
+ }
677
+ }
678
+ }
679
+ this.removeLegendHighlightCollection();
680
+ }
681
+ if (interactProcess) {
682
+ for (let i: number = 0; i < collection.length; i++) {
683
+ const idIndex: number = this.maps.legendSettings.mode === 'Interactive' ?
684
+ parseFloat(targetElement.id.split('_Legend_Index_')[1]) :
685
+ parseFloat(targetElement.id.split('_Legend_Shape_Index_')[1]);
686
+ if (textEle.textContent === collection[i]['text'] && collection[i]['data'].length > 0
687
+ && idIndex === i) {
688
+ const layer: LayerSettingsModel = this.maps.layers[collection[i]['data'][0]['layerIndex']];
689
+ let enable: boolean; let module: HighlightSettingsModel | SelectionSettingsModel;
690
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
691
+ let data: any[];
692
+ if (!isNullOrUndefined(layer)) {
693
+ enable = (value === 'selection') ? layer.selectionSettings.enable : layer.highlightSettings.enable;
694
+ module = void 0;
695
+ module = (value === 'selection') ? layer.selectionSettings : layer.highlightSettings;
696
+ data = collection[i]['data'];
697
+ }
698
+
699
+ if (enable) {
700
+ for (let j: number = 0; j < data.length; j++) {
701
+ let shapeElement: Element;
702
+ shapeIndex = data[j]['shapeIndex'];
703
+ layerIndex = data[j]['layerIndex'];
704
+ dataIndex = data[j]['dataIndex'];
705
+ pointIndex = data[j]['pointIndex'];
706
+ if (pointIndex === -1) {
707
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
708
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex);
709
+ } else {
710
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
711
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex + '_multiLine_' + pointIndex);
712
+ }
713
+ if (shapeElement !== null) {
714
+ let shapeMatch: boolean = true;
715
+ if (this.maps.legendSelectionCollection !== null) {
716
+ for (let i: number = 0; i < this.maps.legendSelectionCollection.length; i++) {
717
+ if (this.maps.legendSelectionCollection[i]['legendElement'] === targetElement) {
718
+ shapeMatch = false;
719
+ break;
720
+ }
721
+ }
722
+ }
723
+ if (value === 'highlight' && shapeMatch) {
724
+ if (j === 0) {
725
+ this.legendHighlightCollection = [];
726
+ this.pushCollection(
727
+ targetElement, this.legendHighlightCollection, collection[i],
728
+ layer.shapeSettings as ShapeSettings);
729
+ }
730
+ length = this.legendHighlightCollection.length;
731
+ const legendHighlightColor: string = this.legendHighlightCollection[length - 1]['legendOldFill'];
732
+ this.legendHighlightCollection[length - 1]['MapShapeCollection']['Elements'].push(shapeElement);
733
+ const shapeItemCount: number = this.legendHighlightCollection[length - 1]['MapShapeCollection']['Elements'].length - 1;
734
+ const shapeOldFillColor: string = shapeElement.getAttribute('fill');
735
+ this.legendHighlightCollection[length - 1]['shapeOldFillColor'].push(shapeOldFillColor);
736
+ const shapeOldColor: string = this.legendHighlightCollection[length - 1]['shapeOldFillColor'][shapeItemCount];
737
+ this.shapePreviousColor = this.legendHighlightCollection[length - 1]['shapeOldFillColor'];
738
+ this.setColor(
739
+ shapeElement, !isNullOrUndefined(module.fill) ? module.fill : shapeOldColor,
740
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'highlight');
741
+ this.setColor(
742
+ targetElement, !isNullOrUndefined(module.fill) ? module.fill : legendHighlightColor,
743
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'highlight');
744
+ } else if (value === 'selection') {
745
+ this.legendHighlightCollection = [];
746
+ this.maps.legendSelectionClass = module;
747
+ if (j === 0) {
748
+ this.pushCollection(
749
+ targetElement, this.maps.legendSelectionCollection, collection[i],
750
+ layer.shapeSettings as ShapeSettings);
751
+ if (multiSelectEnable) {
752
+ this.maps.selectedLegendElementId.push(i);
753
+ } else {
754
+ if (this.maps.selectedLegendElementId.length === 0) {
755
+ this.maps.selectedLegendElementId.push(i);
756
+ } else {
757
+ this.maps.selectedLegendElementId = [];
758
+ this.maps.selectedLegendElementId.push(i);
759
+ }
760
+ }
761
+ }
762
+ selectLength = this.maps.legendSelectionCollection.length;
763
+ const legendSelectionColor: string = this.maps.legendSelectionCollection[selectLength - 1]['legendOldFill'];
764
+ this.maps.legendSelectionCollection[selectLength - 1]['MapShapeCollection']['Elements'].push(shapeElement);
765
+ this.maps.legendSelectionCollection[selectLength - 1]['shapeOldFillColor'] = this.shapePreviousColor;
766
+ this.setColor(
767
+ targetElement, !isNullOrUndefined(module.fill) ? module.fill : legendSelectionColor,
768
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'selection');
769
+ this.setColor(
770
+ shapeElement, !isNullOrUndefined(module.fill) ? module.fill : legendSelectionColor,
771
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'selection');
772
+ if (this.maps.selectedElementId.indexOf(shapeElement.getAttribute('id')) === - 1) {
773
+ this.maps.selectedElementId.push(shapeElement.getAttribute('id'));
774
+ }
775
+ if (j === data.length - 1) {
776
+ this.maps.legendSelection = false;
777
+ this.removeLegend(this.maps.legendSelectionCollection);
778
+ }
779
+ }
780
+ }
781
+ }
782
+ }
783
+ }
784
+ }
785
+ }
786
+ }
787
+
788
+ private setColor(element: Element, fill: string, opacity: string, borderColor: string, borderWidth: string, type: string): void {
789
+ const isLineStringShape: boolean = (element.parentElement.id.indexOf('LineString') > -1);
790
+ if (type === 'selection') {
791
+ maintainStyleClass((isLineStringShape ? 'LineselectionMap' : 'ShapeselectionMap'),
792
+ (isLineStringShape ? 'LineselectionMapStyle' : 'ShapeselectionMapStyle'),
793
+ (isLineStringShape ? 'transparent' : fill),
794
+ opacity, (isLineStringShape ? fill : borderColor), borderWidth, this.maps);
795
+ element.setAttribute('class', isLineStringShape ? 'LineselectionMapStyle' : 'ShapeselectionMapStyle');
796
+ } else {
797
+ element.setAttribute('fill', isLineStringShape ? 'transparent' : fill);
798
+ element.setAttribute('fill-opacity', opacity);
799
+ element.setAttribute('stroke', isLineStringShape ? fill : borderColor);
800
+ element.setAttribute('stroke-width', (Number(borderWidth) / this.maps.scale).toString());
801
+ }
802
+ }
803
+
804
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
805
+ public pushCollection(targetElement: Element, collection: any[], oldElement: any, shapeSettings: ShapeSettings): void {
806
+ collection.push({
807
+ legendElement: targetElement, legendOldFill: oldElement['fill'], legendOldOpacity: oldElement['opacity'],
808
+ legendOldBorderColor: oldElement['borderColor'], legendOldBorderWidth: oldElement['borderWidth'],
809
+ shapeOpacity: shapeSettings.opacity, shapeOldBorderColor: shapeSettings.border.color,
810
+ shapeOldBorderWidth: shapeSettings.border.width
811
+ });
812
+ const length: number = collection.length;
813
+ collection[length - 1]['MapShapeCollection'] = { Elements: [] };
814
+ collection[length - 1]['shapeOldFillColor'] = [];
815
+ }
816
+
817
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
818
+ private removeLegend(collection: any[]): void {
819
+ for (let i: number = 0; i < collection.length; i++) {
820
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
821
+ const item: any = collection[i];
822
+ this.setColor(
823
+ item['legendElement'], item['legendOldFill'], item['legendOldOpacity'],
824
+ item['legendOldBorderColor'], item['legendOldBorderWidth'], 'highlight');
825
+ const dataCount: number = item['MapShapeCollection']['Elements'].length;
826
+ for (let j: number = 0; j < dataCount; j++) {
827
+ const shapeFillColor: string = item['legendOldFill'].indexOf('url') !== -1
828
+ ? item['shapeOldFillColor'][j] : item['legendOldFill'];
829
+ this.setColor(
830
+ item['MapShapeCollection']['Elements'][j], shapeFillColor, item['shapeOpacity'],
831
+ item['shapeOldBorderColor'], item['shapeOldBorderWidth'], 'highlight');
832
+ }
833
+ }
834
+ }
835
+
836
+ public removeLegendHighlightCollection(): void {
837
+ if (this.legendHighlightCollection.length > 0) {
838
+ this.removeLegend(this.legendHighlightCollection);
839
+ this.legendHighlightCollection = [];
840
+ }
841
+ }
842
+
843
+ public removeLegendSelectionCollection(targetElement: Element): void {
844
+ if (this.maps.legendSelectionCollection.length > 0) {
845
+ removeClass(targetElement);
846
+ const shapeElements: string[] = this.shapesOfLegend(targetElement);
847
+ const dataCount: number = shapeElements.length;
848
+ for (let j: number = 0; j < dataCount; j++) {
849
+ const shapeElement: Element = getElement(shapeElements[j]);
850
+ if (shapeElement.getAttribute('class') === 'ShapeselectionMapStyle' ||
851
+ shapeElement.getAttribute('class') === 'LineselectionMapStyle') {
852
+ removeClass(shapeElement);
853
+ const selectedElementIdIndex: number = this.maps.selectedElementId.indexOf(shapeElement.id);
854
+ if (selectedElementIdIndex !== - 1) {
855
+ this.maps.selectedElementId.splice(selectedElementIdIndex, 1);
856
+ }
857
+ }
858
+ }
859
+ }
860
+ }
861
+
862
+ public removeShapeHighlightCollection(): void {
863
+ if (this.shapeHighlightCollection.length > 0) {
864
+ for (let i: number = 0; i < this.shapeHighlightCollection.length; i++) {
865
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
866
+ const item: any = this.shapeHighlightCollection[i];
867
+ let removeFill: boolean = true;
868
+ for (let j: number = 0; j < this.maps.legendSelectionCollection.length; j++) {
869
+ if (this.maps.legendSelectionCollection[j]['legendElement'] === item['legendElement']) {
870
+ removeFill = false;
871
+ }
872
+ }
873
+ if (removeFill) {
874
+ this.setColor(
875
+ item['legendElement'], item['legendOldFill'], item['legendOldOpacity'],
876
+ item['legendOldBorderColor'], item['legendOldBorderWidth'], 'highlight');
877
+ }
878
+ }
879
+ }
880
+ }
881
+
882
+ public shapeHighLightAndSelection(
883
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
884
+ targetElement: Element, data: any, module: SelectionSettingsModel | HighlightSettingsModel,
885
+ getValue: string, layerIndex: number): void {
886
+ if (data !== undefined) {
887
+ this.updateLegendElement();
888
+ this.shapeToggled = true;
889
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
890
+ const collection: any[] = this.maps.legendModule.legendCollection;
891
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
892
+ const indexes: any = this.legendIndexOnShape(data, layerIndex);
893
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
894
+ const shapeElement: any = this.shapeDataOnLegend(targetElement);
895
+ const toggleLegendCheck: number = this.maps.toggledLegendId.indexOf(indexes['actualIndex']);
896
+ if (this.maps.legendSettings.toggleLegendSettings.enable && toggleLegendCheck !== -1) {
897
+ this.shapeToggled = false;
898
+ this.legendHighlightCollection = [];
899
+ const collectionIndex: number = this.getIndexofLegend(this.shapeHighlightCollection, shapeElement['LegendEle']);
900
+ if (collectionIndex !== -1) {
901
+ this.shapeHighlightCollection.splice(collectionIndex, 1);
902
+ }
903
+ this.removeShapeHighlightCollection();
904
+ return null;
905
+ }
906
+ if (indexes['currentIndex'] === undefined && indexes['actualIndex'] === undefined) {
907
+ this.removeShapeHighlightCollection();
908
+ return null;
909
+ }
910
+ if (indexes['currentIndex'] === undefined && getValue === 'selection'
911
+ && !this.maps.layers[layerIndex].selectionSettings.enableMultiSelect &&
912
+ targetElement.getAttribute('class') !== 'ShapeselectionMapStyle') {
913
+ this.maps.legendSelection = false;
914
+ }
915
+ if (getValue === 'selection' && !this.maps.layers[layerIndex].selectionSettings.enableMultiSelect &&
916
+ !this.maps.legendSelection) {
917
+ this.removeAllSelections();
918
+ this.maps.legendSelection = true;
919
+ }
920
+ if (indexes['currentIndex'] === undefined) {
921
+ if (getValue === 'selection' && indexes['actualIndex'] !== undefined) {
922
+ let checkSelection: number = 0;
923
+ for (let i: number = 0; i < shapeElement['Elements'].length; i++) {
924
+ if (shapeElement['Elements'][i].getAttribute('class') === 'ShapeselectionMapStyle') {
925
+ checkSelection++;
926
+ }
927
+ }
928
+ const selectionIndex: number = this.maps.selectedLegendElementId.indexOf(indexes['actualIndex']);
929
+ if (selectionIndex === -1) {
930
+ this.maps.selectedLegendElementId.push(indexes['actualIndex']);
931
+ this.maps.legendSelectionClass = <SelectionSettingsModel>module;
932
+ } else {
933
+ if ((checkSelection <= 1) && (targetElement.getAttribute('class') === 'ShapeselectionMapStyle'
934
+ || targetElement.getAttribute('class') === 'LineselectionMapStyle')) {
935
+ if (!this.maps.layers[layerIndex].selectionSettings.enableMultiSelect) {
936
+ this.maps.selectedLegendElementId.splice(selectionIndex, 1);
937
+ } else {
938
+ if (checkSelection <= 1 && (targetElement.getAttribute('class') === 'ShapeselectionMapStyle'
939
+ || targetElement.getAttribute('class') === 'LineselectionMapStyle')) {
940
+ this.maps.selectedLegendElementId.splice(selectionIndex, 1);
941
+ }
942
+ }
943
+ }
944
+ }
945
+ }
946
+ this.removeShapeHighlightCollection();
947
+ return null;
948
+ }
949
+ const text: string = collection[indexes['actualIndex']]['text'];
950
+ let content: string; let legendShape: Element;
951
+
952
+ if (this.maps.legendSettings.mode === 'Default') {
953
+ if (indexes['currentIndex'] !== undefined) {
954
+ content = document.getElementById(this.maps.element.id + '_Legend_Text_Index_' + indexes['actualIndex']).textContent;
955
+ legendShape = document.getElementById(this.maps.element.id + '_Legend_Shape_Index_' + indexes['actualIndex']);
956
+ }
957
+ } else {
958
+ content = document.getElementById(this.maps.element.id + '_Legend_Index_' + indexes['actualIndex']
959
+ + '_Text').textContent;
960
+ legendShape = document.getElementById(this.maps.element.id + '_Legend_Index_' + indexes['actualIndex']);
961
+ }
962
+ this.oldShapeElement = shapeElement['LegendEle'];
963
+ const length: number = this.maps.legendSelectionCollection.length;
964
+ if (text === content) {
965
+ let shapeMatched: boolean = true;
966
+ if (this.maps.legendSelectionCollection) {
967
+ for (let i: number = 0; i < this.maps.legendSelectionCollection.length; i++) {
968
+ if (this.maps.legendSelectionCollection[i]['legendElement'] === shapeElement['LegendEle']) {
969
+ shapeMatched = false;
970
+ break;
971
+ }
972
+ }
973
+ }
974
+ if (getValue === 'highlight' && shapeMatched) {
975
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
976
+ const selectionEle: any = this.isTargetSelected(shapeElement, this.shapeHighlightCollection);
977
+ if (selectionEle === undefined || (selectionEle && !selectionEle['IsSelected'])) {
978
+ this.pushCollection(
979
+ legendShape, this.shapeHighlightCollection, collection[indexes['actualIndex']],
980
+ this.maps.layers[layerIndex].shapeSettings as ShapeSettings
981
+ );
982
+ }
983
+ for (let j: number = 0; j < this.shapeHighlightCollection.length; j++) {
984
+ if (shapeElement['LegendEle'].id === this.shapeHighlightCollection[j]['legendElement'].id) {
985
+ this.shapeHighlightCollection[j]['legendElement'] = shapeElement['LegendEle'];
986
+ }
987
+ }
988
+ if (length > 0) {
989
+ for (let j: number = 0; j < length; j++) {
990
+ if (shapeElement['LegendEle'] === this.maps.legendSelectionCollection[j]['legendElement']) {
991
+ this.maps.legendSelectionCollection[j]['legendElement'] = shapeElement['LegendEle'];
992
+ this.removeShapeHighlightCollection();
993
+ break;
994
+ } else if (j === length - 1) {
995
+ this.removeShapeHighlightCollection();
996
+ this.setColor(
997
+ legendShape, !isNullOrUndefined(module.fill) ? module.fill : legendShape.getAttribute('fill'),
998
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'highlight');
999
+ }
1000
+ }
1001
+ } else {
1002
+ this.removeShapeHighlightCollection();
1003
+ this.setColor(
1004
+ legendShape, !isNullOrUndefined(module.fill) ? module.fill : legendShape.getAttribute('fill'),
1005
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'highlight');
1006
+ }
1007
+ } else if (getValue === 'selection') {
1008
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1009
+ const selectionEle: any = this.isTargetSelected(shapeElement, this.maps.legendSelectionCollection);
1010
+ if (length > 0) {
1011
+ let j: number = 0;
1012
+ while (j < this.maps.legendSelectionCollection.length) {
1013
+ if (shapeElement['LegendEle'] !== this.maps.legendSelectionCollection[j]['legendElement'] &&
1014
+ !(<SelectionSettingsModel>module).enableMultiSelect) {
1015
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1016
+ const element: any = this.maps.legendSelectionCollection[j];
1017
+ const selectedLegendIndex: number = this.maps.selectedLegendElementId.indexOf(indexes['actualIndex']);
1018
+ this.maps.selectedLegendElementId.splice(selectedLegendIndex, 1);
1019
+ this.maps.legendSelectionCollection.splice(j, 1);
1020
+ removeClass(element['legendElement']);
1021
+ this.maps.shapeSelections = true;
1022
+ j = 0;
1023
+ } else { j++; }
1024
+ }
1025
+ }
1026
+ if (selectionEle && (
1027
+ selectionEle['IsSelected'] && (targetElement.getAttribute('class') === 'ShapeselectionMapStyle'
1028
+ || targetElement.getAttribute('class') === 'LineselectionMapStyle'))) {
1029
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1030
+ const element: any = this.maps.legendSelectionCollection[selectionEle['SelectionIndex']];
1031
+ let multiSelection: number = 0;
1032
+ if ((<SelectionSettingsModel>module).enableMultiSelect) {
1033
+ for (let i: number = 0; i < shapeElement['Elements'].length; i++) {
1034
+ if (targetElement.getAttribute('class') === shapeElement['Elements'][i].getAttribute('class')) {
1035
+ multiSelection++;
1036
+ }
1037
+ }
1038
+ }
1039
+ if (multiSelection <= 1 && (!(<SelectionSettingsModel>module).enableMultiSelect ?
1040
+ this.maps.legendSelection : true)) {
1041
+ this.maps.selectedLegendElementId.splice(this.maps.selectedLegendElementId.indexOf(indexes['actualIndex']), 1);
1042
+ if (!isNullOrUndefined(shapeElement['LegendEle'])) {
1043
+ removeClass(shapeElement['LegendEle']);
1044
+ }
1045
+ this.maps.legendSelectionCollection.splice(selectionEle['SelectionIndex'], 1);
1046
+ this.maps.shapeSelections = true;
1047
+ }
1048
+ } else {
1049
+ if ((selectionEle === undefined || (selectionEle && !selectionEle['IsSelected'])) &&
1050
+ !isNullOrUndefined(legendShape)) {
1051
+ const legendSelectionIndex: number = this.getIndexofLegend(this.maps.legendSelectionCollection, legendShape);
1052
+ if (legendSelectionIndex === -1) {
1053
+ this.pushCollection(
1054
+ legendShape, this.maps.legendSelectionCollection, collection[indexes['actualIndex']],
1055
+ this.maps.layers[layerIndex].shapeSettings as ShapeSettings
1056
+ );
1057
+ }
1058
+ }
1059
+ let addId: boolean = true;
1060
+ for (let i: number = 0; i < this.maps.selectedLegendElementId.length; i++) {
1061
+ if (indexes['actualIndex'] === this.maps.selectedLegendElementId[i]) {
1062
+ addId = false;
1063
+ }
1064
+ }
1065
+ if (addId) {
1066
+ this.maps.selectedLegendElementId.push(indexes['actualIndex']);
1067
+ }
1068
+ this.maps.legendSelectionClass = <SelectionSettingsModel>module;
1069
+ this.removeLegend(this.shapeHighlightCollection);
1070
+ if (!isNullOrUndefined(legendShape)) {
1071
+ this.setColor(
1072
+ legendShape, !isNullOrUndefined(module.fill) ? module.fill : legendShape.getAttribute('fill'),
1073
+ module.opacity.toString(), module.border.color, module.border.width.toString(), 'selection');
1074
+ const legendSelectionIndex: number = this.getIndexofLegend(this.maps.legendSelectionCollection, legendShape);
1075
+ this.maps.legendSelectionCollection[legendSelectionIndex]['MapShapeCollection']['Elements'].push(targetElement);
1076
+ }
1077
+ this.maps.shapeSelections = false;
1078
+ }
1079
+ } else if (document.getElementsByClassName('highlightMapStyle').length > 0) {
1080
+ this.removeShapeHighlightCollection();
1081
+ removeClass(document.getElementsByClassName('highlightMapStyle')[0]);
1082
+ }
1083
+ }
1084
+ } else {
1085
+ this.removeShapeHighlightCollection();
1086
+ }
1087
+ }
1088
+
1089
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1090
+ private isTargetSelected(target: any, collection: any[]): any {
1091
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1092
+ let selectEle: any;
1093
+ for (let i: number = 0; i < collection.length; i++) {
1094
+ if (!isNullOrUndefined(target['LegendEle'].getAttribute('id')) &&
1095
+ (target['LegendEle'].getAttribute('id') === collection[i]['legendElement'].getAttribute('id'))) {
1096
+ selectEle = { IsSelected: true, SelectionIndex: i };
1097
+ }
1098
+ }
1099
+ return selectEle;
1100
+ }
1101
+
1102
+ private updateLegendElement(): void {
1103
+ for (let i: number = 0; i < this.maps.legendSelectionCollection.length; i++) {
1104
+ if (document.getElementById(this.maps.legendSelectionCollection[i]['legendElement'].id)) {
1105
+ this.maps.legendSelectionCollection[i]['legendElement'] =
1106
+ document.getElementById(this.maps.legendSelectionCollection[i]['legendElement'].id);
1107
+ }
1108
+ }
1109
+ }
1110
+
1111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1112
+ private getIndexofLegend(targetCollection: any[], targetElement: Element): number {
1113
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1114
+ const legendIndex: number = targetCollection.map((e: any) => { return e['legendElement']; }).indexOf(targetElement);
1115
+ return legendIndex;
1116
+ }
1117
+
1118
+ private removeAllSelections(): void {
1119
+ for (let i: number = 0; i < this.maps.selectedElementId.length; i++) {
1120
+ const selectedElement: Element = document.getElementById(this.maps.selectedElementId[i]);
1121
+ removeClass(selectedElement);
1122
+ }
1123
+ for (let j: number = 0; j < this.maps.selectedLegendElementId.length; j++) {
1124
+ const idIndex: string = this.maps.legendSettings.mode === 'Interactive' ?
1125
+ this.maps.element.id + '_Legend_Index_' : this.maps.element.id + '_Legend_Shape_Index_';
1126
+ const selectedElement: string = idIndex + this.maps.selectedLegendElementId[j];
1127
+ const legendElement: Element = document.getElementById(selectedElement);
1128
+ if (!isNullOrUndefined(legendElement)) {
1129
+ removeClass(document.getElementById(selectedElement));
1130
+ }
1131
+ }
1132
+ this.maps.legendSelectionCollection = [];
1133
+ this.maps.selectedLegendElementId = [];
1134
+ this.maps.selectedElementId = [];
1135
+ }
1136
+
1137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1138
+ public legendIndexOnShape(data: any, index: number): any {
1139
+ let legendIndex: number;
1140
+ let actualIndex: number;
1141
+ const path: string = this.maps.layers[index].shapeDataPath;
1142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1143
+ const value: any = data[path];
1144
+ const legendType: string = this.maps.legendSettings.mode;
1145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1146
+ const collection: any[] = this.maps.legendModule.legendCollection;
1147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1148
+ let currentCollection: any[];
1149
+ if (legendType === 'Default' && !isNullOrUndefined(this.maps.legendModule.totalPages)) {
1150
+ currentCollection = this.maps.legendModule.totalPages[this.maps.legendModule.currentPage]['Collection'];
1151
+ }
1152
+ const currentCollectionLength: number = legendType === 'Default' ? currentCollection['length'] : 1;
1153
+ for (let i: number = 0; i < collection.length; i++) {
1154
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1155
+ const dataValue: any[] = collection[i]['data'];
1156
+ for (let k: number = 0; k < currentCollectionLength; k++) {
1157
+ if (legendType !== 'Default' || collection[i]['text'] === currentCollection[k]['DisplayText']) {
1158
+ for (let j: number = 0; j < dataValue.length; j++) {
1159
+ if (value === dataValue[j]['name']) {
1160
+ legendIndex = k;
1161
+ }
1162
+ }
1163
+ }
1164
+ }
1165
+ for (let j: number = 0; j < dataValue.length; j++) {
1166
+ if (value === dataValue[j]['name']) {
1167
+ actualIndex = i;
1168
+ }
1169
+ }
1170
+
1171
+ }
1172
+ return { currentIndex: legendIndex, actualIndex: actualIndex };
1173
+ }
1174
+
1175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1176
+ private shapeDataOnLegend(targetElement: Element): any {
1177
+ let shapeIndex: number;
1178
+ let layerIndex: number;
1179
+ let dataIndex: number;
1180
+ let pointIndex: number;
1181
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1182
+ const collection: any[] = this.maps.legendModule.legendCollection;
1183
+ const legend: LegendSettingsModel = this.maps.legendSettings;
1184
+ for (let i: number = 0; i < collection.length; i++) {
1185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1186
+ const data: any[] = collection[i]['data'];
1187
+ let process: boolean = false;
1188
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1189
+ const elements: any[] = [];
1190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1191
+ const currentElement: any = { Elements: [] };
1192
+ for (let j: number = 0; j < data.length; j++) {
1193
+ let shapeElement: Element;
1194
+ shapeIndex = data[j]['shapeIndex'];
1195
+ layerIndex = data[j]['layerIndex'];
1196
+ dataIndex = data[j]['dataIndex'];
1197
+ pointIndex = data[j]['pointIndex'];
1198
+ if (pointIndex === -1) {
1199
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
1200
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex);
1201
+ } else {
1202
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
1203
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex + '_multiLine_'+ pointIndex);
1204
+ }
1205
+ if (targetElement === shapeElement) {
1206
+ process = true;
1207
+ }
1208
+ elements.push(shapeElement);
1209
+ }
1210
+ if (process) {
1211
+ if (isNullOrUndefined(currentElement['LegendEle'])) {
1212
+ currentElement['LegendEle'] = legend.mode === 'Default' ?
1213
+ document.getElementById(this.maps.element.id + '_Legend_Shape_Index_' + i) :
1214
+ document.getElementById(this.maps.element.id + '_Legend_Index_' + i);
1215
+ }
1216
+ currentElement['Elements'] = elements;
1217
+ return currentElement;
1218
+ }
1219
+ }
1220
+ return null;
1221
+ }
1222
+
1223
+ private shapesOfLegend(targetElement: Element): string[] {
1224
+ let shapeIndex: number;
1225
+ let layerIndex: number;
1226
+ let dataIndex: number;
1227
+ let pointIndex: number;
1228
+ const idIndex: number = parseFloat(targetElement.id.charAt(targetElement.id.length - 1));
1229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1230
+ const data: any[] = this.maps.legendModule.legendCollection[idIndex]['data'];
1231
+ const legendShapeElements: string[] = [];
1232
+ for (let i: number = 0; i < data.length; i++) {
1233
+ let shapeElement: Element;
1234
+ shapeIndex = data[i]['shapeIndex'];
1235
+ layerIndex = data[i]['layerIndex'];
1236
+ dataIndex = data[i]['dataIndex'];
1237
+ pointIndex = data[i]['pointIndex'];
1238
+ if (pointIndex === -1) {
1239
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
1240
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex);
1241
+ } else {
1242
+ shapeElement = document.getElementById(this.maps.element.id + '_LayerIndex_' +
1243
+ layerIndex + '_shapeIndex_' + shapeIndex + '_dataIndex_' + dataIndex + '_multiLine_' + pointIndex);
1244
+ }
1245
+ if (!isNullOrUndefined(shapeElement)) {
1246
+ legendShapeElements.push(shapeElement.id);
1247
+ }
1248
+ }
1249
+ return legendShapeElements;
1250
+ }
1251
+
1252
+ private legendToggle(): void {
1253
+ const map: Maps = this.maps;
1254
+ const legend: LegendSettingsModel = <LegendSettingsModel>map.legendSettings;
1255
+ if (this.maps.selectedLegendElementId) {
1256
+ // To maintain the state of legend selection during page resize.
1257
+ for (let j: number = 0; j < this.maps.selectedLegendElementId.length; j++) {
1258
+ const idIndex: string = legend.mode === 'Interactive' ? this.maps.element.id + '_Legend_Index_' : this.maps.element.id + '_Legend_Shape_Index_';
1259
+ const selectedElement: Element = map.svgObject.querySelector('#' + idIndex + this.maps.selectedLegendElementId[j]);
1260
+ if (!isNullOrUndefined(selectedElement)) {
1261
+ const fill: string = !isNullOrUndefined(this.maps.legendSelectionClass.fill) ?
1262
+ this.maps.legendSelectionClass.fill : selectedElement.getAttribute('fill');
1263
+ this.setColor(
1264
+ selectedElement, fill, this.maps.legendSelectionClass.opacity.toString(),
1265
+ this.maps.legendSelectionClass.border.color, this.maps.legendSelectionClass.border.width.toString(), 'selection');
1266
+ for (let i: number = 0; i < this.maps.legendSelectionCollection.length; i++) {
1267
+ if (this.maps.legendSelectionCollection[i]['legendElement'].id === selectedElement.id) {
1268
+ this.maps.legendSelectionCollection[i]['legendElement'] = selectedElement;
1269
+ }
1270
+ }
1271
+ const legendSelectionIndex: number = this.getIndexofLegend(this.maps.legendSelectionCollection, selectedElement);
1272
+ if (legendSelectionIndex === -1) {
1273
+ const layerIndex: number = this.maps.legendModule.legendCollection[this.maps.selectedLegendElementId[j]]['data'][j]['layerIndex'];
1274
+ this.pushCollection(
1275
+ selectedElement, this.maps.legendSelectionCollection, this.maps.legendModule.legendCollection[this.maps.selectedLegendElementId[j]],
1276
+ this.maps.layers[layerIndex].shapeSettings as ShapeSettings
1277
+ );
1278
+ }
1279
+ }
1280
+ }
1281
+ }
1282
+ if (this.maps.toggledLegendId) {
1283
+ for (let j: number = 0; j < this.maps.toggledLegendId.length; j++) {
1284
+ const legendTextId: string = legend.mode === 'Interactive' ? ('#' + this.maps.element.id + '_Legend_Index_' + this.maps.toggledLegendId[j] + '_Text') : ('#' + this.maps.element.id + '_Legend_Text_Index_' + this.maps.toggledLegendId[j]);
1285
+ const textElement: Element = map.svgObject.querySelector(legendTextId);
1286
+ if (!isNullOrUndefined(textElement)) {
1287
+ textElement.setAttribute('fill', '#E5E5E5');
1288
+ }
1289
+ const legendShapeId: string = legend.mode === 'Interactive' ? ('#' + this.maps.element.id + '_Legend_Index_' + this.maps.toggledLegendId[j]) : ('#' + this.maps.element.id + '_Legend_Shape_Index_' + this.maps.toggledLegendId[j]);
1290
+ const legendElement: Element = map.svgObject.querySelector(legendShapeId);
1291
+ if (!isNullOrUndefined(legendElement)) {
1292
+ legendElement.setAttribute('fill', '#E5E5E5');
1293
+ }
1294
+ }
1295
+ }
1296
+ }
1297
+
1298
+ private renderLegendBorder(): void {
1299
+ const map: Maps = this.maps;
1300
+ const legend: LegendSettingsModel = <LegendSettingsModel>map.legendSettings;
1301
+ const legendTitle: string = legend.title.text;
1302
+ const textStyle: FontModel = {
1303
+ fontFamily: legend.titleStyle.fontFamily, fontStyle: legend.titleStyle.fontStyle,
1304
+ fontWeight: legend.titleStyle.fontWeight, size: legend.titleStyle.size, color: legend.titleStyle.color, opacity: legend.titleStyle.opacity
1305
+ };
1306
+ let textOptions: TextOption;
1307
+ const spacing: number = 10;
1308
+ const trimTitle: string = textTrim((this.legendItemRect.width + (spacing * 2)), legendTitle, textStyle);
1309
+ const textSize: Size = measureText(trimTitle, textStyle);
1310
+ this.legendBorderRect = new Rect(
1311
+ (this.legendItemRect.x - spacing),
1312
+ (this.legendItemRect.y - spacing - textSize.height),
1313
+ (this.legendItemRect.width) + (spacing * 2),
1314
+ (this.legendItemRect.height) + (spacing * 2) + textSize.height +
1315
+ (legend.mode === 'Interactive' ? 0 : (this.page !== 0) ? spacing : 0)
1316
+ );
1317
+ const legendBorder: BorderModel = {
1318
+ color: legend.border.color, width: legend.border.width, opacity: legend.border.opacity
1319
+ };
1320
+ legendBorder.opacity = isNullOrUndefined(legendBorder.opacity) ? 1 : legendBorder.opacity;
1321
+ const renderOptions: RectOption = new RectOption(
1322
+ map.element.id + '_Legend_Border', legend.background, legendBorder, 1,
1323
+ this.legendBorderRect, null, null, '', ''
1324
+ );
1325
+ this.legendGroup.appendChild(map.renderer.drawRectangle(renderOptions));
1326
+ this.getLegendAlignment(map, this.legendBorderRect.width, this.legendBorderRect.height, legend);
1327
+ this.legendGroup.setAttribute('transform', 'translate( ' + (this.translate.x + (-this.legendBorderRect.x)) + ' ' +
1328
+ (this.translate.y + (-(this.legendBorderRect.y)) ) + ' )');
1329
+ if (legend.position !== 'Float') {
1330
+ map.svgObject.appendChild(this.legendGroup);
1331
+ }
1332
+ if (legendTitle) {
1333
+ textStyle.color = (textStyle.color !== null) ? textStyle.color : this.maps.themeStyle.legendTitleFontColor;
1334
+ textStyle.fontFamily = !isNullOrUndefined(textStyle.fontFamily) ? textStyle.fontFamily : this.maps.themeStyle.fontFamily;
1335
+ textOptions = new TextOption(
1336
+ map.element.id + '_LegendTitle',
1337
+ (this.legendItemRect.x) + (this.legendItemRect.width / 2),
1338
+ this.legendItemRect.y - (textSize.height / 2) - spacing / 2,
1339
+ 'middle', trimTitle, '');
1340
+ renderTextElement(textOptions, textStyle, textStyle.color, this.legendGroup);
1341
+ }
1342
+ }
1343
+
1344
+ public changeNextPage(e: PointerEvent): void {
1345
+ this.currentPage = ((<Element>e.target).id.indexOf('_Left_Page_') > -1) ? (this.currentPage - 1) :
1346
+ (this.currentPage + 1);
1347
+ this.legendGroup = this.maps.renderer.createGroup({ id: this.maps.element.id + '_Legend_Group' });
1348
+ this.maps.mapAreaRect = this.initialMapAreaRect;
1349
+ this.drawLegendItem(this.currentPage);
1350
+ if (!isNullOrUndefined(this.maps.legendModule) && this.maps.legendSettings.position === 'Float') {
1351
+ if (this.maps.isTileMap) {
1352
+ this.maps.mapLayerPanel.layerGroup.appendChild(this.maps.legendModule.legendGroup);
1353
+ }
1354
+ else {
1355
+ this.maps.svgObject.appendChild(this.maps.legendModule.legendGroup);
1356
+ }
1357
+ }
1358
+ if (querySelector(this.maps.element.id + '_Legend_Border', this.maps.element.id)) {
1359
+ (<HTMLElement>querySelector(this.maps.element.id + '_Legend_Border', this.maps.element.id)).style.pointerEvents = 'none';
1360
+ }
1361
+ }
1362
+
1363
+ private getLegendAlignment(map: Maps, width: number, height: number, legend: LegendSettingsModel): void {
1364
+ let x: number; let y: number;
1365
+ const spacing: number = 10;
1366
+ let totalRect: Rect;
1367
+ // eslint-disable-next-line prefer-const
1368
+ totalRect = extend({}, map.mapAreaRect, totalRect, true) as Rect;
1369
+ const areaX: number = totalRect.x;
1370
+ const areaY: number = totalRect.y;
1371
+ const areaHeight: number = totalRect.height;
1372
+ const areaWidth: number = totalRect.width;
1373
+ const totalWidth: number = map.availableSize.width;
1374
+ const totalHeight: number = map.availableSize.height;
1375
+ const locationX: number = !isNullOrUndefined(legend.location.x) ? legend.location.x : 0;
1376
+ const locationY: number = !isNullOrUndefined(legend.location.y) ? legend.location.y : 0;
1377
+ if (legend.position === 'Float') {
1378
+ this.translate = map.isTileMap ? new Point(locationX, locationY + (spacing / 4)) : new Point(locationX + map.mapAreaRect.x, locationY + map.mapAreaRect.y);
1379
+ this.legendTotalRect = map.mapAreaRect;
1380
+ } else {
1381
+ switch (legend.position) {
1382
+ case 'Top':
1383
+ case 'Bottom':
1384
+ totalRect.height = (legend.position === 'Top') ? (areaHeight - height) : (areaHeight - height - (spacing * 2));
1385
+ x = (totalWidth / 2) - (width / 2);
1386
+ y = (legend.position === 'Top') ? areaY : (areaY + totalRect.height);
1387
+ totalRect.y = (legend.position === 'Top') ? areaY + height + (map.isTileMap ? (spacing / 2) : spacing) : areaY - (spacing / 2);
1388
+ break;
1389
+ case 'Left':
1390
+ case 'Right':
1391
+ totalRect.width = (areaWidth - width - map.mapAreaRect.x);
1392
+ x = (legend.position === 'Left') ? areaX + (spacing / 2) : (areaX + totalRect.width + spacing);
1393
+ y = (totalHeight / 2) - (height / 2);
1394
+ totalRect.x = (legend.position === 'Left') ? areaX + width + spacing : areaX;
1395
+ break;
1396
+ }
1397
+ switch (legend.alignment) {
1398
+ case 'Near':
1399
+ if (legend.position === 'Top' || legend.position === 'Bottom') {
1400
+ x = totalRect.x - (legend.mode === 'Interactive' ? spacing : 0);
1401
+ }
1402
+ else {
1403
+ y = totalRect.y - (!(legend.height && legend.width) && legend.mode === 'Interactive' ? map.mapAreaRect.x : 0);
1404
+ }
1405
+ break;
1406
+ case 'Far':
1407
+ if (legend.position === 'Top' || legend.position === 'Bottom') {
1408
+ x = (totalWidth - width) - (legend.mode === 'Interactive' ? 0 : spacing);
1409
+ }
1410
+ else {
1411
+ y = totalHeight - height - (legend.mode === 'Default' ? spacing : 0);
1412
+ }
1413
+ break;
1414
+ }
1415
+ if ((legend.height || legend.width) && legend.mode !== 'Interactive') {
1416
+ this.legendTotalRect = map.mapAreaRect = map.totalRect = totalRect;
1417
+ } else {
1418
+ map.totalRect = null;
1419
+ if ((legend.height || legend.width) && legend.mode === 'Interactive')
1420
+ {
1421
+ map.totalRect = totalRect;
1422
+ }
1423
+ this.legendTotalRect = map.mapAreaRect = totalRect;
1424
+ }
1425
+ if (legend.position === 'Left') {
1426
+ map.mapAreaRect.width = totalRect.width;
1427
+ }
1428
+ this.translate = new Point(x, y);
1429
+ }
1430
+ }
1431
+
1432
+ private getMarkersLegendCollections(layerIndex: number, markers: MarkerSettingsModel[]): void {
1433
+ Array.prototype.forEach.call(markers, (marker: MarkerSettings, markerIndex: number) => {
1434
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1435
+ const dataSource: any[] = marker.dataSource as any[];
1436
+ const field: string = marker.legendText;
1437
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1438
+ let templateFn: any;
1439
+ let isDuplicate: boolean;
1440
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1441
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1442
+ let imageSrc: string = null;
1443
+ const showLegend: boolean = isNullOrUndefined(data[this.maps.legendSettings.showLegendPath]) ? true :
1444
+ data[this.maps.legendSettings.showLegendPath];
1445
+ if (marker.visible && showLegend && (!isNullOrUndefined(data['latitude'])) && (!isNullOrUndefined(data['longitude']))) {
1446
+ if (marker.template) {
1447
+ templateFn = getTemplateFunction(marker.template, this.maps);
1448
+ const templateElement: Element = templateFn(this.maps);
1449
+ const markerEle: Element = isNullOrUndefined(templateElement.childElementCount) ? templateElement[0] :
1450
+ templateElement;
1451
+ imageSrc = markerEle.querySelector('img').src;
1452
+ }
1453
+ const text: string = isNullOrUndefined(data[field]) ? '' : data[field];
1454
+ const legendFill: string = !isNullOrUndefined(marker.colorValuePath) ? data[marker.colorValuePath] : marker.fill;
1455
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1456
+ const newData: any[] = [];
1457
+ if (this.maps.legendSettings.removeDuplicateLegend) {
1458
+ newData.push(this.getMarkerLegendData(layerIndex, text, legendFill));
1459
+ this.getOverallLegendItemsCollection(text, legendFill, newData, showLegend);
1460
+ } else {
1461
+ newData.push({layerIndex : layerIndex, markerIndex: markerIndex, dataIndex: dataIndex, value: legendFill, name: text,
1462
+ shape: (!isNullOrUndefined(marker.shapeValuePath) && !isNullOrUndefined(data[marker.shapeValuePath]) && data[marker.shapeValuePath] !== '') ? data[marker.shapeValuePath] : (this.maps.legendSettings.useMarkerShape ? marker.shape: this.maps.legendSettings.shape)});
1463
+ this.getOverallLegendItemsCollection(text, legendFill, newData, showLegend);
1464
+ }
1465
+ }
1466
+ });
1467
+ });
1468
+ }
1469
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1470
+ private getMarkerLegendData(layerIndex: number, text: string, legendFill: string): any[] {
1471
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1472
+ const legendData: any[] = [];
1473
+ this.maps.layers[layerIndex].markerSettings.map((markerSettings: MarkerSettings, markerIndex: number) => {
1474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1475
+ const markerData: any[] = <any[]>markerSettings.dataSource;
1476
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1477
+ Array.prototype.forEach.call(markerData, (data: any, dataIndex: number) => {
1478
+ const marker: MarkerSettingsModel = this.maps.layers[layerIndex].markerSettings[markerIndex];
1479
+ if ((text === data[marker.legendText] || text === '') && legendFill === data[marker.colorValuePath]) {
1480
+ legendData.push({layerIndex : layerIndex, markerIndex: markerIndex, dataIndex: dataIndex, value: legendFill, name: text,
1481
+ shape: !isNullOrUndefined(marker.shapeValuePath) ? data[marker.shapeValuePath] : marker.shape});
1482
+ }
1483
+ });
1484
+ });
1485
+ return legendData;
1486
+ }
1487
+
1488
+ private getRangeLegendCollection(
1489
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1490
+ layerIndex: number, layerData: any[], colorMapping: ColorMappingSettings[], dataSource: any[],
1491
+ dataPath: string, colorValuePath: string, propertyPath: string | string[]
1492
+ ): void {
1493
+ let legendText: string; let legendIndex: number = 0;
1494
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1495
+ const fill: string = this.maps.legendSettings.fill; let rangeData: any[] = [];
1496
+ for (const colorMap of colorMapping) {
1497
+ if (!isNullOrUndefined(colorMap.from) && !isNullOrUndefined(colorMap.to)) {
1498
+ legendText = !isNullOrUndefined(colorMap.label) ? colorMap.label : colorMap.from + ' - ' + colorMap.to;
1499
+ rangeData = [];
1500
+ let colorMapProcess: boolean = false;
1501
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1502
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1503
+ const colorValue: number = (colorValuePath.indexOf('.') > -1) ? Number(getValueFromObject(data, colorValuePath)) :
1504
+ parseFloat(data[colorValuePath]);
1505
+ if (colorValue >= colorMap.from && colorValue <= colorMap.to) {
1506
+ colorMapProcess = true;
1507
+ rangeData.push(this.getLegendData(layerIndex, dataIndex, data, dataPath, layerData, propertyPath, colorValue));
1508
+ }
1509
+ });
1510
+ if (!colorMapProcess) {
1511
+ rangeData.push({
1512
+ layerIndex: layerIndex, shapeIndex: null, dataIndex: null,
1513
+ name: null, value: null
1514
+ });
1515
+ }
1516
+ const legendFill: string = (isNullOrUndefined(fill)) ? Object.prototype.toString.call(colorMap.color) === '[object Array]' ?
1517
+ !isNullOrUndefined(colorMap.value) ? colorMap.color[0] : this.legendGradientColor(colorMap, legendIndex) :
1518
+ <string>colorMap.color : fill;
1519
+ legendIndex++;
1520
+ this.getOverallLegendItemsCollection(legendText, legendFill, rangeData, colorMap.showLegend);
1521
+ }
1522
+ }
1523
+ }
1524
+
1525
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1526
+ private getOverallLegendItemsCollection(legendText: string, legendFill: string, legendData: any[], showLegend: boolean): void {
1527
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1528
+ const newColllection: any[] = [];
1529
+ const legend: LegendSettingsModel = this.maps.legendSettings;
1530
+ if (legendData.length > 0 && showLegend) {
1531
+ for (let i: number = 0; i < legendData.length; i++) {
1532
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1533
+ const collection: any[] = <any[]>legendData[i];
1534
+ if (collection.length > 0) {
1535
+ for (let j: number = 0; j < collection.length; j++) {
1536
+ newColllection.push(collection[j]);
1537
+ }
1538
+ } else {
1539
+ newColllection.push(legendData[i]);
1540
+ }
1541
+ newColllection['_isVisible'] = true;
1542
+ }
1543
+ const isDuplicate: boolean = this.maps.legendSettings.removeDuplicateLegend ?
1544
+ this.removeDuplicates(this.legendCollection, legendText, legendFill) : false;
1545
+ if (!isDuplicate) {
1546
+ this.legendCollection.push({
1547
+ text: legendText, fill: legendFill, data: newColllection, opacity: legend.opacity,
1548
+ borderColor: legend.shapeBorder.color, borderWidth: legend.shapeBorder.width
1549
+ });
1550
+ } else {
1551
+ for (let i: number = 0; i < this.legendCollection.length; i++) {
1552
+ if (this.legendCollection[i]['text'] === legendText && this.legendCollection[i]['fill'] === legendFill) {
1553
+ this.legendCollection[i].data.push(newColllection[0]);
1554
+ }
1555
+ }
1556
+ }
1557
+ }
1558
+ }
1559
+
1560
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1561
+ private removeDuplicates(legendCollection: any[], text: string, legendFill: string): boolean {
1562
+ let isDuplicate: boolean = false;
1563
+ for (let i: number = 0; i < legendCollection.length; i++) {
1564
+ if ((legendCollection[i]['text'] === text || legendCollection[i]['text'] === '') && legendCollection[i]['fill'] === legendFill) {
1565
+ isDuplicate = true;
1566
+ break;
1567
+ } else {
1568
+ continue;
1569
+ }
1570
+ }
1571
+ return isDuplicate;
1572
+ }
1573
+
1574
+ private getEqualLegendCollection(
1575
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1576
+ layerIndex: number, layerData: any[], colorMapping: ColorMappingSettings[], dataSource: any[],
1577
+ dataPath: string, colorValuePath: string, propertyPath: string | string[]
1578
+ ): void {
1579
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1580
+ const fill: string = this.maps.legendSettings.fill; const equalValues: any[] = [];
1581
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1582
+ let legendText: string; let legendIndex: number = 0; let equalData: any[] = [];
1583
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1584
+ const outOfRangeValues: any[] = []; const outOfRange: any[] = [];
1585
+ for (const colorMap of colorMapping) {
1586
+ if (!isNullOrUndefined(colorMap.value)) {
1587
+ legendText = !isNullOrUndefined(colorMap.label) ? colorMap.label : colorMap.value;
1588
+ equalData = [];
1589
+ let eqaulColorProcess: boolean = false;
1590
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1591
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1592
+ const equalValue: string = ((colorValuePath.indexOf('.') > -1) ? (getValueFromObject(data, colorValuePath)) :
1593
+ (data[colorValuePath]));
1594
+ if (equalValue === colorMap.value) {
1595
+ eqaulColorProcess = true;
1596
+ if (equalValues.indexOf(equalValue) === -1) {
1597
+ equalValues.push(equalValue);
1598
+ }
1599
+ equalData.push(this.getLegendData(layerIndex, dataIndex, data, dataPath, layerData, propertyPath, equalValue));
1600
+ } else {
1601
+ if (outOfRangeValues.indexOf(equalValue) === -1) {
1602
+ outOfRangeValues.push(equalValue);
1603
+ }
1604
+ }
1605
+ });
1606
+ for (let x: number = 0; x < equalValues.length; x++) {
1607
+ for (let y: number = 0; y < outOfRangeValues.length; y++) {
1608
+ if (equalValues[x] === outOfRangeValues[y]) {
1609
+ const equalIndex: number = outOfRangeValues.indexOf(equalValues[x]);
1610
+ outOfRangeValues.splice(equalIndex, 1);
1611
+ }
1612
+ }
1613
+ }
1614
+ if (!eqaulColorProcess) {
1615
+ equalData.push({
1616
+ layerIndex: layerIndex, shapeIndex: null, dataIndex: null,
1617
+ name: null, value: null
1618
+ });
1619
+ }
1620
+ const legendFill: string = (isNullOrUndefined(fill)) ? Object.prototype.toString.call(colorMap.color) === '[object Array]'
1621
+ ? colorMap.color[0] : <string>colorMap.color : fill;
1622
+ legendIndex++;
1623
+ this.getOverallLegendItemsCollection(legendText, legendFill, equalData, colorMap.showLegend);
1624
+ } else if (isNullOrUndefined(colorMap.minOpacity) && isNullOrUndefined(colorMap.maxOpacity) && isNullOrUndefined(colorMap.value)
1625
+ && isNullOrUndefined(colorMap.from) && isNullOrUndefined(colorMap.to) && !isNullOrUndefined(colorMap.color)) {
1626
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1627
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1628
+ const equalValue: string = ((colorValuePath.indexOf('.') > -1) ? (getValueFromObject(data, colorValuePath)) :
1629
+ (data[colorValuePath]));
1630
+ for (let k: number = 0; k < outOfRangeValues.length; k++) {
1631
+ if (equalValue === outOfRangeValues[k]) {
1632
+ outOfRange.push(
1633
+ this.getLegendData(layerIndex, dataIndex, data, dataPath, layerData, propertyPath, equalValue));
1634
+ }
1635
+ }
1636
+ });
1637
+ if (outOfRangeValues.length === 0) {
1638
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1639
+ let range: boolean = false; const outRange: any[] = [];
1640
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1641
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1642
+ range = false;
1643
+ const rangeValue: number = data[colorValuePath];
1644
+ for (let z: number = 0; z < colorMapping.length; z++) {
1645
+ if (!isNullOrUndefined(rangeValue) && !isNaN(rangeValue)) {
1646
+ if (rangeValue >= colorMapping[z].from && rangeValue <= colorMapping[z].to) {
1647
+ range = true;
1648
+ }
1649
+ } else if (!range) {
1650
+ range = false;
1651
+ }
1652
+ }
1653
+ if (!range) {
1654
+ outOfRange.push(this.getLegendData(layerIndex, dataIndex, data, dataPath, layerData, propertyPath, rangeValue));
1655
+ }
1656
+ });
1657
+ }
1658
+ legendText = !isNullOrUndefined(colorMap.label) ? colorMap.label : 'Others';
1659
+ const outfill: string = ((Object.prototype.toString.call(colorMap.color) === '[object Array]'))
1660
+ ? colorMap.color[0] : <string>colorMap.color;
1661
+ const legendOutFill: string = outfill;
1662
+ legendIndex++;
1663
+ this.getOverallLegendItemsCollection(legendText, legendOutFill, outOfRange, colorMap.showLegend);
1664
+ }
1665
+ }
1666
+ }
1667
+
1668
+ private getDataLegendCollection(
1669
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1670
+ layerIndex: number, layerData: any[], colorMapping: ColorMappingSettings[], dataSource: any[],
1671
+ dataPath: string, colorValuePath: string, propertyPath: string | string[]
1672
+ ): void {
1673
+ let legendText: string;
1674
+ const fill: string = this.maps.legendSettings.fill;
1675
+ const valuePath: string = this.maps.legendSettings.valuePath;
1676
+ if (!isNullOrUndefined(colorValuePath) && !isNullOrUndefined(dataSource)) {
1677
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1678
+ Array.prototype.forEach.call(dataSource, (data: any, dataIndex: number) => {
1679
+ const showLegend: boolean = isNullOrUndefined(this.maps.legendSettings.showLegendPath) ?
1680
+ true : isNullOrUndefined(data[this.maps.legendSettings.showLegendPath]) ?
1681
+ false : data[this.maps.legendSettings.showLegendPath];
1682
+ const dataValue: string = ((colorValuePath.indexOf('.') > -1) ? (getValueFromObject(data, colorValuePath)) :
1683
+ (data[colorValuePath]));
1684
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1685
+ const newData: any[] = [];
1686
+ const legendFill: string = (isNullOrUndefined(fill)) ? dataValue : fill;
1687
+ if (!isNullOrUndefined(dataValue) && colorMapping.length === 0) {
1688
+ legendText = !isNullOrUndefined(data[valuePath]) ? ((valuePath.indexOf('.') > -1) ?
1689
+ getValueFromObject(data, valuePath) : data[valuePath]) : ((dataPath.indexOf('.') > -1) ?
1690
+ getValueFromObject(data, dataPath) : data[dataPath]);
1691
+ newData.push(this.getLegendData(layerIndex, dataIndex, data, dataPath, layerData, propertyPath, dataValue));
1692
+ }
1693
+ this.getOverallLegendItemsCollection(legendText, legendFill, newData, showLegend);
1694
+ });
1695
+ }
1696
+ }
1697
+
1698
+ public interactiveHandler(e: PointerEvent): void {
1699
+ const target: Element = <Element>e.target;
1700
+ const legend: LegendSettingsModel = <LegendSettingsModel>this.maps.legendSettings;
1701
+ const id: string = this.maps.element.id + '_Interactive_Legend';
1702
+ const hoverId: string = legend.type === 'Layers' ? '_shapeIndex_' : (legend.type === 'Markers') ? '_MarkerIndex_' :
1703
+ '_BubbleIndex_';
1704
+ if (target.id.indexOf(hoverId) > 1) {
1705
+ const layerIndex: number = parseFloat(target.id.split('_LayerIndex_')[1].split('_')[0]);
1706
+ const dataIndex: number = parseFloat(target.id.split(/_dataIndex_/i)[1].split('_')[0]);
1707
+ let fill: string; let stroke: string; let strokeWidth: number;
1708
+ if (!(isNullOrUndefined(querySelector(id, this.maps.element.id)))) {
1709
+ remove(querySelector(id, this.maps.element.id));
1710
+ }
1711
+ const layer: LayerSettings = (<LayerSettings>this.maps.layersCollection[layerIndex]);
1712
+ const markerVisible: boolean = (legend.type === 'Layers' ? layer.visible :
1713
+ legend.type === 'Markers' ? layer.markerSettings[parseFloat(target.id.split('_MarkerIndex_')[1].split('_')[0])].visible :
1714
+ (this.maps.getBubbleVisible(<LayerSettings>this.maps.layersCollection[layerIndex])));
1715
+ if (legend.visible && this.legendRenderingCollections.length > 0
1716
+ && legend.mode === 'Interactive' && markerVisible
1717
+ ) {
1718
+ const svgRect: ClientRect = this.maps.svgObject.getBoundingClientRect();
1719
+ for (let i: number = 0; i < this.legendCollection.length; i++) {
1720
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1721
+ const currentData: any = this.legendCollection[i];
1722
+ const legendElement: Element = querySelector(this.maps.element.id + '_Legend_Index_' + i, this.maps.element.id);
1723
+ const legendRect: ClientRect = <ClientRect>legendElement.getBoundingClientRect();
1724
+ const rect: Rect = new Rect(
1725
+ Math.abs(legendRect.left - svgRect.left), Math.abs(legendRect.top - svgRect.top),
1726
+ legendRect.width, legendRect.height
1727
+ );
1728
+ fill = legendElement.getAttribute('fill');
1729
+ stroke = legend.shapeBorder.color;
1730
+ strokeWidth = legend.shapeBorder.width;
1731
+ if (!isNullOrUndefined(currentData['data'])) {
1732
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1733
+ const data: any[] = <any[]>currentData['data'];
1734
+ for (let j: number = 0; j < data.length; j++) {
1735
+ if (dataIndex === data[j]['dataIndex'] && layerIndex === data[j]['layerIndex']) {
1736
+ this.renderInteractivePointer(legend, fill, stroke, id, strokeWidth, rect);
1737
+ break;
1738
+ }
1739
+ }
1740
+ }
1741
+ }
1742
+ }
1743
+ } else {
1744
+ if (!(isNullOrUndefined(querySelector(id, this.maps.element.id)))) {
1745
+ remove(querySelector(id, this.maps.element.id));
1746
+ }
1747
+ }
1748
+ }
1749
+
1750
+ private renderInteractivePointer(
1751
+
1752
+ legend: LegendSettingsModel, fill: string, stroke: string, id: string, strokeWidth: number, rect: Rect
1753
+ ): void {
1754
+ let path: string;
1755
+ let locX: number; let locY: number;
1756
+ const height: number = 10; const width: number = 10;
1757
+ const direction: string = (legend.orientation === 'None') ? (legend.position === 'Top' || legend.position === 'Bottom')
1758
+ ? 'Horizontal' : 'Vertical' : legend.orientation;
1759
+ rect.y = legend.position === 'Float' && this.maps.isTileMap ? rect.y - this.maps.mapAreaRect.y : rect.y;
1760
+ if (direction === 'Horizontal') {
1761
+ if (!legend.invertedPointer) {
1762
+ locX = rect.x + (rect.width / 2) - (legend.position === 'Float' && this.maps.isTileMap ? this.maps.mapAreaRect.x : 0)
1763
+ locY = rect.y;
1764
+ path = ' M ' + locX + ' ' + locY + ' L ' + (locX - width) + ' ' + (locY - height) +
1765
+ ' L ' + (locX + width) + ' ' + (locY - height) + ' Z ';
1766
+ } else {
1767
+ locX = rect.x + (rect.width / 2) - (legend.position === 'Float' && this.maps.isTileMap ? this.maps.mapAreaRect.x : 0)
1768
+ locY = rect.y + (rect.height);
1769
+ path = ' M ' + locX + ' ' + locY + ' L ' + (locX - width) + ' ' + (locY + height) +
1770
+ ' L ' + (locX + width) + ' ' + (locY + height) + ' Z ';
1771
+ }
1772
+ } else {
1773
+ if (!legend.invertedPointer) {
1774
+ locX = rect.x + rect.width - (legend.position === 'Float' && this.maps.isTileMap ? this.maps.mapAreaRect.x : 0);
1775
+ locY = rect.y + (rect.height / 2);
1776
+ path = ' M ' + locX + ' ' + locY + ' L ' + (locX + width) + ' ' + (locY - height) +
1777
+ ' L ' + (locX + width) + ' ' + (locY + height) + ' z ';
1778
+ } else {
1779
+ locX = rect.x - (legend.position === 'Float' && this.maps.isTileMap ? this.maps.mapAreaRect.x : 0);
1780
+ locY = rect.y + (rect.height / 2);
1781
+ path = ' M ' + locX + ' ' + locY + ' L ' + (locX - width) + ' ' + (locY - height) +
1782
+ ' L ' + (locX - width) + ' ' + (locY + height) + ' z ';
1783
+ }
1784
+ }
1785
+ const pathOptions: PathOption = new PathOption(id, fill, strokeWidth, stroke, 1, 1, '', path);
1786
+ if (legend.position === 'Float' && this.maps.isTileMap) {
1787
+ this.maps.mapLayerPanel.layerGroup.appendChild(this.maps.renderer.drawPath(pathOptions) as SVGPathElement);
1788
+ } else {
1789
+ this.maps.svgObject.appendChild(this.maps.renderer.drawPath(pathOptions) as SVGPathElement);
1790
+ }
1791
+ }
1792
+
1793
+ public wireEvents(element: Element): void {
1794
+ EventHandler.add(element, Browser.touchStartEvent, this.changeNextPage, this);
1795
+ }
1796
+
1797
+ public addEventListener(): void {
1798
+ if (this.maps.isDestroyed) {
1799
+ return;
1800
+ }
1801
+ this.maps.on(Browser.touchMoveEvent, this.interactiveHandler, this);
1802
+ this.maps.on(Browser.touchEndEvent, this.interactiveHandler, this);
1803
+ this.maps.on(click, this.legendClick, this);
1804
+ }
1805
+
1806
+ private markerToggleSelection(mapElement: Element, layerIndex: number, markerIndex: number, legendIndex: number): void {
1807
+ mapElement.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
1808
+ mapElement.setAttribute('stroke', this.maps.layers[layerIndex].markerSettings[markerIndex].border.color);
1809
+ mapElement.setAttribute('fill-opacity', (this.maps.layers[layerIndex].markerSettings[markerIndex].opacity).toString());
1810
+ mapElement.setAttribute('stroke-width', (this.maps.layers[layerIndex].markerSettings[markerIndex].border.width).toString());
1811
+ mapElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[layerIndex].markerSettings[markerIndex].border.opacity) ?
1812
+ this.maps.layers[layerIndex].markerSettings[markerIndex].opacity :
1813
+ this.maps.layers[layerIndex].markerSettings[markerIndex].border.opacity).toString());
1814
+ }
1815
+
1816
+ private bubbleToggleSelection(mapElement: Element, layerIndex: number, bubbleIndex: number, legendIndex: number): void {
1817
+ mapElement.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
1818
+ mapElement.setAttribute('stroke', this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].border.color);
1819
+ mapElement.setAttribute('fill-opacity', (this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].opacity).toString());
1820
+ mapElement.setAttribute('stroke-width', (this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].border.width).toString());
1821
+ mapElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].border.opacity) ?
1822
+ this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].opacity :
1823
+ this.maps.layers[layerIndex].bubbleSettings[bubbleIndex].border.opacity).toString());
1824
+ }
1825
+
1826
+ private legendClick(targetEle: Element): void {
1827
+ let legendShapeId: Element;
1828
+ let legendTextId: Element;
1829
+ let legendTextColor: string;
1830
+ const legendToggleFill: string = this.maps.legendSettings.toggleLegendSettings.fill;
1831
+ const legendToggleOpacity: number = this.maps.legendSettings.toggleLegendSettings.opacity;
1832
+ const legendToggleBorderColor: string = this.maps.legendSettings.toggleLegendSettings.border.color;
1833
+ const legendToggleBorderWidth: number = this.maps.legendSettings.toggleLegendSettings.border.width;
1834
+ const legendToggleBorderOpacity: number = isNullOrUndefined(this.maps.legendSettings.toggleLegendSettings.border.opacity) ?
1835
+ this.maps.legendSettings.toggleLegendSettings.opacity : this.maps.legendSettings.toggleLegendSettings.border.opacity;
1836
+ if (targetEle.parentNode['id'].indexOf(this.maps.element.id + '_Legend_Index_') > -1) {
1837
+ let mapElement: Element;
1838
+ const legendIndex: number = parseFloat(targetEle.parentElement.id.substr((this.maps.element.id + '_Legend_Index_').length));
1839
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1840
+ const selectedItem: any[] = this.legendCollection[legendIndex]['data'];
1841
+ let isVisible: boolean = selectedItem['_isVisible'];
1842
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1843
+ let shape: any;
1844
+ if (this.maps.legendSettings.toggleLegendSettings.enable && (this.maps.legendSettings.type === 'Bubbles' || this.maps.legendSettings.type === 'Markers')) {
1845
+ for (let k: number = 0; k < this.maps.layers.length; k++) {
1846
+ for (let j: number = 0; j < (this.maps.legendSettings.type === 'Bubbles' ? this.maps.layers[k].bubbleSettings.length : this.maps.layers[k].markerSettings.length); j++) {
1847
+ for (let i: number = 0; i < selectedItem.length; i++) {
1848
+ shape = this.legendCollection[legendIndex]['data'][i];
1849
+ mapElement = this.maps.legendSettings.type === 'Bubbles' ? querySelector(this.maps.element.id + '_LayerIndex_' + shape['layerIndex'] +
1850
+ '_BubbleIndex_' + j + '_dataIndex_' + shape['dataIndex'], this.maps.element.id) : querySelector(this.maps.element.id + '_LayerIndex_' + shape['layerIndex'] +
1851
+ '_MarkerIndex_' + shape['markerIndex'] + '_dataIndex_' + shape['dataIndex'], this.maps.element.id);
1852
+ if (!isNullOrUndefined(shape['shape']) && shape['shape'] === 'Balloon') {
1853
+ mapElement = this.maps.legendSettings.type === 'Bubbles' ? querySelector(this.maps.element.id + '_LayerIndex_' + shape['layerIndex'] +
1854
+ '_BubbleIndex_' + j + '_dataIndex_' + shape['dataIndex'] + '_Group', this.maps.element.id) : querySelector(this.maps.element.id + '_LayerIndex_' + shape['layerIndex'] +
1855
+ '_MarkerIndex_' + shape['markerIndex'] + '_dataIndex_' + shape['dataIndex'] + '_Group', this.maps.element.id);
1856
+ mapElement = mapElement.children[0];
1857
+ }
1858
+ if (isVisible && mapElement !== null) {
1859
+ if (this.maps.legendSettings.toggleLegendSettings.applyShapeSettings) {
1860
+ mapElement.setAttribute('fill', this.maps.layers[k].shapeSettings.fill);
1861
+ mapElement.setAttribute('stroke', this.maps.layers[k].shapeSettings.border.color);
1862
+ mapElement.setAttribute('fill-opacity', (this.maps.layers[k].shapeSettings.opacity).toString());
1863
+ mapElement.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.width) ? 0 : this.maps.layers[k].shapeSettings.border.width).toString());
1864
+ mapElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.opacity) ?
1865
+ this.maps.layers[k].shapeSettings.opacity :
1866
+ this.maps.layers[k].shapeSettings.border.opacity).toString());
1867
+ } else {
1868
+ mapElement.setAttribute('fill', legendToggleFill);
1869
+ mapElement.setAttribute('fill-opacity', (legendToggleOpacity).toString());
1870
+ mapElement.setAttribute('stroke', legendToggleBorderColor);
1871
+ mapElement.setAttribute('stroke-width', (legendToggleBorderWidth).toString());
1872
+ mapElement.setAttribute('stroke-opacity', (legendToggleBorderOpacity).toString());
1873
+ }
1874
+ if (targetEle !== null) {
1875
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Shape_Index_' + legendIndex, this.maps.element.id);
1876
+ legendShapeId.setAttribute('fill', '#E5E5E5');
1877
+ if (this.maps.legendSettings.shape === 'HorizontalLine' || this.maps.legendSettings.shape === 'VerticalLine' || this.maps.legendSettings.shape === 'Cross') {
1878
+ legendShapeId.setAttribute('stroke', '#E5E5E5');
1879
+ }
1880
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Text_Index_' + legendIndex, this.maps.element.id);
1881
+ legendTextId.setAttribute('fill', '#E5E5E5');
1882
+ }
1883
+ } else {
1884
+ if (this.maps.legendSettings.type === 'Markers') {
1885
+ this.markerToggleSelection(mapElement, k, j, legendIndex);
1886
+ } else {
1887
+ this.bubbleToggleSelection(mapElement, k, j, legendIndex);
1888
+ }
1889
+ if (targetEle !== null) {
1890
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Shape_Index_' + legendIndex, this.maps.element.id);
1891
+ legendShapeId.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
1892
+ if (this.maps.legendSettings.shape === 'HorizontalLine' || this.maps.legendSettings.shape === 'VerticalLine' || this.maps.legendSettings.shape === 'Cross') {
1893
+ legendShapeId.setAttribute('stroke', this.legendCollection[legendIndex]['fill']);
1894
+ }
1895
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Text_Index_' + legendIndex, this.maps.element.id);
1896
+ legendTextId.setAttribute('fill', '#757575');
1897
+ }
1898
+ }
1899
+ }
1900
+ selectedItem['_isVisible'] = isVisible ? false : true;
1901
+ }
1902
+ }
1903
+ }
1904
+ if (this.maps.legendSettings.type === 'Layers' && this.maps.legendSettings.toggleLegendSettings.enable) {
1905
+ let layerElement: Element;
1906
+ this.removeCollections(targetEle, legendIndex);
1907
+ const toggledLegendIdIndex: number = this.maps.toggledLegendId.indexOf(legendIndex);
1908
+ if (toggledLegendIdIndex !== -1) { isVisible = false; }
1909
+ for (let j: number = 0; j < this.maps.layers.length; j++) {
1910
+ for (let i: number = 0; i < selectedItem.length; i++) {
1911
+ shape = this.legendCollection[legendIndex]['data'][i];
1912
+ layerElement = querySelector(this.maps.element.id + '_LayerIndex_' + shape['layerIndex'] +
1913
+ '_shapeIndex_' + shape['shapeIndex'] + '_dataIndex_' + shape['dataIndex'], this.maps.element.id);
1914
+ if (layerElement !== null) {
1915
+ const toggledShapeIdIndex: number = this.maps.toggledShapeElementId.indexOf(layerElement.id);
1916
+ if (isVisible) {
1917
+ if (i === 0) {
1918
+ this.maps.toggledLegendId.push(legendIndex);
1919
+ }
1920
+ if (toggledShapeIdIndex === -1) {
1921
+ this.maps.toggledShapeElementId.push(layerElement.id);
1922
+ }
1923
+ if (this.maps.legendSettings.toggleLegendSettings.applyShapeSettings) {
1924
+ layerElement.setAttribute('fill', this.maps.layers[j].shapeSettings.fill);
1925
+ layerElement.setAttribute('fill-opacity', (this.maps.layers[j].shapeSettings.opacity).toString());
1926
+ layerElement.setAttribute('stroke', this.maps.layers[j].shapeSettings.border.color);
1927
+ layerElement.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[j].shapeSettings.border.width) ? 0 : this.maps.layers[j].shapeSettings.border.width).toString());
1928
+ layerElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[j].shapeSettings.border.opacity) ?
1929
+ this.maps.layers[j].shapeSettings.opacity :
1930
+ this.maps.layers[j].shapeSettings.border.opacity).toString());
1931
+ } else {
1932
+ layerElement.setAttribute('fill', legendToggleFill);
1933
+ layerElement.setAttribute('fill-opacity', (legendToggleOpacity).toString());
1934
+ layerElement.setAttribute('stroke', legendToggleBorderColor);
1935
+ layerElement.setAttribute('stroke-width', (legendToggleBorderWidth).toString());
1936
+ layerElement.setAttribute('stroke-opacity', (legendToggleBorderOpacity).toString());
1937
+ }
1938
+ if (targetEle !== null) {
1939
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Text_Index_' + legendIndex, this.maps.element.id);
1940
+ legendTextId.setAttribute('fill', '#E5E5E5');
1941
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Shape_Index_' + legendIndex, this.maps.element.id);
1942
+ legendShapeId.setAttribute('fill', '#E5E5E5');
1943
+ }
1944
+ } else {
1945
+ if (toggledLegendIdIndex !== -1 && i === 0) {
1946
+ this.maps.toggledLegendId.splice(toggledLegendIdIndex, 1);
1947
+ }
1948
+ if (toggledShapeIdIndex !== -1) {
1949
+ this.maps.toggledShapeElementId.splice(toggledShapeIdIndex, 1);
1950
+ }
1951
+ layerElement.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
1952
+ layerElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[j].shapeSettings.border.opacity) ?
1953
+ this.maps.layers[j].shapeSettings.opacity :
1954
+ this.maps.layers[j].shapeSettings.border.opacity).toString());
1955
+ layerElement.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[j].shapeSettings.border.width) ? 0 : this.maps.layers[j].shapeSettings.border.width).toString());
1956
+ layerElement.setAttribute('fill-opacity', (this.maps.layers[j].shapeSettings.opacity).toString());
1957
+ layerElement.setAttribute('stroke', this.maps.layers[j].shapeSettings.border.color);
1958
+ if (targetEle !== null) {
1959
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Text_Index_' + legendIndex, this.maps.element.id);
1960
+ legendTextId.setAttribute('fill', '#757575');
1961
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Shape_Index_' + legendIndex, this.maps.element.id);
1962
+ legendShapeId.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
1963
+ }
1964
+ }
1965
+ }
1966
+ }
1967
+ }
1968
+ selectedItem['_isVisible'] = isVisible ? false : true;
1969
+ }
1970
+ } else if (!isNullOrUndefined(targetEle.id) && (targetEle.id.indexOf(this.maps.element.id + '_Legend_Shape_Index') > -1 ||
1971
+ targetEle.id.indexOf(this.maps.element.id + '_Legend_Index') !== -1) && this.maps.legendSettings.visible &&
1972
+ targetEle.id.indexOf('_Text') === -1) {
1973
+ let LegendInteractive: Element;
1974
+ const legendIndex: number = parseFloat(targetEle.id.split(this.maps.element.id + '_Legend_Index_')[1]);
1975
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1976
+ let mapdata: any;
1977
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1978
+ const selectedItem: any[] = this.legendCollection[legendIndex]['data'];
1979
+ let isVisible: boolean = selectedItem['_isVisible'];
1980
+ if ((this.maps.legendSettings.type === 'Bubbles' || this.maps.legendSettings.type === 'Markers') && this.maps.legendSettings.toggleLegendSettings.enable) {
1981
+ for (let k: number = 0; k < this.maps.layers.length; k++) {
1982
+ for (let j: number = 0; j < (this.maps.legendSettings.type === 'Bubbles' ? this.maps.layers[k].bubbleSettings.length : this.maps.layers[k].markerSettings.length); j++) {
1983
+ for (let i: number = 0; i < selectedItem.length; i++) {
1984
+ mapdata = this.legendCollection[legendIndex]['data'][i];
1985
+ LegendInteractive = this.maps.legendSettings.type === 'Bubbles' ? querySelector(this.maps.element.id + '_LayerIndex_' + mapdata['layerIndex'] +
1986
+ '_BubbleIndex_' + j + '_dataIndex_' + mapdata['dataIndex'], this.maps.element.id) : querySelector(this.maps.element.id + '_LayerIndex_' + mapdata['layerIndex'] +
1987
+ '_MarkerIndex_' + j + '_dataIndex_' + mapdata['dataIndex'], this.maps.element.id);
1988
+ if (!isNullOrUndefined(mapdata['shape']) && mapdata['shape'] === 'Balloon') {
1989
+ LegendInteractive = this.maps.legendSettings.type === 'Bubbles' ? querySelector(this.maps.element.id + '_LayerIndex_' + mapdata['layerIndex'] +
1990
+ '_BubbleIndex_' + j + '_dataIndex_' + mapdata['dataIndex'] + '_Group', this.maps.element.id) : querySelector(this.maps.element.id + '_LayerIndex_' + mapdata['layerIndex'] +
1991
+ '_MarkerIndex_' + j + '_dataIndex_' + mapdata['dataIndex'] + '_Group', this.maps.element.id);
1992
+ LegendInteractive = LegendInteractive.children[0];
1993
+ }
1994
+ if (isVisible && LegendInteractive !== null) {
1995
+
1996
+ if (this.maps.legendSettings.toggleLegendSettings.applyShapeSettings) {
1997
+ LegendInteractive.setAttribute('fill', this.maps.layers[k].shapeSettings.fill);
1998
+ LegendInteractive.setAttribute('stroke', this.maps.layers[k].shapeSettings.border.color);
1999
+ LegendInteractive.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.width) ? 0 : this.maps.layers[k].shapeSettings.border.width).toString());
2000
+ LegendInteractive.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.opacity) ?
2001
+ this.maps.layers[k].shapeSettings.opacity :
2002
+ this.maps.layers[k].shapeSettings.border.opacity).toString());
2003
+ LegendInteractive.setAttribute('fill-opacity', (this.maps.layers[k].shapeSettings.opacity).toString());
2004
+ } else {
2005
+ LegendInteractive.setAttribute('fill', legendToggleFill);
2006
+ LegendInteractive.setAttribute('fill-opacity', (legendToggleOpacity).toString());
2007
+ LegendInteractive.setAttribute('stroke', legendToggleBorderColor);
2008
+ LegendInteractive.setAttribute('stroke-width', (legendToggleBorderWidth).toString());
2009
+ LegendInteractive.setAttribute('stroke-opacity', (legendToggleBorderOpacity).toString());
2010
+ }
2011
+ if (targetEle !== null) {
2012
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex + '_Text', this.maps.element.id);
2013
+ legendTextId.setAttribute('fill', '#E5E5E5');
2014
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex, this.maps.element.id);
2015
+ legendShapeId.setAttribute('fill', '#E5E5E5');
2016
+ }
2017
+ } else {
2018
+ if (this.maps.legendSettings.type === 'Markers') {
2019
+ this.markerToggleSelection(LegendInteractive, k, j, legendIndex);
2020
+ } else {
2021
+ this.bubbleToggleSelection(LegendInteractive, k, j, legendIndex);
2022
+ }
2023
+ if (targetEle !== null) {
2024
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex, this.maps.element.id);
2025
+ legendShapeId.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
2026
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex + '_Text', this.maps.element.id);
2027
+ legendTextId.setAttribute('fill', '#757575');
2028
+ }
2029
+ }
2030
+ }
2031
+ selectedItem['_isVisible'] = isVisible ? false : true;
2032
+ }
2033
+ }
2034
+ }
2035
+ if (this.maps.legendSettings.type === 'Layers' && this.maps.legendSettings.toggleLegendSettings.enable) {
2036
+ let mapLegendElement: Element;
2037
+ this.removeCollections(targetEle, legendIndex);
2038
+ const toggleLegendIdIndex: number = this.maps.toggledLegendId.indexOf(legendIndex);
2039
+ if (toggleLegendIdIndex !== -1) { isVisible = false; }
2040
+ for (let k: number = 0; k < this.maps.layers.length; k++) {
2041
+ for (let i: number = 0; i < selectedItem.length; i++) {
2042
+ mapdata = this.legendCollection[legendIndex]['data'][i];
2043
+ mapLegendElement = querySelector(this.maps.element.id + '_LayerIndex_' + mapdata['layerIndex'] +
2044
+ '_shapeIndex_' + mapdata['shapeIndex'] + '_dataIndex_' + mapdata['dataIndex'], this.maps.element.id);
2045
+ if (mapLegendElement !== null) {
2046
+ const toggledShapeIdIndex: number = this.maps.toggledShapeElementId.indexOf(mapLegendElement.id);
2047
+ if (isVisible) {
2048
+ if (i === 0) {
2049
+ this.maps.toggledLegendId.push(legendIndex);
2050
+ }
2051
+ if (toggledShapeIdIndex === -1) {
2052
+ this.maps.toggledShapeElementId.push(mapLegendElement.id);
2053
+ }
2054
+ if (this.maps.legendSettings.toggleLegendSettings.applyShapeSettings) {
2055
+ mapLegendElement.setAttribute('fill', this.maps.layers[0].shapeSettings.fill);
2056
+ mapLegendElement.setAttribute('stroke', this.maps.layers[0].shapeSettings.border.color);
2057
+ mapLegendElement.setAttribute('fill-opacity', (this.maps.layers[k].shapeSettings.opacity).toString());
2058
+ mapLegendElement.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.width) ? 0 : this.maps.layers[k].shapeSettings.border.width).toString());
2059
+ mapLegendElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.opacity) ?
2060
+ this.maps.layers[k].shapeSettings.opacity :
2061
+ this.maps.layers[k].shapeSettings.border.opacity).toString());
2062
+ } else {
2063
+ mapLegendElement.setAttribute('fill', legendToggleFill);
2064
+ mapLegendElement.setAttribute('fill-opacity', (legendToggleOpacity).toString());
2065
+ mapLegendElement.setAttribute('stroke', legendToggleBorderColor);
2066
+ mapLegendElement.setAttribute('stroke-width', (legendToggleBorderWidth).toString());
2067
+ mapLegendElement.setAttribute('stroke-opacity', (legendToggleBorderOpacity).toString());
2068
+ }
2069
+ if (targetEle !== null) {
2070
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex, this.maps.element.id);
2071
+ legendShapeId.setAttribute('fill', '#E5E5E5');
2072
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex + '_Text', this.maps.element.id);
2073
+ legendTextId.setAttribute('fill', '#E5E5E5');
2074
+ }
2075
+ } else {
2076
+ if (toggleLegendIdIndex !== -1 && i === 0) {
2077
+ this.maps.toggledLegendId.splice(toggleLegendIdIndex, 1);
2078
+ }
2079
+ if (toggledShapeIdIndex !== -1) {
2080
+ this.maps.toggledShapeElementId.splice(toggledShapeIdIndex, 1);
2081
+ }
2082
+ mapLegendElement.setAttribute('fill-opacity', (this.maps.layers[k].shapeSettings.opacity).toString());
2083
+ mapLegendElement.setAttribute('stroke-width', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.width) ? 0 : this.maps.layers[k].shapeSettings.border.width).toString());
2084
+ mapLegendElement.setAttribute('stroke', this.maps.layers[0].shapeSettings.border.color);
2085
+ mapLegendElement.setAttribute('stroke-opacity', (isNullOrUndefined(this.maps.layers[k].shapeSettings.border.opacity) ?
2086
+ this.maps.layers[k].shapeSettings.opacity : this.maps.layers[k].shapeSettings.border.opacity).toString());
2087
+ mapLegendElement.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
2088
+ if (targetEle !== null) {
2089
+ legendTextId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex + '_Text', this.maps.element.id);
2090
+ legendTextId.setAttribute('fill', '#757575');
2091
+ legendShapeId = querySelector(this.maps.element.id + '_Legend_Index_' + legendIndex, this.maps.element.id);
2092
+ legendShapeId.setAttribute('fill', this.legendCollection[legendIndex]['fill']);
2093
+ }
2094
+ }
2095
+ }
2096
+ }
2097
+ }
2098
+ selectedItem['_isVisible'] = isVisible ? false : true;
2099
+ }
2100
+ }
2101
+ }
2102
+
2103
+ private removeCollections(targetEle: Element, legendIndex: number): void {
2104
+ this.removeLegendSelectionCollection(targetEle);
2105
+ const legendSelectionIndex: number = this.getIndexofLegend(this.maps.legendSelectionCollection, targetEle);
2106
+ if (legendSelectionIndex !== -1) {
2107
+ this.maps.legendSelectionCollection.splice(legendSelectionIndex, 1);
2108
+ }
2109
+ const legendHighlightIndex: number = this.getIndexofLegend(this.legendHighlightCollection, targetEle);
2110
+ if (legendHighlightIndex !== -1) {
2111
+ this.legendHighlightCollection.splice(legendSelectionIndex, 1);
2112
+ }
2113
+ const shapeHighlightIndex: number = this.getIndexofLegend(this.shapeHighlightCollection, targetEle);
2114
+ if (shapeHighlightIndex !== -1) {
2115
+ this.shapeHighlightCollection.splice(shapeHighlightIndex, 1);
2116
+ }
2117
+ const selectedIndex: number = this.maps.selectedLegendElementId.indexOf(legendIndex);
2118
+ if (selectedIndex !== -1) { this.maps.selectedLegendElementId.splice(selectedIndex, 1); }
2119
+ }
2120
+
2121
+ public removeEventListener(): void {
2122
+ if (this.maps.isDestroyed) {
2123
+ return;
2124
+ }
2125
+ this.maps.off(Browser.touchMoveEvent, this.interactiveHandler);
2126
+ this.maps.off(Browser.touchEndEvent, this.interactiveHandler);
2127
+ this.maps.off(click, this.legendClick);
2128
+ }
2129
+
2130
+ private getLegendData(
2131
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2132
+ layerIndex: number, dataIndex: number, data: any, dataPath: string,
2133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2134
+ layerData: any[], shapePropertyPath: string | string[], value: string | number
2135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2136
+ ): any[] {
2137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2138
+ const legendData: any[] = [];
2139
+ if (Object.prototype.toString.call(layerData) === '[object Array]') {
2140
+ for (let i: number = 0; i < layerData.length; i++) {
2141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2142
+ const shapeData: any = layerData[i];
2143
+ const dataPathValue: string = (dataPath.indexOf('.') > -1 ) ? getValueFromObject(data, dataPath) : data[dataPath];
2144
+ const shapePath: string = checkPropertyPath(data[dataPath], shapePropertyPath, shapeData['properties']);
2145
+ const dataPathValueCase : string | number = !isNullOrUndefined(dataPathValue)
2146
+ ? dataPathValue.toLowerCase() : dataPathValue;
2147
+ const shapeDataValueCase : string = !isNullOrUndefined(shapeData['properties'][shapePath])
2148
+ && isNaN(shapeData['properties'][shapePath]) ? shapeData['properties'][shapePath].toLowerCase() : shapeData['properties'][shapePath];
2149
+ if (shapeDataValueCase === dataPathValueCase) {
2150
+ if (shapeData['geometry']['type'] != 'MultiPoint') {
2151
+ legendData.push({
2152
+ layerIndex: layerIndex, shapeIndex: i, dataIndex: dataIndex,
2153
+ name: data[dataPath], value: value, pointIndex: -1
2154
+ });
2155
+ } else {
2156
+ for (let j: number = 0; j < shapeData['geometry'].coordinates.length; j++) {
2157
+ legendData.push({
2158
+ layerIndex: layerIndex, shapeIndex: i, dataIndex: dataIndex,
2159
+ name: data[dataPath], value: value, pointIndex: j
2160
+ });
2161
+ }
2162
+ }
2163
+ }
2164
+ }
2165
+ }
2166
+ return legendData;
2167
+ }
2168
+
2169
+ public legendGradientColor(colorMap: ColorMappingSettings, legendIndex: number): string {
2170
+ let legendFillColor: string;
2171
+ const xmlns: string = 'http://www.w3.org/2000/svg';
2172
+ if (!isNullOrUndefined(colorMap.color) && typeof (colorMap.color) === 'object') {
2173
+ const linerGradientEle: Element = document.createElementNS(xmlns, 'linearGradient');
2174
+ const opacity: number = 1; const position: LegendPosition = this.maps.legendSettings.position;
2175
+ const x2: string = position === 'Top' || position === 'Bottom' ? '100' : '0';
2176
+ const y2: string = position === 'Top' || position === 'Bottom' ? '0' : '100';
2177
+ linerGradientEle.setAttribute('id', 'linear_' + legendIndex + '_' + this.maps.element.id);
2178
+ linerGradientEle.setAttribute('x1', 0 + '%');
2179
+ linerGradientEle.setAttribute('y1', 0 + '%');
2180
+ linerGradientEle.setAttribute('x2', x2 + '%');
2181
+ linerGradientEle.setAttribute('y2', y2 + '%');
2182
+ for (let b: number = 0; b < colorMap.color.length; b++) {
2183
+ const offsetColor: number = 100 / (colorMap.color.length - 1);
2184
+ const stopEle: Element = document.createElementNS(xmlns, 'stop');
2185
+ stopEle.setAttribute('offset', b * offsetColor + '%');
2186
+ stopEle.setAttribute('stop-color', colorMap.color[b]);
2187
+ stopEle.setAttribute('stop-opacity', opacity.toString());
2188
+ linerGradientEle.appendChild(stopEle);
2189
+ }
2190
+ this.legendLinearGradient = linerGradientEle;
2191
+ const color: string = 'url(' + '#linear_' + legendIndex + '_' + this.maps.element.id + ')';
2192
+ this.defsElement.appendChild(linerGradientEle);
2193
+ legendFillColor = color;
2194
+ }
2195
+ return legendFillColor;
2196
+ }
2197
+
2198
+
2199
+ /**
2200
+ * Get module name.
2201
+ *
2202
+ * @returns {string} - Returns the module name
2203
+ */
2204
+ protected getModuleName(): string {
2205
+ return 'Legend';
2206
+ }
2207
+
2208
+ /**
2209
+ * To destroy the legend.
2210
+ *
2211
+ * @returns {void}
2212
+ * @private
2213
+ */
2214
+ public destroy(): void {
2215
+ this.legendCollection = [];
2216
+ this.legendRenderingCollections = [];
2217
+ this.translate = null;
2218
+ this.legendBorderRect = null;
2219
+ this.initialMapAreaRect = null;
2220
+ this.legendTotalRect = null;
2221
+ this.totalPages = [];
2222
+ this.legendItemRect = null;
2223
+ this.legendGroup = null;
2224
+ this.shapeHighlightCollection = [];
2225
+ this.legendHighlightCollection = [];
2226
+ this.shapePreviousColor = [];
2227
+ this.selectedNonLegendShapes = [];
2228
+ this.legendLinearGradient = null;
2229
+ this.currentLayer = null;
2230
+ this.defsElement = null;
2231
+ this.legendElement = [];
2232
+ this.oldShapeElement = null;
2233
+ this.removeEventListener();
2234
+ this.maps = null;
2235
+ }
2236
+ }