arcgis测量面积长度

//放大
function zoomBig() {

map.setZoom(map.getZoom()+1);
};


// 缩小
function zoomSmall() {

map.setZoom(map.getZoom()-1);
};


// 全图
function zoomTotal() {
restMapToolBarImg();
$(".d2_li").attr("src", "./images/2d3d_ed.png");
map.setExtent(initialExtent);
};




var toolbar_measure=null;
var measuregeometry;
var geometryService;


function initToolbar() {
toolbar_measure = new esri.toolbars.Draw(map);
    //添加toolbar画图完成后事件监听调用    doMeasure
    dojo.connect(toolbar_measure, "onDrawEnd", doMeasure);
    //实例化GeometryService
    var serviceurl=SysConfigInfo.getLayerURL("geometryservice");
    geometryService = new esri.tasks.GeometryService(serviceurl);
}


var lengthClick=true;
// 测距
function zoomLength() {
//restMapToolBarImg();
areaClick=true;
if(lengthClick){
canelMarker();
$(".rang_li").attr("src", "./images/rang_ed.png");
if(toolbar_measure==null)initToolbar();
map.graphics.clear(); 
toolbar_measure.activate(esri.toolbars.Draw.POLYLINE); 
canMouseSearch=false;
lengthClick=false;
}else{
lengthClick=true;

restMapToolBarImg();
toolbar_measure.deactivate();
}

};
var areaClick=true;
// 测面积
function zoomSquare() {
lengthClick=true;
if(areaClick){
//restMapToolBarImg();
canelMarker();
$(".area_li").attr("src", "./images/area_ed.png");
if(toolbar_measure==null)initToolbar();
map.graphics.clear(); 
toolbar_measure.activate(esri.toolbars.Draw.POLYGON);
canMouseSearch=false;
areaClick=false;
}else{
areaClick=true;

restMapToolBarImg();
toolbar_measure.deactivate();
}

};





//量算  
function doMeasure(geometry) { 
measuregeometry = geometry;   
toolbar_measure.deactivate();  
    var symbol="";
    switch (geometry.type) {  
        case "polyline":  
            symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
                new dojo.Color([0, 0, 0]), 2);  
            break;  
        case "polygon":  
            symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, 
                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, 
                    new dojo.Color([255, 0, 0]), 2), 
                    new dojo.Color([255, 255, 0, 0.25]));  
            break;  
    }  
    //设置样式  
    var graphic = new esri.Graphic(geometry,symbol);  
    //清除上一次的画图内容  
     map.graphics.add(graphic);  
    //进行投影转换,完成后调用projectComplete  
    MeasureGeometry(geometry);  
}  
  
//投影转换完成后调用方法  
function MeasureGeometry(geometry) {  
    //如果为线类型就进行lengths距离测算  
    if (geometry.type == "polyline") {  
        var lengthParams = new esri.tasks.LengthsParameters();  
        lengthParams.polylines = [geometry];  
        lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER;  
        lengthParams.geodesic = true;  
        lengthParams.polylines[0].spatialReference = new esri.SpatialReference({"wkt":"PROJCS[\"CGCS_2000_Albers\",GEOGCS[\"GCS_CGCS_2000\",DATUM[\"D_CGCS_2000\",SPHEROID[\"CGCS_2000\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Albers\"],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",105.0],PARAMETER[\"standard_parallel_1\",25.0],PARAMETER[\"standard_parallel_2\",47.0],PARAMETER[\"latitude_of_origin\",0.0],UNIT[\"Meters\",1.0]]"});  
        geometryService.lengths(lengthParams);  
        dojo.connect(geometryService, "onLengthsComplete", outputDistance);  
    }  
    //如果为面类型需要先进行simplify操作在进行面积测算  
    else if (geometry.type == "polygon") {  
        var areasAndLengthParams = new esri.tasks.AreasAndLengthsParameters();  
        areasAndLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER;  
        areasAndLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_SQUARE_METERS;  
        this.outSR = new esri.SpatialReference({"wkt":"PROJCS[\"CGCS_2000_Albers\",GEOGCS[\"GCS_CGCS_2000\",DATUM[\"D_CGCS_2000\",SPHEROID[\"CGCS_2000\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Albers\"],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",105.0],PARAMETER[\"standard_parallel_1\",25.0],PARAMETER[\"standard_parallel_2\",47.0],PARAMETER[\"latitude_of_origin\",0.0],UNIT[\"Meters\",1.0]]"});  
        geometryService.project([geometry], this.outSR, function (geometry) {  
            geometryService.simplify(geometry, function (simplifiedGeometries) {  
                areasAndLengthParams.polygons = simplifiedGeometries;  
                areasAndLengthParams.polygons[0].spatialReference = new esri.SpatialReference({"wkt":"PROJCS[\"CGCS_2000_Albers\",GEOGCS[\"GCS_CGCS_2000\",DATUM[\"D_CGCS_2000\",SPHEROID[\"CGCS_2000\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Albers\"],PARAMETER[\"false_easting\",0.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",105.0],PARAMETER[\"standard_parallel_1\",25.0],PARAMETER[\"standard_parallel_2\",47.0],PARAMETER[\"latitude_of_origin\",0.0],UNIT[\"Meters\",1.0]]"});  
                geometryService.areasAndLengths(areasAndLengthParams);  
            });  
        });  
        dojo.connect(geometryService, "onAreasAndLengthsComplete", outputAreaAndLength);  
    }  
}  
  
//显示测量距离  
function outputDistance(result) {  
    var CurX = measuregeometry.paths[0][measuregeometry.paths[0].length - 1][0];  
    var CurY = measuregeometry.paths[0][measuregeometry.paths[0].length - 1][1];  
    var  CurPos  =  new  esri.geometry.Point(CurX,  CurY, map.spatialReference);  
    map.infoWindow.setTitle("距离测量");  
    map.infoWindow.setContent(" 测 量 长 度 : <strong>" + parseInt(String(result.lengths[0])) + "米</strong>");  
    map.infoWindow.show(CurPos);  
}  
  
//显示测量面积  
function outputAreaAndLength(result) {
    var CurX = (measuregeometry.getExtent().xmax + measuregeometry.getExtent().xmin) / 2;  
    var CurY = (measuregeometry.getExtent().ymax + measuregeometry.getExtent().ymin) / 2; 
    var CurPos = new esri.geometry.Point(CurX, CurY, map.spatialReference);  
    map.infoWindow.setTitle("面积测量");  
    map.infoWindow.setContent(" 面积:" + parseInt(String(result.areas[0])) + "平方米(" + parsefloat(String(0.0015*result.areas[0])) + "亩) <br>\
        周长:" + parseInt(String(result.lengths[0])) + "米");  
    map.infoWindow.show(CurPos);  
}  




//地图打印
function printMap(){
//restMapToolBarImg();
canelMarker();
if(toolbar_measure!==null){
toolbar_measure.deactivate();
}
areaClick=true;
lengthClick=true;
$(".print_li").attr("src", "./images/print_ed.png");
require(["esri/tasks/PrintTemplate",
"esri/tasks/PrintTask",
"esri/tasks/PrintParameters"], function (PrintTemplate, PrintTask, PrintParameters) {
//创建地图打印对象
debugger
var printUrl = SysConfigInfo.getLayerURL("PrintService");
var printMap = new PrintTask(printUrl);


//创建地图打印模版
var template = new PrintTemplate();
//创建地图的打印参数,参数里面包括:模版和地图
var params = new PrintParameters();
//输出图片的空间参考
printMap.outSpatialReference = map.SpatialReference;
//打印图片的各种参数
template.exportOptions = {
width: 1000,
height: 1000,
dpi: 96
};


var tText = "地图打印";
var aText = "map";
var tempString = "map";
//打印输出的格式
template.format = "PDF";
//输出地图的布局
template.layout = "A4 Landscape";
//        template.showLabels="true";
//设置打印地图排版信息
template.layoutOptions = {
"hasCustomTextElements": true,
"authorText": aText,
"copyrightText": tempString,
"legendLayers": [],
"titleText": tText,
"scalebarUnit": "Kilometers",
"customTextElements": [{ "Text": "123456" },
{ "SubTitle": "Te123456" }
]
};
//设置参数地图
params.map = map;
//设置参数模版
params.template = template;
//运行结果
printMap.execute(params, function (result) {
//网页打开生成的地图
if (result != null) {
// debugger;
url = result.url;
printevent(url);
}
});
});
}




function printevent(url) {
// 打开页面,此处最好使用提示页面
var newWin = window.open("rest/page/index");
var ajax = $.ajax({
});
//    addWaterMarker("中科天启",url);
ajax.done(function () {
// 重定向到目标页面
newWin.location.href = url;
});
}




/**
 * 书签方法
 */
var point;
function bookMark() {


restMapToolBarImg();
if(toolbar_measure!==null){
toolbar_measure.deactivate();
}
areaClick=true;
lengthClick=true;
// 显示书签的提示信息
//bookMarkTips();
if(canMark){
mark = true;
canMark=false;
$(".bookmark_li").attr("src", "./images/bookmark_ed.png");
}else{
mark = false;
canMark=true;
}

}




/**
 * 书签提示信息---文字跟随图标移动
 */
function bookMarkTips() {
// $("#map_div").prepend("#bookmarkTxt");


$("#bookmarkTxt").show();
var container = document.getElementById("map_div");
var p = container.getElementsByTagName("span");


document.onmousemove = function () {
p[0].style.left = event.clientX + 20 + "px";
p[0].style.top = event.clientY + 6 + "px";
for (var i = 1; i < p.length; i++) {
p[i].style.left = p[i - 1].offsetLeft + "px";
p[i].style.top = p[i - 1].offsetTop + "px";
}
}
}


function addMarker(xx, yy, screenpoint) {
if (mark) {
//设置标注的经纬度
var pt = new esri.geometry.Point(xx, yy, map.spatialReference);
var symbol1 = new esri.symbol.PictureMarkerSymbol("images/locat.png", 25, 25);
var graphic = new esri.Graphic(pt, symbol1);
markgraphicLayer.add(graphic);
//$("#bookmarkTxt").hide();
openWindow(screenpoint);
point = pt;
}


}




/**
 * 打开信息窗口
 */
function openWindow(screenpoint) {
var oDiv = document.createElement('div');
oDiv.setAttribute("id", "oDiv");
oDiv.style.left = screenpoint.x + 'px';  // 指定创建的DIV在文档中距离左侧的位置
oDiv.style.top = screenpoint.y + 'px';  // 指定创建的DIV在文档中距离顶部的位置
var index_content = '<label>标记点采集</label>' +
'<span>描述:</span><textarea id="bz" style="margin-left:46px;margin-bottom:9px;"></textarea>' +
'<div class="btnGroup_div" style="float:right;margin-right:10px;"><button class="canelBtn btn btn-sm btn-success" οnclick="canelMarker()" style="margin-right: 6px;">取消</button>' +
'<button class="saveBtn btn btn-sm btn-info" οnclick="saveMarker()">保存</button></div>';


// $(index_content).appendTo("#oDiv");
document.body.appendChild(oDiv);
$("#oDiv").append(index_content);
}


/**
 * 保存兴趣点
 */
function saveMarker() {
var content = $("#bz").val();
var time = getNowFormatDate();

require(["esri/layers/FeatureLayer", "esri/graphic"], function (FeatureLayer, Graphic) {
var attr = { "UserID": userid, "Content": content, "MarkTime": time };
var symbol1 = new esri.symbol.PictureMarkerSymbol("images/locat.png", 25, 25);
// markgraphicLayer.clear();
var graphic = new Graphic(point, symbol1, attr, null);
var markurl = SysConfigInfo.getLayerURL("interestmarkpoint");
markurl = markurl.replace("MapServer", "FeatureServer/0");
var interestLayer = new FeatureLayer(markurl);
interestLayer.applyEdits([graphic], null, null, function () {
alert("添加成功!");
canelMarker();
/* swal({
title: "",
text: "保存成功",
type: "success",
});*/
mark = false;
canMark = true;
dynamicservice_interest.refush();
dynamicservice_interest.visible=true;
/*restMapToolBarImg();
canelMarker();
var layer = map_home.getLayer("101");
layer.refresh();*/
});
});
}


/**
 * 取消兴趣点
 */
function canelMarker() {
restMapToolBarImg();
mark = false;
canMark=true;


var node = document.getElementById('oDiv');//通过id你要删除的div
if (node != null) {
document.body.removeChild(node);
}
// if(hassaved==0){
markgraphicLayer.clear();



// }
}




/**
 * 删除标签
 */
function dropMark() {
require(["esri/layers/FeatureLayer", "esri/graphic", "esri/dijit/editing/Delete"],
function (FeatureLayer, Graphic, Delete) {
$.post("rest/dataoperate/dropMark", { id: thisOBJECTID }, function (result) {
if (result) {
alert("删除成功!");
var layer = dynamicservice_interest;;
layer.refresh();
markgraphicLayer.clear();
map.infoWindow.hide();
} else {
alert("删除失败");
}
});
});
}






/**
 * 获取时间
 * @returns {String}
 */
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2=":";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    var hour=date.getHours();
    var minutes=date.getMinutes();
    var seconds=date.getSeconds();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if(hour<10){
    hour = "0" + hour;
    }
    if(minutes<10){
    minutes = "0" + minutes;
    }
    if(seconds<10){
    seconds = "0" + seconds;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate+" "+hour+seperator2+minutes+seperator2+seconds;
    return currentdate;
}


/**
 * 兴趣点图层符号化
 */
function markMapShowPoint(){
var symbol1 = new esri.symbol.PictureMarkerSymbol("images/locat.png", 25, 25);
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.where="1='1'";
var queryTask = new esri.tasks.QueryTask(SysConfigInfo.getLayerURL("interestmarkpoint")+ "/0");
queryTask.execute(query, function(results) {
var arr=results.features;
if(arr.length>0){
for(var i=0;i<arr.length;i++){
var point = arr[i].geometry;
var graphic = new esri.Graphic(point, symbol1);
markgraphicLayer.add(graphic);
}
}
});
}


/**
 * //恢复所有的地图工具栏图标
 */
function restMapToolBarImg() {
$(".d2_li").attr("src", "./images/2d3d.png");
$(".rang_li").attr("src", "./images/rang.png");
$(".area_li").attr("src", "./images/area.png");
$(".bookmark_li").attr("src", "./images/bookmark.png");
$(".print_li").attr("src", "./images/print.png");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值