Commit 08c8d935685c1e4fc72556e7ce5741a5fc63a1c0
Committed by
GitHub
1 parent
39ff12fe
UI:fix. Map widget2 (#2413)
preserves previous data on map if no data for current date range received
Showing
1 changed file
with
40 additions
and
38 deletions
... | ... | @@ -584,51 +584,53 @@ export default class TbMapWidgetV2 { |
584 | 584 | var latData = data[location.latIndex].data; |
585 | 585 | var lngData = data[location.lngIndex].data; |
586 | 586 | var lat, lng, latLng; |
587 | - if (latData.length > 0 && lngData.length > 0) { | |
588 | - if (tbMap.drawRoutes) { | |
589 | - // Create or update route | |
590 | - var latLngs = []; | |
591 | - for (var i = 0; i < latData.length; i++) { | |
592 | - lat = latData[i][1]; | |
593 | - lng = lngData[i][1]; | |
594 | - if (angular.isDefined(lat) && lat != null && angular.isDefined(lng) && lng != null) { | |
595 | - latLng = tbMap.map.createLatLng(lat, lng); | |
596 | - if (i == 0 || !latLngs[latLngs.length - 1].equals(latLng)) { | |
597 | - latLngs.push(latLng); | |
598 | - } | |
599 | - } | |
600 | - } | |
601 | - if (latLngs.length > 0) { | |
602 | - var markerLocation = latLngs[latLngs.length - 1]; | |
603 | - createOrUpdateLocationMarker(location, markerLocation, dataMap); | |
604 | - } | |
605 | - if (!location.polyline) { | |
606 | - location.polyline = tbMap.map.createPolyline(latLngs, location.settings); | |
607 | - tbMap.polylines.push(location.polyline); | |
608 | - locationChanged = true; | |
609 | - } else { | |
610 | - var prevPath = tbMap.map.getPolylineLatLngs(location.polyline); | |
611 | - if (!prevPath || !arraysEqual(prevPath, latLngs)) { | |
612 | - tbMap.map.setPolylineLatLngs(location.polyline, latLngs); | |
613 | - locationChanged = true; | |
614 | - } | |
615 | - } | |
616 | - } else { | |
617 | - // Create or update marker | |
618 | - lat = latData[latData.length - 1][1]; | |
619 | - lng = lngData[lngData.length - 1][1]; | |
587 | + | |
588 | + if (tbMap.drawRoutes) { | |
589 | + // Create or update route | |
590 | + var latLngs = []; | |
591 | + for (var i = 0; i < latData.length; i++) { | |
592 | + lat = latData[i][1]; | |
593 | + lng = lngData[i][1]; | |
620 | 594 | if (angular.isDefined(lat) && lat != null && angular.isDefined(lng) && lng != null) { |
621 | 595 | latLng = tbMap.map.createLatLng(lat, lng); |
622 | - if (createOrUpdateLocationMarker(location, latLng, dataMap)) { | |
623 | - locationChanged = true; | |
596 | + if (i == 0 || !latLngs[latLngs.length - 1].equals(latLng)) { | |
597 | + latLngs.push(latLng); | |
624 | 598 | } |
625 | 599 | } |
626 | 600 | } |
627 | - if (location.marker) { | |
628 | - updateLocationStyle(location, dataMap); | |
601 | + if (latLngs.length > 0) { | |
602 | + var markerLocation = latLngs[latLngs.length - 1]; | |
603 | + createOrUpdateLocationMarker(location, markerLocation, dataMap); | |
604 | + } else if (location.marker) { | |
605 | + tbMap.map.removeMarker(location.marker); | |
606 | + delete location.marker; | |
607 | + } | |
608 | + if (!location.polyline) { | |
609 | + location.polyline = tbMap.map.createPolyline(latLngs, location.settings); | |
610 | + tbMap.polylines.push(location.polyline); | |
611 | + locationChanged = true; | |
612 | + } else { | |
613 | + var prevPath = tbMap.map.getPolylineLatLngs(location.polyline); | |
614 | + if (!prevPath || !arraysEqual(prevPath, latLngs)) { | |
615 | + tbMap.map.setPolylineLatLngs(location.polyline, latLngs); | |
616 | + locationChanged = true; | |
617 | + } | |
618 | + } | |
619 | + } else { | |
620 | + // Create or update marker | |
621 | + lat = latData[latData.length - 1][1]; | |
622 | + lng = lngData[lngData.length - 1][1]; | |
623 | + if (angular.isDefined(lat) && lat != null && angular.isDefined(lng) && lng != null) { | |
624 | + latLng = tbMap.map.createLatLng(lat, lng); | |
625 | + if (createOrUpdateLocationMarker(location, latLng, dataMap)) { | |
626 | + locationChanged = true; | |
627 | + } | |
629 | 628 | } |
630 | - | |
631 | 629 | } |
630 | + if (location.marker) { | |
631 | + updateLocationStyle(location, dataMap); | |
632 | + } | |
633 | + | |
632 | 634 | } |
633 | 635 | return locationChanged; |
634 | 636 | } | ... | ... |