vue使用maptalks-gl-layer.js加载三维地图

vue使用maptalks-gl-layer.js加载三维地图

  1. 复制下面的内容到vue项目中public/index.html文件里
  <link rel="stylesheet" href="https://maptalks.com/api/maptalks.css" />
  <script type="text/javascript" src="https://maptalks.com/api/maptalks.min.js"></script>
  <script type="text/javascript" src="https://maptalks.com/api/maptalks-gl-layers.js"></script>
  <script type="text/javascript" src="https://maptalks.com/api/dat.gui.min.js"></script>

在这里插入图片描述
在这里插入图片描述
2. 在.vue文件的中写下面的代码:

<template>
	<div id="map" class="container"></div>
</template>
  1. 将官网中script中的内容(也就是下面的代码),复制到.vuemounted函数中
const map = new maptalks.Map("map", {
      center: [-74.00912099912109, 40.71107610933129],
      zoom: 16,
    });

    const vt = new maptalks.VectorTileLayer("vt", {
      urlTemplate: "http://tile.maptalks.com/test/planet-single/{z}/{x}/{y}.mvt",
      spatialReference: "preset-vt-3857",
    });

    const style = {
      style: [{
        filter: [
          "all",
          ["==", "$layer", "building"],
          ["==", "$type", "Polygon"],
        ],
        renderPlugin: {
          dataConfig: {
            type: "3d-extrusion",
            altitudeProperty: "height",
            minHeightProperty: "min_height",
            altitudeScale: 1,
            defaultAltitude: 10,
            topThickness: 0,
            top: true,
            side: true,
          },
          sceneConfig: {
            animation: "swing",
            animationDuration: 800,
          },
          type: "lit",
        },
        symbol: {
          bloom: false,
          ssr: false,
          polygonOpacity: 1,
          material: {
            baseColorTexture: null,
            baseColorFactor: [0.53, 0.73, 0.48, 1],
            hsv: [0, 0, 0],
            baseColorIntensity: 1,
            contrast: 1,
            outputSRGB: 1,
            metallicRoughnessTexture: null,
            roughnessFactor: 1,
            metallicFactor: 1,
            normalTexture: null,
            noiseTexture: null,
            uvScale: [1, 1],
            uvOffset: [0, 0],
            uvRotation: 0,
            uvOffsetAnim: [0, 0],
            normalMapFactor: 1,
            normalMapFlipY: 0,
            bumpTexture: null,
            bumpScale: 0.02,
            clearCoatThickness: 5,
            clearCoatFactor: 0,
            clearCoatIor: 1.4,
            clearCoatRoughnessFactor: 0.04,
            occlusionTexture: null,
            emissiveTexture: null,
            emissiveFactor: [0, 0, 0],
            emitColorFactor: 1,
            emitMultiplicative: 0,
          },
        },
      }, ],
    };
    vt.setStyle(style);

    const sceneConfig = {
      postProcess: {
        enable: true,
        antialias: {
          enable: true
        }
      },
    };

    const groupLayer = new maptalks.GroupGLLayer("group", [vt], {
      sceneConfig,
    });
    groupLayer.addTo(map);

在这里插入图片描述
container随便设置一个想要的大小,比如:

.container{width:1000px;height:800px;margin: 50px;}
  1. 编译运行后的效果:
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值