commonMap.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div id="place_map_wrap">
  3. <div class="place_map_box">
  4. <div id="place_map">
  5. <div id="allmap" :style="mapStyle"></div>
  6. </div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'commonMap',
  13. data() {
  14. return{
  15. mapStyle:{
  16. width:'100%',
  17. height:'100%'
  18. }
  19. }
  20. },
  21. props:{
  22. mapData: {
  23. type: Object,
  24. // 地图在该视图上的高度
  25. mapHeight:{
  26. type:Number,
  27. default:600
  28. },
  29. // 经度
  30. longitude:{
  31. type:Number,
  32. default:113.845282
  33. },
  34. // 纬度
  35. latitude:{
  36. type:Number,
  37. default:22.613041
  38. },
  39. title:{
  40. type:String,
  41. default:'深圳市田田家园家具有限公司'
  42. },
  43. description:{
  44. type:String,
  45. default:'地址:深圳市宝安区西乡街道泰华梧桐岛11栋5-9楼'
  46. }
  47. }
  48. },
  49. mounted (){
  50. var map =new BMap.Map("allmap");
  51. var point =new BMap.Point(this.mapData.longitude,this.mapData.latitude);
  52. var marker =new BMap.Marker(point); // 创建标注
  53. map.enableScrollWheelZoom(); //启用滚轮放大缩小,默认禁用
  54. map.enableContinuousZoom(); //启用地图惯性拖拽,默认禁用
  55. map.setMapStyle({style:'dark'}); //地图添加黑夜主题背景
  56. map.addOverlay(marker); // 将标注添加到地图中
  57. map.centerAndZoom(point,15);
  58. // 信息窗的配置信息
  59. var opts ={
  60. width :250,
  61. height:120,
  62. title :this.mapData.title,
  63. }
  64. var infoWindow =new BMap.InfoWindow(this.mapData.description, opts);// 创建信息窗口对象
  65. marker.addEventListener("click",function(){
  66. map.openInfoWindow(infoWindow,point);
  67. });
  68. map.enableScrollWheelZoom(true);
  69. map.openInfoWindow(infoWindow,point);//开启信息窗口
  70. var top_left_navigation = new BMap.NavigationControl(); //左上角,添加默认缩放平移控件
  71. map.addControl(top_left_navigation);
  72. }
  73. }
  74. </script>
  75. <style scoped>
  76. #place_map_wrap {
  77. width: 100%;
  78. }
  79. .place_map_box {
  80. overflow: hidden;
  81. width: 100%;
  82. height: 600px;
  83. margin: 0 auto;
  84. }
  85. div#place_map {
  86. overflow: hidden;
  87. width: 100%;
  88. height: 100%;
  89. }
  90. .anchorBL, .BMap_cpyCtrl.BMap_noprint.anchorBL{
  91. display: none !important;
  92. }
  93. </style>