@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.
- package/.eslintrc.json +18 -3
- package/.github/PULL_REQUEST_TEMPLATE/Bug.md +72 -72
- package/.github/PULL_REQUEST_TEMPLATE/Feature.md +49 -49
- package/CHANGELOG.md +441 -439
- package/README.md +73 -73
- package/dist/ej2-maps.umd.min.js +1 -10
- package/dist/ej2-maps.umd.min.js.map +1 -1
- package/dist/es6/ej2-maps.es2015.js +1161 -638
- package/dist/es6/ej2-maps.es2015.js.map +1 -1
- package/dist/es6/ej2-maps.es5.js +1200 -678
- package/dist/es6/ej2-maps.es5.js.map +1 -1
- package/dist/global/ej2-maps.min.js +1 -10
- package/dist/global/ej2-maps.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/maps/layers/bing-map.ts +50 -0
- package/dist/ts/maps/layers/bubble.ts +290 -0
- package/dist/ts/maps/layers/color-mapping.ts +226 -0
- package/dist/ts/maps/layers/data-label.ts +418 -0
- package/dist/ts/maps/layers/layer-panel.ts +1480 -0
- package/dist/ts/maps/layers/legend.ts +2236 -0
- package/dist/ts/maps/layers/marker.ts +453 -0
- package/dist/ts/maps/layers/navigation-selected-line.ts +167 -0
- package/dist/ts/maps/maps.ts +2886 -0
- package/dist/ts/maps/model/base.ts +1843 -0
- package/dist/ts/maps/model/constants.ts +200 -0
- package/dist/ts/maps/model/export-image.ts +178 -0
- package/dist/ts/maps/model/export-pdf.ts +170 -0
- package/dist/ts/maps/model/interface.ts +823 -0
- package/dist/ts/maps/model/print.ts +104 -0
- package/dist/ts/maps/model/theme.ts +554 -0
- package/dist/ts/maps/user-interaction/annotation.ts +127 -0
- package/dist/ts/maps/user-interaction/highlight.ts +233 -0
- package/dist/ts/maps/user-interaction/selection.ts +321 -0
- package/dist/ts/maps/user-interaction/tooltip.ts +387 -0
- package/dist/ts/maps/user-interaction/zoom.ts +1767 -0
- package/dist/ts/maps/utils/enum.ts +368 -0
- package/dist/ts/maps/utils/helper.ts +3421 -0
- package/helper/e2e/index.js +3 -3
- package/helper/e2e/maps-helper.js +13 -13
- package/license +9 -9
- package/package.json +85 -85
- package/src/maps/layers/bing-map.d.ts +4 -0
- package/src/maps/layers/bing-map.js +16 -3
- package/src/maps/layers/bubble.d.ts +1 -2
- package/src/maps/layers/bubble.js +7 -12
- package/src/maps/layers/data-label.d.ts +1 -4
- package/src/maps/layers/data-label.js +32 -35
- package/src/maps/layers/layer-panel.d.ts +18 -1
- package/src/maps/layers/layer-panel.js +226 -72
- package/src/maps/layers/legend.d.ts +5 -2
- package/src/maps/layers/legend.js +170 -61
- package/src/maps/layers/marker.d.ts +2 -4
- package/src/maps/layers/marker.js +49 -48
- package/src/maps/layers/navigation-selected-line.d.ts +1 -2
- package/src/maps/layers/navigation-selected-line.js +7 -13
- package/src/maps/maps-model.d.ts +259 -251
- package/src/maps/maps.d.ts +24 -3
- package/src/maps/maps.js +152 -90
- package/src/maps/model/base-model.d.ts +1025 -1021
- package/src/maps/model/base.d.ts +5 -1
- package/src/maps/model/base.js +24 -24
- package/src/maps/model/constants.d.ts +6 -0
- package/src/maps/model/constants.js +6 -0
- package/src/maps/model/export-image.d.ts +2 -4
- package/src/maps/model/export-image.js +26 -32
- package/src/maps/model/export-pdf.d.ts +4 -6
- package/src/maps/model/export-pdf.js +27 -35
- package/src/maps/model/interface.d.ts +34 -26
- package/src/maps/model/print.d.ts +2 -5
- package/src/maps/model/print.js +33 -21
- package/src/maps/model/theme.js +7 -4
- package/src/maps/user-interaction/annotation.d.ts +1 -2
- package/src/maps/user-interaction/annotation.js +3 -4
- package/src/maps/user-interaction/highlight.d.ts +1 -2
- package/src/maps/user-interaction/highlight.js +11 -10
- package/src/maps/user-interaction/selection.d.ts +1 -2
- package/src/maps/user-interaction/selection.js +42 -19
- package/src/maps/user-interaction/tooltip.d.ts +3 -5
- package/src/maps/user-interaction/tooltip.js +27 -14
- package/src/maps/user-interaction/zoom.d.ts +3 -8
- package/src/maps/user-interaction/zoom.js +282 -162
- package/src/maps/utils/enum.d.ts +5 -1
- package/src/maps/utils/helper.d.ts +1 -1
- package/src/maps/utils/helper.js +62 -31
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
+
import { Maps } from '../../index';
|
|
4
|
+
import {
|
|
5
|
+
findMidPointOfPolygon, Rect, filter, getTemplateFunction, getZoomTranslate,
|
|
6
|
+
getTranslate, RectOption, convertElementFromLabel, checkPropertyPath,
|
|
7
|
+
Point, TextOption, renderTextElement, MapLocation, textTrim, Size, measureText, Internalize
|
|
8
|
+
} from '../utils/helper';
|
|
9
|
+
import { isNullOrUndefined } from '@syncfusion/ej2-base';
|
|
10
|
+
import { FontModel, DataLabelSettingsModel, ILabelRenderingEventArgs, LayerSettings } from '../index';
|
|
11
|
+
import { dataLabelRendering } from '../model/constants';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* DataLabel Module used to render the maps datalabel
|
|
15
|
+
*/
|
|
16
|
+
export class DataLabel {
|
|
17
|
+
private maps: Maps;
|
|
18
|
+
/**
|
|
19
|
+
* Datalabel collections
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
public dataLabelCollections: any[];
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
private value: any = { rightWidth: 0, leftWidth: 0, heightTop: 0, heightBottom: 0 };
|
|
27
|
+
constructor(maps: Maps) {
|
|
28
|
+
this.maps = maps;
|
|
29
|
+
this.dataLabelCollections = [];
|
|
30
|
+
}
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
private getDataLabel(dataSource: any[], labelPath: string, shapeName: string, shapeDataPath: string): any {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
let text: any; let shapeNameValue : string;
|
|
35
|
+
for (let i: number = 0; i < dataSource.length; i++) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
const data: any = dataSource[i];
|
|
38
|
+
const dataShapePathValue : string = !isNullOrUndefined(data[shapeDataPath]) && isNaN(data[shapeDataPath]) ?
|
|
39
|
+
data[shapeDataPath].toLowerCase() : data[shapeDataPath];
|
|
40
|
+
shapeName = !isNullOrUndefined(shapeName) ? shapeName.toString() : shapeName;
|
|
41
|
+
shapeNameValue = !isNullOrUndefined(shapeName) ? shapeName.toLowerCase() : shapeName;
|
|
42
|
+
if ((dataShapePathValue) === shapeNameValue) {
|
|
43
|
+
text = data;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return text;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* To render label for maps
|
|
51
|
+
*
|
|
52
|
+
* @param {LayerSettings} layer - Specifies the layer settings
|
|
53
|
+
* @param {number} layerIndex - Specifies the layer index.
|
|
54
|
+
* @param {any} shape - Specifies the shape.
|
|
55
|
+
* @param {any[]} layerData - Specifies the layer data.
|
|
56
|
+
* @param {Element} group Specifies the element.
|
|
57
|
+
* @param {HTMLElement} labelTemplateElement - Specifies the template element.
|
|
58
|
+
* @param {number} index - Specifies the index number.
|
|
59
|
+
* @param {any[]} intersect - Specifies the intersect.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
public renderLabel(
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
+
layer: LayerSettings, layerIndex: number, shape: any,
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
layerData: any[], group: Element, labelTemplateElement: HTMLElement, index: number, intersect: any[]
|
|
67
|
+
): void {
|
|
68
|
+
const dataLabel: DataLabelSettingsModel = layer.dataLabelSettings;
|
|
69
|
+
const style: FontModel = layer.dataLabelSettings.textStyle;
|
|
70
|
+
let markerEle: Element;
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
+
let templateFn: any;
|
|
73
|
+
let options: TextOption;
|
|
74
|
+
const dataLabelSettings: DataLabelSettingsModel = layer.dataLabelSettings;
|
|
75
|
+
const labelpath: string = layer.dataLabelSettings.labelPath;
|
|
76
|
+
let shapePoint: [MapLocation[]] = [[]];
|
|
77
|
+
let midIndex: number = 0;
|
|
78
|
+
let pointsLength: number = 0;
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const shapeData: any = shape;
|
|
81
|
+
let element: Element;
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
let data: any;
|
|
84
|
+
let text: string = '';
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
+
let datasrcObj: any;
|
|
87
|
+
let currentLength: number = 0; let oldIndex : number;
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
let location: any;
|
|
90
|
+
let sublayerIndexLabel : boolean = false;
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
const shapeProperties: any = shape['properties'];
|
|
93
|
+
const labelId: string = this.maps.element.id + '_LayerIndex_' + layerIndex + '_shapeIndex_' + index + '_LabelIndex_' + index;
|
|
94
|
+
const textLocation: Point = new Point(0, 0);
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
+
const shapes: any = layerData[index]; let locationX: any; let locationY: any;
|
|
97
|
+
style.fontFamily = this.maps.theme.toLowerCase() !== 'material' ? this.maps.themeStyle.labelFontFamily : style.fontFamily;
|
|
98
|
+
shape = shapes['property'];
|
|
99
|
+
const properties: string[] = (Object.prototype.toString.call(layer.shapePropertyPath) === '[object Array]' ?
|
|
100
|
+
layer.shapePropertyPath : [layer.shapePropertyPath]) as string[];
|
|
101
|
+
let propertyPath: string; let isPoint : boolean = false;
|
|
102
|
+
const animate: boolean = layer.animationDuration !== 0 || isNullOrUndefined(this.maps.zoomModule);
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
const translate: any = (this.maps.isTileMap) ? new Object() : ((this.maps.zoomSettings.zoomFactor > 1 &&
|
|
105
|
+
!isNullOrUndefined(this.maps.zoomModule)) ? getZoomTranslate(this.maps, layer, animate) :
|
|
106
|
+
getTranslate(this.maps, layer, animate));
|
|
107
|
+
const scale: number = (this.maps.isTileMap) ? this.maps.scale : translate['scale'];
|
|
108
|
+
const transPoint: Point = (this.maps.isTileMap) ? this.maps.translatePoint : translate['location'] as Point;
|
|
109
|
+
const zoomTransPoint : Point = this.maps.zoomTranslatePoint; let shapeWidth: number;
|
|
110
|
+
const scaleZoomValue : number = !isNullOrUndefined(this.maps.scale) ? Math.floor(this.maps.scale) : 1;
|
|
111
|
+
const zoomLabelsPosition : boolean = this.maps.zoomSettings.enable ? !isNullOrUndefined(this.maps.zoomShapeCollection) &&
|
|
112
|
+
this.maps.zoomShapeCollection.length > 0 && !this.maps.isAddLayer : this.maps.zoomSettings.enable; this.maps.translateType = 'labels';
|
|
113
|
+
for (let j: number = 0; j < properties.length; j++) {
|
|
114
|
+
if (shapeProperties[properties[j]]) {
|
|
115
|
+
propertyPath = properties[j];
|
|
116
|
+
datasrcObj = this.getDataLabel(
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
+
layer.dataSource as any[], layer.shapeDataPath, shapeData['properties'][propertyPath], layer.shapeDataPath);
|
|
119
|
+
if (datasrcObj) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
datasrcObj = this.getDataLabel(
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
layer.dataSource as any[], layer.shapeDataPath, shapeData['properties'][propertyPath], layer.shapeDataPath);
|
|
127
|
+
if (!isNullOrUndefined(shapes['property'])) {
|
|
128
|
+
shapePoint = [[]];
|
|
129
|
+
if (!layerData[index]['_isMultiPolygon'] && layerData[index]['type'] !== 'Point' && layerData[index]['type'] !== 'MultiPoint') {
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
131
|
+
shapePoint.push(this.getPoint(layerData[index] as any[], []));
|
|
132
|
+
currentLength = shapePoint[shapePoint.length - 1].length;
|
|
133
|
+
if (pointsLength < currentLength) {
|
|
134
|
+
pointsLength = currentLength;
|
|
135
|
+
midIndex = shapePoint.length - 1;
|
|
136
|
+
}
|
|
137
|
+
} else if (layerData[index]['type'] !== 'Point' && layerData[index]['type'] !== 'MultiPoint') {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
const layer: any[] = <any[]>layerData[index];
|
|
140
|
+
for (let j: number = 0; j < layer.length; j++) {
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
|
+
shapePoint.push(this.getPoint(layer[j] as any[], []));
|
|
143
|
+
currentLength = shapePoint[shapePoint.length - 1].length;
|
|
144
|
+
if (pointsLength < currentLength) {
|
|
145
|
+
pointsLength = currentLength;
|
|
146
|
+
midIndex = shapePoint.length - 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
text = (!isNullOrUndefined(datasrcObj)) ? !isNullOrUndefined(datasrcObj[labelpath]) ?
|
|
152
|
+
datasrcObj[labelpath].toString() : datasrcObj[layer.shapeDataPath] : shapeData['properties'][labelpath];
|
|
153
|
+
if ((Object.prototype.toString.call(layer.shapePropertyPath) === '[object Array]') &&
|
|
154
|
+
(isNullOrUndefined(text) && layer.dataSource['length'] === 0)) {
|
|
155
|
+
for (let l: number = 0; l < layer.shapePropertyPath.length; l++) {
|
|
156
|
+
if (shapeData['properties'][layer.shapePropertyPath[l]]) {
|
|
157
|
+
text = shapeData['properties'][layer.shapePropertyPath[l]];
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (isNullOrUndefined(text) && (layer.dataLabelSettings.template !== '' && layer.dataSource['length'] === 0)) {
|
|
163
|
+
text = shapeData['properties'][layer.shapePropertyPath as string];
|
|
164
|
+
}
|
|
165
|
+
const dataLabelText : string = text;
|
|
166
|
+
const projectionType : string = this.maps.projectionType;
|
|
167
|
+
if (isPoint) {
|
|
168
|
+
location = {
|
|
169
|
+
x: shapePoint[midIndex][index]['x'], y: shapePoint[midIndex][index]['y'],
|
|
170
|
+
rightMin: 0, rightMax: 0, leftMin: 0, leftMax: 0,
|
|
171
|
+
points: shapePoint[midIndex][index], topMax: 0, topMin: 0,
|
|
172
|
+
bottomMax: 0, bottomMin: 0, height: 0
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
location = findMidPointOfPolygon(shapePoint[midIndex], projectionType, layer.geometryType);
|
|
176
|
+
}
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
const firstLevelMapLocation : any = location;
|
|
179
|
+
if (!isNullOrUndefined(text) && !isNullOrUndefined(location)) {
|
|
180
|
+
if (zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied && dataLabel.template === '') {
|
|
181
|
+
if (layerIndex > 0){
|
|
182
|
+
for (let k : number = 0; k < this.maps.zoomLabelPositions.length; k++){
|
|
183
|
+
if (this.maps.zoomLabelPositions[k]['dataLabelText'] === text) {
|
|
184
|
+
oldIndex = index;
|
|
185
|
+
index = k;
|
|
186
|
+
sublayerIndexLabel = true;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
locationX = location['x'];
|
|
192
|
+
locationY = location['y'];
|
|
193
|
+
location['x'] = ((location['x'] + zoomTransPoint['x']) * scale);
|
|
194
|
+
location['y'] = ((location['y'] + zoomTransPoint['y']) * scale);
|
|
195
|
+
}
|
|
196
|
+
location['y'] = (this.maps.projectionType === 'Mercator') || layer.geometryType === 'Normal' ? location['y'] : (-location['y']);
|
|
197
|
+
data = location;
|
|
198
|
+
if (!isNullOrUndefined(this.maps.format) && !isNaN(parseFloat(text))) {
|
|
199
|
+
if (this.maps.useGroupingSeparator) {
|
|
200
|
+
text = Internalize(this.maps, parseFloat(text));
|
|
201
|
+
if (!isNullOrUndefined(datasrcObj)) {
|
|
202
|
+
datasrcObj[labelpath] = text;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const eventargs: ILabelRenderingEventArgs = {
|
|
207
|
+
name: dataLabelRendering, maps: this.maps, cancel: false, border: { color: dataLabel.border.color,
|
|
208
|
+
width: dataLabel.border.width, opacity: dataLabel.border.opacity }, datalabel: dataLabel,
|
|
209
|
+
fill: dataLabel.fill, template: dataLabel.template, text: text, offsetX: 0, offsetY: 0
|
|
210
|
+
};
|
|
211
|
+
this.maps.trigger('dataLabelRendering', eventargs, (labelArgs: ILabelRenderingEventArgs) => {
|
|
212
|
+
if (eventargs.cancel) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
216
|
+
const border: any = { color: 'yellow' };
|
|
217
|
+
let position: MapLocation[] = [];
|
|
218
|
+
let width: number = zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied
|
|
219
|
+
&& this.maps.zoomShapeCollection.length > index ? this.maps.zoomShapeCollection[index]['width'] :
|
|
220
|
+
(location['rightMax']['x'] - location['leftMax']['x']) * scale;
|
|
221
|
+
if (!isNullOrUndefined(this.maps.dataLabelShape)){
|
|
222
|
+
shapeWidth = firstLevelMapLocation['rightMax']['x'] - firstLevelMapLocation['leftMax']['x'];
|
|
223
|
+
this.maps.dataLabelShape.push(shapeWidth);
|
|
224
|
+
}
|
|
225
|
+
if (eventargs.text !== text && !eventargs.cancel){
|
|
226
|
+
text = eventargs.text;
|
|
227
|
+
}
|
|
228
|
+
const textSize: Size = measureText(text, style);
|
|
229
|
+
let trimmedLable: string = text;
|
|
230
|
+
let elementSize: Size = textSize;
|
|
231
|
+
const startY: number = location['y'] - textSize['height'] / 4;
|
|
232
|
+
const endY: number = location['y'] + textSize['height'] / 4;
|
|
233
|
+
const start: number = ((location['y'] + transPoint['y']) * scale) - textSize['height'] / 4;
|
|
234
|
+
const end: number = ((location['y'] + transPoint['y']) * scale) + textSize['height'] / 4;
|
|
235
|
+
position = filter(shapePoint[midIndex], startY, endY);
|
|
236
|
+
if (!isPoint && position.length > 5 && (shapeData['geometry']['type'] !== 'MultiPolygon') &&
|
|
237
|
+
(shapeData['type'] !== 'MultiPolygon')) {
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
239
|
+
const location1: any = findMidPointOfPolygon(position, projectionType, layer.geometryType);
|
|
240
|
+
if (zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied && eventargs.template === '') {
|
|
241
|
+
location1['x'] = ((this.maps.zoomLabelPositions[index]['location']['x'] + zoomTransPoint['x']) * scale);
|
|
242
|
+
location1['y'] = ((this.maps.zoomLabelPositions[index]['location']['y'] + zoomTransPoint['y']) * scale);
|
|
243
|
+
}
|
|
244
|
+
locationX = location1['x'];
|
|
245
|
+
location['x'] = location1['x'];
|
|
246
|
+
width = zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied
|
|
247
|
+
&& this.maps.zoomShapeCollection.length > index ? this.maps.zoomShapeCollection[index]['width'] :
|
|
248
|
+
(location1['rightMax']['x'] - location1['leftMax']['x']) * scale;
|
|
249
|
+
}
|
|
250
|
+
const xpositionEnds: number = ((location['x'] + transPoint['x']) * scale) + textSize['width'] / 2;
|
|
251
|
+
const xpositionStart: number = ((location['x'] + transPoint['x']) * scale) - textSize['width'] / 2;
|
|
252
|
+
this.value[index] = { rightWidth: xpositionEnds, leftWidth: xpositionStart, heightTop: start, heightBottom: end };
|
|
253
|
+
let labelElement: HTMLElement;
|
|
254
|
+
if (eventargs.template !== '') {
|
|
255
|
+
templateFn = getTemplateFunction(eventargs.template, this.maps);
|
|
256
|
+
const templateElement: Element = templateFn ? templateFn(!isNullOrUndefined(datasrcObj) ?
|
|
257
|
+
datasrcObj : shapeData['properties'], this.maps, eventargs.template, this.maps.element.id + '_LabelTemplate', false) : document.createElement('div');
|
|
258
|
+
templateElement.innerHTML = !templateFn ? eventargs.template : '';
|
|
259
|
+
labelElement = <HTMLElement>convertElementFromLabel(
|
|
260
|
+
templateElement, labelId, !isNullOrUndefined(datasrcObj) ? datasrcObj : shapeData['properties'], index, this.maps);
|
|
261
|
+
labelElement.style.left = ((Math.abs(this.maps.baseMapRectBounds['min']['x'] - location['x'])) * scale) + labelArgs.offsetX + 'px';
|
|
262
|
+
labelElement.style.top = ((Math.abs(this.maps.baseMapRectBounds['min']['y'] - location['y'])) * scale) + labelArgs.offsetY + 'px';
|
|
263
|
+
labelTemplateElement.appendChild(labelElement);
|
|
264
|
+
} else {
|
|
265
|
+
if (dataLabelSettings.smartLabelMode === 'Trim') {
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
267
|
+
const textType: any = typeof text === 'number' ? (text as any).toString() : text;
|
|
268
|
+
trimmedLable = textTrim(width, textType, style);
|
|
269
|
+
elementSize = measureText(trimmedLable, style);
|
|
270
|
+
options = new TextOption(labelId, textLocation.x, textLocation.y, 'middle', trimmedLable, '', '');
|
|
271
|
+
}
|
|
272
|
+
if (dataLabelSettings.smartLabelMode === 'None') {
|
|
273
|
+
options = new TextOption(labelId, (textLocation.x), textLocation.y, 'middle', text, '', '');
|
|
274
|
+
}
|
|
275
|
+
if (dataLabelSettings.smartLabelMode === 'Hide') {
|
|
276
|
+
text = (width >= textSize['width']) ? text : '';
|
|
277
|
+
options = new TextOption(labelId, (textLocation.x), (textLocation.y), 'middle', text, '', '');
|
|
278
|
+
}
|
|
279
|
+
text = options['text'] as string;
|
|
280
|
+
if (dataLabelSettings.intersectionAction === 'Hide') {
|
|
281
|
+
for (let i: number = 0; i < intersect.length; i++) {
|
|
282
|
+
if (!isNullOrUndefined(intersect[i])) {
|
|
283
|
+
if (!(this.value[index]['leftWidth'] > intersect[i]['rightWidth']
|
|
284
|
+
|| this.value[index]['rightWidth'] < intersect[i]['leftWidth']
|
|
285
|
+
|| this.value[index]['heightTop'] > intersect[i]['heightBottom']
|
|
286
|
+
|| this.value[index]['heightBottom'] < intersect[i]['heightTop'])) {
|
|
287
|
+
text = '';
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
intersect.push(this.value[index]);
|
|
293
|
+
options = new TextOption(labelId, textLocation.x, textLocation.y, 'middle', text, '', '');
|
|
294
|
+
}
|
|
295
|
+
let difference: number;
|
|
296
|
+
if (dataLabelSettings.intersectionAction === 'Trim') {
|
|
297
|
+
for (let j: number = 0; j < intersect.length; j++) {
|
|
298
|
+
if (!isNullOrUndefined(intersect[j])) {
|
|
299
|
+
if (intersect[j]['rightWidth'] < this.value[index]['leftWidth']
|
|
300
|
+
|| intersect[j]['leftWidth'] > this.value[index]['rightWidth']
|
|
301
|
+
|| intersect[j]['heightBottom'] < this.value[index]['heightTop']
|
|
302
|
+
|| intersect[j]['heightTop'] > this.value[index]['heightBottom']) {
|
|
303
|
+
trimmedLable = text;
|
|
304
|
+
difference = 0;
|
|
305
|
+
} else {
|
|
306
|
+
if (this.value[index]['leftWidth'] > intersect[j]['leftWidth']) {
|
|
307
|
+
width = intersect[j]['rightWidth'] - this.value[index]['leftWidth'];
|
|
308
|
+
difference = width - (this.value[index]['rightWidth'] - this.value[index]['leftWidth']);
|
|
309
|
+
trimmedLable = textTrim(difference, text, style);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
if (this.value[index]['leftWidth'] < intersect[j]['leftWidth']) {
|
|
313
|
+
width = this.value[index]['rightWidth'] - intersect[j]['leftWidth'];
|
|
314
|
+
difference = Math.abs(width - (this.value[index]['rightWidth'] - this.value[index]['leftWidth']));
|
|
315
|
+
trimmedLable = textTrim(difference, text, style);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
elementSize = measureText(trimmedLable, style);
|
|
322
|
+
intersect.push(this.value[index]);
|
|
323
|
+
options = new TextOption(labelId, textLocation.x, (textLocation.y), 'middle', trimmedLable, '', '');
|
|
324
|
+
}
|
|
325
|
+
if (dataLabelSettings.intersectionAction === 'None') {
|
|
326
|
+
options = new TextOption(labelId, (textLocation.x), (textLocation.y), 'middle', text, '', '');
|
|
327
|
+
}
|
|
328
|
+
if (trimmedLable.length > 1) {
|
|
329
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
+
const border: any = eventargs.border;
|
|
331
|
+
if (border['width'] > 1) {
|
|
332
|
+
const fill: string = eventargs.fill;
|
|
333
|
+
const opacity: number = dataLabelSettings.opacity;
|
|
334
|
+
const rx: number = dataLabelSettings.rx;
|
|
335
|
+
const ry: number = dataLabelSettings.ry;
|
|
336
|
+
let x : number ; let y : number; const padding : number = 5;
|
|
337
|
+
if (zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied) {
|
|
338
|
+
x = ((location['x'] ) ) - textSize['width'] / 2;
|
|
339
|
+
y = ((location['y'] ) ) - textSize['height'] / 2 - padding;
|
|
340
|
+
} else {
|
|
341
|
+
x = ((location['x'] + transPoint['x']) * scale) - textSize['width'] / 2;
|
|
342
|
+
y = ((location['y'] + transPoint['y'] ) * scale) - textSize['height'] / 2;
|
|
343
|
+
}
|
|
344
|
+
border.opacity = isNullOrUndefined(border.opacity) ? opacity : border.opacity;
|
|
345
|
+
const rectOptions: RectOption = new RectOption(
|
|
346
|
+
this.maps.element.id + '_LayerIndex_' + layerIndex + '_shapeIndex_' + index + '_rectIndex_' + index,
|
|
347
|
+
fill, border, opacity, new Rect((x + labelArgs.offsetX), (y + labelArgs.offsetY), textSize['width'], textSize['height']), rx, ry
|
|
348
|
+
);
|
|
349
|
+
const rect: Element = this.maps.renderer.drawRectangle(rectOptions) as SVGRectElement;
|
|
350
|
+
group.appendChild(rect);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
element = renderTextElement(options, style, style.color || this.maps.themeStyle.dataLabelFontColor, group);
|
|
354
|
+
if (zoomLabelsPosition && scaleZoomValue > 1 && !this.maps.zoomNotApplied){
|
|
355
|
+
element.setAttribute('transform', 'translate( ' + ((location['x'] + labelArgs.offsetX) ) + ' '
|
|
356
|
+
+ (((location['y'] + labelArgs.offsetY) ) ) + ' )');
|
|
357
|
+
location['x'] = locationX;
|
|
358
|
+
location['y'] = locationY;
|
|
359
|
+
} else {
|
|
360
|
+
element.setAttribute('transform', 'translate( ' + (((location['x'] + transPoint.x) * scale) + labelArgs.offsetX) + ' '
|
|
361
|
+
+ ((((location['y'] + transPoint.y) * scale) + (elementSize.height / 4)) + labelArgs.offsetY) + ' )');
|
|
362
|
+
}
|
|
363
|
+
group.appendChild(element);
|
|
364
|
+
}
|
|
365
|
+
this.dataLabelCollections.push({
|
|
366
|
+
location: { x: location['x'] + labelArgs.offsetX, y: location['y'] + labelArgs.offsetY },
|
|
367
|
+
element: isNullOrUndefined(labelElement) ? element : labelElement,
|
|
368
|
+
layerIndex: layerIndex,
|
|
369
|
+
shapeIndex: sublayerIndexLabel ? oldIndex : index,
|
|
370
|
+
labelIndex: sublayerIndexLabel ? oldIndex : index,
|
|
371
|
+
dataLabelText: dataLabelText
|
|
372
|
+
});
|
|
373
|
+
if (labelTemplateElement.childElementCount > 0 && !this.maps.element.contains(labelTemplateElement)) {
|
|
374
|
+
document.getElementById(this.maps.element.id + '_Secondary_Element').appendChild(labelTemplateElement);
|
|
375
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
376
|
+
(this.maps as any).renderReactTemplates();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
382
|
+
private getPoint(shapes: any[], points: MapLocation[]): MapLocation[] {
|
|
383
|
+
if (shapes['type'] === 'MultiLineString') {
|
|
384
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
385
|
+
shapes.map((current: any) => {
|
|
386
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
|
+
current.map((shape: any) => {
|
|
388
|
+
points.push(new Point(shape['point']['x'], shape['point']['y']));
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
} else {
|
|
392
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
393
|
+
shapes.map((current: any, index: number) => {
|
|
394
|
+
points.push(new Point(current['point']['x'], current['point']['y']));
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
return points;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Get module name.
|
|
401
|
+
*
|
|
402
|
+
* @returns {string} - Returns the module name.
|
|
403
|
+
*/
|
|
404
|
+
protected getModuleName(): string {
|
|
405
|
+
return 'DataLabel';
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
*
|
|
410
|
+
* @returns {void}
|
|
411
|
+
* @private
|
|
412
|
+
*/
|
|
413
|
+
public destroy(): void {
|
|
414
|
+
this.dataLabelCollections = [];
|
|
415
|
+
this.value = null;
|
|
416
|
+
this.maps = null;
|
|
417
|
+
}
|
|
418
|
+
}
|