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

📄 toolie.js

📁 Get Map Coordinat by click on map
💻 JS
📖 第 1 页 / 共 2 页
字号:
		// Create hidden field when tool is activated, to handle multiple maps and tool controls on the same page
		MapInfoWebSetCurrentTool(map.id, toolName);
		var _map =MapInfoWebGetMap(map.id);
		_map.style.cursor = tool.cursorUrl;
		var theform = document.forms[0];
		MapInfoWebCreateHiddenField(theform, _map.id + "_CurrentToolName", _map.id + "_CurrentToolName", _map.MapTools.CurrentTool.Name);
		MapInfoWebCreateHiddenField(theform, _map.id + "_ToolControlParent", _map.id + "_ToolControlParent", tool.parentControl);
	} 
}

// Activate the tool by setting the image source to active image
function MapInfoWebToolActivate(tool)
{
	tool.src = tool.activeSrc;
	tool.active = true;
}

// Deactivate the tool by setting the image source to inactive image
function MapInfoWebToolDeactivate(tool)
{
	tool.src = this.inactiveSrc;
	tool.active = false;
}

function MapInfoWebToolOnMouseDown()
{
	this.PointsData.AddPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);
	return false;
}

function MapInfoWebToolOnMouseUp()
{
	var theform = document.forms[0];
	
	// Get the current point
	this.PointsData.AddPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);
	
	// Create hidden field for current tool
	MapInfoWebCreateHiddenField(theform, this.id + "_CurrentToolName", this.id + "_CurrentToolName", this.MapTools.CurrentTool.Name);
	
	// Create hidden field for points data
	this.PointsData.CreatePointsField(this.id);
	
	// Create hidden field that will store selectable layers
	MapInfoWebCreateSelectableLayerField(this.parentElement.id);

	// Do the postback
	this.DoPostBack();
}
//////////////////////////////////////////////////////////////////////////////////////////
// ZoomInTool, RectangleSelect methods:

function MapInfoWebRectangleStart(map)
{
	if(!this.started)
	{
		// Set up the point data object
		map.PointsData = new MapInfoWebPointsData();
		
		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		
		map.onmousedown = MapInfoWebToolOnMouseDown;
		map.onmousemove = MapInfoWebRectangleOnMouseMove;
		map.onmouseup = MapInfoWebRectangleOnMouseUp;

		this.started = true;
	}
}


function MapInfoWebRectangleStop(map)
{
	if(this.started)
	{
		map.onmousedown = null;
		map.onmousemove = null;
		map.onmouseup = null;
		this.started = false;
	}
}

function MapInfoWebRectangleOnMouseMove()
{
	var startPoint = this.PointsData.GetPoint(0);
	if(window.event.button == 1 &&  startPoint != null)
	{
		MapInfoWebUpdateRectangle(this, startPoint, new MapInfoWebPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop));
		return false;
	}
}

function MapInfoWebRectangleOnMouseUp()
{
	var theform = document.forms[0];
	
	// Get the current point
	this.PointsData.AddPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);
	if (this.PointsData.Points.length == 2) {
		var fir = this.PointsData.GetPoint(0);
		var sec = this.PointsData.GetPoint(1);
		var dx = this.PointsData.GetPoint(1).x - this.PointsData.GetPoint(0).x;
		var dy = this.PointsData.GetPoint(1).y - this.PointsData.GetPoint(0).y;
		
		if (dx < 0 && dy < 0) {
			this.PointsData.Points.length = 0;
			this.PointsData.AddPoint(sec.x, sec.y);
			this.PointsData.AddPoint(fir.x, fir.y);
		} else if (dx < 0 && dy > 0) {
			this.PointsData.Points.length = 0;
			this.PointsData.AddPoint(sec.x, fir.y);
			this.PointsData.AddPoint(fir.x, sec.y);
		} else if (dx > 0 && dy < 0) {
			this.PointsData.Points.length = 0;
			this.PointsData.AddPoint(fir.x, sec.y);
			this.PointsData.AddPoint(sec.x, fir.y);
		}
	}
	
	// Create hidden field for current tool
	MapInfoWebCreateHiddenField(theform, this.id + "_CurrentToolName", this.id + "_CurrentToolName", this.MapTools.CurrentTool.Name);
	
	// Create hidden field for points data
	this.PointsData.CreatePointsField(this.id);
	
	// Create hidden field that will store selectable layers
	MapInfoWebCreateSelectableLayerField(this.parentElement.id);

	// Do the postback
	this.DoPostBack();
}

//////////////////////////////////////////////////////////////////////////////////////////
// ZoomOutTool, InfoTool methods:

function MapInfoWebPointStart(map)
{
	if(!this.started)
	{
		map.PointsData = new MapInfoWebPointsData();
		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		
		map.onmouseup = MapInfoWebToolOnMouseUp;
		this.started = true;
	}
}


function MapInfoWebPointStop(map)
{
	if(this.started)
	{
		map.onmouseup = null;
		this.started = false;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// PanTool methods:


function MapInfoWebPanStart(map)
{
	if(!this.started)
	{
		map.PointsData = new MapInfoWebPointsData();

		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		
		map.onmousedown = MapInfoWebPanOnMouseDown;
		map.onmousemove = MapInfoWebPanOnMouseMove;
		map.onmouseup = MapInfoWebToolOnMouseUp;
		this.started = true;
	}
}

function MapInfoWebPanStop(map)
{
	if(this.started)
	{
		map.onmousedown = null;
		map.onmousemove = null;
		map.onmouseup = null;
		this.started = false;
	}
}

function MapInfoWebPanOnMouseDown()
{
	this.parentElement.style.position = 'absolute';
	this.PointsData = new MapInfoWebPointsData();
	this.PointsData.AddPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);
	return false;
}

function MapInfoWebPanOnMouseMove()
{
	if ( this.PointsData != null )
	{
		var startPoint = this.PointsData.GetPoint(0);
		if(window.event.button == 1 &&  startPoint != null)
		{
			MapInfoWebPanImage(this, startPoint, new MapInfoWebPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop));
			return false;
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// RadiusTool methods:

function MapInfoWebCircleStart(map)
{
	if (!this.started)
	{
		// Set up the point data object
		map.PointsData = new MapInfoWebPointsData();
		
		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		
		map.onmousedown = MapInfoWebToolOnMouseDown;
		map.onmousemove = MapInfoWebCircleOnMouseMove;
		map.onmouseup = MapInfoWebCircleOnMouseUp;
	
		this.started = true;
	}
}

function MapInfoWebCircleStop(map)
{
	if(this.started)
	{
		map.onmousedown = null;
		map.onmousemove = null;
		map.onmouseup = null;
		this.started = false;
	}
}

function MapInfoWebCircleOnMouseMove()
{
	var startPoint = this.PointsData.GetPoint(0);
	if(window.event.button == 1 &&  startPoint != null)
	{
		MapInfoWebUpdateCircle(this, startPoint, new MapInfoWebPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop));
		return false;
	}
}

function MapInfoWebCircleOnMouseUp()
{
	var theform = document.forms[0];
	
	var endPoint = new MapInfoWebPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);
	// Get the current point
	this.PointsData.AddPoint(endPoint.x, endPoint.y);
	
	var startPoint = this.PointsData.GetPoint(0);

	// The startpoint is the center and radius is the distance
	// between the start point and the end point
	
	var radius = Math.sqrt(Math.pow((endPoint.x - startPoint.x), 2) +
							 Math.pow((endPoint.y - startPoint.y), 2));

	// Add radius to pointData object.  x value of xy pair will contain radius value.  y value will be set to 0;
	this.PointsData.AddPoint(radius, -99999);

	// Create hidden field for current tool
	MapInfoWebCreateHiddenField(theform, this.id + "_CurrentToolName", this.id + "_CurrentToolName", this.MapTools.CurrentTool.Name);
	
	// Create hidden field for points data
	this.PointsData.CreatePointsField(this.id);
	
	// Create hidden field that will store selectable layers
	MapInfoWebCreateSelectableLayerField(this.parentElement.id);

	// Do the postback
	this.DoPostBack();
}

//////////////////////////////////////////////////////////////////////////////////////////
// DistanceTool methods:

function MapInfoWebDistanceStart(map)
{
	if(!this.started)
	{
		map.PointsData = new MapInfoWebPointsData();

		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		map.doPolygon = false;

		// Add event handlers to map		
		map.onmousemove = MapInfoWebPolygonOnMouseMove;
		map.onclick = MapInfoWebPolygonOnMouseClick;
		map.ondblclick = MapInfoWebPolygonOnDblClick;
		this.started = true;

	}
}

//////////////////////////////////////////////////////////////////////////////////////////
// PolygonSelectionTool methods:

function MapInfoWebPolygonStart(map)
{
	if(!this.started)
	{
		map.PointsData = new MapInfoWebPointsData();

		// Get the absolute map position:
		map.origin = MapInfoWebGetAbsolutePosition(map);
		map.doPolygon = true;

		// Add event handlers to map		
		map.onmousemove = MapInfoWebPolygonOnMouseMove;
		map.onclick = MapInfoWebPolygonOnMouseClick;
		map.ondblclick = MapInfoWebPolygonOnDblClick;
		this.started = true;

	}
}

function MapInfoWebPolygonStop(map)
{
	if(this.started)
	{
		map.onmousemove = null;
		map.onclick = null;
		map.ondblclick = null;
		this.started = false;
	}
}

function MapInfoWebPolygonOnMouseClick()
{
	var map = MapInfoWebGetMapInternal(this);
	var line = document.getElementById("MapInfoWebEntity");
	// create the vml polyline element		
	if(!line)
	{
		MapInfoWebEnableVML();
		// TODO Should we expose line styles at the tool level???
		// Create a vml polyline with absolute positioning:
		line = document.createElement("<v:polyline points=\"0,0\"/>");
		line.style.position = "absolute";
		line.style.visibility = "visible";
		line.id = "MapInfoWebEntity";
		
		// Set the style to the map parent's z-index:
		line.style.zIndex = map.parentElement.style.zIndex + 200;
		
		// Create a fill with no opacity:
		if (map.doPolygon == true) {
			var fill = document.createElement("<v:fill opacity=0.40></v:fill>");
		} else {
			var fill = document.createElement("<v:fill opacity=0.00></v:fill>");
		}
		
		// Create a dashed stroke:
		var stroke = document.createElement("<v:stroke dashstyle='solid'></v:fill>");
		
		// Add to the document body:
		document.body.appendChild(line);
		
		// Add the stroke and fill to the polyline:
		line.appendChild(fill);		
		line.appendChild(stroke);
		
		// Now add the event handlers for this line which point to event handlers of the map
		// the reason for doing this is when a closed vml shape is formed, any mouse activities
		// within that closed shaped become events for that vml entity not map
		line.onmousemove = MapInfoWebPolygonOnMouseMove;
		line.onclick = MapInfoWebPolygonOnMouseClick;
		line.ondblclick = MapInfoWebPolygonOnDblClick;
		line.activeTool = map.activeTool;
		line.map = map;

		// Store the offset of the polyline we just inserted		
		line.lineOffset = new MapInfoWebPoint(line.offsetLeft, line.offsetTop);
	}
	
	map.PointsData.AddPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop);

	return false;
}

function MapInfoWebPolygonOnMouseMove()
{
	var map = MapInfoWebGetMapInternal(this);
	var line = document.getElementById("MapInfoWebEntity");
	if(line)
	{
		MapInfoWebUpdatePolygon(map, new MapInfoWebPoint(event.x+document.body.scrollLeft, event.y+document.body.scrollTop), map.doPolygon);
	}

	return false;

}

function MapInfoWebPolygonOnDblClick()
{
	var map = MapInfoWebGetMapInternal(this);
	map.onmousemove = null;
	if (this.map != null) this.onmousemove = null;
	
	var theform = document.forms[0];

	// Create hidden field for current tool
	MapInfoWebCreateHiddenField(theform, map.id + "_CurrentToolName", map.id + "_CurrentToolName", map.MapTools.CurrentTool.Name);
	
	// Create hidden field for points data
	map.PointsData.CreatePointsField(map.id);
	
	// Create hidden field that will store selectable layers
	MapInfoWebCreateSelectableLayerField(map.parentElement.id);

	// Do the postback
	map.DoPostBack();
}

⌨️ 快捷键说明

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