高德地图 LOCA 数据可视化 API 2.0— 中国某年 GDP 展示

高德地图 LOCA 数据可视化 API 2.0— 中国某年 GDP 展示

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>棱柱点—中国城市人口数量及GDP排行</title>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        #map {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }


        .demo-title {
            position: absolute;
            top: 50px;
            left: 50px;
            z-index: 1;
        }

        h1 {
            margin: 0;
            color: #ACB3BB;
        }

        h3 {
            font-weight: normal;
            margin-top: 5px;
            color: #8E939D;
        }
    </style>
</head>

<body>
    <div class="demo-title">
        <h1>多面棱柱—中国城市人口数量及GDP排行</h1>
        <h3>中国城市各人口数量,总GDP数量和人均GDP排行情况</h3>
    </div>
    <div id="map"></div>
    <script>
        window.movingDraw = true;
    </script>
    <script
        src="https://webapi.amap.com/maps?v=2.0&key=您申请的key值&plugin=AMap.Scale,AMap.ToolBar"></script>
    <script type="text/javascript"
        src="https://webapi.amap.com/loca?v=2.0.0&key=您申请的key值"></script>
  
    <script>
      var map = new AMap.Map('map', {
          zoom: 5,
          showLabel: false,
          viewMode: '3D',
          pitch: 55,
          center: [103.594884,36.964587],
          mapStyle: 'amap://styles/9d89a78e93bd0ee7506030fa35b9de47',
      });

      var loca = new Loca.Container({
          map,
      });

      loca.ambLight = {
          intensity: 0.7,
          color: '#7b7bff',
      };
      loca.dirLight = {
          intensity: 0.8,
          color: '#fff',
          target: [0, 0, 0],
          position: [0, -1, 1],
      };
      loca.pointLight = {
          color: 'rgb(240,88,25)',
          position: [112.028276, 31.58538, 2000000],
          intensity: 3,
          // 距离表示从光源到光照强度为 0 的位置,0 就是光不会消失。
          distance: 5000000,
      };

      var pl = new Loca.PrismLayer({
          zIndex: 10,
          opacity: 1,
          visible: false,
          hasSide: true,
      });

      var geo = new Loca.GeoJSONSource({
          url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/gdp.json',
      });
      pl.setSource(geo);
      // top3 的城市增加文字
      var topConf = {
          '上海市': 'https://a.amap.com/Loca/static/loca-v2/demos/images/top-one.png',
          '北京市': 'https://a.amap.com/Loca/static/loca-v2/demos/images/top-two.png',
          '广州市': 'https://a.amap.com/Loca/static/loca-v2/demos/images/top-three.png',
      };
      pl.setStyle({
          unit: 'meter',
          sideNumber: 32,
          topColor: (index, f) => {
              var n = f.properties['GDP'];
              return n > 7000 ? '#E97091' : '#2852F1';
          },
          sideTopColor: (index, f) => {
              var n = f.properties['GDP'];
              return n > 7000 ? '#E97091' : '#2852F1';
          },
          sideBottomColor: '#002bb9',
          radius: 15000,
          height: (index, f) => {
              var props = f.properties;
              var height = Math.max(100, Math.sqrt(props['GDP']) * 9000 - 50000);
              var conf = topConf[props['名称']];
              // top3 的数据,增加文字表达
              if (conf) {
                  map.add(
                      new AMap.Marker({
                          anchor: 'bottom-center',
                          position: [f.coordinates[0], f.coordinates[1], height],
                          content: '<div style="margin-bottom: 10px; float: left; font-size: 14px;height: 57px; width: 180px; color:#fff; background: no-repeat url(' +
                              conf +
                              '); background-size: 100%;"><p style="margin: 7px 0 0 35px; height: 20px; line-height:20px;">' +
                              props['名称'] + '人口 ' + props['人口'] + '</p>' +
                              '<p style="margin: 4px 0 0 35px; height: 20px; line-height:20px; color: #00a9ff; font-size: 13px;">' +
                              props['GDP'] + ' 元' +
                              '</p></div>',
                      }),
                  );
              }
              return height;
              // return 60000 + n * 100;
          },
          // rotation: 360 * 100,
          altitude: 0,
      });
      loca.add(pl);
      map.on('complete', function () {
          setTimeout(function () {
              pl.show(500);
              pl.addAnimate({
                  key: 'height',
                  value: [0, 1],
                  duration: 500,
                  easing: 'Linear',
                  transform: 500,
                  random: true,
                  delay: 5000,
              });
          }, 800);
      });
      loca.animate.start();

      var dat = new Loca.Dat();
      dat.addLayer(pl, 'GDP');

      dat.addLight(loca.ambLight, loca, '环境光');
      dat.addLight(loca.dirLight, loca, '平行光');
      dat.addLight(loca.pointLight, loca, '点光');

      // 点击事件处理
      var clickInfo = new AMap.Marker({
          anchor: 'bottom-center',
          position: [116.396923, 39.918203, 0],
      });
      clickInfo.setMap(map);
      clickInfo.hide();
      // 动画测试
      map.on('click', function (e) {
          var feat = pl.queryFeature(e.pixel.toArray());
          if (feat) {
              clickInfo.show();
              var props = feat.properties;
              var height = Math.max(100, Math.sqrt(props['GDP']) * 9000 - 50000);
              clickInfo.setPosition([feat.coordinates[0], feat.coordinates[1], height]);
              clickInfo.setContent(
                  '<div style="text-align: center; height: 20px; width: 150px; color:#fff; font-size: 14px;">' +
                  feat.properties['名称'] + ': ' + feat.properties['GDP'] +
                  ' 元</div>'
              );
          } else {
              clickInfo.hide();
          }
      });

  
    </script>
</body>

</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x