arcgis api for 4.x + vue 開發(fā)筆記

安裝esri-loader

npm install --save esri-loader

加載線上地圖+小部件 并向地圖添加一個(gè)點(diǎn)

<template>
  <div id="SceneView"></div>
</template>

<script>
import { loadModules } from "esri-loader";
export default {
  data() {
    return {
      markpic:require('../assets/images/icon/manyouImg.png')
    };
  },
  methods: {
    //創(chuàng)建視圖
    createView() {
      let options = {
        url: "https://js.arcgis.com/4.15/",
        css: "https://js.arcgis.com/4.15/esri/themes/light/main.css",
      };
      //  "esri/views/SceneView" 3d  2d是MapView
      loadModules(
        [
          "esri/Map",
          "esri/views/SceneView",
          "esri/layers/TileLayer", //地圖圖層可以使用這個(gè)類來添加
          //"esri/layers/FeatureLayer",//自定義的圖層
          "esri/Graphic", //圖像,點(diǎn)線面等
          "esri/widgets/Fullscreen", //全屏小部件
          "esri/widgets/Zoom", //放大縮小部件
          "dojo/domReady!",
        ],
        options
      ).then(([Map, SceneView, TileLayer, Graphic, Fullscreen, Zoom]) => {
        let map = new Map({
          basemap: "streets",
          ground: "world-elevation",
        });

        let mapview = new SceneView({
          container: "SceneView", // Reference to the DOM node that will contain the view
          map: map, // References the map object created in step 3
          zoom: 5,
          center: [120.7346125, 25.0563901],
        });
        //在右上角添加全屏組件
        mapview.ui.add(
          new Fullscreen({
            view: mapview,
          }),
          "top-right"
        );
        // mapview.ui.add(new Zoom({ view: mapview }), "top-right"); //在右上角添加縮放組件
        var point = {
          //創(chuàng)建點(diǎn),并確定點(diǎn)的經(jīng)度和緯度
          type: "point", // autocasts as new Polyline()
          x: 120.3,
          y: 30.68,
        };
        var point2 = {
          type: "point", // autocasts as new Polyline()
          x: 115.3,
          y: 27.68,
        };
        //添加圖片修飾點(diǎn)
        var lineSymbol = {
          type: "picture-marker", // autocasts as new PictureMarkerSymbol()
          url: this.markpic,
          //   width: "64px",
          //   height: "64px"
        };
        var pointGraphic = new Graphic({
          geometry: point2,
          symbol: lineSymbol,
          // attributes: lineAtt,
          // popupTemplate: template,
        });
        //將繪制的點(diǎn)加入地圖圖層
        mapview.graphics.addMany([pointGraphic]);
      });
    },
  },
  mounted() {
    this.createView();
  },
};
</script>

<style scoped>
#SceneView {
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容