版本
Vue 2
ArcGIS JavaScript 4.22
注意 ArcGIS JavaScript3.x 和ArcGIS JavaScript 4.x框架差异较大
环境搭建
新建vue
可以使用vue ui创建项目
增加ArcGIS JavaScript 包引用
package.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | "dependencies" : { "core-js" : "^3.8.3" , "vue" : "^2.6.14" , "@arcgis/core" : "4.22.2" , "ncp" : "^2.0.0" }, "devDependencies" : { "@babel/core" : "^7.12.16" , "@babel/eslint-parser" : "^7.12.16" , "@vue/cli-plugin-babel" : "~5.0.0" , "@vue/cli-plugin-eslint" : "~5.0.0" , "@vue/cli-service" : "~5.0.0" , "eslint" : "^6.8.0" , "eslint-plugin-vue" : "^5.2.3" , "vue-template-compiler" : "^2.6.14" }, |
ncp: 主要用于拷贝资源信息
@arcgis/core 是arcgis_js仓库
拷贝资源信息
package.json中配置copy命令
1 2 3 4 5 6 | "scripts" : { "serve" : "vue-cli-service serve" , "build" : "vue-cli-service build" , "lint" : "vue-cli-service lint" , "copy" : "ncp ./node_modules/@arcgis/core/assets ./public/assets" }, |
安装完依赖后运行 copy命令
1 2 3 4 5 6 7 | yarn yarn copy yarn serve ------------------- npm i npm run copy npm run serve |
运行完copy命令后,会将arcgis相关资源拷贝到public/assets目录下
全局引入
main.js
1 2 3 | import '@arcgis/core/assets/esri/themes/light/main.css' import esriConfig from '@arcgis/core/config.js' esriConfig.assetsPath = './assets' |
页面测试
helloworld.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | <template><div class = "hello" > <div id= "map" class = "map" v-show= "flag == 'map'" > </div> <div id= "earth" class = "map" v-show= "flag == 'earth'" ></div> </div> </template><script> import Map from '@arcgis/core/Map' import MapView from '@arcgis/core/views/MapView' import MapImageLayer from '@arcgis/core/layers/MapImageLayer' import ElevationLayer from '@arcgis/core/layers/ElevationLayer' import BaseElevationLayer from '@arcgis/core/layers/BaseElevationLayer' import SpatialReference from '@arcgis/core/geometry/SpatialReference' import SceneView from '@arcgis/core/views/SceneView' import Basemap from '@arcgis/core/Basemap' import TileLayer from '@arcgis/core/layers/TileLayer' export default { name: 'HelloWorld' , data() { return { mapView: null , map: null , map3d: null , flag: 'earth' } }, mounted() { this .initBasemap() }, methods: { initBasemap() { const self = this //二维 const mapImageLayer = new MapImageLayer({ }) this .map = new Map({ // basemap: basemap, layers: [mapImageLayer] }) this .mapView = new MapView({ container: 'map' , map: self.map, spatialReference: new SpatialReference({ wkid: 3857 }), rotation: 41.2, zoom: 3 }) // 三维地形 const ExaggeratedElevationLayer = BaseElevationLayer.createSubclass({ properties: { exaggeration: 10 }, load: function () { // TopoBathy3D contains elevation values for both land and ocean ground this ._elevation = new ElevationLayer({ }); this .addResolvingPromise( this ._elevation.load().then(() => { this .tileInfo = this ._elevation.tileInfo; this .spatialReference = this ._elevation.spatialReference; this .fullExtent = this ._elevation.fullExtent; }) ); return this ; }, // Fetches the tile(s) visible in the view fetchTile: function (level, row, col, options) { // calls fetchTile() on the elevationlayer for the tiles // visible in the view return this ._elevation.fetchTile(level, row, col, options).then( function (data) { const exaggeration = this .exaggeration; for ( let i = 0; i < data.values.length; i++) { // Multiply the given pixel value // by the exaggeration value data.values[i] = data.values[i] * exaggeration; } return data; }.bind( this ) ); } }); const basemap = new Basemap({ baseLayers: [ new TileLayer({ }), new TileLayer({ url: }), ] }); const elevationLayer = new ExaggeratedElevationLayer(); this .map3d = new Map({ basemap: basemap, ground: { layers: [elevationLayer] } }); const view = new SceneView({ container: "earth" , map: this .map3d, alphaCompositingEnabled: true , qualityProfile: "high" , camera: { position: [-55.039, 14.948, 19921223.3], heading: 2.03, tilt: 0.13 }, environment: { background: { type: "color" , color: [255, 252, 244, 0] }, starsEnabled: true , atmosphereEnabled: true , lighting: { type: "virtual" } }, }); this .map3d.ground = { layers: [elevationLayer] }; } } } </script><style scoped= "" > .hello { width: 100%; height: 100%; } .map { width: 100%; height: 100%; } </style> |
https://gitee.com/wolf_pro/vue_arcgis4.22.git
到此这篇关于Vue+ ArcGIS JavaScript APi的文章就介绍到这了,更多相关Vue+ ArcGIS JavaScript APi内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!