Arcgis for Js之GeometryService实现测量距离和面积
距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryService实现测量面积和距离。先看看实现后的效果:
距离 面积
首先,进行配置:
//identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters. //If this null or not available the project and lengths operation will not work. Otherwise it will do a http post to the proxy. esriConfig.defaults.io.proxyUrl = "/proxy"; esriConfig.defaults.io.alwaysUseProxy = false;
接着,定义GeometryService和绘图工具:
var gsvc = new GeometryService("http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var measureToolbar = new esri.toolbars.Draw(map);
接下来,绘图结束后将所绘制图形添加到地图上面,并返回测量结果,那么增加measureToolbar的draw-end事件:
measureToolbar.on("draw-end",showMeasureResults);
/**
* 显示测量结果
* @param evt
*/
var showPt=null;
function showMeasureResults(evt){
measureToolbar.deactivate();
map.setMapCursor("default");
var geometry = evt.geometry;
switch (geometry.type) {
case "polyline":{
var length = geometry.paths[0].length;
showPt = new Point(geometry.paths[0][length-1],map.spatialReference);
var lengthParams = new LengthsParameters();
lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_KILOMETER;
lengthParams.polylines = [geometry];
gsvc.lengths(lengthParams);
break;
}
case "polygon":{
showPt = new Point(geometry.rings[0][0],map.spatialReference);
var areasAndLengthParams = new AreasAndLengthsParameters();
areasAndLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_KILOMETER;
areasAndLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_SQUARE_KILOMETERS;
gsvc.simplify([geometry], function(simplifiedGeometries) {
areasAndLengthParams.polygons = simplifiedGeometries;
gsvc.areasAndLengths(areasAndLengthParams);
});
break;
}
}
var graphic = new Graphic(geometry, getGeometrySymbol(geometry.type));
map.graphics.add(graphic);
}
根据geometry的类型,增加GeometryService的lengths-complete或者areas-and-lengths-complete事件:
gsvc.on("lengths-complete",outputLength);
function outputLength(evtObj){
var result = evtObj.result;
showmeasureInfo(showPt, result.lengths[0].toFixed(3), "千米");
};
gsvc.on("areas-and-lengths-complete",outputAreaAndLength);
function outputAreaAndLength(evtObj){
var result = evtObj.result;
showmeasureInfo(showPt, result.areas[0].toFixed(3), "平方千米");
};
最后,将返回的结果显示在地图上:
/**
* 显示测量结果
* @param showPnt
* @param data
* @param unit
*/
function measureInfo(showPnt,data,unit){
var measureDiv=$("#measure");
var isShow = false;
var screenPnt=map.toScreen(showPnt);
measureDiv.css("left",screenPnt.x+"px");
measureDiv.css("top",screenPnt.y+"px");
measureDiv.css("position","absolute");
measureDiv.css("height","20px");
measureDiv.css("display","block");
isShow = true;
measureDiv.css("z-index","999");
if(unit==="千米"){
measureDiv.css("width","90px");
}
else{
measureDiv.css("width","130px");
}
$("#result").html(data+unit);
$("#infoclose").click(function(){
map.graphics.clear();
measureDiv.css("display","none");
isShow = false;
});
map.on("pan-start", function(){
measureDiv.css("display","none");
});
map.on("pan-end", function(panend){
if(isShow == true){
screenPnt=map.toScreen(showPnt);
measureDiv.css("left",screenPnt.x+"px");
measureDiv.css("top",screenPnt.y+"px");
measureDiv.css("position","absolute");
measureDiv.css("height","20px");
measureDiv.css("display","block");
}
});
map.on("zoom-start", function(){
measureDiv.css("display","none");
});
map.on("zoom-end", function(){
if(isShow == true){
screenPnt=map.toScreen(showPnt);
measureDiv.css("left",screenPnt.x+"px");
measureDiv.css("top",screenPnt.y+"px");
measureDiv.css("position","absolute");
measureDiv.css("height","20px");
measureDiv.css("display","block");
}
});
};
结果的显示我是通过一个div来显示的,并且做了缩放和地图移动的处理。
Arcgis for Js之GeometryService实现测量距离和面积的更多相关文章
- (转)Arcgis for Js之GeometryService实现测量距离和面积
http://blog.csdn.net/gisshixisheng/article/details/40540601 距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryServ ...
- ArcGIS Runtime SDK for WPF之测量距离和面积
bu不多说,上代码 using System.Windows; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Tasks; using ESRI ...
- OpenLayers测量距离和面积
<!DOCTYPE html> <html> <head> <title>测量距离和面积</title> <meta http-equ ...
- Arcgis for Js之GeometryService实现測量距离和面积
距离和面积的測量时GIS常见的功能.在本节,讲述的是通过GeometryService实现測量面积和距离.先看看实现后的效果: watermark/2/text/aHR0cDovL2Jsb2cuY3N ...
- OpenLayers动态测量距离和面积,并可自定义测量的线样式
全局操作变量 /** * @description 标注弹出框 */ HtmlPopup = null; /** * @description 临时图层类数据源 */ VectorSource = n ...
- CAD图在线Web测量工具代码实现(测量距离、面积、角度等)
CAD如今在各个领域均得到了普遍的应用并大大提高了工程技术人员的工作效率.在桌面端,AutoCAD测量工具已经非常强大:然后在Web端,如何准确.快速的对CAD图在Web进行测量呢? 功能 能Web在 ...
- Arcgis for JS之Cluster聚类分析的实现(基于区域范围的)
原文:Arcgis for JS之Cluster聚类分析的实现(基于区域范围的) 咱们书接上文,在上文,实现了基于距离的空间聚类的算法实现,在本文,将继续介绍空间聚类之基于区域范围的实现方式,好了,闲 ...
- Arcgis for JS之Cluster聚类分析的实现
原文:Arcgis for JS之Cluster聚类分析的实现 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来 的,包含XY坐标信息的,通过graphic和graphicla ...
- (转)Arcgis for JS之Cluster聚类分析的实现
http://blog.csdn.net/gisshixisheng/article/details/40711075 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来的,包含 ...
随机推荐
- yii2查询数据倒序显示
public function selectall(){ return $this->findBySql("SELECT * FROM article order by art_tim ...
- Windows Live Writer 网易博客配置
一.去官网下载 Windows Live Write 组件 二.配置,选中其它服务,然后会到如下界面 主要是这里经常不知道选择什么,容易忘记. 下拉框选中metaweblog API 类型,把这个地址 ...
- undefined symbol: PyUnicodeUCS4_AsUTF8String
python 默认是ucs2编码进行编译,重新编译使用ucs4. python: ./configure --enable-unicode=ucs4 make && ...
- 什么时候需要用super
1.子类构造函数调用父类构造函数用super 2.子类重写(覆盖)父类方法后,若想调用父类中被重写的方法,用super 3.未被重写的方法可以直接调用.
- Linux下Mysql的安装步骤
(1).下载安装包 https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar [roo ...
- python3给socket模块设置代理
最近需要在公司学习socket编程,但是不能直接连接外网,需要设置一个代理才能正常访问.报错示例: import socket def blocking(wd): sock = socket.sock ...
- System.load 和 System.loadLibrary详解
System.load 和 System.loadLibrary详解 1.它们都可以用来装载库文件,不论是JNI库文件还是非JNI库文件.在任何本地方法被调用之前必须先用这个两个方法之一把相应的JNI ...
- Mybatis导入原生配置文件
在Spring-Mybatis中导入Mybatis原生配置文件 在sqlSessionFactory Bean中设置设置configLocation属性 <property name=" ...
- JavaWeb -- Struts2 模型驱动
1. 模型驱动 示例: 注册表单reg.jsp <%@ page language="java" contentType="text/html; charset=u ...
- MySQL安装配置教程
环境:Windows 7 旗舰版 64位MySQL版本:mysql-5.5.14-winx64MySQL下载地址:http://dev.mysql.com/downloads/installer/ 1 ...