@syncfusion/ej2-maps 30.2.4 → 31.1.17

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