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

📄 toolnetscape.js

📁 Get Map Coordinat by click on map
💻 JS
📖 第 1 页 / 共 3 页
字号:
		
		circle.map = map;
		document.map = map;
	}

	circle.innerHTML = '';

	// 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 = circle.left = startPoint.x - radius;
	circle.style.top = circle.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 +')';
	MapInfoWebmkEllipse(circle, startPoint.x - radius, startPoint.y - radius, radius*2, radius*2);
}

function MapInfoWebUpdatePolygon(map, currentPoint, doPolygon)
{
	// 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 line = document.getElementById("MapInfoWebEntity");

	var tempX = new Array();
	var tempY = new Array();
	for (i=0; i<map.PointsData.Points.length; i++) {
		var pt = map.PointsData.GetPoint(i);
		tempX[i] = pt.x;
		tempY[i] = pt.y;
	}
	
	tempX[tempX.length]  = currentPoint.x;
	tempY[tempY.length]  = currentPoint.y;
	if (doPolygon) {
		var firstPoint = map.PointsData.GetPoint(0);
		tempX[tempX.length]  = firstPoint.x;
		tempY[tempY.length]  = firstPoint.y;
	}	
	
	line.innerHTML = '';
	MapInfoWebmkPolyline(line, tempX, tempY);
}

// 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 +')';
}

//////////////////////////////////////////////////////////////////////////////////////////
// Common methods:

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 += ","
		}
		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)
{
	var v = document.getElementById(tool.parentControl);
	if (v) {
		if (v.attributes['disabled']) {
			if (v.attributes['disabled'].value == '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);
		}
		
		// 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);
		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(evt)
{
	map = MapInfoWebGetMapInternal(this);
	map.PointsData.AddPoint(evt.clientX+document.body.scrollLeft, evt.clientY+document.body.scrollTop);
	return false;
}

function MapInfoWebToolOnMouseUp(evt)
{
	
	var map = MapInfoWebGetMapInternal(this);
	map.onmousemove = null;
	if (this.map != null) this.onmousemove = null;

	var theform = document.forms[0];
	
	// Get the current point
	map.PointsData.AddPoint(evt.clientX+document.body.scrollLeft, evt.clientY+document.body.scrollTop);
	
	// 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.parentNode.id);

	// Do the postback
	map.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 = MapInfoWebRectangleOnMouseDown;
		map.onmouseup = MapInfoWebRectangleOnMouseUp;

		this.started = true;
		return false;
	}
}

function MapInfoWebRectangleOnMouseDown(evt)
{
	var map = MapInfoWebGetMapInternal(this);
	map.PointsData = new MapInfoWebPointsData();
	map.PointsData.AddPoint(evt.clientX+document.body.scrollLeft, evt.clientY+document.body.scrollTop);
	map.onmousemove = MapInfoWebRectangleOnMouseMove;
	return false;
}

⌨️ 快捷键说明

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