Vue2初始化arcgis并添加天地图

arcgis官网

安装esri-loader

esri-loader官网

npm install --save esri-loader

or

yarn add esri-loader

初始化地图

//mixin.js

import { loadModules } from "esri-loader";
//密钥
import { MapConfig } from '@/./TDTKey';	

export const aboutMap = {
  data() {
    return {
      TDT_IMG_C: 'http://{subDomain}.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + MapConfig.TDTKey,

      TDT_CIA_W: 'http://{subDomain}.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=' + MapConfig.TDTKey,

    }
  },
  methods: {
    // 加载地图
    createView() {
      let options = {
      	url: "https://js.arcgis.com/4.26/",
        css: "https://js.arcgis.com/4.26/esri/themes/light/main.css"       
      };

      loadModules([
        "esri/Map",
        "esri/views/SceneView",
        "esri/layers/WebTileLayer"
      ], options).then(
        ([Map, SceneView, WebTileLayer]) => {
          const map = new Map({
            basemap: "",
          });

          const view = new SceneView({
            container: "SceneView",
            map: map,
            zoom: 11,
            center: [117.122375, 36.661649]
          });

          // 天地图底图
          const tiledLayer = new WebTileLayer({
            urlTemplate: this.TDT_IMG_C,
            subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
          });

          // 天地图注记
          const tiledLayer_z = new WebTileLayer({
            urlTemplate: this.TDT_CIA_W,
            subDomains: ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7'],
          });

          map.add(tiledLayer);
          map.add(tiledLayer_z);

          // 去除自带的组件
	      cViewer.ui.components = [];
	      // cViewer.ui.remove("zoom"); //清除放大缩小按钮
	      // cViewer.ui.remove("attribution"); //清除底部powered by ESRI
	      // cViewer.ui.remove("navigation-toggle"); //清除导航按钮
	      // cViewer.ui.remove("compass"); //清除罗盘仪
        }
      );


    }
  }
}

调用

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

<script>
import { aboutMap } from "@/mixin";
export default {
  mixins: [aboutMap],
  mounted() {
    this.createView()
  }
}
</script>

<style lang="scss" scoped> 
#SceneView{
  width: 100%;
  height: 100%;
}

// 隐藏底部版权信息
::v-deep .esri-ui-manual-container>.esri-component{
  display: none;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在Vue2中使用ArcGIS地图小工具来刷新地图,可以通过以下步骤实现: 1. 在Vue组件中引入ArcGIS API for JavaScript: ``` import { loadModules } from 'esri-loader'; export default { name: 'MapComponent', data() { return { map: null, view: null, layer: null, } }, mounted() { this.initMap(); }, methods: { async initMap() { // Load the ArcGIS API for JavaScript modules const [Map, MapView, FeatureLayer] = await loadModules(['esri/Map', 'esri/views/MapView', 'esri/layers/FeatureLayer']); // Create the map this.map = new Map({ basemap: 'streets-navigation-vector' }); // Create the view this.view = new MapView({ container: this.$refs.mapContainer, map: this.map, center: [-118.244, 34.052], zoom: 12 }); // Create the layer this.layer = new FeatureLayer({ url: 'https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/LA_County_City_Facilities/FeatureServer/0', outFields: ['*'], popupTemplate: { title: '{NAME}', content: [{ type: 'fields', fieldInfos: [{ fieldName: 'CITY_NAME', label: 'City' }, { fieldName: 'ZIP', label: 'ZIP Code' }] }] } }); // Add the layer to the map this.map.add(this.layer); }, refreshMap() { // Refresh the layer this.layer.refresh(); } } } ``` 2. 在Vue模板中添加地图容器和刷新按钮: ``` <template> <div> <div ref="mapContainer" style="height: 500px;"></div> <button @click="refreshMap">Refresh Map</button> </div> </template> ``` 3. 在刷新按钮的点击事件中调用刷新方法: ``` <button @click="refreshMap">Refresh Map</button> ... methods: { refreshMap() { // Refresh the layer this.layer.refresh(); } } ``` 这样就可以在Vue2中使用ArcGIS地图小工具刷新地图了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值