Commit fd3208cf827e22c185542abdc0dc7208b9089c5b
1 parent
65027b9c
2nd part of additions to fix after review
Showing
2 changed files
with
31 additions
and
38 deletions
... | ... | @@ -608,30 +608,30 @@ export default abstract class LeafletMap { |
608 | 608 | return polygon; |
609 | 609 | } |
610 | 610 | |
611 | - updatePoints(pointsData: FormattedData[][], getTooltip: (point: FormattedData[], setTooltip?: boolean) => string) { | |
612 | - for(let i = 0; i < pointsData.length; i++) { | |
613 | - let pointsList = pointsData[i]; | |
614 | - if(i === 0) { | |
615 | - if (this.points) { | |
616 | - this.map.removeLayer(this.points); | |
617 | - } | |
618 | - this.points = new FeatureGroup(); | |
611 | + updatePoints(pointsData: FormattedData[][], getTooltip: (point: FormattedData) => string) { | |
612 | + if(pointsData.length) { | |
613 | + if (this.points) { | |
614 | + this.map.removeLayer(this.points); | |
619 | 615 | } |
616 | + this.points = new FeatureGroup(); | |
617 | + } | |
618 | + for(let i = 0; i < pointsData.length; i++) { | |
619 | + const pointsList = pointsData[i]; | |
620 | 620 | pointsList.filter(pdata => !!this.convertPosition(pdata)).forEach(data => { |
621 | 621 | const point = L.circleMarker(this.convertPosition(data), { |
622 | 622 | color: this.options.pointColor, |
623 | 623 | radius: this.options.pointSize |
624 | 624 | }); |
625 | 625 | if (!this.options.pointTooltipOnRightPanel) { |
626 | - point.on('click', () => getTooltip([data])); | |
626 | + point.on('click', () => getTooltip(data)); | |
627 | 627 | } else { |
628 | - createTooltip(point, this.options, data.$datasource, getTooltip([data], false)); | |
628 | + createTooltip(point, this.options, data.$datasource, getTooltip(data)); | |
629 | 629 | } |
630 | 630 | this.points.addLayer(point); |
631 | 631 | }); |
632 | - if(i === (pointsData.length - 1)) { | |
633 | - this.map.addLayer(this.points); | |
634 | - } | |
632 | + } | |
633 | + if(pointsData.length) { | |
634 | + this.map.addLayer(this.points); | |
635 | 635 | } |
636 | 636 | } |
637 | 637 | ... | ... |
... | ... | @@ -166,8 +166,8 @@ export class TripAnimationComponent implements OnInit, AfterViewInit, OnDestroy |
166 | 166 | currentPosition[j] = this.calculateLastPoints(this.interpolatedTimeData[j], time); |
167 | 167 | } |
168 | 168 | } |
169 | - this.calcLabel(currentPosition); | |
170 | - this.calcTooltip(currentPosition, true); | |
169 | + this.calcLabel(); | |
170 | + this.calcMainTooltip(currentPosition); | |
171 | 171 | if (this.mapWidget && this.mapWidget.map && this.mapWidget.map.map) { |
172 | 172 | const formattedInterpolatedTimeData = this.interpolatedTimeData.map(ds => _.values(ds)); |
173 | 173 | this.mapWidget.map.updatePolylines(formattedInterpolatedTimeData, true); |
... | ... | @@ -221,33 +221,26 @@ export class TripAnimationComponent implements OnInit, AfterViewInit, OnDestroy |
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - calcTooltip = (points?: FormattedData[], isMainTooltip: boolean = false): string => { | |
225 | - let tooltipText; | |
226 | - if(isMainTooltip) { | |
227 | - this.mainTooltips = [] | |
228 | - } | |
224 | + calcTooltip = (point: FormattedData): string => { | |
225 | + const data = point ? point : this.activeTrip; | |
226 | + const tooltipPattern: string = this.settings.useTooltipFunction ? | |
227 | + safeExecute(this.settings.tooltipFunction, [data, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern; | |
228 | + return parseWithTranslation.parseTemplate(tooltipPattern, data, true); | |
229 | + } | |
230 | + | |
231 | + private calcMainTooltip(points: FormattedData[]): void { | |
232 | + const tooltips = []; | |
229 | 233 | for (let point of points) { |
230 | - const data = point ? point : this.activeTrip; | |
231 | - const tooltipPattern: string = this.settings.useTooltipFunction ? | |
232 | - safeExecute(this.settings.tooltipFunction, [data, this.historicalData, point.dsIndex]) : this.settings.tooltipPattern; | |
233 | - tooltipText = parseWithTranslation.parseTemplate(tooltipPattern, data, true); | |
234 | - if(isMainTooltip) { | |
235 | - this.mainTooltips.push(this.sanitizer.sanitize(SecurityContext.HTML, tooltipText)); | |
236 | - } | |
234 | + tooltips.push(this.sanitizer.sanitize(SecurityContext.HTML, this.calcTooltip(point))); | |
237 | 235 | } |
238 | - this.cd.detectChanges(); | |
239 | - return tooltipText; | |
236 | + this.mainTooltips = tooltips; | |
240 | 237 | } |
241 | 238 | |
242 | - calcLabel(formattedDataArr: FormattedData[]) { | |
243 | - let labelToSet = ''; | |
244 | - for (let formattedData of formattedDataArr) { | |
245 | - const labelText: string = this.settings.useLabelFunction ? | |
246 | - safeExecute(this.settings.labelFunction, [formattedData, this.historicalData, formattedData.dsIndex]) : this.settings.label; | |
247 | - const label = (parseWithTranslation.parseTemplate(labelText, formattedData, true)); | |
248 | - labelToSet = labelToSet.length ? labelToSet + ',' + label : label; | |
249 | - } | |
250 | - this.label = labelToSet; | |
239 | + calcLabel() { | |
240 | + const data = this.activeTrip; | |
241 | + const labelText: string = this.settings.useLabelFunction ? | |
242 | + safeExecute(this.settings.labelFunction, [data, this.historicalData, data.dsIndex]) : this.settings.label; | |
243 | + this.label = (parseWithTranslation.parseTemplate(labelText, data, true)); | |
251 | 244 | } |
252 | 245 | |
253 | 246 | interpolateArray(originData: FormattedData[]) { | ... | ... |