zoukankan      html  css  js  c++  java
  • Vue2使用百度地图

    Vue2使用百度地图的简单例子


    1.第一步

    在index文件引入百度js

    2.第二步

    在组件中使用

    <template>
    <div id="map" :style="style"></div>
    </template>
    <script>
      export default{
        data(){
          return{
            style:{
              '100%',
              height:'100%',
              position:'absolute'
            },
            startPoint:{
                x: 121.409992,
                y: 31.178243
            },
            zoom:15,
            styleJson:{
                styleJson: [
                    {
                      'featureType': 'water',
                      'elementType': 'all',
                      'stylers': {
                        'color': '#031628'
                      }
                    },
                    {
                      'featureType': 'land',
                      'elementType': 'geometry',
                      'stylers': {
                        'color': '#000102'
                      }
                    },
                    {
                      'featureType': 'highway',
                      'elementType': 'all',
                      'stylers': {
                        'visibility': 'off'
                      }
                    },
                    {
                      'featureType': 'arterial',
                      'elementType': 'geometry.fill',
                      'stylers': {
                        'color': '#000000'
                      }
                    },
                    {
                      'featureType': 'arterial',
                      'elementType': 'geometry.stroke',
                      'stylers': {
                        'color': '#0b3d51'
                      }
                    },
                    {
                      'featureType': 'local',
                      'elementType': 'geometry',
                      'stylers': {
                        'color': '#000000'
                      }
                    },
                    {
                      'featureType': 'railway',
                      'elementType': 'geometry.fill',
                      'stylers': {
                        'color': '#000000'
                      }
                    },
                    {
                      'featureType': 'railway',
                      'elementType': 'geometry.stroke',
                      'stylers': {
                        'color': '#08304b'
                      }
                    },
                    {
                      'featureType': 'subway',
                      'elementType': 'geometry',
                      'stylers': {
                        'lightness': -70
                      }
                    },
                    {
                      'featureType': 'building',
                      'elementType': 'geometry.fill',
                      'stylers': {
                        'color': '#000000'
                      }
                    },
                    {
                      'featureType': 'all',
                      'elementType': 'labels.text.fill',
                      'stylers': {
                        'color': '#857f7f'
                      }
                    },
                    {
                      'featureType': 'all',
                      'elementType': 'labels.text.stroke',
                      'stylers': {
                        'color': '#000000'
                      }
                    },
                    {
                      'featureType': 'building',
                      'elementType': 'geometry',
                      'stylers': {
                        'color': '#022338'
                      }
                    },
                    {
                      'featureType': 'green',
                      'elementType': 'geometry',
                      'stylers': {
                        'color': '#062032'
                      }
                    },
                    {
                      'featureType': 'boundary',
                      'elementType': 'all',
                      'stylers': {
                        'color': '#465b6c'
                      }
                    },
                    {
                      'featureType': 'manmade',
                      'elementType': 'all',
                      'stylers': {
                        'color': '#022338'
                      }
                    },
                    {
                      'featureType': 'label',
                      'elementType': 'all',
                      'stylers': {
                        'visibility': 'off'
                      }
                    },
                    {
                        "featureType": "poi",
                        "elementType": "all",
                        "stylers": {
                                  "color": "#022338",
                                  "visibility": "off"
                        }
              }
    
                  ]
           }
          }
        },
        mounted(){
           // 百度地图API功能
        var map = new BMap.Map("map");    // 创建Map实例
        map.centerAndZoom(new BMap.Point(this.startPoint.x,this.startPoint.y), this.zoom);  // 初始化地图,设置中心点坐标和地图级别
        map.setCurrentCity("上海");          // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        map.setMapStyle(this.styleJson)  //地图样式
        }
      }
    </script>

    注:要让地图高度100%显示,一定在样式上加   

    position:'absolute'

    3.取消百度logo

     .anchorBL{  
           display:none;  
       } 

    4.预览

    npm run dev

  • 相关阅读:
    芯片光刻的流程详解
    中国半导体上市公司2018年的表现盘点:材料和设备篇
    中国半导体上市公司2018年的表现盘点:代工和封测篇
    spring-cloud-sleuth 和 分布式链路跟踪系统
    Jdk和Spring Boot版本选择
    mockplus 原型设计工具
    showdoc 文档管理系统
    禅道项目管理系统
    docker 基础知识分享ppt
    项目管理成功之要素-转载
  • 原文地址:https://www.cnblogs.com/zry2510/p/6919727.html
Copyright © 2011-2022 走看看