vue 引入 esri-loader 并加载地图

记录一下:

npm i esri-loader

引入css

在app.vue中

<style>
@import url('https://js.arcgis.com/4.6/esri/css/main.css');
</style>

新建js文件

在js文件中引入esri-loader

并加载其init.js文件

加载init.js 需要其中的loadScript

部分如下:

import * as esriLoader from 'esri-loader';async loadScript() {await esriLoader.loadScript({url: 'https://js.arcgis.com/4.14/init.js',});
}
async loadInit () {this.loadScript()let that = this;await esriLoader.loadModules(this.gisModules, gisOptions).then(this.loading).then(obj => {that.mapEsri = obj;}).catch(err => {console.error(err.message);});
}

map.js文件放置在文章最后

加载地图vue页面文件:

<div id="mapContainer" class="map-container"> </div>import mapApi from "@/utils/map";mapApi.mapInit("mapContainer", () => {mapApi.createTileLayer('baselayer_arcgis', 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer', { visible: false });mapApi.showBaseMap(["vec_w", "cva_w"], true);
});

map.js文件如下:

import * as esriLoader from 'esri-loader';
import mapConfig from './mapConfig';
class MapApi {constructor() {this.map = null;this.view = null;this.views = [];this.curBaseMap = null;this.popup = {};this.mapEsri = null;// this.geometryService = mapConfig.geometryService;this.measurementWidget = null;this.sketchView = null;this.gisModules = ["esri/Map",// views"esri/views/MapView",// layers"esri/layers/TileLayer","esri/layers/WebTileLayer","esri/layers/MapImageLayer","esri/layers/GraphicsLayer",// graphic"esri/Graphic",// geometry"esri/geometry/Point","esri/geometry/Polyline",// tasks"esri/tasks/GeometryService","esri/tasks/IdentifyTask","esri/tasks/support/IdentifyParameters","esri/tasks/support/LengthsParameters","esri/tasks/support/AreasAndLengthsParameters",// widgets"esri/widgets/Fullscreen","esri/widgets/Fullscreen/FullscreenViewModel","esri/widgets/Sketch","esri/widgets/Sketch/SketchViewModel","esri/widgets/DistanceMeasurement2D","esri/widgets/AreaMeasurement2D",];}async loadScript() {await esriLoader.loadScript({url: 'https://js.arcgis.com/4.14/init.js',});}async loadInit () {this.loadScript()let that = this;const gisOptions = {// url: mapConfig.esriJsUrl,// css: mapConfig.esriCssUrl};await esriLoader.loadModules(this.gisModules, gisOptions).then(this.loading).then(obj => {that.mapEsri = obj;}).catch(err => {console.error(err.message);});}loading (args) {let modules = {};for (let n in args) {let name = mapApi.gisModules[n].split('/').pop();modules[name] = args[n];}return modules;}/*** 初始化地图* @param {string} mapId 地图容器id* @param {function} onLoadComplete 地图加载完毕后回调*/mapInit (mapId, onLoadComplete) {let that = this;console.log('nihao')console.log('setInterval',that.mapEsri)let mapEsriTimer = setInterval(() => {if (that.mapEsri && Object.keys(that.mapEsri).length == this.gisModules.length) {clearInterval(mapEsriTimer);that.map = new that.mapEsri.Map();// 创建二维地图that.view = new that.mapEsri.MapView({container: mapId,map: that.map,center: mapConfig.mapCenter,zoom: mapConfig.mapZoom,padding: {top: 0},});// 地图缩放及旋转约束that.view.constraints = {minZoom: mapConfig.mapMinZoom,maxZoom: mapConfig.mapMaxZoom,rotationEnabled: false // 地图旋转};// 清除地图底部内容(powered by ESRI)that.view.ui.remove('attribution');// 移除默认的zoom部件that.view.ui.remove('zoom');that.views.push(that.view);// 加载完毕回调if (onLoadComplete) onLoadComplete();}}, 10);}// 获取所有图层getLayers () {return this.map.layers.items;}/*** 根据图层id获取图层* @param {string} layerId 图层id* @return {object} 图层*/getLayerById (layerId) {if (!layerId) return;const layer = this.map.findLayerById(layerId);if (layer) {return layer;}}/*** 创建瓦片图层* @param {string} layerId 图层id* @param {string} layerUrl 图层地址* @return {object} option 配置项*/createTileLayer (layerId, layerUrl, option) {if (!option) option = {};let tileLayer = new this.mapEsri.TileLayer({id: layerId,url: layerUrl,title: option.title || "",maxScale: Array.isArray(option.scale) && option.scale.length > 0 ? option.scale[0] : 0,minScale: Array.isArray(option.scale) && option.scale.length > 0 ? option.scale[1] : 0,visible: option.visible == undefined ? true : option.visible,listMode: option.listMode == undefined ? "show" : option.listMode});this.map.add(tileLayer)}/*** 底图展示* @param {(string | array)} layerTypes 底图类型  * @param {boolean} layerSwitch 图层切换,默认为false * google(m:矢量 s:影像 t:地形 h:影像标注)  * tianditu(墨卡托投影[vec_w:矢量底图 cva_w:矢量注记 img_w:影像底图 cia_w:影像注记 ter_w:地形底图 cta_w:地形注记 ibo_w:境界(省级以上) eva_w:矢量英文注记 eia_w:影像英文注记])  * tianditu(经纬度投影[vec_c:矢量底图 cva_c:矢量注记 img_c:影像底图 cia_c:影像注记 ter_c:地形底图 cta_c:地形注记 ibo_c:境界(省级以上) eva_c:矢量英文注记 eia_c:影像英文注记])*/showBaseMap (layerTypes, layerSwitch) {const that = this;const google = ["m", "s", "t", "h"];const tianditu = ["vec_w", "cva_w", "img_w", "cia_w", "ter_w", "cta_w", "ibo_w", "eva_w", "eia_w", "vec_c", "cva_c", "img_c", "cia_c", "ter_c", "cta_c", "ibo_c", "eva_c", "eia_c"];hideLayer();if (typeof layerTypes === "string") {showLayer(layerTypes);} else if (typeof layerTypes === "object" && Array.isArray(layerTypes)) {layerTypes.forEach(item => {showLayer(item);});}// 获取底图idfunction getLayerId (sType) {if (google.indexOf(sType) != -1) {that.curBaseMap = "google";} else if (tianditu.indexOf(sType) != -1) {that.curBaseMap = "tianditu";}let layerId = "basemap_" + that.curBaseMap + "_" + sType;return layerId;}// 隐藏其他底图function hideLayer () {if (layerSwitch) {let layers = that.getLayers();let keepLayers = [];layers.forEach(item => {if (item.id.indexOf("basemap") != -1) {if (typeof layerTypes === "string") {item.id == getLayerId(layerTypes) ? item.visible = true : item.visible = false;} else if (typeof layerTypes === "object" && Array.isArray(layerTypes)) {item.visible = false;layerTypes.forEach(i => {if (item.id == getLayerId(i)) keepLayers.push(item);});}}});keepLayers.forEach(item => {item.visible = true;})}}// 展示底图function showLayer (sType) {const layerId = getLayerId(sType);let baseMap = that.getLayerById(layerId);if (!baseMap) {let gMap;switch (that.curBaseMap) {case "google":if (sType == "t") {gMap = new that.mapEsri.WebTileLayer({"urlTemplate": "http://mt{subDomain}.google.cn/maps/vt?lyrs=" + sType + "@132,r&hl=zh-CN&gl=CN&x={col}&y={row}&z={level}","id": layerId,"listMode": 'hide',"subDomains": ["0", "1", "2"]});} else {gMap = new that.mapEsri.WebTileLayer({"urlTemplate": "http://mt{subDomain}.google.cn/maps/vt?lyrs=" + sType + "&hl=zh-CN&gl=CN&x={col}&y={row}&z={level}","id": layerId,"listMode": 'hide',"subDomains": ["0", "1", "2"]});}break;case "tianditu":gMap = new that.mapEsri.WebTileLayer({"urlTemplate": "http://{subDomain}.tianditu.com/DataServer?T=" + sType + "&x={col}&y={row}&l={level}&tk=a8ceffa313eb053d916f4ae995493f5a","id": layerId,"listMode": 'hide',"subDomains": ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"]});break;}that.map.add(gMap);}}}/*** 创建专题图层【MapImageLayer】* @param {string} layerId 图层id* @param {string} layerUrl 图层地址 * @param {object} option 图层可选参数* @return {object} 专题图层对象*/createImageLayer (layerId, layerUrl, option) {if (!option) option = {};let imageLayer = new this.mapEsri.MapImageLayer({id: layerId,url: layerUrl,title: option.title || "",spatialReference: option.spatialReference || { wkid: 4326 },dpi: 96,opacity: typeof option.opacity == "number" ? option.opacity === 0 ? 0 : option.opacity : 1,maxScale: Array.isArray(option.scale) && option.scale.length > 0 ? option.scale[0] : 0,minScale: Array.isArray(option.scale) && option.scale.length > 0 ? option.scale[1] : 0,visible: option.visible == undefined ? true : option.visible,listMode: option.listMode == undefined ? "show" : option.listMode});if (option.sublayers) imageLayer.sublayers = option.sublayers;return imageLayer;}
}const mapApi = new MapApi();setInterval(() => {mapApi.loadInit();
}, 1);export default mapApi;window['mapApi'] = mapApi;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1544156.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

【第十九章:Sentosa_DSML社区版-机器学习之模型评估】

目录 19.1 评估 19.2 混淆矩阵 19.3 ROC-AUC 19.4 时间序列模型评估 【第十九章&#xff1a;Sentosa_DSML社区版-机器学习之模型评估】 19.1 评估 1.算子介绍 评估算子(EvaluationNode) 用于评估用当前数据训练出来的模型的正确性&#xff0c;显示对模型各个评价指标的具…

从零预训练一个tiny-llama#Datawhale组队学习Task2

完整的教程请参考&#xff1a;datawhalechina/tiny-universe: 《大模型白盒子构建指南》&#xff1a;一个全手搓的Tiny-Universe (github.com) 这是Task2的学习任务 目录 Qwen-blog Tokenizer&#xff08;分词器&#xff09; Embedding&#xff08;嵌入&#xff09; RMS …

个人行政复议在线预约系统开发+ssm论文源码调试讲解

第二章 开发工具及关键技术介绍 2.1 JAVA技术 Java主要采用CORBA技术和安全模型&#xff0c;可以在互联网应用的数据保护。它还提供了对EJB&#xff08;Enterprise JavaBeans&#xff09;的全面支持&#xff0c;java servlet API&#xff0c;JSP&#xff08;java server pages…

武汉正向科技 格雷母线定位系统生产厂家

为了适应机车无人化项目对地址高精度的要求&#xff0c;我们推出了高精度格雷母线&#xff0c;根据地址的检测原理&#xff0c;地址精度取决于格雷母线最小交叉环的精度&#xff0c;传统的格雷母线内胆采用柔性泡沫内胆&#xff08;图片1&#xff09;&#xff0c;格雷母线最小交…

末端无人配送产业链

末端无人配送产业链涵盖部件、系统、整车制造、运营服务、应用场景等五大环节。 四类企业竞逐末端配送&#xff0c;“科技公司物流企业”成最佳CP、平台公司蓄势待发

浏览器指纹修改指南2024 -了解SpeechVoice(四)

引言 随着互联网技术的飞速发展,用户隐私保护的重要性日益凸显。浏览器作为我们访问互联网的主要工具之一,其独特的指纹信息却成为了用户隐私的一大隐患。浏览器指纹技术利用浏览器的各种特性,如用户代理(User Agent)、字体列表、插件等,生成一个独一无二的识别码,使得用户即便…

详细分析SpringMvc中HandlerInterceptor拦截器的基本知识(附Demo)

目录 前言1. 基本知识2. Demo3. 实战解析 前言 对于Java的基本知识推荐阅读&#xff1a; java框架 零基础从入门到精通的学习路线 附开源项目面经等&#xff08;超全&#xff09;【Java项目】实战CRUD的功能整理&#xff08;持续更新&#xff09; 1. 基本知识 HandlerInter…

MFC - 复杂控件_2

前言 各位师傅大家好&#xff0c;我是qmx_07&#xff0c;今天讲解剩下的复杂控件知识点 IP地址栏 绘图准备: 调整windows窗口大小、设置 ip address control设置 Button按钮&#xff0c;修改名称 添加IP栏 变量&#xff1a;m_IP 获取IP栏内容 void CMFCApplication3Dlg::…

C++中的string模拟实现

上一章讲了库中的string函数&#xff0c;这次我们来讲一讲模拟实现 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<assert.h> using namespace std; //域名 namespace zzj {class String {public:typedef char* iterator;typedef const char* cons…

【Java 问题】基础——Java 概述

Java 概述 1. 什么是 Java ?2. Java 语言有哪些特点3. JVM、JDK 和 JRE 有什么区别&#xff1f;4. 说说什么是跨平台性&#xff1f;原理是什么&#xff1f;5. 什么是字节码&#xff1f;采用字节码的好处是什么&#xff1f;6. 为什么说 Java 语言 "编译与解释并存"?…

将 Go 作为脚本语言用及一些好用的包

前言 Go 作为一种可用于创建高性能网络和并发系统的编程语言&#xff0c;它的生态应用变得越来越广泛&#xff0c;同时&#xff0c;这也激发了开发人员使用 Go 作为脚本语言的兴趣。虽然目前 Go 还未准备好作为脚本语言 “开箱即用” 的特性&#xff0c;用来替代 Python 和 Ba…

OpenHarmony(鸿蒙南向开发)——小型系统内核(LiteOS-A)【Perf调测】

往期知识点记录&#xff1a; 鸿蒙&#xff08;HarmonyOS&#xff09;应用层开发&#xff08;北向&#xff09;知识点汇总 鸿蒙&#xff08;OpenHarmony&#xff09;南向开发保姆级知识点汇总~ 持续更新中…… 基本概念 Perf为性能分析工具&#xff0c;依赖PMU&#xff08;Per…

HTML讲解(三)通用部分

目录 1.空格标记 2.特殊文字的标记 3.注释语句 4.对文字字体的设置 5.修改文字形态 6.换行标记 7.居中标记 8.水平线标记 9.设置滚动弹幕 1.空格标记 在HTML中&#xff0c;我们想打印空格并不能直接敲一个空格键&#xff0c;因为如果是敲空格键&#xff0c;那无论你敲…

2万字长文超全详解!深度学习时代阴影检测、去除与生成在图像与视频中的全面综述

论文链接&#xff1a;https://arxiv.org/pdf/2409.02108 Github链接&#xff1a;https://github.com/xw-hu/Unveiling-Deep-Shadows 亮点直击 深度学习时代阴影分析的全面综述。本文对阴影分析进行了深入的综述&#xff0c;涵盖了任务、监督级别和学习范式等各个方面。本文的分…

SpringBoot整合ELK实现日志监控(保姆级教程)

新建SpringBoot项目 pom依赖 <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.…

虚幻引擎的三种输入模式和将控件显示到屏幕上

首先要知道一个概念 , HUD 和 Input 都是由 PlayerController 来控制的 而虚幻的Input控制模式有三种 Set Input Mode Game Only (设置输入模式仅限游戏): 视角会跟着鼠标旋转 , 就是正常游戏的模式 , 这也是游戏默认输入模式 Set Input Mode UI Only (设置输入模式仅限UI): …

231. 2 的幂 简单递归 python除法的类型

已解答 简单 相关标签 相关企业 给你一个整数 n&#xff0c;请你判断该整数是否是 2 的幂次方。如果是&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 如果存在一个整数 x 使得 n 2x &#xff0c;则认为 n 是 2 的幂次方。 示例 1&#xff1a; 输入&…

傅里叶变换(对称美)

傅里叶变换&#xff08;对称美&#xff09; 冲浪时发现的有趣文章&#xff0c;学习自https://zhuanlan.zhihu.com/p/718139299 摘下来的内容&#xff1a; 傅里叶变换之所以“怪美的嘞”&#xff0c;根本在于它有一种内在的对称性&#xff0c;这一点在上面的图并没有表现出来…

保障电气安全的电气火灾监控系统主要组成有哪些?

电气火灾是什么&#xff1f; 电气火灾一般是指由于电气线路、用电设备、器具以及供配电设备出现故障性释放的热能&#xff1a;如高温、电弧、电火花以及非故障性释放的能量&#xff1b;如电热器具的炽热表面&#xff0c;在具备燃烧条件下引燃本体或其他可燃物而造成的火灾&…

移动端列表筛选封装

适合场景&#xff1a;Vue2vant 移动端项目&#xff0c;数据填充添加全部选项及相关逻辑处理&#xff0c;支持多选、单选以及筛选状态返回 效果图 选中交互 使用说明 <filter-box ref"filterBox" :isMultiple"true" //是否多选:params"waitData&q…