﻿/// <reference path="OpenLayers/OpenLayers.js" />
/// <reference path="GbgMap.API.js" />


GbgMap.API.Actions = {

    map: GbgMap.API.getMapInstance(),

    zoomEndCallback: null,

    panRight: function () {

        map.pan(250, 0);
    },

    panLeft: function () {

        map.pan(-250, 0);
    },

    panUp: function () {

        map.pan(0, -250);
    },

    panDown: function () {

        map.pan(0, 250);
    },

    zoomIn: function () {

        map.zoomIn();
    },

    zoomOut: function () {

        map.zoomOut();
    },

    zoomTo: function (zoomLevel) {

        map.zoomTo(zoomLevel);
    },

    changeBackgroundTo: function (backgroundName) {
        
        var newBackgroundLayer = map.getLayersByName(backgroundName)[0];

        if (newBackgroundLayer != null)
            map.setBaseLayer(newBackgroundLayer);
    },

    onZoomEnd: function (callback) {

        //Ensure we set callback function only once
        if (!GbgMap.API.Actions.zoomEndCallback) {

            GbgMap.API.Actions.zoomEndCallback = callback;

            map.events.on({ "zoomend": GbgMap.API.Actions.zoomEndCallback });
        }
    }
}

