Vue加载百度地图GL版本和mapvgl

原创
01/21 14:05
阅读数 3.2K

1、安装依赖组件

npm install vue-bmap-gl --save
npm install vue-mapvgl --save

2、在main.js中加载组件

import VueBMap from 'vue-bmap-gl';
import 'vue-bmap-gl/dist/style.css'
import VueMapvgl  from 'vue-mapvgl';

Vue.use(VueBMap);
Vue.use(VueMapvgl);
VueBMap.initBMapApiLoader({
  ak: 'YOUR_KEY',
  v: '1.0'
});

该处的ak对应的值需要在百度的控制台中申请: http://lbsyun.baidu.com/apiconsole/key#/home 

3、加载点数据

<template>
    <div class="amap-page-container">
      <el-bmap vid="amapDemo" :zoom="zoom" :center="center" class="amap-demo">
        <el-bmap-marker vid="component-marker" :position="componentMarker.position" ></el-bmap-marker>
        <el-bmap-marker v-for="(marker, index) in markers" :icon="marker.icon" :visible="marker.visible" :position="marker.position" :title="marker.title" :label="marker.label" :events="marker.events" :vid="index" :enable-dragging="marker.enableDragging"></el-bmap-marker>
      </el-bmap>
      <div class="toolbar">
        <button type="button" name="button" v-on:click="changePosition">change position</button>
        <button type="button" name="button" v-on:click="chnageDraggle">change draggle</button>
        <button type="button" name="button" v-on:click="addMarker">add marker</button>
        <button type="button" name="button" v-on:click="removeMarker">remove marker</button>
        <button type="button" name="button" v-on:click="visibleMarker">切换显隐</button>
      </div>
    </div>
  </template>

  <style>
    .amap-demo {
      height: 300px;
    }
  </style>

  <script>

    module.exports = {
      name: 'bmap-page',
      data() {
        let carIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAABYCAYAAACONxXWAAAABmJLR0QA/wD/AP+gvaeTAAARoElEQVRo3r1be2wc53Gf3dt783h35JE8PiVRFkXbkhzbelhFWluu29hFLdmu4dZOUsFFYaF146qwWrRxjahBkARFDEcx0gSpC8RpYBeSnThQoNRGUyNI3D8URTJFWdaDlELxcTyRvAePPO69dju/b3dPJ/KOPJJHrbDi8m732/nmm/nNb+YbSrSK4/jx455cbu4eIq2DSPfJuiTbFMUu84HvC3pBz+fzO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ixYu8I35J3AWcCj+4KpMeMa4oaaQ2M/+yuHDNDoyei6b17+cyZTfL64ocDqtjno97uS1a0O7rly54nnggfslVa19S7kdzR2M7X/7139Fg4ODQIWD/JeMnyxbw1i12bR6qs5n+/7VK8NXOYy6ejb3tnEvmVJTiSUp9tUv/8uP+/v7v+TzJf5+bEwdoOVWL0uP8fEZ9AB9t6FBeVOX9XsZ8g7y75/mFzWsRk5eqRgHiZ9qufyr7BqfTE0lMlNV/HXospuAkRTy9sFWBrJ9jIkP8os7EV+QzvAkHGXJLgc2flEG1JWvp/n6Q842vs+B4hRD17L21FbVtYwGacbgdr7cqMtyK2s/WGbMPDtWlCc2mVeU4WQ0Osp/jZhd6Tv/H+I8f4qezBoAAAAAAElFTkSuQmCC';

        return {
          count: 1,
          slotStyle: {
            padding: '2px 8px',
            background: '#eee',
            color: '#333',
            border: '1px solid #aaa'
          },
          zoom: 14,
          center: [121.5273285, 31.21515044],
          markers: [
            {
              position: [121.5273285, 31.21515044],
              title: 'markers1',
              visible: true,
              icon: {
                url: carIcon,
                size: [44, 88],
              },
              label: {
                content: 'markers1',
                style: {
                    color: '#dcdcdc'
                }
              },
              events: {
                click: () => {
                  alert('click marker');
                },
                dragend: (e) => {
                  console.log('---event---: dragend');
                  this.markers[0].position = [e.latLng.lng, e.latLng.lat];
                }
              },
              enableDragging: false,
            }
          ],
          componentMarker: {
            position: [121.5273285, 31.21315058],
          },
          slotMarker: {
            position: [121.5073285, 31.21715058]
          }
        };
      },
      methods: {
        visibleMarker(){
          this.markers[0].visible = !this.markers[0].visible;
        },
        onClick() {
          this.count += 1;
        },
        changePosition() {
          let position = this.markers[0].position;
          this.markers[0].position = [position[0] + 0.002, position[1] - 0.002];
        },
        chnageDraggle() {
          let draggable = this.markers[0].enableDragging;
          this.markers[0].enableDragging = !draggable;
        },
        toggleVisible() {
          let visableVar = this.markers[0].visible;
          this.markers[0].visible = !visableVar;
        },
        addMarker() {
          let marker = {
            position: [121.5273285 + (Math.random() - 0.5) * 0.02, 31.21515044 + (Math.random() - 0.5) * 0.02],
            enableDragging: false
          };
          this.markers.push(marker);
        },
        removeMarker() {
          if (!this.markers.length) return;
          this.markers.splice(this.markers.length - 1, 1);
        }
      }
    };
</script>

4、使用vue-mapvgl进行大数据展示,示例为波点图

<template>
    <div class="bmap-page-container">
      <el-bmap vid="bmapDemo" :zoom="zoom" :center="center" class="bmap-demo">
        <el-bmapv-view>
            <el-bmapv-ripple-layer :size="size" :color="color" :data="data"></el-bmapv-ripple-layer>
        </el-bmapv-view>
      </el-bmap>
    </div>
  </template>

  <style>
    .bmap-demo {
      height: 300px;
    }
  </style>

  <script>

    module.exports = {
      name: 'bmap-page',
      data() {

        return {
          count: 1,
          zoom: 14,
          center: [121.5273285, 31.21515044],
          color: '#ffffff',
          size: 100,
          data: [{
              geometry: {
                  type: 'Point',
                  coordinates: [121.5273285, 31.21515044],
              },
              properties: {
                size: 300,
                color: 'red'
              }
              },{
              geometry: {
                  type: 'Point',
                  coordinates: [121.5373285, 31.21515044],
              },
              properties: {
                  size: 400,
                  color: 'green'
              }
          },{
             geometry: {
                 type: 'Point',
                 coordinates: [121.5573285, 31.21515044],
             },
             properties: {
             }
         }]
        };
      },
      mounted(){
      },
      methods: {
      }
    };
</script>

5、详细示例以及API方法可以查看文档

vue-bmap-gl: https://guyangyang.gitee.io/vue-bmap-gl/#/zh-cn/coverings/marker

vue-mapvgl:https://guyangyang.gitee.io/vue-mapvgl/#/zh-cn/layer/RippleLayer

展开阅读全文
打赏
1
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
1
分享
返回顶部
顶部