高德地图海量点

1.先建个js文件

import AMapLoader from "@amap/amap-jsapi-loader";

const initMap = async (config) => {

return new Promise((resolve, reject) => {

AMapLoader.load({

key: "0650fbe85c708dc3388fe803d0e5d861",

// key: config.key,

version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15

plugins: [],

Loca: {

// 是否加载 Loca, 缺省不加载

version: "2.0.0", // Loca 版本,缺省 1.3.2

},

}).then((AMap) => {

resolve(AMap)

}).catch(err => {

reject(err)

})

})

}

export default initMap

2. vue组件

复制代码
<template>
  <div class="box">
    <div :id="id" class="container" ref="container"></div>
  </div>
</template>

<script>
import initMap from "../../utils/initMap";
export default {
  data() {
    return {
      id: "maps",
      mapsFlag: false,
      markerList: [],
      aMap: null,
      url1: require("../../assets/img/background_img/bg_nav.png"),
      url2: require("../../assets/img/background_img/bg_header.png")
    };
  },
  /* 必传
    id
    center
  */
  props: {
    center: {
      type: Array,
      default: () => []
    },
    mapStyle: {
      type: String,
      // default: "amap://styles/ebfa0ae6f5c3e8c2f7c1b31f3912c232",
      default: "amap://styles/835378d49c95f3bb1522a957afdad78c"
    },
    // 拖拽
    dragEnable: {
      type: Boolean,
      default: false
    },
    // 缩放
    zoomEnable: {
      type: Boolean,
      default: false
    },
    // 双击变大
    doubleClickZoom: {
      type: Boolean,
      default: false
    },
    // ctrl
    keyboardEnable: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    flyingLineObj: {
      handler(newName, oldName) {
        setTimeout(() => {
          this.init();
        }, 1000);
      },
      deep: true
    }
  },
  methods: {
    async init() {
      let that = this;
      initMap()
        .then(AMap => {
          this.aMap = new AMap.Map(this.id, {
            zoom: 5,
            viewMode: "3D",
            pitch: 48,
            center: this.center,
            mapStyle: this.mapStyle,
            dragEnable: this.dragEnable,
            zoomEnable: this.zoomEnable,
            doubleClickZoom: this.doubleClickZoom,
            keyboardEnable: this.keyboardEnable
          });

          // 创建 Loca 实例
          var loca = new Loca.Container({
            map: this.aMap
          });
          // 创建数据源
          let events = [
            {
              type: "Feature",
              properties: {},
              geometry: {
                type: "Point",
                coordinates: [lon, lat]
              }
            },
            {
              type: "Feature",
              properties: {},
              geometry: {
                type: "Point",
                coordinates: [lon, lat]
              }
            },
            {
              type: "Feature",
              properties: {},
              geometry: {
                type: "Point",
                coordinates: [lon, lat]
              }
            }
          ];
          // 图层的数据源
          var dataSource = new Loca.GeoJSONSource({
            data: {
              type: "FeatureCollection",
              features: events
            }
          });
          // 创建圆点图层
          var pointLayer = new Loca.PointLayer({
            zIndex: 10,
            opacity: 1,
            visible: true,
            blend: "lighter"
          });
          // 图层添加数据
          pointLayer.setSource(dataSource);

          // 设置样式
          pointLayer.setStyle({
            radius: 30,
            color: "red",
            borderWidth: 10,
            borderColor: "#fff",
            unit: "px"
          });
          // 添加到地图上
          loca.add(pointLayer);
        })
        .catch(e => {
          console.log(e);
        });
    }
  },
  components: {}
};
</script>

<style scoped>
.box {
  width: 100%;
  height: 1000px;
  border-radius: 12px;
  background: rgb(8, 34, 97);
}
.container {
  width: 100%;
  height: 100%;
  background: rgb(8, 34, 97);
}
::v-deep .amap-logo {
  display: none;
  opacity: 0 !important;
}
::v-deep .amap-copyright {
  opacity: 0;
}
</style>
相关推荐
gnip3 分钟前
总结一期正则表达式
javascript·正则表达式
军训猫猫头15 分钟前
1.如何对多个控件进行高效的绑定 C#例子 WPF例子
开发语言·算法·c#·.net
爱分享的程序员20 分钟前
前端面试专栏-算法篇:18. 查找算法(二分查找、哈希查找)
前端·javascript·node.js
翻滚吧键盘25 分钟前
vue 条件渲染(v-if v-else-if v-else v-show)
前端·javascript·vue.js
vim怎么退出27 分钟前
万字长文带你了解微前端架构
前端·微服务·前端框架
你这个年龄怎么睡得着的27 分钟前
为什么 JavaScript 中 'str' 不是对象,却能调用方法?
前端·javascript·面试
真的想上岸啊29 分钟前
学习C++、QT---18(C++ 记事本项目的stylesheet)
开发语言·c++·学习
Java水解30 分钟前
前端常用单位em/px/rem/vh/vm到底有什么区别?
前端
CAD老兵33 分钟前
Vite 如何借助 esbuild 实现极速 Dev Server 体验,并支持无 source map 的源码调试
前端
南屿im33 分钟前
JavaScript 手写实现防抖与节流:优化高频事件处理的利器
前端·javascript