【百度地图2.5D、3D在Vue项目中的使用】嵌入二维百度地图、三维百度地图、多种显示模式风格样式颜色的百度地图

简介: 【百度地图2.5D、3D在Vue项目中的使用】嵌入二维百度地图、三维百度地图、多种显示模式风格样式颜色的百度地图

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,显示二维地图 (午夜蓝风格)

模板页可以查看 去这个位置编辑个性化地图


image.png

访问路径的时候带参数?type=0&style=grayscale,显示二维地图 (高端灰风格)

 访问路径的时候带参数?type=1,显示实景地图

访问路径的时候带参数?type=2,显示实景地图(带有地名)

访问路径的时候带参数?type=3,显示三维3D地图

相关文章
|
8天前
uni-app项目中如何添加百度统计代码?
uni-app项目中如何添加百度统计代码?
|
5月前
|
JavaScript 定位技术 PHP
【百度地图】——利用三级联动加载百度地图
【百度地图】——利用三级联动加载百度地图
|
8天前
|
JavaScript 前端开发 定位技术
GPS坐标显示在百度地图上(Qt+百度地图)
GPS坐标显示在百度地图上(Qt+百度地图)
17 0
|
8天前
|
Ubuntu Linux
百度搜索:蓝易云【Linux平台下构建TigerVNC项目教程】
至此,你已经成功在Linux平台下构建并安装了TigerVNC项目。现在你可以启动VNC服务器并通过VNC客户端连接到远程桌面。请注意,上述步骤仅适用于一般情况,具体的构建步骤可能会因为不同的系统环境和版本而有所不同。在实际操作中,可能还需要根据实际情况进行一些调整。
36 1
|
8天前
|
前端开发 安全 Go
无法通过 iframe 将百度首页嵌入到自己的前端应用里
无法通过 iframe 将百度首页嵌入到自己的前端应用里
316 0
|
8天前
|
前端开发 JavaScript 应用服务中间件
百度搜索:蓝易云【服务器如何配置支持history模式】
配置完毕后,服务器将会将所有请求重定向到你的应用的index.html文件,使得history模式能够正常运行。这样,当用户在浏览器中直接访问子路径时,服务器会正确地返回index.html,并由前端路由接管处理。
67 1
|
8天前
|
Java Docker 容器
百度搜索:蓝易云【Docker部署jar项目教程】
请注意,以上是一个基本的教程,具体的步骤可能因项目结构和需求而有所不同。您可能需要根据实际情况进行调整和配置。同时,确保您的系统已经正确安装并配置了Docker。
50 1
|
8天前
|
存储 运维 监控
百度搜索:蓝易云【【NOSQL】redis哨兵模式、集群搭建详解。】
总结来说,Redis哨兵模式和集群都是为了提高Redis的高可用性和可伸缩性。哨兵模式适用于少数几个Redis节点的环境,当主节点不可用时能够自动进行故障切换。而集群则适用于大规模数据存储和处理的场景,通过数据分片和故障检测实现分布式的高性能Redis环境。根据具体需求,选择适合的方案来搭建Redis环境。
42 0
|
8天前
|
IDE 定位技术 开发工具
百度地图如何创建一个属于自己的地图,附加到项目中?
百度地图如何创建一个属于自己的地图,附加到项目中?
68 0
|
8天前
|
存储 Kubernetes 容器
百度搜索:蓝易云【Kubernetes使用helm部署NFS Provisioner】
现在,你已经成功使用Helm部署了NFS Provisioner,并且可以在Kubernetes中创建使用NFS存储的PersistentVolumeClaim。
52 10