﻿
function gvConvertGMapZoomToGVZoom(zoom)
{
		// We map GV zoom levels to farthest out zoom levels for GMaps, as the Zoom control will then
		// remove ticks for any zoom levels higher than we allow. (We map it in this way because it doesn't
		// do the same for zoom levels lower than we allow).
		return (gvMinZoomLevel + 1) - zoom;
}

function gvConvertGVZoomToGMapZoom(zoom)
{
		// We map GV zoom levels to farthest out zoom levels for GMaps, as the Zoom control will then
		// remove ticks for any zoom levels higher than we allow. (We map it in this way because it doesn't
		// do the same for zoom levels lower than we allow).
		return (gvMinZoomLevel + 1) - zoom;
}

GVMap.prototype.zoomIn = function()
{
		if (this.GMap != null)
		{
				if (this.options && this.options.zoomMax)
				{
						// Client specified zoom limit, so enforce it
						if (this.getCurrentZoomLevel() <= this.options.zoomMax)
								return;
				}
				
				// Ok to zoom in
				this.GMap.zoomIn();
		}
}

GVMap.prototype.zoomOut = function()
{
		if (this.GMap != null)
		{                           
				if (this.options && this.options.zoomMin)
				{
						// Client specified zoom limit, so enforce it
						if (this.getCurrentZoomLevel() >= this.options.zoomMin)
								return;
				}
				
				this.GMap.zoomOut();
		}
}

GVMap.prototype.getCurrentZoomLevel = function()
{
		if (this.GMap != null)
		{                           
				return gvConvertGMapZoomToGVZoom(this.GMap.getZoom());
		}
}

GVMap.prototype._forceZoomToLimits = function(zoom)
{
		// Enforce zoom limits specified by client
		if (this.options && this.options.zoomMax)
		{
				if (zoom < this.options.zoomMax)
						zoom = this.options.zoomMax;
		}
		
		if (this.options && this.options.zoomMin)
		{
				if (zoom > this.options.zoomMin)
						zoom = this.options.zoomMin;
		}
		
		return zoom;
}

GVMap.prototype.setCurrentZoomLevel = function(zoom)
{
		if (this.GMap != null)
		{                           
				// Enforce zoom limits specified by client
				zoom = this._forceZoomToLimits(zoom);
				
				this.GMap.setZoom(gvConvertGVZoomToGMapZoom(zoom));
		}
}
