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

📄 smismapcontrolie.js

📁 使用ASP.NET 2.0 (c#) 实现的gis 的地图系统
💻 JS
📖 第 1 页 / 共 4 页
字号:
/////		 Last Update @ 2006-05-16			  /////
/////		 Version: 5.2.0.27731				  /////
///////////////////////////////////////////////////////
//////   SuperMap IS WebControl Client JavaScript /////
//////         For Internet Explorer browser      /////
///////////////////////////////////////////////////////

// 获取 map image 对象.  //
function SMISGetMap(mapId)
{
	var _map = document.getElementById(mapId +"_MVIMAGE");
	if(!_map)   _map = document.getElementById(mapId);
	if(!_map)   return null;
	if(!_map.mapId){ _map.mapId = mapId; }
	return _map;
}

function Map_DoCallback(methodName, methodParameters)
{
    showBusyFlag(this.mapId);
    // "PAN|33&33"
    var argument = methodName + "|" + methodParameters;
    WebForm_DoCallback(this.mapId, argument, MapControl_Callback, null, null, false);
}

// Action 
function SMISActionStart(mapID, action)
{
	mapID = mapID.replace("_MVIMAGE", "");
	var _map = SMISGetMap(mapID);
	if(!BeforeActionStart(_map)){ return; }
	
	// 用于解决在 MyIE2 中出现的 ActionStart 之后,地图图片消失的异常bug。 //
	var v = _map.style.visibility;
	_map.CurrentAction = "";
	eval(mapID + "_SMISMapActionStart(_map, action)");
	_map.style.visibility = v;
	AfterActionStarted(_map);
	
	_map.DoCallback = Map_DoCallback;
}

function SMISMapActionStop(map)
{
	if(!BeforeActionStop(map)){ return; }
	
	map.onmousedown = null;
	map.onmousemove = null;
	map.onmouseup = null;
	map.onclick = null;
	map.ondblclick = null;
	map.style.cursor = "";
	map.bActionStarted = false;
	
	AfterActionStopped(map);
}

//***************************** Mouse Event ********************************

function SMISOnMouseDown()
{
	this.bActionStarted = true;
	var relativePos = SMISGetMouseMapRelativePosition(this);
	this.PointsParam.AddPoint(relativePos.x, relativePos.y);
	return false;
}

function SMISPanOnMouseDown()
{
	this.bActionStarted = true;
	// hide the customLayer. --ahnan 2004-07-08
	var customLayerID = this.id.replace("_MVIMAGE","") + "_divCustomLayer";
	var customLayer = document.getElementById(customLayerID);
	if (customLayer){ customLayer.style.visibility = "hidden";}
	
	var relativePos;
	if(this.map)
	{
		relativePos = SMISGetMouseMapRelativePosition(this.map);
	}
	else
	{
		relativePos = SMISGetMouseMapRelativePosition(this);
	}
	this.PointsParam.AddPoint(relativePos.x, relativePos.y);
	
	// set to absolute
	this.style.position = "absolute";
	this.style.left = this.offset.x+"px";
	this.style.top = this.offset.y+"px";
	return false;
}

function SMISOnMouseUp()
{
	var map = this;
	if(this.map){map = this.map;}
	if(this.bActionStarted){
		SMISMapActionStop(map);
		var relativePos = SMISGetMouseMapRelativePosition(map);
		this.PointsParam.AddPoint(relativePos.x, relativePos.y);
		var theform = document.forms[0];
		SMISCreateHiddenField(theform, map.id + "_Action", map.id + "_Action", map.CurrentAction);
		var pointsString = this.PointsParam.GeneratePointsString();
		SMISCreateHiddenField(theform, map.id + "_PointsParam", map.id + "_PointsParam",pointsString);
		
//  debug script callback. --ahnan 2005-06-15
		map.DoPostBack();
		return;

		var startPoint = this.PointsParam.GetPoint(0);
        
		var argument = "";
		var params = "";
		switch(map.CurrentAction){
			case "PAN": 
				argument = "PanByPixel"; 
		        var offsetX = relativePos.x - startPoint.x;
				var offsetY = relativePos.y - startPoint.y;
				params = offsetX + "&" + offsetY;
				break;
			case "ZOOMIN": 
				argument = "ZoomIn";
				params = startPoint.x + "&" + startPoint.y + "&" + relativePos.x + "&" + relativePos.y;
				SMISRemoveRect(map);
				break;
			case "ZOOMOUT": 
				argument = "ZoomOut";
				params = startPoint.x + "&" + startPoint.y + "&" + relativePos.x + "&" + relativePos.y;
				SMISRemoveRect(map);
				break;
			default:
				map.DoPostBack();
				return;
				break;
		}
		
		if(!map.DoCallback)	{ map.DoCallback = Map_DoCallback; }
        map.DoCallback(argument, params);
        
		//reset values.
        while(this.PointsParam.Points.length > 0){this.PointsParam.Points.pop();}
        this.PointsParam.Points = null;
		SMISCreateHiddenField(theform, map.id + "_Action", map.id + "_Action", "");
		SMISCreateHiddenField(theform, map.id + "_PointsParam", map.id + "_PointsParam", "");

		SMISActionStart(map.id, map.CurrentAction);
	}
}

function SMISCircleOnMouseUp()
{
	if(!this.bActionStarted){return false;}
	var posEnd = SMISGetMouseMapRelativePosition(this);
	SMISMapActionStop(this);
	this.PointsParam.AddPoint(posEnd.x, posEnd.y);
	var theform = document.forms[0];
	SMISCreateHiddenField(theform, this.id + "_Action", this.id + "_Action", this.CurrentAction);
	var pointsString = this.PointsParam.GeneratePointsString();
	SMISCreateHiddenField(theform, this.id + "_PointsParam", this.id + "_PointsParam",pointsString);
	
	this.DoPostBack();
}

function SMISRectOnMouseMove()
{
	if(!this.bActionStarted){return false;}
	var startPoint = this.PointsParam.GetPoint(0);
	if(startPoint){
		startPoint.x += this.origin.x;
		startPoint.y += this.origin.y;
	}
	if(window.event.button == 1 &&  startPoint != null){
		var absolutePos = SMISGetMouseAbsolutePosition();
		SMISDrawingRect(this, startPoint, absolutePos);
		return false;
	}
}

//must return false,otherwise mouseup event will not be invoked
function SMISPanOnMouseMove()
{	
	if(!this.bActionStarted){return false;}
	var startPoint = this.PointsParam.GetPoint(0);
	if(startPoint){
		startPoint.x += this.origin.x;
		startPoint.y += this.origin.y;
	}
	if(window.event.button == 1 && startPoint != null){
		if(!SMISCheckMousePosition(this)){return false;}
		var absolutePos = SMISGetMouseAbsolutePosition();
		SMISPaningImage(this,startPoint,absolutePos);
		return false;
	}
}

//must return false ,otherwise mouseup event will not be invoked
function SMISCircleOnMouseMove()
{
	if(!this.bActionStarted){return false;}
	var startPoint = this.PointsParam.GetPoint(0);
	if(startPoint){
		startPoint.x += this.origin.x;
		startPoint.y += this.origin.y;
	}
	if(window.event.button == 1 &&  startPoint != null){
		var absolutePos = SMISGetMouseAbsolutePosition();
		SMISDrawingCircle(this, startPoint, absolutePos);
		return false;
	}
}

function SMISPolygonOnMouseMove()
{
	if(!this.bActionStarted){return false;}
	var map = SMISGetInnerMap(this);
	var line = document.getElementById("SMISLine");
	if(line){
		var absolutePos = SMISGetMouseAbsolutePosition();
		SMISDrawingPolygon(map, absolutePos, map.PolygonClosed);
	}
	return false;
}

function SMISPolygonOnMouseClick()
{
	this.bActionStarted = true;
	
	var map = SMISGetInnerMap(this);
	var line = document.getElementById("SMISLine");
	if(!line){
		SMISEnableVML();
		line = document.createElement("<v:polyline points=\"0,0\"/>");
		line.style.position = "absolute";
		line.style.visibility = "visible";
		line.id = "SMISLine";
		line.style.zIndex = this.parentElement.style.zIndex + 200;
		var fill = document.createElement("<v:fill opacity=0.0></v:fill>");
		var stroke = document.createElement("<v:stroke dashstyle='solid' color='blue'></v:stroke>");
		document.body.appendChild(line);
		line.appendChild(fill);		
		line.appendChild(stroke);
		line.onmousemove = SMISPolygonOnMouseMove;
		line.onclick = SMISPolygonOnMouseClick;
		line.ondblclick = SMISPolygonOnDblClick;
		line.map = map;
		line.lineOffset = new SMISPoint(line.offsetLeft, line.offsetTop);
	}
	var relativePos = SMISGetMouseMapRelativePosition(map);
	map.PointsParam.AddPoint(relativePos.x, relativePos.y);
	
	return false;
}

function SMISPolygonOnDblClick()
{
	var map = SMISGetInnerMap(this);
	SMISMapActionStop(this);
	SMISMapActionStop(map);
	var theform = document.forms[0];
	SMISCreateHiddenField(theform, map.id + "_Action", map.id + "_Action", map.CurrentAction);
	var pointsString = map.PointsParam.GeneratePointsString();
	SMISCreateHiddenField(theform, map.id + "_PointsParam", map.id + "_PointsParam",pointsString);
	map.DoPostBack();
}

//***************************** End Mouse Event ****************************

//Paning Image
function SMISPaningImage(map, startPoint, curPoint)
{
	//PanWorkLayer(map, startPoint, curPoint);
	if(!map.map){
	    PanMapCells(map, startPoint, curPoint);
    	return;
	}

	var clipTop, clipRight, clipBottom, clipLeft;
	var currentLeft, currentTop, currentRight, currentBottom;
	
	// Calculate absolute current coordinates of the image
	currentLeft = map.offset.x + (curPoint.x - startPoint.x);
	currentTop = map.offset.y + (curPoint.y - startPoint.y);

	if(map.map){
		map.style.left = currentLeft+"px"; 
		map.style.top = currentTop+"px";	
		SMISClipPolygon(map, true, curPoint.x - startPoint.x, curPoint.y - startPoint.y);
		return;
	}

	try{
		currentRight = currentLeft + map.width;
		currentBottom = currentTop + map.height;
	}
	catch(e){
		currentRight = currentLeft + map.map.width;
		currentBottom = currentTop + map.map.height;
	}
			
	// Check to see if image goes out of bounds, and if so, set the clipping parameters
	if ( currentTop > map.offset.y )
		clipTop = 0;
	else
		clipTop = map.offset.y - currentTop;
			
	if (currentRight > (map.offset.x + map.width)) 
		clipRight = (map.offset.x + map.width) - currentLeft;
	else 
		clipRight = currentRight - currentLeft;
		
	if (currentBottom > (map.offset.y + map.height)) 
		clipBottom = (map.offset.y + map.height) - currentTop;
	else 
		clipBottom = currentBottom - currentTop;
			
	if (currentLeft > map.offset.x) 
		clipLeft = 0;
	else 
		clipLeft = map.offset.x - currentLeft;
	// Set the map image's style parameters to actually move the image	
	map.style.left = currentLeft+"px"; 
	map.style.top = currentTop+"px";	
	map.style.clip = 'rect(' + clipTop + ' ' +  clipRight + ' ' + clipBottom + ' ' + clipLeft +')';
}

//***************************** Drawing ************************************
//Enable VML support
function SMISEnableVML()
{
	// todo: support ie5.0, ie5.5
	if(document.namespaces){
	    document.namespaces.add("v", "urn:schemas-microsoft-com:vml")
    }
	if(document.styleSheets.length < 1){
		var _oStyle = document.createElement("style");
		document.body.appendChild(_oStyle);
	}
	document.styleSheets.item(0).addRule("v\\:*", "behavior:url(#default#VML)");
}

function SMISDrawingRect(map, startPoint, curPoint)
{
	var rect = document.getElementById("SMISRect");
	if(!rect){
		SMISEnableVML();
		var rect = document.createElement("<v:rect/>");
		rect.id = "SMISRect";
		rect.style.position = "absolute";
		rect.style.visibility = 'visible';
		rect.style.zIndex = map.parentElement.style.zIndex + 200;
		var fill = document.createElement("<v:fill opacity=0.1 color='#316AC5'></v:fill>");
		var stroke = document.createElement("<v:stroke dashstyle='solid' Color='#316AC5' weight='1px'></v:stroke>");
		document.body.appendChild(rect);
		rect.appendChild(fill);		
		rect.appendChild(stroke);	
	}
	curPoint.x = Math.max(map.origin.x, Math.min(curPoint.x, map.origin.x + map.offsetWidth+2));
	curPoint.y = Math.max(map.origin.y, Math.min(curPoint.y, map.origin.y + map.offsetHeight+2));
	rect.style.top = Math.min(startPoint.y, curPoint.y)+"px";
	rect.style.left = Math.min(startPoint.x, curPoint.x)+"px";
	rect.style.width = Math.abs(curPoint.x - startPoint.x)+"px";
	rect.style.height =  Math.abs(curPoint.y - startPoint.y)+"px";
	rect = null;
}

function SMISRemoveRect(map)
{
	var rect = document.getElementById("SMISRect");
	if(rect) { document.body.removeChild(rect);	}
	rect = null;
}


function SMISDrawingCircle(map, startPoint, curPoint)
{
	var circle = document.getElementById("SMISCircle");
	if(!circle){
		SMISEnableVML();
		circle = document.createElement("<v:arc startangle='0' endangle='360'/>");
		circle.style.position = "absolute";
		circle.style.visibility = 'visible';
		circle.id = "SMISCircle";
		circle.style.zIndex = map.parentElement.style.zIndex + 200;
		var fill = document.createElement("<v:fill opacity=0.3></v:fill>");
		var stroke = document.createElement("<v:stroke dashstyle='solid' Color='blue'></v:stroke>");
		document.body.appendChild(circle);
		circle.appendChild(fill);
		circle.appendChild(stroke);
	}

	curPoint.x = Math.max(map.origin.x, Math.min(curPoint.x, map.origin.x + map.offsetWidth+2));
	curPoint.y = Math.max(map.origin.y, Math.min(curPoint.y, map.origin.y + map.offsetHeight+2));

	var radius = Math.sqrt(Math.pow((curPoint.x - startPoint.x), 2) + Math.pow((curPoint.y - startPoint.y), 2))

	circle.style.left = (startPoint.x - radius)+"px";
	circle.style.top = (startPoint.y - radius)+"px";
	
	circle.style.width = 2*radius+"px";
	circle.style.height =  circle.style.width;
	
	var clipTop, clipRight, clipBottom, clipLeft;
	currentLeft = parseInt(circle.style.left);
	currentTop = parseInt(circle.style.top);
	currentRight = currentLeft + parseInt(circle.style.width);
	currentBottom = currentTop + parseInt(circle.style.height);
			

⌨️ 快捷键说明

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