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

📄 interaction.js

📁 c#中用MapXtreme开发的地理信息系统
💻 JS
📖 第 1 页 / 共 3 页
字号:
Object.prototype.eventHandler=function(a){
	var b=this;
	b=b;
	return function(c) 
	{
		if (!c) c=GetEvent(this, c);
		if(c){
			if (!c.target) c.target=c.srcElement;
			if (BrowserType() == IE) {
				c.target.doc = c.target.document;
			} else if (BrowserType() == NS) {
				c.target.doc = c.target.ownerDocument;
			}
		}
		if (a != null) return b[a](c);
	}
}

function GetEvent(element, evt)
{
	var imgEvent = null;
	if (element.Frame == null) {
		if (evt != null) {
			imgEvent = evt;
		} else {
			try {imgEvent = event;}catch(e){;}
		}
	}
	else {
		imgEvent = element.Frame.event;
	}
	return imgEvent;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Point data handling methods

function Point(x, y)
{
	this.x = parseInt(x);
	this.y = parseInt(y);
}

function PointsData()
{
	this.Points = new Array();
}

// Append the point to points collection
PointsData.prototype.NumPoints = function()
{
	return this.Points.length;
}

PointsData.prototype.AddPoint = function(x, y)
{
	this.Points[this.Points.length] = new Point(x,y);
}

// Get point from points collection
PointsData.prototype.GetPoint = function(indx)
{
	if (this.Points[indx] != null) {
		return new Point(this.Points[indx].x, this.Points[indx].y);
	} else {
		return null;
	}
}

// Return the string representation of point collection, The format is "numpts,x y,x y,x y...,x y"
PointsData.prototype.GetPointsString = function(offset)
{
	var pointString = "" + this.Points.length + ",";
	for (i = 0; i < this.Points.length; i++) {
		if (i>0)
		{
			pointString += ","
		}
		// In case of radius tool the third point is radius, -99999 we don't want to offset it.
		if (this.Points[i].y != -99999) {
			pointString += (this.Points[i].x - offset.x) + "_" + (this.Points[i].y - offset.y);	
		} else {
			pointString += (this.Points[i].x) + "_" + (this.Points[i].y);	
		}
	}
	return pointString;
}

// Return the string representation of point collection, The format is "x,y x,y x,y ... x,y"
PointsData.prototype.GetPointsValue = function(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;
}

PointsData.prototype.Clear = function()
{
	this.Points.length = 0;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Misc methods

function GetAbsPos(elem)
{
	if (elem == null) { return new Point(0,0); }
	var left = elem.offsetLeft;
	var top = elem.offsetTop;
	if(elem.offsetParent)
	{
		pt = GetAbsPos(elem.offsetParent);
		left += pt.x;
		top += pt.y;
	}
	return new Point(left, top);
}

// Get browser type
var IE = 1;
var NS = 2;
function BrowserType()
{
	if (navigator.appName.toLowerCase().indexOf("microsoft") >= 0) {
		return IE;
	} else if (navigator.appName.toLowerCase().indexOf("netscape") >= 0) {
		return NS;
	}
}

// Check to see if the left button was held down
function LButtonDown(e)
{
	if (BrowserType() == IE) {
		if (e.button == 1) { return true;}
	} else if (BrowserType() == NS) {
		if (e.button == 0) return true;
	}
	return false;
}

function GetElementInternal(object)
{
	var element = null;
	if (object.element) {
		element = object.element;
	} else {
		element = object;
	}
	return element;
}

function FindElement(id)
{
	var i;
	var ele = document.getElementById(id);
	if (ele != null) {
		return ele;
	}

	if (parent.frames.length > 0) {
		for (i=0;i<parent.frames.length;i++) {
			var doc = parent.frames[i].document;
			var ele = doc.getElementById(id);
			if (ele != null) {
				ele.Frame = parent.frames[i];
				return ele;
			}
		}
	}
	return null;
}

// Get proper scrollTop and ScrollLeft. Depending upon the doctype used in the html it may not return the right value
function GetScrollTop(element)
{
    return Math.max(element.doc.body.scrollTop, element.doc.documentElement.scrollTop);
}

function GetScrollLeft(element)
{
    return Math.max(element.doc.body.scrollLeft, element.doc.documentElement.scrollLeft);
}

//////////////////////////////////////////////////////////////////////////////////////////
// VML related methods:

function EnableVML(element)
{
	element.doc.namespaces.add("v", "urn:schemas-microsoft-com:vml")
	if(element.doc.styleSheets.length < 1)
	{
	var oStyleEl = element.doc.createElement("style");
	element.doc.body.appendChild(oStyleEl);
	}
	element.doc.styleSheets.item(0).addRule("v\\:*", "behavior:url(#default#VML)");
}

//////////////////////////////////////////////////////////////////////////////////////////
// Mozilla related methods
function AddElement(element, id)
{
	var obj = document.createElement(element);
	obj.id = id;
	return(obj);
}

function MkDiv(object, x, y, w, h)
{
	x = x - object.left;
	y = y - object.top;
	var divObj = AddElement("DIV", "");
	divObj.style.position = 'absolute';
	divObj.style.left = x + 'px'; 
	divObj.style.top = y + 'px'; 
	divObj.style.width = w + 'px'; 
	divObj.style.height = h + 'px';
	divObj.style.clip = 'rect(0,'+w+'px,'+h+'px,0)';
	divObj.style.overflow = 'hidden';
	divObj.style.backgroundColor = 'black';
	object.appendChild(divObj);
}

function MkOvQds(object,cx, cy, xl, xr, yt, yb, w, h)
{
	this.MkDiv(object,xr+cx, yt+cy, w, h);
	this.MkDiv(object,xr+cx, yb+cy, w, h);
	this.MkDiv(object,xl+cx, yb+cy, w, h);
	this.MkDiv(object,xl+cx, yt+cy, w, h);
}

function MkLin(object, x1, y1, x2, y2)
{
	if (x1 > x2)
	{
		var _x2 = x2;
		var _y2 = y2;
		x2 = x1;
		y2 = y1;
		x1 = _x2;
		y1 = _y2;
	}
	var dx = x2-x1, dy = Math.abs(y2-y1),
	x = x1, y = y1,
	yIncr = (y1 > y2)? -1 : 1;

	if (dx >= dy)
	{
		var pr = dy<<1,
		pru = pr - (dx<<1),
		p = pr-dx,
		ox = x;
		while ((dx--) > 0)
		{
			++x;
			if (p > 0)
			{
				MkDiv(object, ox, y, x-ox, 1);
				y += yIncr;
				p += pru;
				ox = x;
			}
			else p += pr;
		}
		MkDiv(object, ox, y, x2-ox+1, 1);
	}

	else
	{
		var pr = dx<<1,
		pru = pr - (dy<<1),
		p = pr-dy,
		oy = y;
		if (y2 <= y1)
		{
			while ((dy--) > 0)
			{
				if (p > 0)
				{
					MkDiv(object, x++, y, 1, oy-y);
					y += yIncr;
					p += pru;
					oy = y;
				}
				else
				{
					y += yIncr;
					p += pr;
				}
			}
			MkDiv(object, x2, y2, 1, oy-y2);
		}
		else
		{
			while ((dy--) > 0)
			{
				y += yIncr;
				if (p > 0)
				{
					MkDiv(object, x++, oy, 1, y-oy);
					p += pru;
					oy = y;
				}
				else p += pr;
			}
			MkDiv(object, x2, oy, 1, y2-oy);
		}
	}
}

function MkRect(object, x, y, w, h)
{
	var stroke = 1;
	MkDiv(object, x, y, w, stroke);
	MkDiv(object, x+w, y, stroke, h);
	MkDiv(object, x, y+h, w+stroke, stroke);
	MkDiv(object, x, y+stroke, stroke, h-stroke);
}

function MkEllipse(object, left, top, width, height)
{
	var a = width>>1, b = height>>1,
	wod = width&1, hod = (height&1)+1,
	cx = left+a, cy = top+b,
	x = 0, y = b,
	ox = 0, oy = b,
	aa = (a*a)<<1, bb = (b*b)<<1,
	st = (aa>>1)*(1-(b<<1)) + bb,
	tt = (bb>>1) - aa*((b<<1)-1),
	w, h;
	while (y > 0)
	{
		if (st < 0)
		{
			st += bb*((x<<1)+0x3);
			tt += (bb<<1)*(++x);
		}
		else if (tt < 0)
		{
			st += bb*((x<<1)+0x3) - (aa<<1)*(y-1);
			tt += (bb<<1)*(++x) - aa*(((y--)<<1)-0x3);
			w = x-ox;
			h = oy-y;
			if (w&0x2 && h&0x2)
			{
				MkOvQds(object,cx, cy, -x+0x2, ox+wod, -oy, oy-1+hod, 1, 1);
				MkOvQds(object,cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
			}
			else MkOvQds(object,cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);
			ox = x;
			oy = y;
		}
		else
		{
			tt -= aa*((y<<1)-0x3);
			st -= (aa<<1)*(--y);
		}
	}
	MkDiv(object,cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
	MkDiv(object,cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
}

function MkPolyline(object, x, y)
{
	var i = x.length-1; 
	while (i >= 0) {
		MkLin(object, x[i], y[i], x[--i], y[i]);
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// Base class for interaction
function Interaction(elementID, onComplete)
{
	if (arguments.length > 0) {
		this.InitParams(elementID, onComplete);
	}
}

Interaction.prototype.InitParams = function(elementID, onComplete)
{
	this.elementID = elementID;
	this.onComplete = onComplete;
	this.PointsData = new PointsData();
	this.dragReqd = true;
	this.clearOnEsc = false;
};

Interaction.prototype.InitHandlers = function()
{
	if (this.element == null) this.element = FindElement(this.elementID);
	this.element.origin = GetAbsPos(this.element);
	this.element.onmouseover = this.eventHandler("OnOver");
	this.element.onmousedown = this.eventHandler("OnDown");
	this.element.onmousemove = this.eventHandler("OnMove");
	this.element.onmouseup = this.eventHandler("OnUp");
	this.element.onclick = this.eventHandler("OnClick");
	this.element.ondblclick = this.eventHandler("OnDblClick");
}

Interaction.prototype.DeinitHandlers = function()
{
	this.element.onmouseover = null;
	this.element.onmousedown = null;
	this.element.onmousemove = null;
	this.element.onmouseup = null;
	this.element.onclick = null;
	this.element.ondblclick = null;
}

Interaction.prototype.OnOver = function(e)
{
	this.element.event = e;
}

Interaction.prototype.OnDown = function(e)
{
	if (LButtonDown(e)) {
		this.Clear();
		this.PointsData.AddPoint(e.clientX+GetScrollLeft(this.element), e.clientY+GetScrollTop(this.element));
		return false;

⌨️ 快捷键说明

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