// Эвклидова Проекция
var EuclideanProjection = function (){

    /**
     * autor: CTAPbIu_MABP
     * email: ctapbiumabp@gmail.com
     * site: http://mabp.kiev.ua/2010/08/16/custom-maptype-projection-in-google-map-api-v3/
     * license: GPL
     * last update: 04.09.2010
     * version: 0.4
     */

	// Ширина, она же высота одного кусочка картинки
	var EUCLIDEAN_RANGE = 256; 
	// Центр этой самой картинки
	this.pixelOrigin = new google.maps.Point(EUCLIDEAN_RANGE / 2, EUCLIDEAN_RANGE / 2);
	// Количество градусов в одном пикселе картинки
	this.pixelsPerLonDegree = EUCLIDEAN_RANGE / 360;
	// Количество радиан в одном пикселе картинки
	this.pixelsPerLonRadian = EUCLIDEAN_RANGE / (2 * Math.PI);
	this.scaleLat = 2;
	this.scaleLng = 1;
	//this.offsetLat = 0;
	//this.offsetLng = -180;
};

// Эти два метода надо реализовать в классе проекции
// http://code.google.com/apis/maps/documentation/javascript/maptypes.html#Projections
EuclideanProjection.prototype = {
	pixelOrigin : new google.maps.Point(0,0),
	pixelsPerLonDegree : 0,
	pixelsPerLonRadian : 0,
	scaleLat : 0,
	scaleLng : 0,
	offsetLat : 0,
	offsetLng : 0,
	
	// код взят из 
	// http://library.ucf.edu/Web/JS/Maps.js
	// в работе можно глянуть тут
	// http://library.ucf.edu/Administration/Maps/
	// страна должна знать героев в лицо
	fromLatLngToPoint : function(latLng, opt_point) {
		var point = opt_point || new google.maps.Point(0, 0);
		point.x = this.pixelOrigin.x + (latLng.lng() + this.offsetLng) * this.pixelsPerLonDegree * this.scaleLng;
		point.y = this.pixelOrigin.y + (-1 * latLng.lat() + this.offsetLat) * this.pixelsPerLonDegree * this.scaleLat;
		return point;
	},
	 
	fromPointToLatLng : function(point) {
		var lng = (point.x - this.pixelOrigin.x) / this.pixelsPerLonDegree / this.scaleLng - this.offsetLng,
			lat = -1 * (point.y - this.pixelOrigin.y) / this.pixelsPerLonDegree / this.scaleLat - this.offsetLat;
		return new google.maps.LatLng(lat , lng, true);
	}
};
