antv L7结合高德地图使用dome1


官网文档

一、设置底图

// 引入高德数据可视化api2.0
import AMapLoader from '@amap/amap-jsapi-loader';
// 初始化地图数据
 this.$nextTick(() => {
      AMapLoader.load({
        "key": "xxxx",              // 申请好的Web端开发者Key,首次调用 load 时必填 这里的key要和使用功能权限一致才行
        "version": "2.0",       // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
        "plugins": [],
        "Loca": {                // 是否加载 Loca, 缺省不加载
          "version": '2.0.0'  // Loca 版本,缺省 1.3.2
        },
      }).then((AMap) => {
        initMap(AMap)//掉用 antv L7方法
      }).catch(e => {
        console.log(e);
      })
    })

二 、添加antv L7 中要使用的dome

1. 安装L7 依赖
npm install --save @antv/l7
// 安装第三方底图依赖
npm install --save @antv/l7-maps
2. 使用的dome 、以下使用的是浮动功能
function initMap(AMap) {
  // 全局加载高德地图API
  const map = new AMap.Map('container', {
    viewMode: '3D',
    mapStyle: 'amap://styles/darkblue',
    center: [121.435159, 31.256971],
    zoom: 14.89,
    minZoom: 10
  });
  const scene = new Scene({
    id: 'container',
    map: new GaodeMap({
      mapInstance: map
    })
  });
  scene.on('loaded', () => {
    let lineDown,
      lineUp,
      textLayer;

    fetch('https://gw.alipayobjects.com/os/bmw-prod/ecd1aaac-44c0-4232-b66c-c0ced76d5c7d.json')
      .then(res => res.json())
      .then(data => {
        const texts = [];

        data.features.map(option => {
          const { name, center } = option.properties;
          const [lng, lat] = center;
          texts.push({ name, lng, lat });
          return '';
        });

        textLayer = new PointLayer({ zIndex: 2 })
          .source(texts, {
            parser: {
              type: 'json',
              x: 'lng',
              y: 'lat'
            }
          })
          .shape('name', 'text')
          .size(14)
          .color('#0ff')
          .style({
            textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
            spacing: 2, // 字符间距
            padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
            stroke: '#0ff', // 描边颜色
            strokeWidth: 0.2, // 描边宽度
            raisingHeight: 200000 + 150000 + 10000,
            textAllowOverlap: true
          });
        scene.addLayer(textLayer);

        lineDown = new LineLayer()
          .source(data)
          .shape('line')
          .color('#0DCCFF')
          .size(1)
          .style({
            raisingHeight: 200000
          });

        lineUp = new LineLayer({ zIndex: 1 })
          .source(data)
          .shape('line')
          .color('#0DCCFF')
          .size(1)
          .style({
            raisingHeight: 200000 + 150000
          });

        scene.addLayer(lineDown);
        scene.addLayer(lineUp);
        return '';
      });

    fetch('https://gw.alipayobjects.com/os/bmw-prod/d434cac3-124e-4922-8eed-ccde01674cd3.json')
      .then(res => res.json())
      .then(data => {
        const lineLayer = new LineLayer()
          .source(data)
          .shape('wall')
          .size(150000)
          .style({
            heightfixed: true,
            opacity: 0.6,
            sourceColor: '#0DCCFF',
            targetColor: 'rbga(255,255,255, 0)'
          });
        scene.addLayer(lineLayer);

        const provincelayer = new PolygonLayer({})
          .source(data)
          .size(150000)
          .shape('extrude')
          .color('#0DCCFF')
          .active({
            color: 'rgb(100,230,255)'
          })
          .style({
            heightfixed: true,
            pickLight: true,
            raisingHeight: 200000,
            opacity: 0.8
          });

        scene.addLayer(provincelayer);

        provincelayer.on('mousemove', () => {
          provincelayer.style({
            raisingHeight: 200000 + 100000
          });
          lineDown.style({
            raisingHeight: 200000 + 100000
          });
          lineUp.style({
            raisingHeight: 200000 + 150000 + 100000
          });
          textLayer.style({
            raisingHeight: 200000 + 150000 + 10000 + 100000
          });
        });

        provincelayer.on('unmousemove', () => {
          provincelayer.style({
            raisingHeight: 200000
          });
          lineDown.style({
            raisingHeight: 200000
          });
          lineUp.style({
            raisingHeight: 200000 + 150000
          });
          textLayer.style({
            raisingHeight: 200000 + 150000 + 10000
          });
        });
        return '';
      });
    return '';
  });
}
3. 运行后显示

在这里插入图片描述

自定义样式修改

1. 设置整个中国地图浮动起来
  1. 先更改地图json文件 ,https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json
    在这里插入图片描述

  2. 运行后(因为我没有高亮部分数据,所以没有高亮,谁有能提供的话非常感谢!)

在这里插入图片描述

自定义标注点

1. 静态标注点
fetch(
      'https://gw.alipayobjects.com/os/basement_prod/337ddbb7-aa3f-4679-ab60-d64359241955.json'
    )
      .then(res => res.json())
      .then(data => {
        data.features = data.features.filter(item => {
          return item.properties.capacity > 800;
        });

        const pointLayer = new PointLayer({})
          .source(data)
          .shape('circle')
          .size('capacity', [0, 16])
          .color('capacity', [
            '#34B6B7',
            '#4AC5AF',
            '#5FD3A6',
            '#7BE39E',
            '#A1EDB8',
            '#CEF8D6'
          ])
          .active(true)
          .style({
            opacity: 0.5,
            strokeWidth: 0
          });

        scene.addLayer(pointLayer);
      });

在这里插入图片描述

2. 动态标注点(点位置需要自己改)
 //动图
    scene.on("loaded", () => {
      fetch(
        "https://gw.alipayobjects.com/os/basement_prod/9078fd36-ce8d-4ee2-91bc-605db8315fdf.csv"
      )
        .then((res) => res.text())
        .then((data) => {
          const pointLayer = new PointLayer({})
            .source(data, {
              parser: {
                type: "csv",
                x: "Longitude",
                y: "Latitude",
              },
            })
            .shape("circle")
            .active(true)
            .animate(true)
            .size(56)
            .color("#4cfd47");

          scene.addLayer(pointLayer);
        });
    });

在这里插入图片描述

3. 完整代码
<template>
  <div id="container"></div>
</template>
<script>
// 引入高德数据可视化api2.0
import AMapLoader from "@amap/amap-jsapi-loader";
import { Scene, PolygonLayer, LineLayer } from "@antv/l7";
// import {  PointLayer } from '@antv/l7';
import { GaodeMap } from "@antv/l7-maps";

function initMap(map) {
  const scene = new Scene({
    id: "container",
    map: new GaodeMap({
      mapInstance: map,
    }),
  });

  //动图
  scene.on("loaded", () => {
    fetch(
      "https://gw.alipayobjects.com/os/basement_prod/9078fd36-ce8d-4ee2-91bc-605db8315fdf.csv"
    )
      .then((res) => res.text())
      .then((data) => {
        const pointLayer = new PointLayer({})
          .source(data, {
            parser: {
              type: "csv",
              x: "Longitude",
              y: "Latitude",
            },
          })
          .shape("circle")
          .active(true)
          .animate(true)
          .size(56)
          .color("#4cfd47");

        scene.addLayer(pointLayer);
      });
  });
  //静图
  scene.on("loaded", () => {
    let lineDown, lineUp;
    //       fetch(
    //   "https://gw.alipayobjects.com/os/bmw-prod/ecd1aaac-44c0-4232-b66c-c0ced76d5c7d.json"
    //   // "../../../555555.json"
    // )
    //   .then((res) => res.json())
    //   .then((data) => {
    //     const texts = [];

    //     data.features.map((option) => {
    //       const { name, center } = option.properties;
    //       const [lng, lat] = center;
    //       texts.push({ name, lng, lat });
    //       return "";
    //     });

    //     textLayer = new PointLayer({ zIndex: 2 })
    //       .source(texts, {
    //         parser: {
    //           type: "json",
    //           x: "lng",
    //           y: "lat",
    //         },
    //       })
    //       .shape("name", "text")
    //       .size(14)
    //       .color("#0ff")
    //       .style({
    //         textAnchor: "center", // 文本相对锚点的位置 center|left|right|top|bottom|top-left
    //         spacing: 2, // 字符间距
    //         padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
    //         stroke: "#0ff", // 描边颜色
    //         strokeWidth: 0.2, // 描边宽度
    //         raisingHeight: 200000 + 150000 + 10000,
    //         textAllowOverlap: true,
    //       });
    //     scene.addLayer(textLayer);

    //     lineDown = new LineLayer()
    //       .source(data)
    //       .shape("line")
    //       .color("#0DCCFF")
    //       .size(1)
    //       .style({
    //         raisingHeight: 200000,
    //       });

    //     lineUp = new LineLayer({ zIndex: 1 })
    //       .source(data)
    //       .shape("line")
    //       .color("#0DCCFF")
    //       .size(1)
    //       .style({
    //         raisingHeight: 200000 + 150000,
    //       });

    //     scene.addLayer(lineDown);
    //     scene.addLayer(lineUp);
    //     return "";
    //   });

    // 自定义标注点
    fetch(
      "https://gw.alipayobjects.com/os/basement_prod/337ddbb7-aa3f-4679-ab60-d64359241955.json"
    )
      .then((res) => res.json())
      .then((data) => {
        data.features = data.features.filter((item) => {
          return item.properties.capacity > 800;
        });

        const pointLayer = new PointLayer({})
          .source(data)
          .shape("circle")
          .size("capacity", [0, 16])
          .color("capacity", [
            "#34B6B7",
            "#4AC5AF",
            "#5FD3A6",
            "#7BE39E",
            "#A1EDB8",
            "#CEF8D6",
          ])
          .active(true)
          .style({
            opacity: 0.5,
            strokeWidth: 0,
          });

        scene.addLayer(pointLayer);
      });

    //阴影范围-样式设置
    fetch("https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json")
      .then((res) => res.json())
      .then((data) => {
        const lineLayer = new LineLayer()
          .source(data)
          .shape("wall")
          .size(150000)
          .style({
            heightfixed: true,
            opacity: 0.9,
            sourceColor: "#0DCCFF",
            targetColor: "rbga(255,255,255, 0)",
          });
        scene.addLayer(lineLayer);

        const provincelayer = new PolygonLayer({})
          .source(data)
          .size(150000)
          .shape("extrude")
          .color("#0DCCFF")
          .active({
            color: "rgb(100,230,255)",
          })
          .style({
            heightfixed: true,
            pickLight: true,
            raisingHeight: 20000,
            opacity: 0.3,
          });

        scene.addLayer(provincelayer);

        provincelayer.on("mousemove", () => {
          provincelayer.style({
            raisingHeight: 20000 + 10000,
          });
          lineDown.style({
            raisingHeight: 20000 + 10000,
          });
          lineUp.style({
            raisingHeight: 20000 + 15000 + 10000,
          });
        });

        provincelayer.on("unmousemove", () => {
          provincelayer.style({
            raisingHeight: 20000,
          });
          lineDown.style({
            raisingHeight: 20000,
          });
          lineUp.style({
            raisingHeight: 20000 + 15000,
          });
        });
        return "";
      });
    return "";
  });
}

export default {
  name: "map-view",
  mounted() {
    this.$nextTick(() => {
      AMapLoader.load({
        key: "", // 申请好的Web端开发者Key,首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
        plugins: [],
        Loca: {
          // 是否加载 Loca, 缺省不加载
          version: "2.0.0", // Loca 版本,缺省 1.3.2
        },
      })
        .then((AMap) => {
          // 全局加载高德地图API
          const map = new AMap.Map("container", {
            viewMode: "3D",
            // pitch: -45,  // 设置地图倾斜角度为 -45 度
            bearing: 0, // 设置地图的旋转角度为 0 度
            mapStyle: "amap://styles/darkblue",

            center: [121.435159, 31.256971],
            zoom: 5,
            minZoom: 5,
          });
          initMap(map);
        })
        .catch((e) => {
          console.log(e);
        });
    });
  },
  methods: {},
};
</script>
<style scoped>
#container {
  width: 100vw;
  height: 100vh;
  background-color: black;
}
</style>
  • 16
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大白菜1号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值