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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值