首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >arcgis草图模块不会装入DOM

arcgis草图模块不会装入DOM
EN

Stack Overflow用户
提问于 2020-04-22 01:54:54
回答 1查看 30关注 0票数 0

我正在尝试在我的vue应用程序中包括arcgis草图模块。由于某种原因,在追加草图模块时,我的浏览器控制台日志输出了第一个参数不是节点类型的错误,那么它无法在浏览器中加载小部件?

我不知道为什么会发生这种情况,但我试图遵循下面的示例代码:https://developers.arcgis.com/javascript/latest/sample-code/sketch-geometries/index.html

代码语言:javascript
复制
<template>
  <div></div>
</template>

<script>
import { loadModules } from "esri-loader";
let E = {}; // placeholder for Esri modules

export default {
  name: "web-map",
  props: {
    coords: {
      type: Object,
      required: true
    },
  },
  data: function() {
    return {
      view: null,
      nodes: []
    };
  },
  mounted() {
    // lazy load the required ArcGIS API for JavaScript modules and CSS
    loadModules([
        "esri/Map", 
        "esri/views/MapView", 
        "esri/geometry/Point", 
        "esri/Graphic",
        "esri/layers/GraphicsLayer",
        "esri/widgets/Sketch"], {
      css: true
    }).then(([ArcGISMap, MapView, Point, GraphicsLayer, Sketch]) => {
      E.ArcGISMap = ArcGISMap;
      E.MapView = MapView;
      E.Point = Point;
      var graphicsLayer = new GraphicsLayer();

      const map = new E.ArcGISMap({
        basemap: "topo-vector"
      });

      this.view = new E.MapView({
        container: this.$el,
        map: map,
        center: [this.coords.latitude, this.coords.longitude],
        zoom: 9
      });

        // create a new sketch widget
        const sketch = new Sketch({
          view:this.view,
          layer: graphicsLayer
        });


       this.view.ui.add(sketch, "top-right");
       map.add(graphicsLayer);


    });

  },
  watch: {
    coords() {
      this.showPos();
    }
  },
  beforeDestroy() {
    if (this.view) {
      this.view.container = null;
    }
  },
  methods: {
    showPos() {
      if (E.Point) {
        const point = new E.Point(this.coords.longitude, this.coords.latitude);
        this.view.goTo({ center: point });
      } else {
        console.log("Map modules are still loading...");
      }
    },

    calcAvg(param){
      console.log('calc average',param)

      switch(param) {
          case 'wind':
            console.log('wind nodes',this.nodes)
            break;
          case 'rain':
            console.log('rain nodes',this.nodes)
            break;
          case 'elevation':
            console.log('elevation nodes',this.nodes)
            break;
          default:
            // code block
        }
    },
  }
};
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-22 19:58:33

您的进口没有对齐。你有:

代码语言:javascript
复制
loadModules([
        "esri/Map", 
        "esri/views/MapView", 
        "esri/geometry/Point", 
        "esri/Graphic",
        "esri/layers/GraphicsLayer",
        "esri/widgets/Sketch"], {
      css: true
    }).then(([ArcGISMap, MapView, Point, GraphicsLayer, Sketch])

这意味着:

esri/Map -> ArcGISMap

esr/views/MapView -> MapView

esri/geometry/Point -> Point

esri/Graphic -> GraphicsLayer

esri/layers/GraphicsLayer -> Sketch

esri/widgets/Sketch ->未分配

您需要确保您的loadModules([])数组与.then([])数组的顺序相同。使用此方法确保组件对齐:

代码语言:javascript
复制
loadModules([
        "esri/Map", 
        "esri/views/MapView", 
        "esri/geometry/Point", 
        "esri/Graphic",
        "esri/layers/GraphicsLayer",
        "esri/widgets/Sketch"], {
      css: true
    }).then(([ArcGISMap, MapView, Point, Graphic, GraphicsLayer, Sketch])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61356027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档