我是靠谱客的博主 调皮睫毛膏,最近开发中收集的这篇文章主要介绍arcgis for js实现计算面积和周长,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.arcgis for js中实现计算面积和周长需要两个服务地址,一个为地图切片资源地址,一个为计算面积和长度的工具服务地址,都可以在本地发布的arcgis server manager中拿到;

显示js代码

 var map, tb;
        var geometryService;
        require([
            "esri/map", "esri/toolbars/draw",
            "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleFillSymbol",
            "esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol",
            "esri/graphic",
            "esri/Color", "dojo/dom", "dojo/on",
            "esri/layers/ArcGISTiledMapServiceLayer",
            "esri/tasks/GeometryService","esri/SpatialReference","esri/tasks/ProjectParameters","esri/tasks/AreasAndLengthsParameters",
            "dojo/domReady!"
        ], function(
            Map, Draw,
            SimpleMarkerSymbol, SimpleFillSymbol,
            PictureFillSymbol, CartographicLineSymbol,
            Graphic,
            Color, dom, on,
            ArcGISTiledMapServiceLayer,GeometryService,SpatialReference,ProjectParameters,AreasAndLengthsParameters
        ) {
            map = new Map("mapDiv", {
                "xmin":126.08797131337525,"ymin":41.88483304829672,"xmax":130.05572254059723,"ymax":47.20292839632739,
                "spatialReference":{"wkid":4326}
            });
            map.on("load", initToolbar);
            var oilAndGasLayer = new ArcGISTiledMapServiceLayer("http://localhost:6080/arcgis/rest/services/itms/MapServer");
            map.addLayer(oilAndGasLayer);
            geometryService=GeometryService("http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
            geometryService.on("areas-and-lengths-complete", function(evt) {
                var result = evt.result;
                dom.byId("area").innerHTML = result.areas[0].toFixed(3) + " acres";
                dom.byId("length").innerHTML = result.lengths[0].toFixed(3) + " feet";
            });

            function initToolbar() {
                tb = new Draw(map);
                tb.on("draw-complete", addGraphic);
                tb.activate(Draw.FREEHAND_POLYGON);
            }

            function addGraphic(evt) {
                var  geometry = evt.geometry;
                map.graphics.clear();
                map.graphics.add(new Graphic(geometry, new SimpleFillSymbol()));
                var areasAndLengthParams = new AreasAndLengthsParameters();
                areasAndLengthParams.lengthUnit = GeometryService.UNIT_FOOT;
                areasAndLengthParams.areaUnit = GeometryService.UNIT_ACRES;
                areasAndLengthParams.calculationType = "geodesic";
                geometryService.simplify([geometry], function (simplifiedGeometries) {
                    areasAndLengthParams.polygons = simplifiedGeometries;
                    geometryService.areasAndLengths(areasAndLengthParams);
                });
            }
        });

创建DIV为

<body>
<div id="mapDiv" style="height: 95%"></div>
Length: <span id="length"></span><br>
Area: <span id="area"></span>
</body>
引用资源类为(实现资源类需要本地搭建arcgis api服务)

    <link rel="stylesheet" type="text/css" href="http://localhost:8087/arcgis_js_api/library/3.22/3.22/esri/css/esri.css" />
    <script src="http://localhost:8087/arcgis_js_api/library/3.22/3.22/init.js"></script>
    <script src="../js/jquery-1.3.1.js"></script>



最后

以上就是调皮睫毛膏为你收集整理的arcgis for js实现计算面积和周长的全部内容,希望文章能够帮你解决arcgis for js实现计算面积和周长所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部