device-map.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. (function() {
  2. var rs = [], //最新的结果
  3. page = 1, // 当前分页索引
  4. pageSize = 100, // 每页条数
  5. diseaseType = "",
  6. diseaseCondition = "",
  7. colorMap = {
  8. "0": ["#19ff8a"], // 绿标
  9. "1": ["#ffae32"], // 黄标
  10. "2": ["#ff2f6a"], // 红标
  11. "-1": ["#aadeff"], // 没有标注
  12. }
  13. var flashTimer = null
  14. Vue.component('device-map', {
  15. template: '<div id="mapWrap">\
  16. <div v-show="percent<100" style="position: absolute;top: 50%;left: 50%;z-index: 999999;margin-left: -50px;">\
  17. <div class="sk-spinner sk-spinner-chasing-dots">\
  18. <div class="sk-dot1"></div>\
  19. <div class="sk-dot2"></div>\
  20. </div>\
  21. <div style="color: #fff;margin-top: 10px;">加载中({{percent}}%)...</div>\
  22. </div>\
  23. <div id="allmap"></div>\
  24. </div>',
  25. props: [],
  26. data: function() {
  27. return {
  28. percent: 0,
  29. points: [],
  30. map: null
  31. }
  32. },
  33. computed: {
  34. },
  35. methods: {
  36. initMap: function() {
  37. var vm = this
  38. // 百度地图API功能
  39. var map = new BMap.Map("allmap", {enableMapClick: false});
  40. map.centerAndZoom(new BMap.Point(118.10,24.46),13);
  41. map.enableScrollWheelZoom();
  42. var mapStyle ={
  43. style : "midnight" //设置地图风格为高端黑
  44. }
  45. map.setMapStyle(mapStyle);
  46. // //单击获取点击的经纬度
  47. map.addEventListener("click",function(e){
  48. map.setCenter(new BMap.Point(e.point.lng, e.point.lat))
  49. map.setZoom(18)
  50. var pts = vm.filterByLocation(e.point.lng , e.point.lat)
  51. if(vm.percent == 100) {
  52. var idcards = _.pluck(pts,"idCard").join(",")
  53. if(idcards) {
  54. intelligentAPI.searchPatient({
  55. idcards: idcards
  56. }).then(function(res) {
  57. if(res.status == 200) {
  58. EventBus.$emit('update-patient-info', {
  59. patientData: JSON.stringify(res.data)
  60. })
  61. }
  62. })
  63. }
  64. }
  65. setTimeout(function() {
  66. map.panTo(new BMap.Point(e.point.lng, e.point.lat));
  67. }, 300)
  68. });
  69. // map.addEventListener("tilesloaded",function(){
  70. //
  71. // });
  72. vm.map = map
  73. window.map = map
  74. },
  75. getLocations: function() {
  76. var vm = this
  77. var pointArr = []
  78. intelligentAPI.findLocationByIdCard({
  79. pageSize: pageSize,
  80. page: page
  81. }).then(function(res) {
  82. if(res.status == 200) {
  83. pointArr = _.map(res.detailModelList, function(o) {
  84. o.lat = o.location.lat
  85. o.lng = o.location.lon
  86. o.lnglat = [o.location.lon, o.location.lat]
  87. o.type = 'circle',
  88. o.speed = 0.1,
  89. o.color = colorMap[o.diseaseCondition][0]
  90. o.max = 5
  91. return o
  92. })
  93. vm.points = vm.points.concat(pointArr)
  94. rs = vm.filterByDisease()
  95. window.clearTimeout(flashTimer)
  96. flashTimer = null
  97. flashTimer = setTimeout(function() {
  98. vm.initFlashMaker()
  99. }, 2000)
  100. vm.percent = ((page / Math.ceil(res.totalCount / pageSize))* 100).toFixed(2)
  101. if(vm.percent >= 100) {
  102. vm.percent = 100
  103. }
  104. if(Math.ceil(res.totalCount / pageSize) > page) {
  105. setTimeout(function() {
  106. page++
  107. vm.getLocations()
  108. }, 300)
  109. } else {
  110. vm.percent = 100
  111. }
  112. } else {
  113. setTimeout(function() {
  114. vm.getLocations()
  115. }, 300)
  116. }
  117. }).catch(function() {
  118. setTimeout(function() {
  119. vm.getLocations()
  120. }, 300)
  121. })
  122. },
  123. filterByLocation: function(lng,lat) {
  124. var vm = this
  125. var p1 = new BMap.Point(lng,lat);
  126. return _.filter(rs, function(o) {
  127. var p2 = new BMap.Point(o.lng,o.lat);
  128. return map.getDistance(p1,p2).toFixed(2) <= 100
  129. })
  130. },
  131. filterByDisease: function() {
  132. // diseaseType值(0:全部;1:高血压;2:糖尿病)
  133. // diseaseCondition(-1:无标签;0:绿标;1黄标;2红标)
  134. var vm = this
  135. if(diseaseType) {
  136. return _.filter(vm.points, function(o) {
  137. return (!diseaseCondition || o.diseaseCondition == diseaseCondition)
  138. && (diseaseType=="0" || (diseaseType == o.label))
  139. })
  140. } else {
  141. return vm.points
  142. }
  143. },
  144. initFlashMaker: function() {
  145. var vm = this
  146. map.clearOverlays()
  147. new FlashMarker(vm.map, rs)
  148. }
  149. },
  150. mounted: function() {
  151. var vm = this
  152. vm.initMap()
  153. vm.getLocations()
  154. EventBus.$on('device-map-filter', function(o) {
  155. diseaseType = o.diseaseType + ""
  156. diseaseCondition = o.diseaseCondition + ""
  157. rs = vm.filterByDisease()
  158. vm.initFlashMaker()
  159. });
  160. }
  161. })
  162. })()