/*-----------------------------------------------------------------------
Coordinates JavaScript File

version: 	4.1
author:		sebastian kupke
email:		sebastian.kupke@baral-geohaus.de
website:	http://www.baral.de
-----------------------------------------------------------------------*/

/* =namespace module address
-----------------------------------------------------------------------*/
ws.m.coordinates = {
	
	/* =init
	-----------------------------------------------------------------------*/
	init: function() {
	
		$('#m_coordinates_scale_number').val(ws.map.getScaleNumber());
		$('#maps').mousemove(function (e) {
			ws.m.coordinates.show(e);
		});
	},
	
	/* =shows the x and y value in the fields
	-----------------------------------------------------------------------*/
	show: function(e) {
		
		var point = ws.map.getCurCoords(e);
		
		$('#m_coordinates_x').val(Math.abs(point.x).toFixed(0));
		$('#m_coordinates_y').val(Math.abs(point.y).toFixed(0));
	},
	
	/* =set the scale factor in the map from the input field
	-----------------------------------------------------------------------*/
	setScaleFactorFromInput: function() {
		
		var scaleNumber = $('#m_coordinates_scale_number').val();
		var checkedScaleNumber = 0;
		
		try {
			checkedScaleNumber = parseInt(scaleNumber);
			ws.map.setScaleFactor(checkedScaleNumber);
			
			ws.map.load();
		} catch (e) {
			
		}
	},
	
	/* =center the map at specific coordinates
	-----------------------------------------------------------------------*/
	center: function() {
		
		var x = parseFloat($('#m_coordinates_x').val());
		var y = parseFloat($('#m_coordinates_y').val());
		
		ws.map.zoomto(x, y);
	}
}











