Vue+ArcGIS API for JS实现地图邮编分区以及定位的区域高亮

前言

最近公司开发国际物流系统,如果使用国内地图,类似百度,腾讯,高德地图,那么国外的地理信息不会那么全,而且获取邮编api只对国内生效,所以考虑使用esri公司的arcgis地图,但是这个地图在国内社区并不完善,踩过很多坑,在网上也找不到相关的解决办法。在此分享给需要做类似需求的小伙伴,希望能帮到大家。

官网:https://www.esri.com/zh-cn/arcgis/products/develop-with-arcgis/overview

使用步骤

创建一个地图有以下步骤:

1、安装esri-loader

npm i esri-loader

2、在文件中引入

import { loadModules } from "esri-loader";

3、创建容器

<div id="arcmap"></div>

注意:需要给容器指定高度,否则无法显示。

4、初始化地图 

_createMapView() {
      const _self = this; //定义一个_self防止后续操作中this丢失
      //定义一个包含有JS API中js包和css样式文件的对象
      const option = {
        url: "https://js.arcgis.com/4.28/",
        css: "https://js.arcgis.com/4.28/esri/themes/light/main.css",
      };

      //通过loadModules来做衔接引入类 以下是一些本文章会使用到的类
      loadModules(
        [
          "esri/Map", // 地图
          "esri/views/MapView", // 地图视图
          "esri/layers/GraphicsLayer", // 图形图层
          "esri/Graphic", // 图形类
          "esri/layers/FeatureLayer", // 用于管理要素图层的数据源
        ],
        option
      )
        .then(([Map, MapView]) => {
          //实例化地图
          this.map = new Map({
            basemap: "streets", // 指定底图
          });
          this.view = new MapView({
            //实例化地图视图
            container: "arcmap",
            map: this.map,
            zoom: 11,// 缩放等级
            center: [this.longitude, this.latitu
  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是一个简单的示例: 1. 在 Vue 项目中安装 arcgis for js 和 axios: ``` npm install --save @arcgis/core axios ``` 2. 在需要使用查询功能的组件中引入模块: ```javascript import * as esriLoader from "@arcgis/core"; // 引入 arcgis for js import axios from "axios"; // 引入 axios ``` 3. 在组件的 `mounted()` 生命周期中初始化地图和查询任务: ```javascript mounted() { // 初始化地图 esriLoader.loadModules(["esri/Map", "esri/views/MapView"]).then(([Map, MapView]) => { const map = new Map({ basemap: "streets-navigation-vector", }); const view = new MapView({ container: "map-container", map: map, center: [-118.80500, 34.02700], zoom: 13, }); }); // 初始化查询任务 esriLoader.loadModules(["esri/tasks/QueryTask", "esri/tasks/support/Query"]).then(([QueryTask, Query]) => { this.queryTask = new QueryTask({ url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3", // 查询图层的 URL }); this.query = new Query(); this.query.returnGeometry = false; // 不返回几何对象 this.query.outFields = ["*"]; // 返回所有字段 }); }, ``` 4. 在查询按钮的点击事件中执行查询: ```javascript methods: { onQuery() { const whereClause = "STATE_NAME = 'California'"; // 查询条件 this.query.where = whereClause; this.queryTask.execute(this.query).then((result) => { const features = result.features; const data = features.map((feature) => { return feature.attributes; }); this.tableData = data; // 将查询结果赋值给表格数据 }); }, }, ``` 5. 在模板中添加查询按钮和表格: ```html <div id="map-container"></div> <button @click="onQuery">查询</button> <table> <thead> <tr> <th v-for="field in fields">{{ field }}</th> </tr> </thead> <tbody> <tr v-for="row in tableData"> <td v-for="field in fields">{{ row[field] }}</td> </tr> </tbody> </table> ``` 6. 在 `data` 中定义表格数据和字段列表: ```javascript data() { return { queryTask: null, query: null, tableData: [], fields: ["STATE_NAME", "POP2000", "POP2007"], }; }, ``` 这样就可以在 Vue 中使用 arcgis for js 的查询功能,并将查询结果以表格形式返回。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值