尝试使用SceneView设置缩放时出错

问题描述

使用esri-loader时,尝试使用以下命令创建SceneView时,该视图无法正确计算缩放比例,并且在控制台中出现以下错误:

[esri.views.3d.support.cameraUtils] #zoomToScale() Cannot compute scale from zoom without a tiling scheme client-hook-3.js:1 [esri.views.3d.state.ViewStateManager] #zoom= Invalid zoom 3

  let map = new WebMap({
    portalItem: {
      id: MAP_ID_HERE
    }
  });

  let view = new SceneView({
    container: "map",viewingMode: "local",map: map,zoom: 3
  });

有人碰巧知道是什么原因造成的吗?浏览SceneView的文档,看来这在构造函数中应该是有效的。

解决方法

我认为在这种特殊情况下,使用网络地图作为地图,您必须等待视图加载才能设置缩放级别。如果没有,则无法计算比例,这就是错误的原因。

这应该有效,

let view = new SceneView({
  container: "map",map: map,viewingMode: "local"
});

view.when(function() {
  view.zoom = 3;
});

更新:(保留其他代码,因为我认为它可以澄清问题和最终答案

好吧,似乎还不足以等待视图,因为底图无法加载所有内容。所以这里有一个可行的替代方法,

const basemap = Basemap.fromId("dark-gray-vector");
      
const sceneView = new SceneView({
  container: this.$el,map: new WebMap({
    basemap,}),center: [US_CENTER.longtitude,US_CENTER.latitude],viewingMode: "local"
});

basemap.loadAll().then(
  () => {
    sceneView.goTo({ zoom: 3 });
  }
);

在这个新解决方案中,我们实际上要等到底图加载所有内容(使用loadAll方法),然后设置视图的缩放比例。

这是您的Map.vue中的完整代码,

<template>
  <div />
</template>

<script>
import { loadArcGISModules } from "@deck.gl/arcgis";
const US_CENTER = { longtitude: -98.5795,latitude: 39.8283 };
export default {
  name: "Map",props: {},mounted() {
    loadArcGISModules(
      [
        "esri/WebMap","esri/views/SceneView","esri/Basemap",],{ css: true }
    ).then(({ DeckRenderer,modules }) => {
      const [WebMap,SceneView,Basemap] = modules;

      const basemap = Basemap.fromId("dark-gray-vector");
      
      const sceneView = new SceneView({
        container: this.$el,map: new WebMap({
          basemap,viewingMode: "local"
      });

      basemap.loadAll().then(
        () => {
          sceneView.goTo({ zoom: 3 });
        }
      );
    });
  },};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
div {
  width: 100%;
  height: 100%;
}
</style>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...