map_control.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Created by 30947 on 2018/7/20.
  3. */
  4. $(function(){
  5. getHt();
  6. initMap();
  7. mapActive();
  8. char1();
  9. page();
  10. mapRestList();
  11. rightChange();
  12. })
  13. //获取div的高度
  14. function getHt(){
  15. var all_height=$(window).height();
  16. var div_height=all_height-84;
  17. $("#car_control").css("height",div_height+"px");
  18. }
  19. //加载地图
  20. function initMap(){
  21. // 百度地图API功能
  22. var map = new BMap.Map("map_box"); // 创建Map实例
  23. map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
  24. //添加地图类型控件
  25. var size1 = new BMap.Size(10, 50);
  26. map.addControl(new BMap.MapTypeControl({
  27. offset: size1,
  28. mapTypes:[
  29. BMAP_NORMAL_MAP,
  30. BMAP_HYBRID_MAP,
  31. ]}));
  32. // 编写自定义函数,创建标注
  33. function addMarker(point){
  34. var marker = new BMap.Marker(point);
  35. map.addOverlay(marker);
  36. }
  37. // 随机向地图添加25个标注
  38. var bounds = map.getBounds();
  39. var sw = bounds.getSouthWest();
  40. var ne = bounds.getNorthEast();
  41. var lngSpan = Math.abs(sw.lng - ne.lng);
  42. var latSpan = Math.abs(ne.lat - sw.lat);
  43. for (var i = 0; i < 25; i ++) {
  44. var point = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7));
  45. addMarker(point);
  46. };
  47. map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
  48. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  49. ////设备地图颜色
  50. //var mapStyle={
  51. // style:"midnight"
  52. //};
  53. //map.setMapStyle(mapStyle);
  54. //加载城市控件
  55. var size = new BMap.Size(10, 50);
  56. map.addControl(new BMap.CityListControl({
  57. anchor: BMAP_ANCHOR_TOP_LEFT,
  58. offset: size,
  59. }));
  60. }
  61. //工具条点击效果
  62. function mapActive(){
  63. $(".map_top>ul>li").click(function(){
  64. $(this).addClass("active").siblings().removeClass("active");
  65. $(this).find("a").addClass("active");
  66. $(this).find("a").parents("li").siblings().find("a").removeClass("active");
  67. })
  68. }
  69. //统计分析图
  70. function char1() {
  71. var myChart = echarts.init($("#char1")[0]);
  72. option = {
  73. tooltip : {
  74. trigger: 'item',
  75. formatter: "{a} <br/>{b} : {c} ({d}%)"
  76. },
  77. legend: {
  78. orient : 'vertical',
  79. x : 'right',
  80. textStyle : {
  81. color : '#ffffff',
  82. },
  83. data:['客运车','危险品车','网约车','学生校车']
  84. },
  85. calculable : false,
  86. series : [
  87. {
  88. name:'车类型',
  89. type:'pie',
  90. radius : ['40%', '70%'],
  91. itemStyle : {
  92. normal : {
  93. label : {
  94. show : false
  95. },
  96. labelLine : {
  97. show : false
  98. }
  99. },
  100. emphasis : {
  101. label : {
  102. show : true,
  103. position : 'center',
  104. textStyle : {
  105. fontSize : '20',
  106. fontWeight : 'bold'
  107. }
  108. }
  109. }
  110. },
  111. data:[
  112. {value:335, name:'客运车'},
  113. {value:310, name:'危险品车'},
  114. {value:234, name:'网约车'},
  115. {value:135, name:'学生校车'}
  116. ]
  117. }
  118. ]
  119. };
  120. myChart.setOption(option);
  121. window.addEventListener('resize', function () {myChart.resize();})
  122. }
  123. function page(){
  124. $("#page").Page({
  125. totalPages: 9,//分页总数
  126. liNums: 1,//分页的数字按钮数(建议取奇数)
  127. activeClass: 'activP', //active 类样式定义
  128. callBack : function(page){
  129. //console.log(page)
  130. }
  131. });
  132. }
  133. //专题图点击
  134. function mapRestList(){
  135. $(".map_work>ul>li").click(function(){
  136. $(".map_work>ul").hide();
  137. $(".map_resList").show();
  138. })
  139. }
  140. //返回
  141. function back(){
  142. $(".map_work>ul").show();
  143. $(".map_resList").hide();
  144. }
  145. //右侧功能界面切换
  146. function rightChange(){
  147. $(".map_right_top>ul>li").click(function(){
  148. var ins=$(this).index();
  149. $(this).addClass("li_active").siblings().removeClass("li_active");
  150. $(".map_con .map_con_div").eq(ins).show().siblings().hide();
  151. })
  152. }