@syncfusion/ej2-maps 19.4.56 → 19.4.57-105067

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.eslintrc.json +18 -3
  2. package/.github/PULL_REQUEST_TEMPLATE/Bug.md +72 -72
  3. package/.github/PULL_REQUEST_TEMPLATE/Feature.md +49 -49
  4. package/CHANGELOG.md +441 -439
  5. package/README.md +73 -73
  6. package/dist/ej2-maps.umd.min.js +1 -10
  7. package/dist/ej2-maps.umd.min.js.map +1 -1
  8. package/dist/es6/ej2-maps.es2015.js +1161 -638
  9. package/dist/es6/ej2-maps.es2015.js.map +1 -1
  10. package/dist/es6/ej2-maps.es5.js +1200 -678
  11. package/dist/es6/ej2-maps.es5.js.map +1 -1
  12. package/dist/global/ej2-maps.min.js +1 -10
  13. package/dist/global/ej2-maps.min.js.map +1 -1
  14. package/dist/global/index.d.ts +0 -9
  15. package/dist/ts/maps/layers/bing-map.ts +50 -0
  16. package/dist/ts/maps/layers/bubble.ts +290 -0
  17. package/dist/ts/maps/layers/color-mapping.ts +226 -0
  18. package/dist/ts/maps/layers/data-label.ts +418 -0
  19. package/dist/ts/maps/layers/layer-panel.ts +1480 -0
  20. package/dist/ts/maps/layers/legend.ts +2236 -0
  21. package/dist/ts/maps/layers/marker.ts +453 -0
  22. package/dist/ts/maps/layers/navigation-selected-line.ts +167 -0
  23. package/dist/ts/maps/maps.ts +2886 -0
  24. package/dist/ts/maps/model/base.ts +1843 -0
  25. package/dist/ts/maps/model/constants.ts +200 -0
  26. package/dist/ts/maps/model/export-image.ts +178 -0
  27. package/dist/ts/maps/model/export-pdf.ts +170 -0
  28. package/dist/ts/maps/model/interface.ts +823 -0
  29. package/dist/ts/maps/model/print.ts +104 -0
  30. package/dist/ts/maps/model/theme.ts +554 -0
  31. package/dist/ts/maps/user-interaction/annotation.ts +127 -0
  32. package/dist/ts/maps/user-interaction/highlight.ts +233 -0
  33. package/dist/ts/maps/user-interaction/selection.ts +321 -0
  34. package/dist/ts/maps/user-interaction/tooltip.ts +387 -0
  35. package/dist/ts/maps/user-interaction/zoom.ts +1767 -0
  36. package/dist/ts/maps/utils/enum.ts +368 -0
  37. package/dist/ts/maps/utils/helper.ts +3421 -0
  38. package/helper/e2e/index.js +3 -3
  39. package/helper/e2e/maps-helper.js +13 -13
  40. package/license +9 -9
  41. package/package.json +85 -85
  42. package/src/maps/layers/bing-map.d.ts +4 -0
  43. package/src/maps/layers/bing-map.js +16 -3
  44. package/src/maps/layers/bubble.d.ts +1 -2
  45. package/src/maps/layers/bubble.js +7 -12
  46. package/src/maps/layers/data-label.d.ts +1 -4
  47. package/src/maps/layers/data-label.js +32 -35
  48. package/src/maps/layers/layer-panel.d.ts +18 -1
  49. package/src/maps/layers/layer-panel.js +226 -72
  50. package/src/maps/layers/legend.d.ts +5 -2
  51. package/src/maps/layers/legend.js +170 -61
  52. package/src/maps/layers/marker.d.ts +2 -4
  53. package/src/maps/layers/marker.js +49 -48
  54. package/src/maps/layers/navigation-selected-line.d.ts +1 -2
  55. package/src/maps/layers/navigation-selected-line.js +7 -13
  56. package/src/maps/maps-model.d.ts +259 -251
  57. package/src/maps/maps.d.ts +24 -3
  58. package/src/maps/maps.js +152 -90
  59. package/src/maps/model/base-model.d.ts +1025 -1021
  60. package/src/maps/model/base.d.ts +5 -1
  61. package/src/maps/model/base.js +24 -24
  62. package/src/maps/model/constants.d.ts +6 -0
  63. package/src/maps/model/constants.js +6 -0
  64. package/src/maps/model/export-image.d.ts +2 -4
  65. package/src/maps/model/export-image.js +26 -32
  66. package/src/maps/model/export-pdf.d.ts +4 -6
  67. package/src/maps/model/export-pdf.js +27 -35
  68. package/src/maps/model/interface.d.ts +34 -26
  69. package/src/maps/model/print.d.ts +2 -5
  70. package/src/maps/model/print.js +33 -21
  71. package/src/maps/model/theme.js +7 -4
  72. package/src/maps/user-interaction/annotation.d.ts +1 -2
  73. package/src/maps/user-interaction/annotation.js +3 -4
  74. package/src/maps/user-interaction/highlight.d.ts +1 -2
  75. package/src/maps/user-interaction/highlight.js +11 -10
  76. package/src/maps/user-interaction/selection.d.ts +1 -2
  77. package/src/maps/user-interaction/selection.js +42 -19
  78. package/src/maps/user-interaction/tooltip.d.ts +3 -5
  79. package/src/maps/user-interaction/tooltip.js +27 -14
  80. package/src/maps/user-interaction/zoom.d.ts +3 -8
  81. package/src/maps/user-interaction/zoom.js +282 -162
  82. package/src/maps/utils/enum.d.ts +5 -1
  83. package/src/maps/utils/helper.d.ts +1 -1
  84. package/src/maps/utils/helper.js +62 -31
@@ -1,12 +1,3 @@
1
- /*!
2
- * filename: index.d.ts
3
- * version : 19.4.56
4
- * Copyright Syncfusion Inc. 2001 - 2020. All rights reserved.
5
- * Use of this code is subject to the terms of our license.
6
- * A copy of the current license can be obtained at any time by e-mailing
7
- * licensing@syncfusion.com. Any infringement will be prosecuted under
8
- * applicable laws.
9
- */
10
1
  import * as _maps from '@syncfusion/ej2-maps';
11
2
 
12
3
  export declare namespace ej {
@@ -0,0 +1,50 @@
1
+ import { Maps } from '../maps';
2
+ import { Tile, BingMapType } from '../index';
3
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
4
+
5
+ /**
6
+ * Bing map src doc
7
+ */
8
+ export class BingMap {
9
+ /**
10
+ * map instance
11
+ */
12
+ private maps: Maps;
13
+ public subDomains: string[];
14
+ public imageUrl: string;
15
+ public maxZoom: string;
16
+ constructor(maps: Maps) {
17
+ this.maps = maps;
18
+ }
19
+
20
+ public getBingMap(tile: Tile, key: string, type: BingMapType, language: string, imageUrl: string, subDomains: string[]): string {
21
+ let quadKey: string = '';
22
+ const maxZoom: number = Math.min(this.maps.tileZoomLevel, parseInt(this.maxZoom, 10));
23
+ for (let i: number = maxZoom; i > 0; i--) {
24
+ let digit: number = 0;
25
+ const mask: number = 1 << (i - 1);
26
+ if ((tile.x & mask) !== 0) {
27
+ digit++;
28
+ }
29
+ if ((tile.y & mask) !== 0) {
30
+ digit += 2;
31
+ }
32
+ quadKey = quadKey + '' + digit;
33
+ }
34
+ if (!isNullOrUndefined(subDomains)) {
35
+ const subDomain: string = subDomains[Math.min(parseInt(quadKey.substr(quadKey.length - 1, 1), 10), subDomains.length)];
36
+ imageUrl = imageUrl.replace('{quadkey}', quadKey).replace('{subdomain}', subDomain);
37
+ return imageUrl += '&mkt=' + language + '&ur=IN&Key=' + key;
38
+ } else {
39
+ return '';
40
+ }
41
+ }
42
+
43
+ /**
44
+ * @private
45
+ */
46
+ public destroy(): void {
47
+ this.maps = null;
48
+ this.subDomains = [];
49
+ }
50
+ }
@@ -0,0 +1,290 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable jsdoc/require-param */
3
+ /* eslint-disable jsdoc/require-returns */
4
+ /* eslint-disable @typescript-eslint/no-unused-vars */
5
+ import { Maps } from '../../index';
6
+ import { BubbleSettingsModel, ColorMapping, IBubbleRenderingEventArgs, bubbleRendering } from '../index';
7
+ import { IBubbleClickEventArgs, bubbleClick, LayerSettings, IBubbleMoveEventArgs, bubbleMouseMove } from '../index';
8
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
9
+ import { CircleOption, MapLocation, findMidPointOfPolygon, Point, drawCircle, elementAnimate, getTranslate } from '../utils/helper';
10
+ import { RectOption, Rect, drawRectangle, checkPropertyPath, getZoomTranslate, getRatioOfBubble, maintainSelection,
11
+ getValueFromObject } from '../utils/helper';
12
+ import { BorderModel } from '../model/base-model';
13
+
14
+ /**
15
+ * Bubble module class
16
+ */
17
+ export class Bubble {
18
+ private maps: Maps;
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ public bubbleCollection: any[];
21
+ /**
22
+ * Bubble Id for current layer
23
+ */
24
+ public id: string = '';
25
+ constructor(maps: Maps) {
26
+ this.maps = maps;
27
+ this.bubbleCollection = [];
28
+ }
29
+ // eslint-disable-next-line valid-jsdoc
30
+ /**
31
+ * To render bubble
32
+ *
33
+ * @private
34
+ */
35
+ public renderBubble(
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ bubbleSettings: BubbleSettingsModel, shapeData: any, color: string, range: { min: number, max: number },
38
+ bubbleIndex: number, dataIndex: number, layerIndex: number, layer: LayerSettings, group: Element, bubbleID? : string
39
+ ): void {
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ const layerData: any[] = layer.layerData; const colorValuePath: string = bubbleSettings.colorValuePath;
42
+ const equalValue: string = (!isNullOrUndefined(colorValuePath)) ? ((colorValuePath.indexOf('.') > -1) ?
43
+ (getValueFromObject(shapeData, bubbleSettings.colorValuePath)) : shapeData[colorValuePath]) : shapeData[colorValuePath];
44
+ const colorValue: number = (!isNullOrUndefined(colorValuePath)) ? ((colorValuePath.indexOf('.') > -1) ?
45
+ Number(getValueFromObject(shapeData, bubbleSettings.colorValuePath)) : Number(shapeData[colorValuePath])) :
46
+ Number(shapeData[colorValuePath]);
47
+ const bubbleValue: number = (!isNullOrUndefined(bubbleSettings.valuePath)) ? ((bubbleSettings.valuePath.indexOf('.') > -1) ?
48
+ Number(getValueFromObject(shapeData, bubbleSettings.valuePath)) : Number(shapeData[bubbleSettings.valuePath])) :
49
+ Number(shapeData[bubbleSettings.valuePath]);
50
+ let opacity: number; let bubbleColor: string;
51
+ if (isNaN(bubbleValue) && isNaN(colorValue) && isNullOrUndefined(equalValue)) {
52
+ return null;
53
+ }
54
+ let radius: number = getRatioOfBubble(bubbleSettings.minRadius, bubbleSettings.maxRadius, bubbleValue, range.min, range.max);
55
+ const colorMapping: ColorMapping = new ColorMapping(this.maps);
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ const shapeColor: any = colorMapping.getColorByValue(bubbleSettings.colorMapping, colorValue, equalValue);
58
+ // eslint-disable-next-line prefer-const
59
+ bubbleColor = (Object.prototype.toString.call(shapeColor) === '[object Object]' &&
60
+ !isNullOrUndefined(shapeColor['fill'])) ? shapeColor['fill'] : color;
61
+ // eslint-disable-next-line prefer-const
62
+ opacity = (Object.prototype.toString.call(shapeColor) === '[object Object]' &&
63
+ !isNullOrUndefined(shapeColor['opacity'])) ? shapeColor['opacity'] : bubbleSettings.opacity;
64
+ const shapePoints: [MapLocation[]] = [[]]; this.maps.translateType = 'bubble';
65
+ let midIndex: number = 0; let pointsLength: number = 0; let currentLength: number = 0;
66
+ for (let i: number = 0, len: number = layerData.length; i < len; i++) {
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ let shape: any = layerData[i];
69
+ shape = shape['property'];
70
+ const shapePath: string = checkPropertyPath(shapeData[layer.shapeDataPath], layer.shapePropertyPath, shape);
71
+ const shapeDataLayerPathValue : string = !isNullOrUndefined(shapeData[layer.shapeDataPath]) &&
72
+ isNaN(shapeData[layer.shapeDataPath]) ? shapeData[layer.shapeDataPath].toLowerCase() : shapeData[layer.shapeDataPath];
73
+ const shapePathValue : string = !isNullOrUndefined(shape[shapePath]) && isNaN(shape[shapePath])
74
+ ? shape[shapePath].toLowerCase() : shape[shapePath];
75
+ if (shapeDataLayerPathValue === shapePathValue && (layerData[i].type !== 'LineString' && layerData[i].type !== 'MultiLineString' && layerData[i]['type'] !== 'Point' && layerData[i]['type'] !== 'MultiPoint')) {
76
+ if (!layerData[i]['_isMultiPolygon']) {
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ shapePoints.push(this.getPoints(layerData[i] as any[], []));
79
+ currentLength = shapePoints[shapePoints.length - 1].length;
80
+ if (pointsLength < currentLength) {
81
+ pointsLength = currentLength;
82
+ midIndex = shapePoints.length - 1;
83
+ }
84
+
85
+ } else {
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ const layer: any[] = <any[]>layerData[i];
88
+ for (let j: number = 0; j < layer.length; j++) {
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ shapePoints.push(this.getPoints(layer[j] as any[], []));
91
+ currentLength = shapePoints[shapePoints.length - 1].length;
92
+ if (pointsLength < currentLength) {
93
+ pointsLength = currentLength;
94
+ midIndex = shapePoints.length - 1;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ const projectionType: string = this.maps.projectionType;
101
+ let centerY: number; let eventArgs: IBubbleRenderingEventArgs;
102
+ const bubbleBorder: BorderModel = {
103
+ color: bubbleSettings.border.color, opacity: bubbleSettings.border.opacity,
104
+ width: bubbleSettings.border.width
105
+ };
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ const center: any = findMidPointOfPolygon(shapePoints[midIndex], projectionType, layer.geometryType);
108
+ if (bubbleSettings.visible) {
109
+ if (!isNullOrUndefined(center)) {
110
+ centerY = this.maps.projectionType === 'Mercator' ? center['y'] : (-center['y']);
111
+ eventArgs = {
112
+ cancel: false, name: bubbleRendering, border: bubbleBorder,
113
+ cx: center['x'], cy: centerY, data: shapeData, fill: bubbleColor,
114
+ maps: this.maps, radius: radius
115
+ };
116
+ } else {
117
+ const shapePointsLength: number = shapePoints.length - 1;
118
+ if (shapePoints[shapePointsLength]['x'] && shapePoints[shapePointsLength]['y']) {
119
+ eventArgs = {
120
+ cancel: false, name: bubbleRendering, border: bubbleBorder,
121
+ cx: shapePoints[shapePointsLength]['x'], cy: shapePoints[shapePointsLength]['y'],
122
+ data: shapeData, fill: bubbleColor, maps: this.maps,
123
+ radius: radius
124
+ };
125
+ } else {
126
+ return;
127
+ }
128
+ }
129
+ this.maps.trigger('bubbleRendering', eventArgs, (bubbleArgs: IBubbleRenderingEventArgs) => {
130
+ if (eventArgs.cancel) {
131
+ return;
132
+ }
133
+ let bubbleElement: Element;
134
+ eventArgs.border.opacity = isNullOrUndefined(eventArgs.border.opacity) ? opacity : eventArgs.border.opacity;
135
+ if (bubbleSettings.bubbleType === 'Circle') {
136
+ const circle: CircleOption = new CircleOption(
137
+ bubbleID, eventArgs.fill, eventArgs.border, opacity,
138
+ 0, 0, eventArgs.radius, null
139
+ );
140
+ bubbleElement = drawCircle(this.maps, circle, group);
141
+ } else {
142
+ const y: number = this.maps.projectionType === 'Mercator' ? (eventArgs.cy - radius) : (eventArgs.cy + radius);
143
+ const rectangle: RectOption = new RectOption(
144
+ bubbleID, eventArgs.fill, eventArgs.border, opacity,
145
+ new Rect(0, 0, radius * 2, radius * 2), 2, 2
146
+ );
147
+ eventArgs.cx -= radius; eventArgs.cy = y;
148
+ bubbleElement = drawRectangle(this.maps, rectangle, group);
149
+ }
150
+ maintainSelection(this.maps.selectedBubbleElementId, this.maps.bubbleSelectionClass, bubbleElement,
151
+ 'BubbleselectionMapStyle');
152
+ this.bubbleCollection.push({
153
+ LayerIndex: layerIndex,
154
+ BubbleIndex: bubbleIndex,
155
+ DataIndex: dataIndex,
156
+ element: bubbleElement,
157
+ center: { x: eventArgs.cx, y: eventArgs.cy }
158
+ });
159
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
160
+ let translate: any;
161
+ const animate: boolean = layer.animationDuration !== 0 || isNullOrUndefined(this.maps.zoomModule);
162
+ if (this.maps.zoomSettings.zoomFactor > 1 && !isNullOrUndefined(this.maps.zoomModule) && !this.maps.isTileMap) {
163
+ translate = getZoomTranslate(this.maps, layer, animate);
164
+ } else {
165
+ translate = getTranslate(this.maps, layer, animate);
166
+ }
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ const bubbleDataSource: any[] = bubbleSettings.dataSource as any[];
169
+ const scale: number = translate['scale']; const transPoint: Point = translate['location'] as Point;
170
+ const position: MapLocation = new MapLocation(
171
+ (this.maps.isTileMap ? (eventArgs.cx) : ((eventArgs.cx + transPoint.x) * scale)),
172
+ (this.maps.isTileMap ? (eventArgs.cy) : ((eventArgs.cy + transPoint.y) * scale)));
173
+ bubbleElement.setAttribute('transform', 'translate( ' + (position.x) + ' ' + (position.y) + ' )');
174
+ const bubble: string = (bubbleDataSource.length - 1) === dataIndex ? 'bubble' : null;
175
+ if (bubbleSettings.bubbleType === 'Square') {
176
+ position.x += radius;
177
+ position.y += radius * (this.maps.projectionType === 'Mercator' ? 1 : -1);
178
+ } else {
179
+ radius = 0;
180
+ }
181
+ if (bubbleSettings.animationDuration > 0) {
182
+ elementAnimate(
183
+ bubbleElement, bubbleSettings.animationDelay, bubbleSettings.animationDuration, position, this.maps, bubble, radius
184
+ );
185
+ }
186
+ });
187
+ }
188
+ }
189
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
+ private getPoints(shape: any[], points: MapLocation[]): MapLocation[] {
191
+ if (isNullOrUndefined(shape.map)) {
192
+ points = shape['point'];
193
+ } else {
194
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
195
+ shape.map((current: any, index: number) => {
196
+ points.push(new Point(current['point']['x'], current['point']['y']));
197
+ });
198
+ }
199
+ return points;
200
+ }
201
+
202
+
203
+ // eslint-disable-next-line valid-jsdoc
204
+ /**
205
+ * To check and trigger bubble click event
206
+ *
207
+ * @private
208
+ */
209
+ public bubbleClick(e: PointerEvent): void {
210
+ const target: string = (e.target as Element).id;
211
+ if (target.indexOf('_LayerIndex_') === -1) {
212
+ return;
213
+ }
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ const data: any = this.getbubble(target);
216
+ if (isNullOrUndefined(data)) {
217
+ return;
218
+ }
219
+ const eventArgs: IBubbleClickEventArgs = {
220
+ cancel: false, name: bubbleClick, data: data, maps: this.maps,
221
+ target: target, x: e.clientX, y: e.clientY
222
+ };
223
+ this.maps.trigger(bubbleClick, eventArgs);
224
+ }
225
+ /**
226
+ * To get bubble from target id
227
+ *
228
+ * @param {string} target - Specifies the target
229
+ * @returns {object} - Returns the object
230
+ */
231
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
+ private getbubble(target: string): any {
233
+ const id: string[] = target.split('_LayerIndex_');
234
+ const index: number = parseInt(id[1].split('_')[0], 10);
235
+ const layer: LayerSettings = <LayerSettings>this.maps.layers[index];
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
+ let data: any;
238
+ if (target.indexOf('_BubbleIndex_') > -1) {
239
+ const bubbleIndex: number = parseInt(id[1].split('_BubbleIndex_')[1], 10);
240
+ const dataIndex: number = parseInt(id[1].split('_BubbleIndex_')[1].split('_dataIndex_')[1], 10);
241
+ if (!isNaN(bubbleIndex)) {
242
+ data = layer.bubbleSettings[bubbleIndex].dataSource[dataIndex];
243
+ return data;
244
+ }
245
+ }
246
+ return null;
247
+ }
248
+ // eslint-disable-next-line valid-jsdoc
249
+ /**
250
+ * To check and trigger bubble move event
251
+ *
252
+ * @private
253
+ */
254
+ public bubbleMove(e: PointerEvent): void {
255
+ const target: string = (e.target as Element).id;
256
+ if (target.indexOf('_LayerIndex_') === -1) {
257
+ return;
258
+ }
259
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
260
+ const data: any = this.getbubble(target);
261
+ if (isNullOrUndefined(data)) {
262
+ return;
263
+ }
264
+ const eventArgs: IBubbleMoveEventArgs = {
265
+ cancel: false, name: bubbleMouseMove, data: data, maps: this.maps,
266
+ target: target, x: e.clientX, y: e.clientY
267
+ };
268
+ this.maps.trigger(bubbleMouseMove, eventArgs);
269
+ }
270
+ /**
271
+ * Get module name.
272
+ *
273
+ * @returns {string} - Returns the module name.
274
+ */
275
+ protected getModuleName(): string {
276
+ return 'Bubble';
277
+ }
278
+
279
+ /**
280
+ * To destroy the bubble.
281
+ *
282
+ * @returns {void}
283
+ * @private
284
+ */
285
+ public destroy(): void {
286
+ this.bubbleCollection = [];
287
+ //TODO: Calling the below code throws spec issue.
288
+ //this.maps = null;
289
+ }
290
+ }
@@ -0,0 +1,226 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable jsdoc/require-param */
3
+ /* eslint-disable jsdoc/require-returns */
4
+ /* eslint-disable @typescript-eslint/no-unused-vars */
5
+ import { Maps } from '../../index';
6
+ import { ShapeSettingsModel, ColorMappingSettingsModel, ColorValue } from '../index';
7
+ import { isNullOrUndefined } from '@syncfusion/ej2-base';
8
+ import { getValueFromObject } from '../utils/helper';
9
+
10
+ /**
11
+ * ColorMapping class
12
+ */
13
+ export class ColorMapping {
14
+ private maps: Maps;
15
+ constructor(maps: Maps) {
16
+ this.maps = maps;
17
+ }
18
+ /**
19
+ * To get color based on shape settings.
20
+ *
21
+ * @param { ShapeSettingsModel } shapeSettings - Specifies the shape settings.
22
+ * @param { object } layerData - Specifies the layer data.
23
+ * @param { string } color - Specifies the color.
24
+ * @returns {Object} - Returns the object.
25
+ * @private
26
+ */
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ public getShapeColorMapping(shapeSettings: ShapeSettingsModel, layerData: any, color: string): any {
29
+ const colorValuePath: string = shapeSettings.colorValuePath ? shapeSettings.colorValuePath : shapeSettings.valuePath;
30
+ const equalValue: string = (!isNullOrUndefined(colorValuePath)) ? ((colorValuePath.indexOf('.') > -1) ?
31
+ getValueFromObject(layerData, colorValuePath) : layerData[colorValuePath]) : layerData[colorValuePath];
32
+ const colorValue: number = Number(equalValue);
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const shapeColor: any = this.getColorByValue(shapeSettings.colorMapping, colorValue, equalValue);
35
+ return !isNullOrUndefined(shapeColor) ? shapeColor : color;
36
+ }
37
+ /**
38
+ * To color by value and color mapping
39
+ */
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ public getColorByValue(colorMapping: ColorMappingSettingsModel[], colorValue: number, equalValue: string): any {
42
+ if (isNaN(colorValue) && isNullOrUndefined(equalValue)) {
43
+ return null;
44
+ }
45
+ let fill: string = ''; let opacity: number; let gradientColor: string[]; let gradientFill: string;
46
+ for (const colorMap of colorMapping) {
47
+
48
+ if ((!isNullOrUndefined(colorMap.from) && !isNullOrUndefined(colorMap.to)
49
+ && (colorValue >= colorMap.from && colorValue <= colorMap.to)) ||
50
+ (colorMap.value === equalValue)) {
51
+ if (Object.prototype.toString.call(colorMap.color) === '[object Array]') {
52
+ if (!isNullOrUndefined(colorMap.value)) {
53
+ fill = colorMap.color[0];
54
+ } else {
55
+ gradientFill = this.getColor(colorMap, colorValue);
56
+ fill = gradientFill;
57
+ }
58
+ } else {
59
+ fill = <string>colorMap.color;
60
+ }
61
+ }
62
+ if (((colorValue >= colorMap.from && colorValue <= colorMap.to) || (colorMap.value === equalValue))
63
+ && (!isNullOrUndefined(colorMap.minOpacity) && !isNullOrUndefined(colorMap.maxOpacity) && fill)) {
64
+ opacity = this.deSaturationColor(colorMap, fill, colorValue, equalValue);
65
+ }
66
+ if ((fill === '' || isNullOrUndefined(fill)) && isNullOrUndefined(colorMap.from) && isNullOrUndefined(colorMap.to)
67
+ && isNullOrUndefined(colorMap.minOpacity) && isNullOrUndefined(colorMap.maxOpacity) && isNullOrUndefined(colorMap.value)) {
68
+ fill = Object.prototype.toString.call(colorMap.color) === '[object Array]' ? colorMap.color[0] : <string>colorMap.color;
69
+ }
70
+ }
71
+ return { fill: fill || ((!colorMapping.length) ? equalValue : null), opacity: opacity };
72
+ }
73
+
74
+ public deSaturationColor(
75
+ colorMapping: ColorMappingSettingsModel, color: string,
76
+ rangeValue: number, equalValue: string): number {
77
+ let opacity: number = 1;
78
+ if (((rangeValue >= colorMapping.from && rangeValue <= colorMapping.to) || colorMapping.value === equalValue)) {
79
+ const ratio: number = !isNaN(rangeValue) ? (rangeValue - colorMapping.from) / (colorMapping.to - colorMapping.from) :
80
+ colorMapping.from / (colorMapping.to - colorMapping.from);
81
+ opacity = (ratio * (colorMapping.maxOpacity - colorMapping.minOpacity)) + colorMapping.minOpacity;
82
+ }
83
+ return opacity;
84
+ }
85
+
86
+ public rgbToHex(r: number, g: number, b: number): string {
87
+ return '#' + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
88
+ }
89
+
90
+ public componentToHex(value: number): string {
91
+ const hex: string = value.toString(16);
92
+ return hex.length === 1 ? '0' + hex : hex;
93
+ }
94
+
95
+ public getColor(colorMap: ColorMappingSettingsModel, value: number): string {
96
+ let color: string = '';
97
+ let rbg: ColorValue;
98
+ if (Number(value) === colorMap.from) {
99
+ color = colorMap.color[0];
100
+ } else if (Number(value) === colorMap.to) {
101
+ color = colorMap.color[colorMap.color.length - 1];
102
+ } else {
103
+ rbg = this.getGradientColor(Number(value), colorMap);
104
+ color = this.rgbToHex(rbg.r, rbg.g, rbg.b);
105
+ }
106
+ return color;
107
+ }
108
+
109
+ public getGradientColor(value: number, colorMap: ColorMappingSettingsModel): ColorValue {
110
+ const previousOffset: number = colorMap.from;
111
+ const nextOffset: number = colorMap.to;
112
+ let percent: number = 0; let prev1: string;
113
+ const full: number = nextOffset - previousOffset; let midColor: string; let midreturn: ColorValue;
114
+ percent = (value - previousOffset) / full; let previousColor: string; let nextColor: string;
115
+ if (colorMap.color.length <= 2) {
116
+ previousColor = colorMap.color[0].charAt(0) === '#' ? colorMap.color[0] : this._colorNameToHex(colorMap.color[0]);
117
+ nextColor = colorMap.color[colorMap.color.length - 1].charAt(0) === '#' ?
118
+ colorMap.color[colorMap.color.length - 1] : this._colorNameToHex(colorMap.color[colorMap.color.length - 1]);
119
+ } else {
120
+ previousColor = colorMap.color[0].charAt(0) === '#' ? colorMap.color[0] : this._colorNameToHex(colorMap.color[0]);
121
+ nextColor = colorMap.color[colorMap.color.length - 1].charAt(0) === '#' ?
122
+ colorMap.color[colorMap.color.length - 1] : this._colorNameToHex(colorMap.color[colorMap.color.length - 1]);
123
+ const a: number = full / (colorMap.color.length - 1); let b: number; let c: number;
124
+
125
+ const length: number = colorMap.color.length - 1;
126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
+ const splitColorValueOffset: any[] = []; let splitColor: any = {};
128
+ for (let j: number = 1; j < length; j++) {
129
+ c = j * a;
130
+ b = previousOffset + c;
131
+ splitColor = { b: b, color: colorMap.color[j] };
132
+ splitColorValueOffset.push(splitColor);
133
+ }
134
+ for (let i: number = 0; i < splitColorValueOffset.length; i++) {
135
+ if (previousOffset <= value && value <= splitColorValueOffset[i]['b'] && i === 0) {
136
+ midColor = splitColorValueOffset[i]['color'].charAt(0) === '#' ?
137
+ splitColorValueOffset[i]['color'] : this._colorNameToHex(splitColorValueOffset[i]['color']);
138
+ nextColor = midColor;
139
+ percent = value < splitColorValueOffset[i]['b'] ? 1 - Math.abs((value - splitColorValueOffset[i]['b']) / a)
140
+ : (value - splitColorValueOffset[i]['b']) / a;
141
+ } else if (splitColorValueOffset[i]['b'] <= value && value <= nextOffset && i === (splitColorValueOffset.length - 1)) {
142
+ midColor = splitColorValueOffset[i]['color'].charAt(0) === '#' ?
143
+ splitColorValueOffset[i]['color'] : this._colorNameToHex(splitColorValueOffset[i]['color']);
144
+ previousColor = midColor;
145
+ percent = value < splitColorValueOffset[i]['b'] ?
146
+ 1 - Math.abs((value - splitColorValueOffset[i]['b']) / a) : (value - splitColorValueOffset[i]['b']) / a;
147
+ }
148
+ if (i !== splitColorValueOffset.length - 1 && i < splitColorValueOffset.length) {
149
+ if (splitColorValueOffset[i]['b'] <= value && value <= splitColorValueOffset[i + 1]['b']) {
150
+ midColor = splitColorValueOffset[i]['color'].charAt(0) === '#' ?
151
+ splitColorValueOffset[i]['color'] : this._colorNameToHex(splitColorValueOffset[i]['color']);
152
+ previousColor = midColor;
153
+ nextColor = splitColorValueOffset[i + 1]['color'].charAt(0) === '#' ?
154
+ splitColorValueOffset[i + 1]['color'] : this._colorNameToHex(splitColorValueOffset[i + 1]['color']);
155
+ percent = Math.abs((value - splitColorValueOffset[i + 1]['b'])) / a;
156
+ }
157
+ }
158
+ }
159
+ }
160
+ return this.getPercentageColor(percent, previousColor, nextColor);
161
+ }
162
+
163
+ public getPercentageColor(percent: number, previous: string, next: string): ColorValue {
164
+ const nextColor: string = next.split('#')[1];
165
+ const prevColor: string = previous.split('#')[1];
166
+ const r: number = this.getPercentage(percent, parseInt(prevColor.substr(0, 2), 16), parseInt(nextColor.substr(0, 2), 16));
167
+ const g: number = this.getPercentage(percent, parseInt(prevColor.substr(2, 2), 16), parseInt(nextColor.substr(2, 2), 16));
168
+ const b: number = this.getPercentage(percent, parseInt(prevColor.substr(4, 2), 16), parseInt(nextColor.substr(4, 2), 16));
169
+ return new ColorValue(r, g, b);
170
+ }
171
+
172
+ public getPercentage(percent: number, previous: number, next: number): number {
173
+ const full: number = next - previous;
174
+ return Math.round((previous + (full * percent)));
175
+ }
176
+
177
+ public _colorNameToHex(color: string): string {
178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
179
+ const colors: any = {
180
+ 'aliceblue': '#f0f8ff', 'antiquewhite': '#faebd7', 'aqua': '#00ffff', 'aquamarine': '#7fffd4', 'azure': '#f0ffff',
181
+ 'beige': '#f5f5dc', 'bisque': '#ffe4c4', 'black': '#000000', 'blanchedalmond': '#ffebcd', 'blue': '#0000ff',
182
+ 'blueviolet': '#8a2be2', 'brown': '#a52a2a', 'burlywood': '#deb887',
183
+ 'cadetblue': '#5f9ea0', 'chartreuse': '#7fff00', 'chocolate': '#d2691e', 'coral': '#ff7f50',
184
+ 'cornflowerblue': '#6495ed', 'cornsilk': '#fff8dc', 'crimson': '#dc143c', 'cyan': '#00ffff',
185
+ 'darkblue': '#00008b', 'darkcyan': '#008b8b', 'darkgoldenrod': '#b8860b', 'darkgray': '#a9a9a9', 'darkgreen': '#006400',
186
+ 'darkkhaki': '#bdb76b', 'darkmagenta': '#8b008b', 'darkolivegreen': '#556b2f',
187
+ 'darkorange': '#ff8c00', 'darkorchid': '#9932cc', 'darkred': '#8b0000', 'darksalmon': '#e9967a', 'darkseagreen': '#8fbc8f',
188
+ 'darkslateblue': '#483d8b', 'darkslategray': '#2f4f4f', 'darkturquoise': '#00ced1',
189
+ 'darkviolet': '#9400d3', 'deeppink': '#ff1493', 'deepskyblue': '#00bfff', 'dimgray': '#696969', 'dodgerblue': '#1e90ff',
190
+ 'firebrick': '#b22222', 'floralwhite': '#fffaf0', 'forestgreen': '#228b22', 'fuchsia': '#ff00ff',
191
+ 'gainsboro': '#dcdcdc', 'ghostwhite': '#f8f8ff', 'gold': '#ffd700', 'goldenrod': '#daa520', 'gray': '#808080',
192
+ 'green': '#008000', 'greenyellow': '#adff2f',
193
+ 'honeydew': '#f0fff0', 'hotpink': '#ff69b4',
194
+ 'indianred ': '#cd5c5c', 'indigo ': '#4b0082', 'ivory': '#fffff0', 'khaki': '#f0e68c',
195
+ 'lavender': '#e6e6fa', 'lavenderblush': '#fff0f5', 'lawngreen': '#7cfc00', 'lemonchiffon': '#fffacd', 'lightblue': '#add8e6',
196
+ 'lightcoral': '#f08080', 'lightcyan': '#e0ffff', 'lightgoldenrodyellow': '#fafad2',
197
+ 'lightgrey': '#d3d3d3', 'lightgreen': '#90ee90', 'lightpink': '#ffb6c1', 'lightsalmon': '#ffa07a', 'lightseagreen': '#20b2aa',
198
+ 'lightskyblue': '#87cefa', 'lightslategray': '#778899', 'lightsteelblue': '#b0c4de',
199
+ 'lightyellow': '#ffffe0', 'lime': '#00ff00', 'limegreen': '#32cd32', 'linen': '#faf0e6',
200
+ 'magenta': '#ff00ff', 'maroon': '#800000', 'mediumaquamarine': '#66cdaa', 'mediumblue': '#0000cd', 'mediumorchid': '#ba55d3',
201
+ 'mediumpurple': '#9370d8', 'mediumseagreen': '#3cb371', 'mediumslateblue': '#7b68ee',
202
+ 'mediumspringgreen': '#00fa9a', 'mediumturquoise': '#48d1cc', 'mediumvioletred': '#c71585', 'midnightblue': '#191970',
203
+ 'mintcream': '#f5fffa', 'mistyrose': '#ffe4e1', 'moccasin': '#ffe4b5',
204
+ 'navajowhite': '#ffdead', 'navy': '#000080', 'orchid': '#da70d6', 'papayawhip': '#ffefd5',
205
+ 'oldlace': '#fdf5e6', 'olive': '#808000', 'olivedrab': '#6b8e23', 'orange': '#ffa500', 'orangered': '#ff4500',
206
+ 'palegoldenrod': '#eee8aa', 'palegreen': '#98fb98', 'paleturquoise': '#afeeee', 'palevioletred': '#d87093',
207
+ 'peachpuff': '#ffdab9', 'peru': '#cd853f', 'pink': '#ffc0cb', 'plum': '#dda0dd', 'powderblue': '#b0e0e6', 'purple': '#800080',
208
+ 'red': '#ff0000', 'rosybrown': '#bc8f8f', 'royalblue': '#4169e1',
209
+ 'saddlebrown': '#8b4513', 'salmon': '#fa8072', 'sandybrown': '#f4a460', 'seagreen': '#2e8b57', 'seashell': '#fff5ee',
210
+ 'sienna': '#a0522d', 'silver': '#c0c0c0', 'skyblue': '#87ceeb', 'slateblue': '#6a5acd',
211
+ 'slategray': '#708090', 'snow': '#fffafa', 'springgreen': '#00ff7f', 'steelblue': '#4682b4',
212
+ 'tan': '#d2b48c', 'teal': '#008080', 'thistle': '#d8bfd8', 'tomato': '#ff6347', 'turquoise': '#40e0d0',
213
+ 'violet': '#ee82ee',
214
+ 'wheat': '#f5deb3', 'white': '#ffffff', 'whitesmoke': '#f5f5f5',
215
+ 'yellow': '#ffff00', 'yellowgreen': '#9acd32'
216
+ };
217
+ if (Object.prototype.toString.call(color) === '[object Array]') {
218
+ return color;
219
+ }
220
+ if (typeof colors[color.toLowerCase()] !== 'undefined') {
221
+ return colors[color.toLowerCase()];
222
+ }
223
+
224
+ return color;
225
+ }
226
+ }