rc\js\main.js
... // 引入普通百度地图----------------------------------------npm install vue-baidu-map --save import BaiduMap from 'vue-baidu-map'; Vue.use(BaiduMap, { ak: 'DvSp7Of3aqrGbjIsGqebqdPAmjhGDndf' });//这个百度APIkey密钥是用百度ID:16*******61注册的,如果要更改密钥权限找强哥! // 引入3D百度地图----------------------------------------npm install vue-bmap-gl --save import VueBMap from 'vue-bmap-gl'; import 'vue-bmap-gl/dist/style.css'; Vue.use(VueBMap); VueBMap.initBMapApiLoader({ ak: '***DvSp7Of3aqrGbjIsGqebqdPAmjhGDndf***',//这个密钥请使用自己注册的 v: '1.0' }); ...
src\vue\components\sgMap.vue
<template> <div class="sgMap-body"> <!-- 引入百度地图 --> <div id="SGbaidu3Dmap" v-show="data.type == 3"></div> <baidu-map id="SGbaidumap" v-if="data.type != 3" @ready="initBaiduMap"> </baidu-map> </div> </template> <script> import custom_map_config from "@/json/custom_map_config"; export default { components: {}, data() { return { map: null, // 百度地图对象 // _MyMap: null,//瓦片图对象 }; }, props: ["data"], mounted() { this.data.type == 3 && setTimeout(() => { this.initBaidu3DMap(); }, 2000); }, methods: { initBaidu3DMap() { this.map = new BMapGL.Map("SGbaidu3Dmap"); this.map.centerAndZoom( new BMapGL.Point(this.data.coordinate[0], this.data.coordinate[1]), this.data.zoom || 19 ); this.map.enableScrollWheelZoom(true); //启用滚轮放大缩小 //设置3D角度---------------------------------------- this.map.setHeading(64.5); this.map.setTilt(73); // 设置自定义mark点位________________________ this.map.addOverlay( new BMapGL.Marker( new BMapGL.Point(this.data.coordinate[0], this.data.coordinate[1]), { icon: new BMapGL.Icon( require("@/assets/sgMap/mark.svg"), new BMapGL.Size(32, 32) //图标的宽高 ), } ) ); // 将标注添加到地图中 }, // 初始化百度地图 initBaiduMap({ BMap, map }) { this.map = map; this.map.setMapStyle({ style: this.data.style || "googlelite" }); //默认:精简风格(googlelite),模板页可以查看http://lbsyun.baidu.com/custom/list.htm // 去这个位置编辑http://lbsyun.baidu.com/apiconsole/custommap个性化地图 // this.map.setMapStyle({ styleJson: custom_map_config }); // this._MyMap = new BMap.MapType('MyMap', this._tileLayer, {minZoom: minZoom || 1, maxZoom: maxZoom || window.maxZoom}); // 设置地图显示类型---------------------------------------- const mapTypes = [ BMAP_NORMAL_MAP, //此地图类型展示普通街道视图 BMAP_SATELLITE_MAP, //此地图类型展示卫星视图 BMAP_HYBRID_MAP, //此地图类型展示卫星和路网的混合视图 ]; if (this.data.type == 3) { this.map.setHeading(64.5), this.map.setTilt(73); //3D地图 } else this.map.setMapType(mapTypes[this.data.type]); // ---------------------------------------- this.map.enableScrollWheelZoom(true); //启用滚轮放大缩小 this.map.centerAndZoom( new BMap.Point(this.data.coordinate[0], this.data.coordinate[1]), this.data.zoom || 14 ); // 初始化地图,设置中心点坐标和地图级别 // 设置自定义mark点位________________________ this.map.addOverlay( new BMap.Marker( new BMap.Point(this.data.coordinate[0], this.data.coordinate[1]), { icon: new BMap.Icon( require("@/assets/sgMap/mark.svg"), new BMap.Size(32, 32) //图标的宽高 ), } ) ); // 将标注添加到地图中 }, }, }; </script> <style lang='scss' scoped> @import "~@/css/sg"; // ---------------------------------------- .sgMap-body { transition: none; position: fixed; width: 100%; height: 100%; top: 0; left: 0; >>> #SGbaidumap, >>> #SGbaidu3Dmap { width: 100%; height: 100%; & > div { background-color: transparent !important; } } } /* 去除百度地图版权 去除右上角[地图、卫星、三维]控件 去除百度地图右上角平移缩放控件的市县区文字 */ >>> .anchorBL, >>> .anchorTR, >>> .BMap_zlHolder { display: none; visibility: hidden; } </style>
src\vue\screen\index.vue
<template> <div class="index-body"> <sgMap class="sg-map" :data="{ coordinate: [118.869472, 28.975293], style: $route.query.style || 'midnight', type: $route.query.type || 0, zoom: $route.query.zoom || 16, }" /> </div> </template> <script> import sgMap from "@/vue/components/sgMap"; export default { components: { sgMap, }, }; </script> <style lang='scss' scoped> .sg-map { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; } </style>
访问路径的时候带参数?type=0&style=midnight,显示二维地图 (午夜蓝风格)
模板页可以查看 去这个位置编辑个性化地图
访问路径的时候带参数?type=0&style=grayscale,显示二维地图 (高端灰风格)
访问路径的时候带参数?type=1,显示实景地图
访问路径的时候带参数?type=2,显示实景地图(带有地名)
访问路径的时候带参数?type=3,显示三维3D地图