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

📄 toolie.js

📁 Get Map Coordinat by click on map
💻 JS
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////
//
//   (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 Microsoft Internet Explorer 

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

//////////////////////////////////////////////////////////////////////////////////////////
// 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 != null && _map.MapTools != null) {
		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 (tool != null) {
				if (toolName == tool.Name) {
					_map.MapTools.CurrentTool = tool;
					_map.style.cursor = tool.cursorUrl;
					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 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);
}

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

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

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

	// If a rectangle VML hasn't been created:
	var rect = document.getElementById("MapInfoWebEntity");
	if(!rect) {	
		MapInfoWebEnableVML();
		// TODO Should we expose line styles at the tool level???
		// Create a vml rect with absolute positioning:
		var rect = document.createElement("<v:rect/>");
		rect.id = "MapInfoWebEntity";
		rect.style.position = "absolute";
		rect.style.visibility = 'visible';
		// Set the rect style to the map parent's z-index:
		rect.style.zIndex = map.parentElement.style.zIndex + 200;
		
		// Create a fill with no opacity:
		var fill = document.createElement("<v:fill opacity=0.40></v:fill>");
		
		// Create a dashed stroke:
		var stroke = document.createElement("<v:stroke dashstyle='solid'></v:fill>");
		
		// Add the rect to the document body:
		document.body.appendChild(rect);
		
		// Add the stroke and fill to the rect:
		rect.appendChild(fill);		
		rect.appendChild(stroke);		
	}
	
	// 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:
	rect.style.top = Math.min(startPoint.y, currentPoint.y);
	rect.style.left = Math.min(startPoint.x, currentPoint.x);
	rect.style.width = Math.abs(currentPoint.x - startPoint.x);
	rect.style.height =  Math.abs(currentPoint.y - startPoint.y);
}

// Method to pan the image and clip if goes out of bounds
function MapInfoWebPanImage (map, startPoint, currentPoint)
{
	var clipTop, clipRight, clipBottom, clipLeft;
	var currentLeft, currentTop, currentRight, currentBottom;
	// Calculate absolute current coordinates of the image
	currentLeft = map.origin.x + (currentPoint.x - startPoint.x);
	currentTop = map.origin.y + (currentPoint.y - startPoint.y);
	currentRight = currentLeft + map.width;
	currentBottom = currentTop + map.height;

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

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

	// If a circle VML hasn't been created:
	var circle = document.getElementById("MapInfoWebEntity");
	if(!circle)
	{	
		MapInfoWebEnableVML();
		// TODO Should we expose line styles at the tool level???
		// Create a vml circle with absolute positioning:
		circle = document.createElement("<v:arc startangle='0' endangle='360'/>");
		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.parentElement.style.zIndex + 200;
		
		// Create a fill with no opacity:
		var fill = document.createElement("<v:fill opacity=0.40></v:fill>");
		
		// Create a dashed stroke:
		var stroke = document.createElement("<v:stroke dashstyle='solid'></v:fill>");
		
		// Add the rect to the document body:
		document.body.appendChild(circle);
		
		// Add the stroke and fill to the rect:
		circle.appendChild(fill);		
		circle.appendChild(stroke);
		
	}

	// 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));

	// Radius is the distance between the center and the current point
	var radius = Math.sqrt(Math.pow((currentPoint.x - startPoint.x), 2) + Math.pow((currentPoint.y - startPoint.y), 2))

	// The left and top are the center minus the radius
	circle.style.left = startPoint.x - radius;
	circle.style.top = startPoint.y - radius;
	
	// The width and height are the same as the diameter
	circle.style.width = 2*radius;
	circle.style.height =  circle.style.width;
	
	// Check to see if circle goes out of bounds, and if so, set the clipping 
	// parameters
	
	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);
		
	if ( currentTop > map.origin.y )
		clipTop = 'auto';
	else
		clipTop = map.origin.y - currentTop;
			
	if (currentRight > (map.origin.x + map.width)) 
		clipRight = (map.origin.x + map.width) - currentLeft;
	else 
		clipRight = 'auto';
		
	if (currentBottom > (map.origin.y + map.height)) 
		clipBottom = (map.origin.y + map.height) - currentTop;
	else 
		clipBottom = 'auto';
			
	if (currentLeft > map.origin.x) 
		clipLeft ='auto';
	else 
		clipLeft = map.origin.x - currentLeft;
	
	circle.style.clip = 'rect(' + clipTop + ' ' +  clipRight + ' ' + clipBottom + ' ' + clipLeft +')';
}

function MapInfoWebUpdatePolygon(map, currentPoint, doPolygon)
{
	var line = document.getElementById("MapInfoWebEntity");

	// 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));

	// Now set the polylines points collection so that it draws the segments
	// it contains all the previously clicked points + current point (which is moving)
	// + the first point to complete the polygon
	var offset = line.lineOffset;
	currentPoint.x = currentPoint.x - offset.x;
	currentPoint.y = currentPoint.y - offset.y;
	if (doPolygon) {
		firstPoint = map.PointsData.GetPoint(0);
		firstPoint.x = firstPoint.x - offset.x;
		firstPoint.y = firstPoint.y - offset.y;
		line.points.value = map.PointsData.GetPointsValue(offset) + 
				" " + currentPoint.x + "," + currentPoint.y + " " +
				firstPoint.x + "," + firstPoint.y;
	} else {
		line.points.value = map.PointsData.GetPointsValue(offset) + 
				" " + currentPoint.x + "," + currentPoint.y;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////
// Common methods:

// if 
function MapInfoWebGetMapInternal(object)
{
	var map = null;
	if (object.map) {
		map = object.map;
	} else {
		map = object;
	}
	
	return map;
}


//////////////////////////////////////////////////////////////////////////////////////////
// Point Data object methods

// Append the point to points collection
function MapInfoWebAddPoint(x, y)
{
	this.Points[this.Points.length] = new MapInfoWebPoint(x,y);
}

// Get point from points collection
function MapInfoWebGetPoint(indx)
{
	if (this.Points[indx] != null) {
		return new MapInfoWebPoint(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"
function MapInfoWebGetPointsString(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"
function MapInfoWebGetPointsValue(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;
}

// Create hidden field containing the string representation of points collection
function MapInfoWebCreatePointsField(id)
{
	var theform = document.forms[0];
	var map = document.getElementById(id);
	var pointstring = this.GetPointsString(map.origin);
	MapInfoWebCreateHiddenField(theform, id+"_PointsData", id+"_PointsData", pointstring);
}

// Point data handling object
function MapInfoWebPointsData()
{
	this.Points = new Array();
	this.AddPoint = MapInfoWebAddPoint;
	this.GetPoint = MapInfoWebGetPoint;
	this.GetPointsString = MapInfoWebGetPointsString;
	this.GetPointsValue = MapInfoWebGetPointsValue;
	this.CreatePointsField = MapInfoWebCreatePointsField;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Point methods:

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

//////////////////////////////////////////////////////////////////////////////////////////
// Tool related objects

// Tool object
function MapInfoWebMapTool()
{
	this.Name = "";
	this.Start = "";
	this.Stop = "";
}

// Tools collection belonging to map
function MapInfoWebMapTools()
{
}

//////////////////////////////////////////////////////////////////////////////////////////
// ToolControl methods:

// Toggle the activation of the tool
function MapInfoWebActivateTool (map, toolName, tool)
{
	if (tool.parentElement.parentElement.disabled) return;
	
	// If we clicked on the same tool control which was active then deactivate it and set current tool to invalid one
	// Otherwise, deactivate the current tool control, and activate the other one. And set the current tool to that one.
	// and create hidden field containing the current toolname
	if (map.activeToolControl != null && map.activeToolControl.id == tool.id && map.activeToolControl.active) {
		map.activeToolControl.Deactivate( map.activeToolControl);
		MapInfoWebSetCurrentTool(map.id, "None");
		var _map = MapInfoWebGetMap(map.id);
		_map.style.cursor = null;
	} else {
		if (map.activeToolControl != null) map.activeToolControl.Deactivate(map.activeToolControl);
		map.activeToolControl = tool;
		if(map.activeToolControl != null)	{
			map.activeToolControl.Activate(tool);
		}
		

⌨️ 快捷键说明

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