arcgis for js——3.2D与3D地图联动显示

1.html文件
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>2D与3D地图联动</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css"/>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://js.arcgis.com/4.14/"></script>
    <script src="index.js"></script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="overviewDiv">
        <div id="extentDiv"></div>
    </div>
  </body>
</html>
2.css文件

      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        z-index: -1;
      }

      #overviewDiv {
        position: absolute;
        top: 12px;
        right: 12px;
        width: 300px;
        height: 200px;
        border: 1px solid black;
        z-index: 1;
        overflow: hidden; 
      }

      #extentDiv {
        background-color: rgba(0, 0, 0, 0.5);
        position: absolute;
        z-index: 2;
      }

3.js文件
require([
    "esri/Map",
    "esri/views/SceneView",
    "esri/views/MapView",
    "esri/Graphic",
    "esri/core/watchUtils"
  ], function(Map, SceneView, MapView, Graphic, watchUtils) {
    // 创建一个地图作为主视图
    var mainMap = new Map({
      basemap: "hybrid",
      ground: "world-elevation"
    });

    // 创建一个地图作为右上角总览视图
    var overviewMap = new Map({
      basemap: "topo"
    });

    // 建立一个三维视图显示3D Map实例
    var mainView = new SceneView({
      container: "viewDiv",  //将三维地图放进对应div中
      map: mainMap,
      camera: {
        position: {
          spatialReference: {
            latestWkid: 3857,
            wkid: 102100
          },
          x: 925151,
          y: 5956309,
          z: 3871
        },
        heading: 203,
        tilt: 72
      }
    });

    //  建立一个二维视图渲染显示2D Map实例
    var mapView = new MapView({
      container: "overviewDiv", //将二维地图放进对应div中
      map: overviewMap,
      constraints: {
        rotationEnabled: false
      }
    });

    //移除默认的组件
    mapView.ui.components = [];

    mapView.when(function() {
      mainView.when(function() {
        setup();
      });
    });

    function setup() {
      //创建一个几何图形
      const extent3Dgraphic = new Graphic({
        geometry: null,
        symbol: {
          type: "simple-fill",
          color: [0, 0, 0, 0.5],
          outline: null
        }
      });
      mapView.graphics.add(extent3Dgraphic); //将矩形图形加到二维地图中
    
      watchUtils.init(mainView, "extent", function(extent) {
        //3D视图稳定不变时,调整总览视图位置
        if (mainView.stationary) {
          mapView.goTo({
            center: mainView.center,
            scale:
              mainView.scale * 2 *
              Math.max(
                mainView.width / mapView.width,
                mainView.height / mapView.height
              )
          });
        }
        extent3Dgraphic.geometry = extent;
      });
    }
  });

欢迎关注我的公众号。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

遥感与地理信息

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

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

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

打赏作者

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

抵扣说明:

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

余额充值