地图面积量算

超图软件SuperMap iDesktop 10i 通常用于地图的制作和绘制,而SuperMap iServer 10i 通常用于地图的发布和管理,iServer中还包含关于地图的诸多相关操作介绍说明和代码说明。
IServer 10i的地址 http://support.supermap.com:8090/iserver/

本文主要说地图的面积量算

以代码说明

var map, layer, drawPolygon, polygonLayer, lineLayer, drawLine, host = 				"http://localhost:8090";
/地图服务地址
var layerURL = host+ "/iserver/services/map-ZHDM_Data/rest/maps/斗门行政地图@ZHDM_Data";
var url = host+ "/iserver/services/transportationAnalyst-ZHDM_Data/rest/networkanalyst/BuildNetwork@ShenZhenDaPeng_Data";

function cdwed() {
   
    //面积量算
    //新建面矢量图层
    polygonLayer = new SuperMap.Layer.Vector("polygonLayer");
    //创建画面控制,图层是polygonLayer
    drawPolygon = new SuperMap.Control.DrawFeature(polygonLayer, 		SuperMap.Handler.Polygon);
    //注册featureadded事件,触发drawCompleted()方法
    drawPolygon.events.on({ "featureadded": drawCompleted })

     // 初始化地图控件
    map = new SuperMap.Map("map",{    
            controls: [
                 new SuperMap.Control.Navigation(),
                 new SuperMap.Control.Zoom(),
                 new SuperMap.Control.LayerSwitcher(),
                 new SuperMap.Control.ScaleLine(),
                 drawPolygon,
                 drawLine,
                 drawPoint,
                 select,
            ], units: "m"
        });

    map.addControl(new SuperMap.Control.MousePosition());
    //地图控件 , 定义layer图层TiledDynamicRESTlAYER:分块动态REST图层
    var layer = new SuperMap.Layer.TiledDynamicRESTLayer("斗门行政地图@ZHDM_Data", layerURL,null, { maxResolution: "auto" });
    //为图层初始化完毕添加addLayer()事件
    layer.events.on({ "layerInitialized": addLayer });
    //加载地图
    function addLayer() {
        //向地图添加图层
        map.addLayer(layer, polygonLayer,);
        //设置地图中心点(根据iserver服务中发布的地图中心的来进行适当的调节)
        map.setCenter(new SuperMap.LonLat(113.23, 22.24), 0);
    }
}

/*--面积量算-*/
function mapMeasurementArea() {
    clearFeatures();//移除图层要素
    drawPolygon.activate();
}
//绘完触发事件
function drawCompleted(drawGeometryArgs) {
    //停止画面控制
    drawPolygon.deactivate();
    //获得图层几何对象
    var geometry = drawGeometryArgs.feature.geometry,
        measureParam = new SuperMap.REST.MeasureParameters(geometry),//MeasureParameters:量算参数类。客户端要量算的地物间的距离或者某个区域的面积
        myMeasuerService = new SuperMap.REST.MeasureService(layerURL);;//MeasureService:量算服务类,该类负责将量算参数传递到服务端,并获取服务端返回的量算结果

    //注册processCompleted事件,触发measureCompleted()方法
    myMeasuerService.events.on({ "processCompleted": measureCompleted });

    //对MeasureService类型进行判断和赋值,当判断出是LineString是设置				   MeasureMode.DISTANCE,否则是MeasureMode.AREA
    myMeasuerService.measureMode = SuperMap.REST.MeasureMode.AREA;

    myMeasuerService.processAsync(measureParam);//processAsyn 负责将客户端的量算参数传递到服务端。
}
//测量结束调用事件
function measureCompleted(measureEventArgs) {
    var area = measureEventArgs.result.area,
        unit = measureEventArgs.result.unit;
    $("#liangshujieguo").text(area +"平方米")
    $("#Diastimeter").css("display", "block");
    //alert("量算结果:" + area + "平方米");
}

//移除图层要素
function clearFeatures() {
    polygonLayer.removeAllFeatures();//面
    lineLayer.removeAllFeatures();//线
}

你可能感兴趣的:(gis)