距离和面积的测量时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实现测量距离和面积的更多相关文章

  1. (转)Arcgis for Js之GeometryService实现测量距离和面积

    http://blog.csdn.net/gisshixisheng/article/details/40540601 距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryServ ...

  2. ArcGIS Runtime SDK for WPF之测量距离和面积

    bu不多说,上代码 using System.Windows; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Tasks; using ESRI ...

  3. OpenLayers测量距离和面积

    <!DOCTYPE html> <html> <head> <title>测量距离和面积</title> <meta http-equ ...

  4. Arcgis for Js之GeometryService实现測量距离和面积

    距离和面积的測量时GIS常见的功能.在本节,讲述的是通过GeometryService实现測量面积和距离.先看看实现后的效果: watermark/2/text/aHR0cDovL2Jsb2cuY3N ...

  5. OpenLayers动态测量距离和面积,并可自定义测量的线样式

    全局操作变量 /** * @description 标注弹出框 */ HtmlPopup = null; /** * @description 临时图层类数据源 */ VectorSource = n ...

  6. CAD图在线Web测量工具代码实现(测量距离、面积、角度等)

    CAD如今在各个领域均得到了普遍的应用并大大提高了工程技术人员的工作效率.在桌面端,AutoCAD测量工具已经非常强大:然后在Web端,如何准确.快速的对CAD图在Web进行测量呢? 功能 能Web在 ...

  7. Arcgis for JS之Cluster聚类分析的实现(基于区域范围的)

    原文:Arcgis for JS之Cluster聚类分析的实现(基于区域范围的) 咱们书接上文,在上文,实现了基于距离的空间聚类的算法实现,在本文,将继续介绍空间聚类之基于区域范围的实现方式,好了,闲 ...

  8. Arcgis for JS之Cluster聚类分析的实现

    原文:Arcgis for JS之Cluster聚类分析的实现 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来 的,包含XY坐标信息的,通过graphic和graphicla ...

  9. (转)Arcgis for JS之Cluster聚类分析的实现

    http://blog.csdn.net/gisshixisheng/article/details/40711075 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来的,包含 ...

随机推荐

  1. Linux时间设置与iptables命令

    日期与时间设置 timedatectl:显示目前时区与时间等信息 [root@localhost zhang]# timedatectl Local time: Thu 2018-01-18 10:1 ...

  2. 《网络攻防》 MSF基础应用

    20145224陈颢文 <网络攻防>MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode: exploit:攻击手段,是能使攻击武器(payloa ...

  3. React Native之Fetch简单封装、获取网络状态

    1.Fetch的使用 fetch的使用非常简单,只需传入请求的url fetch('https://facebook.github.io/react-native/movies.json'); 当然是 ...

  4. Mysql 语句单表查询

    一基本查询 -- 创建商品表 CREATE TABLE products( pid INT PRIMARY KEY AUTO_INCREMENT, pname VARCHAR(20), price D ...

  5. LINUX系统运行查看

    1.查看内存使用情况 free -m 2.查看内存,cpu等使用情况排序,使用ps -aux命令 ps -aux --sort=+rss :按内存升序排列 ps -aux --sort=-rss :按 ...

  6. The revocation function was unable to check revocation for the certificate

    https://stackoverflow.com/questions/45556189/git-the-revocation-function-was-unable-to-check-revocat ...

  7. lucene学习-2 - 一个示例

    接下来我会写一个lucene的实例.实际上在搜索引擎上随便搜索下都能找到这样的东西.不过还是写一下吧,这也是我学习的经历. package com.zhyea.doggie; import java. ...

  8. NFS的安装配置使用

    /////////////////////////////NFS///////////////////////////////////////////////////写在前面:NFS在数据传输/信息传 ...

  9. npm install 时总是报phantomjs-prebuilt@2.1.14安装失败

    在npm install时总是报如下错误, 尝试单独安装:npm install phantomjs-prebuilt@2.1.14 还是报错 Please report this full log ...

  10. Tomcat中HTTP与AJP区别

    Tomcat: HTTP与AJP区别 Tomcat服务器通过Connector连接器组件与客户程序建立连接,Connector组件负责接收客户的请求,以及把Tomcat服务器的响应结果发送给客户. 默 ...