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

📄 toolnetscape.js

📁 Get Map Coordinat by click on map
💻 JS
📖 第 1 页 / 共 3 页
字号:
///////////////////////////////////////////////////////////////////////////////
//
//   (c) Pitney Bowes MapInfo Corporation, 2008.  All rights reserved.
//
//   The source code below is provided as sample code only. The end user of the
//   Licensed Product that contains this code may use the code below for
//   development purposes. This software is provided by Pitney Bowes MapInfo
//   "as is" and any express or implied warranties, including, but not limited
//   to, the implied warranties of merchantability and fitness for a particular
//   purpose are disclaimed.  In no event shall Pitney Bowes MapInfo be liable
//   for any direct, indirect, incidental, special, exemplary, or consequential
//   damages (including, but not limited to, procurement of substitute goods or
//   services; loss of use, data or profits; or business interruption) however
//   caused and whether in contract, strict liability, or tort (including
//   negligence) arising in any way out of the use of this software, even if
//   advised of the possibility of such damage.
//
///////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
// Javascript client side drawing code for Netscape and Mozilla browsers 

function MapInfoWebLog(msg)
{
	var t = document.getElementById("t1");
	if (t != null) {
		t.value = msg;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
// Globals
var color='black';

//////////////////////////////////////////////////////////////////////////////////////////
// Returns map object given name
function MapInfoWebGetMap(mapid)
{
	var _map =document.getElementById(mapid +"_Image");
	return _map;
}

// API to set current tool on the maptools. This method should be used by users to set current tool
// on the client side
function MapInfoWebSetCurrentTool(mapid, toolName)
{
	var _map =MapInfoWebGetMap(mapid);
	if (_map.MapTools.CurrentTool != null) {
		_map.MapTools.CurrentTool.Stop(_map);
	}
	for (i = 0; i < _map.MapTools.Tools.length; i++) {
		var tool = _map.MapTools.Tools[i];
		if (toolName == tool.Name) {
			_map.MapTools.CurrentTool = tool;
			tool.Start(_map);
		}
	}
}

// Return current tool object
function MapInfoWebGetCurrentTool(mapid)
{
	var _map =MapInfoWebGetMap(mapid);
	if (_map != null && _map.MapTools != null) {
		return _map.MapTools.CurrentTool;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
// DHTML related methods:

function MapInfoWebAddElement(element, id)
{
	var obj = document.createElement(element);
	obj.id = id;
	return(obj);
}

function MapInfoWebGetAbsolutePosition(elem)
{
	var left = elem.offsetLeft;
	var top = elem.offsetTop;
	if(elem.offsetParent)
	{
		pt = MapInfoWebGetAbsolutePosition(elem.offsetParent);
		left += pt.x;
		top += pt.y;
	}
	return new MapInfoWebPoint(left, top);
}

////////////////////////
// DHTML related methods
function MapInfoWebmkDiv(object, x, y, w, h)
{
	x = x - object.left;
	y = y - object.top;
	var divObj = MapInfoWebAddElement("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 = color;
	object.appendChild(divObj);
}

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

function MapInfoWebmkLin(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)
			{
				MapInfoWebmkDiv(object, ox, y, x-ox, 1);
				y += yIncr;
				p += pru;
				ox = x;
			}
			else p += pr;
		}
		MapInfoWebmkDiv(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)
				{
					MapInfoWebmkDiv(object, x++, y, 1, oy-y);
					y += yIncr;
					p += pru;
					oy = y;
				}
				else
				{
					y += yIncr;
					p += pr;
				}
			}
			MapInfoWebmkDiv(object, x2, y2, 1, oy-y2);
		}
		else
		{
			while ((dy--) > 0)
			{
				y += yIncr;
				if (p > 0)
				{
					MapInfoWebmkDiv(object, x++, oy, 1, y-oy);
					p += pru;
					oy = y;
				}
				else p += pr;
			}
			MapInfoWebmkDiv(object, x2, oy, 1, y2-oy);
		}
	}
}

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

function MapInfoWebmkEllipse(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)
			{
				MapInfoWebmkOvQds(object,cx, cy, -x+0x2, ox+wod, -oy, oy-1+hod, 1, 1);
				MapInfoWebmkOvQds(object,cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
			}
			else MapInfoWebmkOvQds(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);
		}
	}
	MapInfoWebmkDiv(object,cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
	MapInfoWebmkDiv(object,cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
}

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

function MapInfoWebUpdateLine(map, currentPoint)
{
	// Clip the current point based on the size of the image:
	currentPoint.x = Math.max(map.origin.x, Math.min(currentPoint.x, map.origin.x + map.offsetWidth+2));
	currentPoint.y = Math.max(map.origin.y, Math.min(currentPoint.y, map.origin.y + map.offsetHeight+2));
	
	// Set the starting and ending points
	line = document.GetElementById("MapInfoWebEntity");
	line.innerHTML = '';
	var startPoint = map.GetPoint(0);
	MapInfoWebmkLin(line, startPoint.x, startPoint.y, currentPoint.x, currentPoint.y);
}

function MapInfoWebUpdateRectangle(map, startPoint, currentPoint)
{
	var rect = document.getElementById("MapInfoWebEntity");
	if(!rect)
	{	
		// TODO Should we expose line styles at the tool level???
		var rect = MapInfoWebAddElement("DIV", "RubberRect");
		rect.style.position = 'absolute';
		rect.style.visibility = 'visible';
		rect.id = "MapInfoWebEntity";
		
		
		// Set the rect style to the map parent's z-index:
		rect.style.zIndex = map.parentNode.style.zIndex + 200;
		
		// Add the rect to the document body:
		document.body.appendChild(rect);
		rect.style.left = rect.left = startPoint.x;
		rect.style.top = rect.top = startPoint.y;
		
		// Add event handlers for the element
		rect.onmousedown = MapInfoWebRectangleOnMouseDown;
		rect.onmousemove = MapInfoWebRectangleOnMouseMove;
		rect.onmouseup = MapInfoWebRectangleOnMouseUp;

		rect.map = map;
	}
	
	// Convert the start and current points (which are offset by the map) to absolute
	// positions:
	rect.innerHTML = '';
	//startPoint.x += map.origin.x;
	//startPoint.y += map.origin.y;
	//currentPoint.x += map.origin.x;
	//currentPoint.y += map.origin.y;
	

	// Clip the current point based on the size of the image:
	currentPoint.x = Math.max(map.origin.x, Math.min(currentPoint.x, map.origin.x + map.offsetWidth+2));
	currentPoint.y = Math.max(map.origin.y, Math.min(currentPoint.y, map.origin.y + map.offsetHeight+2));
	
	// Set the rect position based on the adjusted start and current points:
	MapInfoWebmkRect(rect, Math.min(startPoint.x, currentPoint.x), Math.min(startPoint.y, currentPoint.y),
					 Math.abs(currentPoint.x - startPoint.x), Math.abs(currentPoint.y - startPoint.y));
}

function MapInfoWebRemoveRectangle(map)
{
	var rect = document.getElementById("MapInfoWebEntity");
	if(rect)
	{
		document.body.removeChild(rect);
	}
}

function MapInfoWebUpdateCircle(map, startPoint, currentPoint)
{
	// TODO Try/catch

	// If a circle VML hasn't been created:
	var circle = document.getElementById("MapInfoWebEntity");
	if(!circle)
	{	
		// TODO Should we expose line styles at the tool level???
		// Create a vml circle with absolute positioning:
		circle = MapInfoWebAddElement("DIV", "RubberCir");
		circle.style.position = "absolute";
		circle.style.visibility = 'visible';
		circle.id = "MapInfoWebEntity";
		
		// Set the rect style to the map parent's z-index:
		circle.style.zIndex = map.parentNode.style.zIndex + 200;
		
		// Add the rect to the document body:
		document.body.appendChild(circle);
		
		// Add event handlers for the element
		circle.onmousedown = MapInfoWebToolOnMouseDown;
		circle.onmousemove = MapInfoWebCircleOnMouseMove;
		circle.onmouseup = MapInfoWebCircleOnMouseUp;
		document.onmousemove = MapInfoWebCircleOnMouseMove;
		document.onmouseup = MapInfoWebCircleOnMouseUp;

⌨️ 快捷键说明

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