arcgis api for js入门开发系列十一 量算工具模块(含源代码)
来源:互联网 发布:unity3d有发展前景么 编辑:程序博客网 时间:2024/04/29 15:32
众所周知,使用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" }); }
核心算法测距:
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
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)
};
};
1
这里测距的算法有基于地理坐标系以及投影坐标系不同,有不同的计算公式来计算的;
测面的核心算法:
//******求三角形面积****
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;
};
测面算法也是类似,基于地理坐标系以及投影坐标系不同,有不同的计算公式来计算的;
完整的量算工具js文件下载点击打开链接
0 0
- arcgis api for js入门开发系列十一 量算工具模块(含源代码)
- arcgis api for js入门开发系列九 自写算法实现地图量算工具(含源代码)
- arcgis api for js入门开发系列二不同地图服务展示(含源代码)
- arcgis api for js入门开发系列三地图工具栏(含源代码)
- arcgis api for js入门开发系列六地图分屏对比(含源代码)
- arcgis api for js入门开发系列七图层控制(含源代码)
- arcgis api for js入门开发系列八聚合效果(含源代码)
- arcgis api for js入门开发系列二不同地图服务展示(含源代码)
- arcgis api for js入门开发系列三地图工具栏(含源代码)
- arcgis api for js入门开发系列四地图查询(含源代码)
- arcgis api for js入门开发系列五地图态势标绘(含源代码)
- arcgis api for js入门开发系列六地图分屏对比(含源代码)
- arcgis api for js入门开发系列七图层控制(含源代码)
- arcgis api for js入门开发系列八聚合效果(含源代码)
- arcgis api for js入门开发系列十 自定义Navigation控件样式风格(含源代码)
- arcgis api for js入门开发系列十一地图统计图
- arcgis api for js入门开发系列十二 GP服务 实现缓冲区及运算分析(含源代码)
- arcgis api for js入门开发系列十三 通过Ajax的调用执行GP服务 (含源代码)
- Apache的错误日志巨大如何关闭?
- JS打开摄像头并截图上传
- 编写高质量 JavaScript -- 知识点小记
- PKI公开密钥基础设施
- 【开源代码合集】行人重识别
- arcgis api for js入门开发系列十一 量算工具模块(含源代码)
- 掌握 PHP 中的正则表达式
- 米洛修炼术:其实你的梦想应该从这里开始
- 如何写面向互联网公司的求职简历
- 算法原理 第二章
- [LeetCode] 56. Merge Intervals 解题报告
- css垂直居中的六中方法
- 体检套餐
- sort_nat