⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 measure.js

📁 arcims加点的测试程序
💻 JS
字号:
// JScript 文件
var MapDIVObject=null;
function MouseUpFrom(){
    var __ToolMode = map.mode;
    __ToolMode = __ToolMode.toUpperCase();
    switch(__ToolMode){
        case "MEASURE":
        	if (MouseInMap()) {
	            if (MeasureCount>=2){
	                var sDistance = calcDistanceLine(MapXYList);
	                MeasureShow(sDistance);
	                //CreateMeasureDiv(mouseX,mouseY,16,16,'down.gif',sDistance);
	            }
	        }
            break;
    }
}

function MouseDownFrom(){
    var __ToolMode = map.mode;
    __ToolMode = __ToolMode.toUpperCase();
    switch(__ToolMode){
        case "MEASURE":
        	if (MouseInMap()) {
	            getMapXY(mouseX,mouseY);
	            MapXYList += mapX+','+mapY+';';
	            MeasureCount++;
	        }
            break;
    }
}

function MeasureInit(){
    MapDIVObject = document.getElementById('Map1');
    if (MapDIVObject!=null){
        MapDIVObject.onmouseup = MouseUpFrom;
        MapDIVObject.onmousedown = MouseDownFrom;
    }
}
function MeasureClear(){
    MeasureCount = 0;
    MeasureDiv.length = 0;
    MapXYList = "";
    MeasureShow("");
    var _obj = document.getElementById('MeasureTipDiv');
    if (_obj!=null){
    	_obj.innerHTML = "";
    }
}


function MeasureShow(varlist){
    var _obj = document.getElementById('measurediv');
    if (_obj!=null){
        _obj.innerHTML = varlist;
    }
    
}

function MouseInMap(){
	var _bool = false;
	var _MapL = hspc;
	var _MapT = vspc;
	var _MapB = parseInt(iHeight) + parseInt(vspc);
	var _MapR = parseInt(iWidth) + parseInt(hspc);
	if ((mouseX>_MapL) || (mouseY>_MapT) || (mouseX<_MapR) ||(mouseY<_MapB)){
		_bool = true;
	}
	return _bool;
}
//======================================================
var MapXYList = "";
var MeasureCount = 0;
/**
 * 返回地图坐标列长度带地图单位
 * @param {string} 标准坐标串
 */
function calcDistanceLine(PointList){
	var arrPointList = new Array();
	var arrMapPointXY = new Array();
	arrPointList = PointList.split(';');
	currentMeasure = 0;
	for (var i=0;i<arrPointList.length-2;i++){
		arrMapPointXY1 = arrPointList[i].split(',');
		arrMapPointXY2 = arrPointList[i+1].split(',');
		currentMeasure +=PointDistance(arrMapPointXY1[0],arrMapPointXY1[1],arrMapPointXY2[0],arrMapPointXY2[1])
	}
currentMeasure += UnitEnToCn(ScaleBarUnits.toLowerCase());
return currentMeasure;
}
/**
 * 计算两点间距离
 * @param {} 第一点经度
 * @param {} 第一点纬度
 * @param {} 第二点经度
 * @param {} 第二点纬度
 */
function PointDistance(mX2,mY2,mX1,mY1) {
	// Note: decimal are not hard coded to allow use with locales using commas instead of points.
	var MapUnits = 'DEGREES';//map.measureUnits;
    var mUnits = MapUnits;
    var mDistance = 0;
    
    var Lon1 = mX2 * Math.PI / 180;
    var Lon2 = mX1 * Math.PI / 180;
    var Lat1 = mY2 * Math.PI / 180;
    var Lat2 = mY1 * Math.PI / 180;
    var LonDist = Lon1-Lon2;
    var LatDist = Lat1-Lat2;

    if (MapUnits=="DEGREES") {
	    var A = Math.pow(Math.sin(LatDist / 2),2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(LonDist /2),2);
	    //var A = Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(LonDist /2),2);
	    var C = 2 * Math.asin(Math.min(1, Math.sqrt(A)));
	    var D = (3963 - 13 * Math.sin((Lat1 + Lat2) / 2)) * C
	    mDistance = D * 5280;
	    mUnits = "FEET";
    } else {
	    var xD = Math.abs(mX1 - mX2);
	    var yD = Math.abs(mY1 - mY2);
	    mDistance = Math.sqrt(Math.pow(xD,2) + Math.pow(yD,2));
    }
    //var theDist = MeasureConvertUnits(mDistance,mUnits,ScaleBarUnits);
    var theDist = MeasureConvertUnits(mDistance,'FEET','KILOMETERS');
    var u = Math.pow(10,numDecimals);
    var _return = parseInt(theDist*u+(5/10))/u;
    return _return
}

function MeasureConvertUnits(theDist1,mUnits,sUnits) {
	// Note: decimal are not hard coded to allow use with locales using commas instead of points.	
	var theDist = parseFloat(theDist1);
	var mDistance = theDist;
	//alert(theDist);
	if (mUnits == "FEET") {
		if (sUnits=="MILES") {
			mDistance = theDist / 5280;
		} else if (sUnits == "METERS") {
			mDistance = theDist * (3048/10000);
		} else if (sUnits == "KILOMETERS") {
			mDistance = theDist * (3048/10000000);
		}
	} else {
		if (sUnits=="MILES") {
			mDistance = theDist * (6213711922/10000000000000);
		} else if (sUnits == "FEET") {
			mDistance = theDist * (3280839895/1000000000);
		} else if (sUnits == "KILOMETERS") {
			mDistance = theDist / 1000;
		}
	}
	var u = Math.pow(10,numDecimals);
	mDistance = parseInt(mDistance * u + (5/10)) / u
	return mDistance;
}

function UnitEnToCn(Units){
    Units = Units.toUpperCase();
    var CnUnits = "";
	    switch (Units) {
		    case "MILES":
			    CnUnits = "英里";
			    break;
		    case "KILOMETERS":
			    CnUnits = "公里";
			    break;
		    case "FEET":
			    CnUnits = "英尺";
			    break;
		    case "METERS":
			    CnUnits = "米";
			    break;
		    default:
			    CnUnits = "DEGREES"
			    break;
	    }
    return CnUnits;
}

var MeasureDiv = new Array();
function CreateMeasureDiv(Px,Py,W,H,imgUrl,memo){
	//Px = parseInt(Px)+ parseInt(hspc);
	//Py = parseInt(Py)+ parseInt(vspc);
	Px -=W/2;
	Py -=H/2;
	var _Obj = document.getElementById('MeasureTipDiv');
	var _Table = new Array;
	var _DivId = MeasureDiv.length;
	var name = 'MeasureTip'+_DivId;
	MeasureDiv[MeasureDiv.length] = name;
	var ij = 0;
	if (_Obj!=null){
		_Table[ij++] = '<div id="' + name + '" style="position:absolute; left:' + Px + 'px; top:' + Py + 'px; width:' + W + 'px; height:' + H + 'px;' + '; z-index:999; visibility:visible;">';
		if (imgUrl!=''){
			_Table[ij++] = '<img src="'+imgUrl+'" alt="'+memo+'">';
		}else{
			_Table[ij++] = memo;
		}
		_Table[ij++] = '</div>';
		_Obj.innerHTML += _Table.join('');
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -