日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

arcgis api for js共享干货系列之一自写算法实现地图量算工具

發布時間:2024/4/13 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 arcgis api for js共享干货系列之一自写算法实现地图量算工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

眾所周知,使用arcgis api for js實現地圖的量算工具功能,無非是調用arcgisserver的Geometry服務(http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer)提供的Areas and Lengths以及Lengths,如圖:

但是我這里提供另一種實現的思路,就是自己寫算法來實現距離以及面積的量算,這樣的好處是不依賴arcgisserver幾何服務,有些項目不排除有些奇特的客戶不用Geometry服務的,最終的實現效果圖如下:

具體實現思路:創建一個獨立的js文件,里面有量算工具類DCIMeature,DCIMeature類構造函數傳入地圖對象map

construct: function (map) { this._dciMap = map; this._onClickHandler = dojo.hitch(this, this._onClickHandler); this._onMouseMoveHandler = dojo.hitch(this, this._onMouseMoveHandler); this._onDrawEndHandler = dojo.hitch(this, this._onDrawEndHandler); this._onExtentChangeHandler = dojo.hitch(this, this._onExtentChangeHandler); this._onGraphicClearHandler = dojo.hitch(this, this._onGraphicClearHandler); this._graphicsLayer = new esri.layers.GraphicsLayer({ id: "DciMeatureGLyr" }); }

核心算法測距:

DUtil.getDistanceInEarth = function (point1, point2) { var d = new Number(0); //1度等于0.0174532925199432957692222222222弧度 //var radPerDegree=0.0174532925199432957692222222222; var radPerDegree = Math.PI / 180.0; if (DCI.Measure.map.spatialReference.wkid == "4326") { var latLength1 = Math.abs(this.translateLonLatToDistance({ x: point1.x, y: point2.y }).x - this.translateLonLatToDistance({ x: point2.x, y: point2.y }).x); var latLength2 = Math.abs(this.translateLonLatToDistance({ x: point1.x, y: point1.y }).x - this.translateLonLatToDistance({ x: point2.x, y: point1.y }).x); var lonLength = Math.abs(this.translateLonLatToDistance({ x: point1.x, y: point2.y }).y - this.translateLonLatToDistance({ x: point1.x, y: point1.y }).y); d = Math.sqrt(Math.pow(lonLength, 2) - Math.pow(Math.abs(latLength1 - latLength2) / 2, 2) + Math.pow(Math.abs(latLength1 - latLength2) / 2 + Math.min(latLength1, latLength2), 2)); } else { var len_prj = Math.pow((point2.x - point1.x), 2) + Math.pow((point2.y - point1.y), 2); d = Math.sqrt(len_prj); } d = Math.ceil(d); return d; }; DUtil.translateLonLatToDistance = function (point) { var d = new Number(0); //1度等于0.0174532925199432957692222222222弧度 //var radPerDegree=0.0174532925199432957692222222222; var radPerDegree = Math.PI / 180.0; var equatorialCircumference = Math.PI * 2 * 6378137; return { x: Math.cos(point.y * radPerDegree) * equatorialCircumference * Math.abs(point.x / 360), y: equatorialCircumference * Math.abs(point.y / 360) }; };    這里測距的算法有基于地理坐標系以及投影坐標系不同,有不同的計算公式來計算的;

?測面的核心算法:

//******求三角形面積**** DUtil.getTriangleArea = function (point1, point2, point3) { var area = 0; if (!point1 || !point2 || !point3) { return 0; } if (DCI.Measure.map.spatialReference.wkid == "4326") { point1 = this.translateLonLatToDistance(point1); point2 = this.translateLonLatToDistance(point2); point3 = this.translateLonLatToDistance(point3); } area = ((point1.x * point2.y - point2.x * point1.y) + (point2.x * point3.y - point3.x * point2.y) + (point3.x * point1.y - point1.x * point3.y)) / 2; return area; };

?測面算法也是類似,基于地理坐標系以及投影坐標系不同,有不同的計算公式來計算的;

總結

以上是生活随笔為你收集整理的arcgis api for js共享干货系列之一自写算法实现地图量算工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。