vue+arcgis

本文介绍如何在 Vue 项目中集成 ArcGIS API,实现地图展示、比例尺和回首页等功能。具体步骤包括下载 API、安装 esri-loader、配置全局变量、修改 baseURL 并在页面中使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、下载arcgisAPI

二、将api放入项目public文件夹下

类似

 

三、安装esri-loader并引用css

import { loadModules } from 'esri-loader'

import '../public/api/esri/themes/light/main.css'

 

四、设置全局变量

Vue.prototype.$loadModules = loadModules;

Vue.prototype.$option = { url: "./api/init.js" }

五、改变baseURL

dojo.js和init.js

 baseUrl:"https://[HOSTNAME_AND_PATH_TO_JSAPI]dojo"
 //改成
 baseUrl:"./api/dojo/"

六、页面使用

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

<script>
export default {
  name: 'WebMap',
  mounted() {
    let that = this;
    that.$loadModules([
      'esri/Map', 
      'esri/views/MapView',
      "esri/layers/MapImageLayer",
      "esri/widgets/Home",
      "esri/widgets/ScaleBar"
      ],that.$option)
    .then(([Map, MapView,MapImageLayer,Home,ScaleBar]) => {
      
      var ygyx = new MapImageLayer({
        url:
          "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer",
        id:'ygyx'
      });
      // 创建地图
      var map=new Map({
          layers:[ygyx]
      });
      // 地图实例化
      that.view = new MapView({
        container: "mapView",
        map: map,
        center: [120.2494, 30.2867],
        zoom: 11,
      });
      // 比例尺
      var scaleBar = new ScaleBar({
          view: this.view,
          unit: "metric" // The scale bar displays both metric and non-metric units.
        });
      // 比例尺添加到地图左下角
      this.view.ui.add(scaleBar, {
        position: "bottom-left"//左下角
      });
      // home 回到视图中心
      var homeBtn = new Home({
          view: this.view,
          container:"home"
        });
      this.view.ui.add(homeBtn, "top-right");//右上角
    });
  },
  methods: {
  },
};

</script>

<style scoped lang="less">
#mapView{
  position: relative;
  width:100%;
  height:100%;
  .xiao{
    position:absolute;
    right: 20px;
    top: 50px;
  }
  .remove,.add{
    position:absolute;
    right: 70px;
    bottom: 20px;
  }
  .none{
    display: none;
  }
  #widgets{
    position:absolute;
    right: 120px;
    bottom: 20px;
    margin: 0 5px;
    font-size: 11px;
    color: #fff;
  }
}
/deep/ .esri-ui{
  // display: none;
  position: absolute;
}
/deep/ .esri-component.esri-attribution.esri-widget{
  display: none;
}
</style>

七,完结

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值