当前位置:   article > 正文

使用百度地图绘点自定义弹窗_百度地图添加自定义弹窗 js

百度地图添加自定义弹窗 js
  1. <template>
  2. <div>
  3. <div id="map_container" ref="container" class="map-container"></div>
  4. <input type="checkbox" v-model="zfcheck"> 政府
  5. </div>
  6. </templat>
  7. <script>
  8. const carIcon = require("xxx/xxx.png");
  9. import { darkStyle } from "./darkStyle.js"; //自定义模式
  10. export default {
  11. data() {
  12. return {
  13. map: null,
  14. xjcheck: zfcheck,
  15. }
  16. },
  17. watch: {
  18. zfcheck(newVal, oldVal) {
  19. if (newVal) {
  20. this.map.clearOverlays(); //清除图层覆盖物
  21. const local = new BMapGL.LocalSearch(this.map, {
  22. renderOptions: { map: this.map, panel: "r-languageResult" },
  23. onInfoHtmlSet: function(params, html) {
  24. html.innerHTML =`<div style="font-size:30px;white-space:nowrap;font-weight: bold;">`+params.title+`</div>`+
  25. `<div style="font-size:30px;white-space:nowrap;">地址:`+params.address+`</div>`;
  26. },
  27. pageCapacity: 40
  28. });
  29. local.search("政府");
  30. } else {
  31. this.map.clearOverlays(); //清除图层覆盖物
  32. }
  33. }
  34. //学校、医院等都可以使用这种方式自定义弹窗
  35. },
  36. mounted() {
  37. this.init();
  38. },
  39. methods: {
  40. initMap() {
  41. // 地图初始化
  42. const center = [113.55934, 22.271431];
  43. this.map = new BMapGL.Map(this.$refs.container, {
  44. restrictCenter: false,
  45. maxZoom: 25,
  46. minZoom: 8,
  47. displayOptions: {
  48. building: false,
  49. },
  50. });
  51. this.map.setMapStyleV2({
  52. styleJson: darkStyle
  53. //参考链接https://lbsyun.baidu.com/custom/list.htm
  54. });
  55. this.map.centerAndZoom(new BMapGL.Point(center[0], center[1]), 21); //设置中心点坐标和地图级别
  56. this.map.enableScrollWheelZoom(true); //允许地图可被鼠标滚轮缩放
  57. this.map.enableKeyboard(); //启用键盘操作,默认禁用
  58. this.map.enableInertialDragging(); //启用地图惯性拖拽,默认禁用
  59. this.map.setDisplayOptions({
  60. indoor: false
  61. });
  62. //监听地图缩放事件;
  63. this.map.addEventListener("zoomend", ()=> {
  64. this.map.setTilt(0); // 设置地图的倾斜角度
  65. this.map.setHeading(0); //方向偏移
  66. });
  67. },
  68. }
  69. }
  70. </script>
  71. <style scoped>
  72. ::v-deep .BMap_bubble_content{
  73. width: 500px !important;
  74. color: #fff !important;
  75. top: -20px !important;
  76. line-height: 55px !important;
  77. font-size: 23px !important;
  78. }
  79. ::v-deep .BMap_bubble_pop {
  80. background-color: #121b4d !important;
  81. border: 5px solid #408bde !important;
  82. width: 550px !important;
  83. text-align: center;
  84. }
  85. ::v-deep .BMap_bubble_top {
  86. height: 31px !important;
  87. }
  88. ::v-deep .BMap_bubble_title {
  89. display: hidden;
  90. color: #fff !important;
  91. width: 550px !important;
  92. line-height: 50px !important;
  93. }
  94. ::v-deep .BMap_bubble_title p {
  95. display: none !important;
  96. }
  97. ::v-deep .BMap_bubble_title p a {
  98. //详情 链接
  99. display: none !important;
  100. }
  101. ::v-deep .BMap_bubble_pop &>img {
  102. display: none !important;
  103. }
  104. </style>

效果图

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/109658
推荐阅读
相关标签
  

闽ICP备14008679号