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

📄 smismapcontrolns.js

📁 使用ASP.NET 2.0 (c#) 实现的gis 的地图系统
💻 JS
📖 第 1 页 / 共 4 页
字号:
	drawlayer.jg.setStroke(1);
	if (polygonClosed){
		drawlayer.jg.drawPolygon(Xpoints, Ypoints);
	}
	else{
		drawlayer.jg.drawPolyline(Xpoints, Ypoints);
	}
	drawlayer.jg.paint();
}

function SMISRemovePolygon(map)
{
	var line = document.getElementById("SMISLine");
	if(line) { document.body.removeChild(line);	}
	line = null;
}

//***************************** End Drawing ******************************

function hideBusyFlag(mapControlID)
{
	
	if(mapControlID == null || typeof(mapControlID) == "undefined") { return;}
	var divLoading = document.getElementById(mapControlID+"_divLoading");
	if( divLoading != null && divLoading.style != null){
		divLoading.style.visibility = "hidden";
		divLoading.style.zIndex = "-1";
	}
}

function showBusyFlag(mapControlID)
{
	if(mapControlID == null || typeof(mapControlID) == "undefined") { return;}
	var divLoading = document.getElementById(mapControlID+"_divLoading");
	if( divLoading != null && divLoading.style != null){
		divLoading.style.zIndex = "999";
		divLoading.style.visibility = "visible";
	}
}

function SetMapAbsPosition(mapID)
{
	//alert("SetMapAbsPosition");
	// offset 为内部元素定位所需要的相对偏移量 //
	// origin 为绝对座标 //
	
/*
	var mapControl = document.getElementById(mapID.replace("_MVIMAGE",""));
	var map = document.getElementById(mapID);
	map.origin = SMISGetAbsolutePosition(map);
	map.offset = SMISGetOffsetPosition(mapControl);
	*/
	var mapControl = document.getElementById(mapID.replace("_MVIMAGE",""));
	var map = document.getElementById(mapID);
	map.origin = SMISGetAbsolutePosition(map);
	if(mapControl.style.position.toLowerCase() != "absolute"){
		map.offset = map.origin; 
	}
	else{
		map.offset = new SMISPoint(0, 0);	
	}
}

// for layerControl 
function CheckVisibleAll(layerControlID)
{
	var layerCount = eval(document.getElementById(layerControlID + ":LayerCount").value);
	var layerVisible;
	for(var i=0; i<layerCount; i++){
		layerVisible = document.getElementById(layerControlID + ":V" + i);
		if(layerVisible && !layerVisible.disabled) {
			layerVisible.checked = eval(document.getElementById(layerControlID+"_CheckVisibleAll").checked);
		}
	}
}

function CheckQueryableAll(layerControlID)
{
	var layerCount = eval(document.getElementById(layerControlID + ":LayerCount").value);
	var layerQueryable;
	for(var i=0; i<layerCount; i++){
		layerQueryable = document.getElementById(layerControlID + ":Q" + i);
		if(layerQueryable) { layerQueryable.checked = document.getElementById(layerControlID+"_CheckQueryableAll").checked; }
	}
}

function SMISPrintMap(mapControlClientID, mapControlPage, printControlPage, mapUrl, imageHandlerEnabled)
{
	if( !mapControlClientID || !mapControlPage || !printControlPage ) { return false; }
	if ( !mapUrl ) { mapUrl = document.getElementById(mapControlClientID+"_MVIMAGE").src; }
	var address = document.getElementById(mapControlClientID+"_MapServer_Address").value;
	var port	= document.getElementById(mapControlClientID+"_MapServer_Port").value;
	printUrl = printControlPage + "?Address=" + address + "&Port=" + port + "&MapControlClientID=" + mapControlClientID + "&MapControlPage=" + mapControlPage + "&ImageHandlerEnabled=" + imageHandlerEnabled;
	var printWin = window.open(printUrl, "", "resizable,toolbar,menubar,scrollbars,status" );
}

function SMISAdjustCustomDivPosition(customDivID, alignStyle)
{
	var customDiv = document.getElementById(customDivID);
	var offsetX, offsetY;
	if(typeof(customDiv) != "undefined"){
		switch(alignStyle){
			case "LeftTop":		offsetX = 0;	offsetY = 0;	break;
			case "LeftMiddle":	offsetX = 0;	offsetY = customDiv.offsetHeight / 2;	break;
			case "LeftBottom":	offsetX = 0;	offsetY = customDiv.offsetHeight;		break;
			case "CenterTop":	offsetX = customDiv.offsetWidth / 2;	offsetY = 0;	break;
			case "CenterMiddle":offsetX = customDiv.offsetWidth / 2;	offsetY = customDiv.offsetHeight / 2;	break;
			case "CenterBottom":offsetX = customDiv.offsetWidth / 2;	offsetY = customDiv.offsetHeight;		break;
			case "RightTop":	offsetX = customDiv.offsetWidth;		offsetY = 0;	break;
			case "RightMiddle":	offsetX = customDiv.offsetWidth;		offsetY = customDiv.offsetHeight / 2;	break;
			case "RightBottom":	offsetX = customDiv.offsetWidth;		offsetY = customDiv.offsetHeight;		break;
			default:			offsetX = 0;	offsetY = 0;	break;
		}
		customDiv.style.zIndex = 1000;
		customDiv.style.left = (SMISGetNumFromPixel(customDiv.style.left)-offsetX)+"px";
		customDiv.style.top = (SMISGetNumFromPixel(customDiv.style.top)-offsetY)+"px"; 
	}
}

function SMISRegisterToolControl(toolControlID, mapControlID)
{
	var input = document.getElementById(mapControlID + "_ToolControls");
	if(typeof(input) != "undefined" && input.value.indexOf(toolControlID+",") < 0){	// 防止重复注册 //
		input.value += toolControlID + ",";
	}
}

function SMISSwitchCurrentTool(map, action)
{
	var toolControl;
	var toolControlsID = map.id.replace("_MVIMAGE","") + "_ToolControls";
	var toolControls = document.getElementById(toolControlsID);
	if(typeof(toolControls) != "undefined" && toolControls != null){
		var arrToolControls = toolControls.value.split(",");
		for(var i=0; i<arrToolControls.length; i++){
			if(arrToolControls[i] == ""){continue;}
			
			toolControl = document.getElementById(arrToolControls[i]);
			//alert(toolControl.attributes["activesrc"].value);
			if(typeof(toolControl) == "object" && toolControl.attributes["activesrc"].value != "" && toolControl.attributes["inactivesrc"].value != ""){
				if(toolControl.attributes["actionName"].value == action){
					toolControl.src = toolControl.attributes["activesrc"].value;
				}
				else{
					toolControl.src = toolControl.attributes["inactivesrc"].value;
				}
			}
		}
	}
}

function show_props(obj, objName) {
   var result = "";
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + "\n";
   }
   return result;
} 

function SMISGetAbsolutePosition(element, tagName, pos)
{
	var _i=0, _j=0;
	var __DEBUG	= false;
	if(typeof(pos) == "undefined" || pos == null){
		pos = new SMISPoint(0, 0);
	}
	
	while ( ! (element == null || element.tagName == "BODY" || element.tagName.toLowerCase() == tagName) ){
		_i+=1;
		
		pos.x += eval(element.offsetLeft);
		pos.y += eval(element.offsetTop);	

		var bFlag = typeof(element.style.borderLeftWidth) != "unknown";
		if(bFlag && element.style.borderLeftWidth != null && element.style.borderLeftWidth != ""){
			pos.x += SMISGetNumFromPixel(element.style.borderLeftWidth);
			pos.y += SMISGetNumFromPixel(element.style.borderTopWidth);
			if(__DEBUG) alert( "bFlag true & borderLeftWidth is not null. \n pos.Y = " + pos.y);
		}
				
		if(__DEBUG)	alert("current element id = " + element.id + "\n current element tagName = " + element.tagName);
		if(__DEBUG)	if(element.offsetParent != null) alert(element.offsetParent.tagName + "," + element.offsetLeft);

		element = element.offsetParent;
	}
	return pos;
}

//The point object
function SMISPoint(x,y)
{
	this.x = parseInt(x);
	this.y = parseInt(y);
}

//Get Current Mouse Absolute Position
function SMISGetMouseAbsolutePosition(event)
{
    var e=event;
    var posX=0; var posY=0;
    if(e.pageX){
        posX=e.pageX;
        posY=e.pageY;
    }
    else if(e.clientX){
        if(document.documentElement){
            posX=e.clientX+document.documentElement.scrollLeft;
            posY=e.clientY+document.documentElement.scrollTop;
        }
        else if(document.body){
            posX=e.clientX+document.body.scrollLeft;
            posY=e.clientY+document.body.scrollTop;
        }
    }
    return new SMISPoint(posX,posY);
}

//Get Current Mouse Map Relative Position 
function SMISGetMouseMapRelativePosition(event,map)
{
    var x = 0, y = 0;
    
    if(event.offsetX != null && map.id == event.srcElement.id){ //IE6
        x = event.offsetX;
        y = event.offsetY;
    }
//    else if(event.layerX != null && map.id == event.target.id){ //Firefox
//        x = event.layerX;
//        y = event.layerY;
//    }
    else{   //Others
        var mouseAbsPosition=SMISGetMouseAbsolutePosition(event);
        if(map.origin){
	        x = mouseAbsPosition.x - map.origin.x;
	        y = mouseAbsPosition.y - map.origin.y;
	    }
	    else{
	        var absPosition = SMISGetAbsolutePosition(map);
            x = mouseAbsPosition.x - absPosition.x;
            y = mouseAbsPosition.y - absPosition.y;
            absPosition = null;
        }
        mouseAbsPosition = null;
    }

	return new SMISPoint(x,y);
}

function SMISGetNumFromPixel(str)
{
	if(typeof(str) == "undefined" || str == null || str == "") return 0;

	var strResult = str.toString();
	try{
		// 1 pt = 4/3 px; 1 in = 72 pt = 96 px; 
		if(strResult.indexOf("pt") > 0){
			strResult = strResult.replace("pt", "");
			strResult = eval(strResult) * 4.0 / 3.0;
		}
		else if(strResult.indexOf("in") > 0){
			strResult = strResult.replace("in", "");
			strResult = eval(strResult) * 96;
		}
		else{
			strResult = strResult.replace("px", "");
			strResult = eval(strResult);
		}
	}catch(e){alert("error:" + e + ";strResult=" + strResult);}

	return strResult;
}

function SMISGetInnerMap(object)
{
	var _map = null;
	if (object.map) {
		_map = object.map;
	} else {
		_map = object;
	}
	return _map;
}

//Create input hidden field, if exists, then update its value.
function SMISCreateHiddenField(theform, elemID, elemName, elemValue)
{
	var ua = navigator.userAgent.toLowerCase();
	var isIE = ( ua.indexOf("msie") != -1 );
	var elem = document.getElementById(elemID);
	if(elem == null){
		if (isIE){
			elem = document.createElement("<input />");
		} else {
			elem = SMISAddElement("INPUT", elemID);
		}
		elem.type = "hidden";
		elem.id = elemID;
		elem.name = elemName;
		theform.appendChild(elem);
	}
	elem.value = elemValue;
	return elem;
}

function SMISPointsParam()
{
	this.Points = new Array();
	this.AddPoint = SMISPointsParamAddPoint;
	this.GetPoint = SMISPointsParamGetPoint;
	this.GetPolyPointsString = SMISGetPolyPointsString;
	this.GeneratePointsString = SMISGeneratePointsString;
	this.GetPointsString = SMISGetPointsString;
	//format:x,y x,y .......................
	function SMISGetPolyPointsString(offset)
	{
		var pointString = "";
		for (i = 0; i < this.Points.length; i++) {
			if (i>0){	pointString += " ";	}
			pointString += (this.Points[i].x + offset.x) + "," + (this.Points[i].y + offset.y);
		}
		return pointString;
	}

	//format: numofpoints,x y,x y,...........
	function SMISGeneratePointsString()
	{
		var pointString = "" + this.Points.length + ",";
		for (i = 0; i < this.Points.length; i++) {
			if (i>0) {	pointString += ",";	}
			pointString += this.Points[i].x + " " + this.Points[i].y;		
		}
		return pointString;	
	}
	function SMISGetPointsString(offset)
	{
		var pointString = "";
		for (i = 0; i < this.Points.length; i++) {
			if (i>0){	pointString += ",";	}
			pointString += (this.Points[i].x + offset.x) + "," + (this.Points[i].y + offset.y);
		}
		return pointString;
	}
}

function SMISPointsParamAddPoint(x,y)
{
	this.Points[this.Points.length] = new SMISPoint(x,y);
}

function SMISPointsParamGetPoint(indx)
{
	if (this.Points[indx] != null) {
		return new SMISPoint(this.Points[indx].x, this.Points[indx].y);
	} 
	else {
		return null;
	}
}

function SMISCreatePolygon(mapId, points)
{
	var pointsValue = SMISExtractPoints(points);
	var map = SMISGetMap(mapId);
	var mapDiv = document.getElementById(mapId);
	var editPolygonId = "SMISEditLine";
	var line = document.getElementById(editPolygonId);
	if (!line){
		//SMISEnableVML();
		//line = document.createElement("<v:polyline points=\"0,0\"/>");
		line = document.createElement("div");
		document.forms[0].appendChild(line);
		line.style.width =map.style.width;
		line.style.height =map.style.height;
		line.style.left =map.origin.x+"px";
		line.style.top = map.origin.y+"px";
		line.style.position = "absolute";
		line.style.visibility = "visible";
		line.id = editPolygonId;
		line.style.zIndex = 1002;
		//var fill = document.createElement("<v:fill opacity=0.1 color='blue'></v:fill>");
		//var stroke = document.createElement("<v:stroke dashstyle='solid' color='red'></v:stroke>");
		//mapDiv.appendChild(line);
		//line.appendChild(fill);		
		//line.appendChild(stroke);
		line.onmousedown = SMISPanOnMouseDown;
		line.onmousemove = SMISPanOnMouseMove;
		line.onmouseup = SMISOnMouseUp;
		line.PointsParam = new SMISPointsParam();
		line.origin = map.origin;
		line.offset = map.offset;
		line.origin.x = map.origin.x;
		line.origin.y = map.origin.y;
		line.offset.x = map.offset.x;
		line.offset.y = map.offset.y;
		line.DoPostBack = map.DoPostBack;
		line.map = map;
		//line.lineOffset = new SMISPoint(line.offsetLeft, line.offsetTop);
		//line.points = pointsValue;
		var Xpoints = SplitX(pointsValue);
		var Ypoints = SplitY(pointsValue);
		var jg = new jsGraphics(editPolygonId);
		jg.origin = map.origin;
		jg.origin.x = map.origin.x;
		jg.origin.y = map.origin.y;
		jg.setColor("#ff0000"); // red
		jg.setStroke(2);
		jg.drawPolygon(Xpoints, Ypoints);
		jg.paint();
	}
	// var relativePos = SMISGetMouseMapRelativePosition(map);
	//line.style.left = map.offset.x;
	//line.style.top = map.offset.y;
	SMISClipPolygon(line);
}

⌨️ 快捷键说明

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