zoukankan      html  css  js  c++  java
  • Vue.js 项目引入 esri-loader 并加载离线地图

    安装 esri-loader
    >> npm install esri-loader
    1
    Vue 文件中引入 esri-loader
    import { loadCss, setDefaultOptions, loadModules } from "esri-loader";

    setDefaultOptions({url: 'http://localhost/arcgis_js_api/4.15/init.js'})
    loadCss('http://localhost/arcgis_js_api/4.15/esri/themes/light/main.css')
    loadModules([
    "esri/Map",
    "esri/views/MapView",
    "esri/layers/MapImageLayer",
    "esri/tasks/QueryTask",
    "esri/tasks/support/Query"
    ], { css: true }).then(([Map, MapView, MapImageLayer, QueryTask, Query]) => {

    Vue 文件
    ## Map.vue

    <template>
    <el-main style="padding: 0; margin: 0; border: none; outline: none;" :style="{ mapWidth, height: mapHeight}">
    <div id="mapDiv" :style="{ mapWidth, height: mapHeight}"></div>
    <el-input placeholder="请输入搜索内容" v-model="inputData" class="input-with-select">
    <el-select v-model="select" slot="prepend" placeholder="请选择查询属性">
    <el-option label="渠道号" value="1"></el-option>
    <el-option label="渠道名" value="2"></el-option>
    <el-option label="沟道号" value="3"></el-option>
    <el-option label="沟道名" value="4"></el-option>
    </el-select>
    <el-button slot="append" icon="el-icon-search" @click="doQuery"></el-button>
    </el-input>
    </el-main>
    </template>

    <script>
    import { loadCss, setDefaultOptions, loadModules } from "esri-loader";

    export default {
    name: "Map",
    data(){
    return {
    map: null,
    layer: null,
    view: null,
    pointSymbol: null,
    searchUrl: "",
    queryTask: null,
    query: null,
    inputData: '',
    select: '',
    mapWidth: '',
    mapHeight: ''
    }
    },
    mounted() {
    this.mapWidth = (window.screen.width - 44) + 'px'
    this.mapHeight = (window.screen.height - 146) + 'px'

    setDefaultOptions({url: 'http://localhost/arcgis_js_api/4.15/init.js'})
    loadCss('http://localhost/arcgis_js_api/4.15/esri/themes/light/main.css')
    loadModules([
    "esri/Map",
    "esri/views/MapView",
    "esri/layers/MapImageLayer",
    "esri/tasks/QueryTask",
    "esri/tasks/support/Query"
    ], { css: true }).then(([Map, MapView, MapImageLayer, QueryTask, Query]) => {
    this.layer = new MapImageLayer({
    url: "http://localhost:6080/arcgis/rest/services//SampleWorldCities/MapServer"
    });

    this.map = new Map({
    layers: [this.layer]
    });

    this.view = new MapView({
    container: "mapDiv",
    map: this.map,
    ui: {
    components: []
    }
    });

    this.pointSymbol = {
    type: "simple-marker",
    style: "circle",
    color: "red",
    size: 12
    };

    // 要查询的图层
    this.searchUrl = "http://localhost:6080/arcgis/rest/services//SampleWorldCities/MapServer/0";
    this.queryTask = new QueryTask({
    url: this.searchUrl
    });

    // 查询条件
    this.query = new Query({
    outFields: ["*"],
    returnGeometry: true,
    where: `CITY_NAME = '${this.inputData}'`,
    });
    }).catch(err => {
    console.error(err);
    });
    },
    methods: {
    doQuery(){
    // 执行属性查询
    this.queryTask.execute(this.query).then(function(result) {
    this.view.graphics.removeAll();
    if (result.features.length > 0) {
    let features = result.features.map(function(feature) {
    feature.symbol = this.pointSymbol;
    return feature;
    });
    this.view.graphics.addMany(features);
    this.view.goTo(features);
    }
    });
    }
    }
    }
    </script>

    <style scoped>
    #mapDiv {
    border: none;
    outline: none;
    margin: 0;
    padding: 0;
    }

    /deep/.el-input-group__prepend {
    130px;
    background-color: #fff;
    }

    /deep/.input-with-select {
    500px;
    position: fixed;
    top: 80px;
    right: 30px;
    }
    </style>

    运行效果


    ————————————————
    版权声明:本文为CSDN博主「魏晓蕾」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/gongxifacai_believe/article/details/111241190

  • 相关阅读:
    C语言堆栈入门——堆和栈的区别(转)
    3--STM32 USB-三个HID-interface 复合(组合)设备的代码实现-基于固件库(原创)
    Spring 1 控制反转、依赖注入
    Java反射
    java多线程
    (六) 访问控制
    final关键字
    JSP(二):JSP九大内置对象、四个作用域对象
    JSP(一):JSP概要
    Servlet(九):web.xml文件和server.xml文件
  • 原文地址:https://www.cnblogs.com/telwanggs/p/14450941.html
Copyright © 2011-2022 走看看