uniapp+arcgis javascript 4.x api

UNIApp 集成ArcGIS JavaScript

由于arcgis js的库文件都比较大,uniapp使用@arcgis/core的方式没有走通,本文主要通过esriload加载本地部署部署的js库实现集成ArcGIS JavaScript

版本

Vue 2

ArcGIS JavaScript 4.22

注意 ArcGIS JavaScript3.x 和ArcGIS JavaScript 4.x框架差异较大

环境搭建

部署api

从esri deverlopers官网下载api(需要申请账号,有时候还需要翻墙,很麻烦。小编把4.22,4.23.)

为了节省大家时间,小编已经帮各位大人下载,传送门

nginx.conf

server
        {
         listen 8082;
         server_name localhost;
         root /home/arcgisjs/arcgis_js_v422_api/;
         location / {
                #允许跨域请求的域,* 代表所有
                add_header 'Access-Control-Allow-Origin' *;
                #允许带上cookie请求
                add_header 'Access-Control-Allow-Credentials' 'true';
                #允许请求的方法,比如 GET/POST/PUT/DELETE
                add_header 'Access-Control-Allow-Methods' *;
                 #允许请求的header
                add_header 'Access-Control-Allow-Headers' *;
                index install.html;
                }
        }

注意跨域访问就行

新建uni项目

安装包

npm install --save esri-loader

可以直接配置package.json

{
  "dependencies": {
    "esri-loader": "^3.4.0"
  }
}

新建主页并配置

page.json

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "地图展示"
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

index.vue

<template>
	<view class="container">

		<view class="map" id="map" />
		<view class="btn-draw"  @click="myMapViews.drawaPoint">
		</view>
	</view>
</template>


<!-- RenderJS视图层代码 -->
<script module="myMapViews" lang="renderjs" >
	import {
		loadModules
	} from 'esri-loader'
	export default {
		name: 'myMapView',
		data() {
			return {
				map: null,
				mapView: null,
				draw: null,
				drawaction: null,
				pointLayer: null,
			}
		},

		methods: {
			initMap() {
				let self = this;
				const options = {
					url: 'http://192.168.3.156:8082/arcgis_js_api/javascript/4.22/init.js',
					css: 'http://192.168.3.156:8082/arcgis_js_api/javascript/4.22/esri/themes/light/main.css'
				};
				loadModules([
						'esri/Map',
						'esri/views/MapView',
						'esri/layers/MapImageLayer',
						'esri/geometry/SpatialReference',
						"esri/views/draw/Draw",
						"esri/layers/GraphicsLayer",
						'esri/geometry/Extent',
						"esri/config"
					], options)
					.then(([Map, MapView, MapImageLayer, SpatialReference, Draw, GraphicsLayer, Extent, esriConfig]) => {
						esriConfig.fontsUrl = "http://192.168.3.156:8082/fonts/"
						const layer = new MapImageLayer({
							url: 'http://39.98.44.28:6080/arcgis/rest/services/xiangyangjichang/weijie20230309/MapServer'
						});

						self.map = new Map({
							layers: [layer]
						});
						self.mapView = new MapView({
							container: 'map', // Reference to the scene div created in step 5
							map: self.map, // Reference to the map object created before the scene
							spatialReference: new SpatialReference({
								wkid: 3857
							}),
							rotation: 41.2,
							constraints: {
								minScale: 600000000, // 视图最小比例尺
								maxScale: 1130, // 视图最大比例尺
								rotationEnabled: false // 去掉鼠标右键旋转
							}
						});
						self.mapView.extent = self.extent = new Extent({
							xmin: 12103840.013011543,
							ymin: 4086439.3018860994,
							xmax: 12110502.944852674,
							ymax: 4090051.894284931,
							spatialReference: new SpatialReference({
								wkid: 3857
							})
						})
						self.mapView.ui._removeComponents(['zoom']) // 隐藏放大缩小按钮
						// 清楚默认的地图放大缩小的比例
						self.mapView.ui.remove('zoom')
						self.mapView.ui.remove('attribution')
						self.draw = new Draw({
							view: self.mapView
						})
						self.pointLayer = new GraphicsLayer({
							id: 'pointlayer'
						})
						self.map.layers.push(self.pointLayer)

					})
					.catch(err => {
						console.error(err);
					});
			},
		
			drawaPoint() {
				debugger
				let self = this
				const options = {
					url: 'http://192.168.3.156:8082/arcgis_js_api/javascript/4.22/init.js',
					css: 'http://192.168.3.156:8082/arcgis_js_api/javascript/4.22/esri/themes/light/main.css'
				};
				loadModules([
					"esri/Graphic",
					"esri/layers/GraphicsLayer",
					"esri/views/draw/Draw",
					"esri/config"
				],options).then(([Graphic, GraphicsLayer, Draw, esriConfig]) => {
					esriConfig.fontsUrl = "http://192.168.3.156:8082/fonts/"
					if (!self.pointLayer) {
						self.pointLayer = new GraphicsLayer({
							id: 'pointlayer'
						})
						self.map.layers.push(self.pointLayer)
					}
					if (!self.draw) {
						self.draw = new Draw({
							view: self.mapView
						})
					}

					self.drawaction = self.draw.create('point', {
						mode: 'click'
					})
					self.drawaction.on([
						'draw-complete'
					], function(event) {
						if (event.type === 'draw-complete') {
							const point = {
								type: 'point',
								x: event.coordinates[0],
								y: event.coordinates[1],
								spatialReference: self.mapView.spatialReference
							}
							const markerSymbol = {
								type: 'simple-marker',
								color: [255, 0, 0],
								outline: {
									color: [255, 255, 255],
									width: 2
								}
							}

							const inputPoint = new Graphic({
								geometry: point,
								symbol: markerSymbol
							})
							self.pointLayer.add(inputPoint)
							const textPoint = {
								type: 'point',
								x: event.coordinates[0],
								y: event.coordinates[1] + 20,
								spatialReference: self.mapView.spatialReference
							}
							const textSymbol = {
								type: 'text',
								color: 'rgb(235, 41, 75)',
								text: "这是一个点",
								font: {
									//这个属性一定要设置要不然会从sans-serif这个路径下查找文件
									family: 'Arial Unicode MS',
									weight: 'bold',
									size: '12px'
								}
							}
							const textInfo = new Graphic({
								geometry: textPoint,
								symbol: textSymbol
							})
							self.pointLayer.add(textInfo)

						}
					})


				})
			}
		},
		mounted() {
			this.initMap()
		}

	}
</script>

<style>
	.container {
		position: absolute;
		width: 100%;
		height: 100%;
	}

	/deep/.esri-widget--button {
		display: none;
	}

	/deep/.esri-attribution__powered-by {
		display: none;
	}

	/deep/.esri-view .esri-view-surface--inset-outline:focus::after {
		outline: none;
	}

	.map {
		width: 100%;
		height: 100%;
		background-color: rgb(34 50 74);
	}

	.btn-draw {
		position: absolute;
		width: 40px;
		height: 40px;
		right: 20px;
		bottom: 20px;
		background-color: red;
		cursor: pointer;
	}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: ArcGIS JavaScript 4.x 的离线 API 文档是指 ArcGIS JavaScript API 的文档资源,这些资源可以在没有网络连接的情况下访问和使用。离线 API 文档主要用于开发人员在没有网络连接或者需要在限制网络访问的环境中进行开发。 ArcGIS JavaScript 4.x 的离线 API 文档可以通过以下方式获取和使用: 1. 下载离线文档:官方提供了 ArcGIS JavaScript 4.x 的离线文档下载链接,可以将文档下载保存到本地,然后在没有网络连接的情况下通过本地浏览器打开并查看文档。 2. 安装离线文档工具:有一些第三方工具可以将在线 API 文档转换为离线文档形式,开发人员可以选择合适的工具,将 ArcGIS JavaScript 4.x 的在线文档下载到本地,并使用本地浏览器查看。 离线 API 文档提供了 ArcGIS JavaScript 4.x API 所有的类、方法、属性以及示例代码的详细说明和使用方式。开发人员可以通过离线 API 文档来了解和学习如何使用 ArcGIS JavaScript 4.x API 进行地图开发、数据可视化等工作。 在离线开发环境中,使用离线 API 文档可以提高开发效率和便捷性,无需依赖于网络连接和在线文档资源。开发人员可以随时随地访问和查阅文档,避免了对网络的依赖和延迟。 总之,ArcGIS JavaScript 4.x 的离线 API 文档是一种方便开发人员在没有网络连接的情况下学习和使用 ArcGIS JavaScript 4.x API 的工具资源,可以提高开发效率和便捷性。 ### 回答2: ArcGIS JavaScript 4.x的离线API文档是指提供给开发者在没有网络连接的情况下访问API文档的一种资源。由于ArcGIS JavaScript API是基于Web的技术开发的,通常情况下需要通过网络连接来获取最新的API文档。但在某些情况下,开发者可能会面临无法连网的情景,因此需要能够离线访问API文档。 为了解决这个问题,Esri(ArcGIS的开发公司)提供了ArcGIS JavaScript 4.x离线API文档的解决方案。该离线API文档以HTML格式提供,可以在本地计算机上进行访问。开发者可以下载这个离线文档,并在没有网络连接的环境下通过浏览器打开和查看它。 离线API文档包含有关ArcGIS JavaScript 4.x API的所有类、方法、属性和事件的详细说明,开发者可以根据自己的需要浏览和查询。此外,它还提供了示例代码、用法示例和参考资料,帮助开发者更好地理解和使用API。 离线API文档的使用方法很简单。只需将离线文档下载到本地计算机上,然后使用支持HTML的浏览器(如Chrome、Firefox等)打开它。在文档中,开发者可以通过导航栏或搜索框来浏览或搜索特定的类或方法。找到目标内容后,可以点击链接进入详细的说明页面,其中包含如何使用相关API的信息。 总之,ArcGIS JavaScript 4.x的离线API文档为开发者在没有网络连接的情况下提供了非常便捷的查询和浏览API文档的解决方案,使开发工作更加灵活和高效。 ### 回答3: ArcGIS JavaScript 4.x的离线API文档提供了在没有网络连接的情况下使用ArcGIS JavaScript API的指南和参考。这个文档可用于下载并安装在本地计算机上,提供了对API类、属性、方法和事件的说明。它包含了API的核心功能和各种模块的文档,以帮助开发人员在离线环境下使用ArcGIS JavaScript API构建应用程序。 这个离线API文档具有以下特点: 1. 完整的API参考:提供了对ArcGIS JavaScript API所有类、属性、方法和事件的详细描述,并包含了示例代码和参数说明,方便开发人员进行开发和调试。 2. 示例和教程:文档中包含了一些常见的示例和教程,帮助开发人员快速了解如何使用API来实现各种功能,如地图显示、图层操作、空间分析等。 3. 离线使用:这个API文档可以下载并安装在本地计算机上,无需网络连接即可访问,非常适用于无网络环境或者需要频繁离线访问API文档的开发人员。 4. 更新和维护:ArcGIS JavaScript 4.x的离线API文档与在线文档同步更新,确保获取到最新的API文档信息,并及时修复错误和更新内容。 总之,ArcGIS JavaScript 4.x的离线API文档是一个非常有用的资源,可以帮助开发人员在无网络环境下使用ArcGIS JavaScript API进行开发和调试,并提供了对API类、属性、方法和事件的详细说明,以及示例和教程帮助开发人员快速上手。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值