﻿/* Map Controller which contains the map view */

com.timmons.srl.mapManager = function() {

    //Declare private properties here
    var _mapView;
    //var _mapViewType; //20090915 nvs
    var _configurationSettings = null;

    // Private Methods here

    var _initialize = function(configurationSettings) {

        _configurationSettings = configurationSettings;

        //_mapViewType = defaultMapSettings.MapSource; //20090915 nvs

        // Need to change to support other base map types
        //if (_mapViewType == "Google") { //20090915 nvs
        if (_configurationSettings.apiType == com.timmons.srl.configManager.apiType.Google) {

            _mapView = new com.timmons.srl.googleMap();
            //_mapView.initialize("srlRequestMap", defaultMapSettings); //20090915 nvs
            _mapView.initialize("srlRequestMap", _configurationSettings);

            //} else if (_mapViewType == "ESRI") {
        } else if (_configurationSettings.apiType == com.timmons.srl.configManager.apiType.ESRI) {

            _mapView = new com.timmons.srl.esriJsMap();
            //_mapView.initialize("srlRequestMap", defaultMapSettings); //20090915 nvs
            _mapView.initialize("srlRequestMap", _configurationSettings);

        } else { }

    };

    return {
        //Declare public properties here
        //Declare public methods here
        initialize: function(configurationSettings) {

            _initialize(configurationSettings);
        },
        refreshMap: function() {

            _mapView.refreshMap();
        },
        getMapViewType: function() {

            //return _mapViewType; //20090915 nvs
            return _configurationSettings.apiType;
        },
        findAddress: function(address, cityStateList, obj, callback) {

            _mapView.geocodeAddress(address, cityStateList, obj, callback);
        },
        enableMapClickLocation: function(cityStateList, obj, callback) {

            // For now this will only be implemented for google map api
            if (_configurationSettings.apiType == com.timmons.srl.configManager.apiType.Google) {

                _mapView.enableMapClickLocation(cityStateList, obj, callback);
            }
        },
        setMainMarkerRequestType: function(requestType) {

            // For now this will only be implemented for google map api
            if (_configurationSettings.apiType == com.timmons.srl.configManager.apiType.Google) {

                _mapView.setMainMarkerRequestType(requestType);
            }
        },
        addMarkers: function(markersJson) {

            _mapView.addMarkers(markersJson);
        },
        getAddress: function() {

            return _mapView.getAddress();
        },
        displayMap: function(obj, callback) {

            if (!_mapView.isMapCreated()) _mapView.createMap(obj, callback);
            else _mapView.refreshMap();
        },
        isMapClear: function() {

            return !_mapView.hasMarkers();
        },
        clear: function() {
            _mapView.clear();
        }
    };
};
