首页 / 浏览问题 / 云GIS / 问题详情
client for js量算功能无法实现
2EXP 2017年03月22日
新手求教,代码如下
        // 加载图层
        function addLayer() {
            // 向Map添加图层
            map.addLayers([layer,lineLayer]);
            map.setCenter(new SuperMap.LonLat(0,0),0);
        }
       
        // 绘制线段结束后触发函数,获取绘制的线段,并执行量算
        function drawCompleted(arguments){
            //屏蔽绘制线段控件
            drawLine.deactivate();
            // 获取绘制的线段
            var geometry = arguments.feature.geometry,
            measureParam = new SuperMap.REST.MeasureParameters(geometry);
           
            // 定义量算服务对象,执行量算
            var measureService = new SuperMap.REST.MeasureService(url, {
                                            measureMode: SuperMap.REST.MeasureMode.DISTANCE,
                                            eventListeners:{'processCompleted': measureCompleted,'processFailed':processFailed}
                                            });
            measureService.processAsync(measureParam);
        }

        //距离量算
        function distanceMeasure(){
            //清空上一次绘制的线段
             lineLayer.removeAllFeatures();
            // 激活绘制线段控件
            drawLine.activate();
        }

        // 获取量算结果
        function measureCompleted(measureEventArgs){
            // 获取量算结果和计量单位
            var distance = measureEventArgs.result.distance,
                unit = measureEventArgs.result.unit;
            if (distance != -1) {
                alert(distance +unit);
            }
        }
        //量算失败触发函数
        function processFailed(MeasureEventArgs){
           alert("ok");
        }
        // 绘制线段结束后触发函数,获取绘制的线段,并执行量算
        function drawCompleted(arguments){
            //屏蔽绘制线段控件
            drawPolygon.deactivate();
            // 获取绘制的线段
            var geometry = arguments.feature.geometry,
            measureParam = new SuperMap.REST.MeasureParameters(geometry);
           
            // 定义量算服务对象,执行量算
            var measureService = new SuperMap.REST.MeasureService(url, {
                                            measureMode: SuperMap.REST.MeasureMode.AREA,
                                            eventListeners:{'processCompleted': measureCompleted,'processFailed':processFailed}
                                            });
            measureService.processAsync(measureParam);
        }
        //面积量算
        function areaMeasure(){
            //清空上一次绘制的面
             lineLayer.removeAllFeatures();
            // 激活绘制面控件
            drawPolygon.activate();
        }

        // 获取量算结果
        function measureCompleted(measureEventArgs){
            // 获取量算结果和计量单位
            var area = measureEventArgs.result.area,
                unit = measureEventArgs.result.unit;
            if (area != -1) {
                alert(area +unit);
            }
        }
        //量算失败触发函数
        function processFailed(MeasureEventArgs){
           alert("ok");
        }
结果距离量算测出的是面积值
能具体说明一下怎样修改吗

1个回答

你好,你的绘制面结束后和绘制线结束后的回调函数名称是一样的,而且你绘制线和面后量算的回调函数名称也是一样的,你把名称修改成不一样的。

绘制面的回调函数对应写面积量算的代码,绘制线的回调函数对应写长度量算的代码。
1,603EXP 2017年03月22日
...