ArcGis for js 4.x实现测量,测距,高程的功能

news/2025/2/26 0:02:24/

文章目录

  • 前言
  • 一、三维测量,测距,高程是什么?
  • 二、使用步骤
    • 1.引入库
    • 2.初始化Draw
    • 3.初始化图层
    • 4.测量距离功能
    • 5.测量面积
    • 5.测量高程
  • 清理地图图层


前言

ArcGIS for JS广泛应用于需要在Web上展示和分析空间数据的各种场景中,包括教育、科研和商业领域。它特别适合GIS分析师、IT开发人员以及任何需要在Web上分享和利用地理信息的人员‌


一、三维测量,测距,高程是什么?

三维测量‌是指对物体进行全方位测量,确定其三维坐标测量数据。其测量原理包括测距、角位移、扫描和定向四个方面。根据三维技术原理研发的仪器主要有拍照式(结构光)三维扫描仪、激光三维扫描仪和三坐标测量机等‌
‌测距‌是三维测量中的一个重要组成部分,它通过测量物体与测量设备之间的距离来确定物体的位置。测距的方法有多种,包括激光测距、超声波测距、红外测距等。激光测距是最常见的一种,通过发射激光并测量其反射时间来计算距离‌。
‌高程‌指的是某点沿铅垂线方向到绝对基面的距离,称为绝对高程,简称高程。高程是地理测量中的一个重要概念,用于表示地面点的高低。高程系统采用不同的基准面表示地面点的高低,常见的系统包括正高、正常高、力高和大地高程等‌
‌高程测量‌主要有水准测量和三角高程测量等方法。水准测量是利用水平视线来测量两点间的高差,由于其精度较高,因此是高程测量中最主要的方法。三角高程测量则是通过测量两点间的水平距离或斜距和竖直角来计算高差,一般精度较低,仅在适当条件下采用‌

二、使用步骤

1.引入库

代码如下(示例):

import { Polyline } from '@arcgis/core/geometry';
import Graphic from '@arcgis/core/Graphic';
import Point from '@arcgis/core/geometry/Point';
import * as geometryEngine from '@arcgis/core/geometry/geometryEngine';
import Draw from '@arcgis/core/views/draw/Draw';
import GraphicsLayer from '@arcgis/core/layers/GraphicsLayer';
import Polygon from '@arcgis/core/geometry/Polygon';
import TextSymbol from '@arcgis/core/symbols/TextSymbol';
import ElevationLayer from '@arcgis/core/layers/ElevationLayer';
import SimpleMarkerSymbol from '@arcgis/core/symbols/SimpleMarkerSymbol';

2.初始化Draw

初始化的时候必须保证三维view初始化结束

 drawBar = new Draw({ view: view3d });

3.初始化图层

必须初始化点线面的图层为的就是好管理地图操作

 const newLineLayer = new GraphicsLayer({id: 'LandQueryDrawLayer',elevationInfo: {mode: 'on-the-ground',},});view3d.map.add(newLineLayer);const newPolygonLayer = new GraphicsLayer({id: 'LandQueryPolygonDrawLayer',elevationInfo: {mode: 'on-the-ground',},});view3d.map.add(newPolygonLayer);const newPointLayer = new GraphicsLayer({id: 'LandQueryPointDrawLayer',elevationInfo: {mode: 'on-the-ground',},});

4.测量距离功能

绘制点成线,利用arcgis的计算模块进行

测量距离const measureDistance = () => {clearMeasureActionAndGraphics();distanceMeasure = true; //激活距离测量let action = drawBar.create('polyline'); //创建画线实例view3d.focus();action.on(['vertex-add', // when a vertex is added  鼠标单击'vertex-remove', // when a vertex is removed 移除'cursor-update', // when the pointer moves 鼠标移动'draw-complete', // when the drawing is completed 鼠标双击],function (evt) {createLine(evt.vertices);},);};const createLine = (vertices) => {view3d.map.findLayerById('LandQueryDrawLayer').removeAll(); //清空上次绘制的线let symbol = {//点样式type: 'simple-marker',color: [47, 79, 79],width: 0.5,size: 4,outline: {color: [0, 0, 0],width: 1,},};//将起点添加到地图let startGraphics = new Graphic({geometry: new Point({type: 'point',x: vertices[0][0], //当底图是投影坐标系时用x,地理坐标系用longitudey: vertices[0][1], //当底图是投影坐标系时用y,地理坐标系用latitudespatialReference: view3d.spatialReference, //和底图相同的坐标系}),symbol: symbol,});view3d.map.findLayerById('LandQueryDrawLayer').add(startGraphics);//将线添加到地图let lineGraphics = new Graphic({geometry: new Polyline({paths: vertices,spatialReference: view.spatialReference,}),symbol: {//线样式type: 'simple-line', // autocasts as new SimpleFillSymbolstyle: 'dash',color: [176, 196, 222],width: 2,},});view3d.map.findLayerById('LandQueryDrawLayer').add(lineGraphics);//测距let linePath = []; //线段坐标集合let pointStart = []; //起点pointStart.push(vertices[0][0]);pointStart.push(vertices[0][1]);linePath.push(pointStart);for (let i = 1; i < vertices.length; i++) {//获得鼠标移动的坐标信息let point = {type: 'point',x: vertices[i][0],y: vertices[i][1],spatialReference: view3d.spatialReference,};//鼠标位置let mouseGraphics = new Graphic({geometry: point,symbol: symbol,});let xy = []; //鼠标当前经纬度xy.push(vertices[i][0]);xy.push(vertices[i][1]);linePath.push(xy);let line = new Polyline({//起点到当前鼠标的线段paths: linePath,spatialReference: view3d.spatialReference,});let length = geometryEngine.geodesicLength(line, 'meters').toFixed(2); //测距let lengthText = lengthFormat(length); //单位转换let textSymbol = {//距离标注type: 'text',color: 'white',haloColor: 'black',haloSize: '2px',text: lengthText,xoffset: '50px',yoffset: '-5px',font: {size: 12,family: 'sans-serif',weight: 'bold',},};let textGraphics = new Graphic({//标注位置为鼠标位置geometry: point,symbol: textSymbol,});//将标注和鼠标位置添加到地图view3d.map.findLayerById('LandQueryDrawLayer').addMany([textGraphics, mouseGraphics]);}};

5.测量面积

 /*** 面积测量,对外暴露*/const measureArea = () => {clearMeasureActionAndGraphics();areaMeasure = true;let action = drawBar.create('polygon'); //创建画线实例view3d.focus();action.on(['vertex-add', // when a vertex is added  鼠标单击'vertex-remove', // when a vertex is removed 移除'cursor-update', // when the pointer moves 鼠标移动'draw-complete', // when the drawing is completed 鼠标双击],function (evt) {// 检查在绘制完成时,vertices 是否构成有效的多边形let vertices = evt.vertices;if (vertices.length < 3) {console.error('至少需要三个点来形成有效的多边形!');return;}// 确保多边形是封闭的:将第一个点添加到末尾if (!isPolygonClosed(vertices)) {vertices.push(vertices[0]); // 添加第一个点到末尾,封闭多边形}createPolygon(vertices); // 调用函数绘制多边形},);};//画面和测量面积const createPolygon = (vertices) => {view3d.map.findLayerById('LandQueryPolygonDrawLayer').removeAll();let symbol = {//点样式type: 'simple-marker',color: [47, 79, 79],width: 0.5,size: 4,outline: {color: [0, 0, 0],width: 1,},};let fillSymbol = {//面样式type: 'simple-fill', // autocasts as new SimpleFillSymbol()color: [3, 255, 240, 0.1],outline: {// autocasts as new SimpleLineSymbol()color: [255, 116, 3],width: 2,},};let polygon = new Polygon({rings: vertices,spatialReference: view3d.spatialReference,});let polygonGraphics = new Graphic({geometry: polygon,symbol: fillSymbol,});view3d.map.findLayerById('LandQueryPolygonDrawLayer').add(polygonGraphics);const area = Math.abs(geometryEngine.geodesicArea(polygon, 'square-meters'),);let areaText = areaFormat(area);let center = polygon.centroid;let pointCenter = {type: 'point',longitude: center.longitude,latitude: center.latitude,};let textSymbol = {//面积标注type: 'text',color: 'white',haloColor: 'black',haloSize: '2px',text: areaText,//xoffset: '50px',//yoffset: '-5px',font: {size: 12,family: 'sans-serif',weight: 'bold',},};let textGraphics = new Graphic({//标注为面中心位置geometry: pointCenter,symbol: textSymbol,});view3d.map.findLayerById('LandQueryPolygonDrawLayer').add(textGraphics);for (let i = 0; i < vertices.length; i++) {let point = {type: 'point',x: vertices[i][0],y: vertices[i][1],spatialReference: view3d.spatialReference,};let pointGraphics = new Graphic({geometry: point,symbol: symbol,});view3d.map.findLayerById('LandQueryPolygonDrawLayer').add(pointGraphics);}};

5.测量高程

添加地图点击事件

 view3d.on('click', (event) => {const point = event.mapPoint;if (heightMeasure) {// 查询高程getElevation(point);}});
//获取高程const getElevation = (point) => {console.log(5555555, point);const pointGeometry = new Point({longitude: point.longitude,latitude: point.latitude,});displayElevationOnMap(pointGeometry, point.z);elevationLayer.queryElevation([pointGeometry]).then(function (result) {const elevation = result[0].z; // 获取返回的第一个样本的高程值console.log('Elevation at clicked point:', elevation);// 在地图上显示高程displayElevationOnMap(pointGeometry, point.z);}).catch(function (error) {console.error('Error fetching elevation:', error);});};// 显示高程信息在地图上const displayElevationOnMap = (point, elevation) => {if (view3d.map.findLayerById('LandQueryPointDrawLayer')) {view3d.map.findLayerById('LandQueryPointDrawLayer').removeAll();}// 创建文本符号const textSymbol = new TextSymbol({text: `高程值: ${elevation.toFixed(2)}米`,color: 'white',haloColor: 'black',haloSize: '2px',font: {size: 12,family: 'sans-serif',weight: 'bold',},});const markerSymbol = new SimpleMarkerSymbol({color: [226, 119, 40], // 设置标记颜色size: '10px', // 设置标记大小outline: {// 设置边框color: [255, 0, 0],width: 2,},});// 创建图形const graphicPoint = new Graphic({geometry: point,symbol: markerSymbol,});const graphicText = new Graphic({geometry: point,symbol: textSymbol,});// 将图形添加到视图中view3d.map.findLayerById('LandQueryPointDrawLayer').add(graphicPoint);view3d.map.findLayerById('LandQueryPointDrawLayer').add(graphicText);};const lengthFormat = (length) => {if (length < 2000) {return length + '米';} else {length = (length / 1000).toFixed(2);return length + '千米';}};const areaFormat = (area) => {if (area < 2000) {area = area.toFixed(2);return area + '平方米';} else {area = (area / 10000).toFixed(2);return area + '平方千米';}};const clearMeasureActionAndGraphics = () => {distanceMeasure = false;areaMeasure = false;heightMeasure = false;drawBar.destroy();};

清理地图图层

整个关于ARCGIS的测量功能就完美实现了

const clearMeasureActionAndGraphicsLine = () => {if (view3d.map.findLayerById('LandQueryDrawLayer')) {view3d.map.findLayerById('LandQueryDrawLayer').removeAll();}clearMeasureActionAndGraphics();};const clearMeasureActionAndGraphicsPolygon = () => {if (view3d.map.findLayerById('LandQueryPolygonDrawLayer')) {view3d.map.findLayerById('LandQueryPolygonDrawLayer').removeAll();}clearMeasureActionAndGraphics();};const clearMeasureActionAndGraphicsPoint = () => {if (view3d.map.findLayerById('LandQueryPointDrawLayer')) {view3d.map.findLayerById('LandQueryPointDrawLayer').removeAll();}clearMeasureActionAndGraphics();};

http://www.ppmy.cn/news/1574921.html

相关文章

Apache部署Vue操作手册

背景 本文介绍了如何在windows下使用apache web来部署前后端分离的应用&#xff08;若依&#xff09;。 1. 下载apache软件 下载地址&#xff1a;Apache VS17 binaries and modules download 下载时间很慢也可以在我这资源直接下载。 2. 将下载好的apache注册成服务 在cmd里以…

千字长文!最通俗易懂的Transformer模型架构详解!(图文并茂)

2017 年 Google 在论文《Attention Is All You Need》中提出 Transformer 模型架构&#xff0c;该架构是基于 Encoder-Decoder &#xff08;编码器-解码器&#xff09;的架构。作为当下最先进的深度学习架构之一&#xff0c;Transformer 被广泛应用于自然语言处理领域&#xff…

Github 2025-02-24 开源项目周报 Top15

根据Github Trendings的统计,本周(2025-02-24统计)共有15个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Python项目9TypeScript项目5Jupyter Notebook项目1C++项目1Rust项目1HTML项目1JavaScript项目1Dify.AI: 开源的LLM应用程序开发平台 创建周期:…

TD时间差分算法

TD算法用来估计value-state 给定data/experiece of algorithm&#xff0c; TD算法&#xff1a; 其中TD error&#xff1a; δ t v ( s t ) − [ r t 1 γ v ( s t 1 ) ] v ( s t ) − v t ‾ \delta_t v(s_t) -[r_{t1} \gamma v(s_{t1})]v(s_t) - \overline{v_{t}} δ…

Android之APP更新(通过接口更新)

文章目录 前言一、效果图二、实现步骤1.AndroidManifest权限申请2.activity实现3.有版本更新弹框UpdateappUtilDialog4.下载弹框DownloadAppUtils5.弹框背景图 总结 前言 对于做Android的朋友来说&#xff0c;APP更新功能再常见不过了&#xff0c;因为平台更新审核时间较长&am…

云夹平台:一站式学习与生活效率工具

在数字化时代&#xff0c;高效管理知识、资源和日常事务成为现代人的核心需求。云夹平台正是这样一款集多功能于一体的智能工具&#xff0c;致力于为用户提供便捷、个性化的服务体验。无论你是学生、职场人士还是终身学习者&#xff0c;云夹都能成为你的得力助手。 1. 书签管理…

elasticsearch在windows上的配置

写在最前面&#xff1a; 上资源 第一步 解压&#xff1a; 第二步 配置两个环境变量 第三步 如果是其他资源需要将标蓝的文件中的内容加一句 xpack.security.enabled: false 不同版本的yaml文件可能配置不同&#xff0c;末尾加这个 xpack.security.enabled: true打开bin目…

什么是DeFi (去中心化金融)

DeFi (去中心化金融) 概述 &#x1f4b0; 1. DeFi 基础概念 1.1 什么是 DeFi&#xff1f; DeFi 是建立在区块链上的金融服务生态系统&#xff0c;它&#xff1a; 无需中心化中介开放且透明无需许可即可参与代码即法律 1.2 DeFi 的优势 开放性&#xff1a;任何人都可以参与…