API Docs for:
Show:

File: Inventory\ShowDealerMap.js

/**
* To Manage Fleet
* @module Inventory
*/



/**
* This class contains functions related to show device details and their state (Operational/Non-operational/Disabled/Archive/All")
* @class ShowDealerMap
* @constructor
*/


var ccplMap = null,
    geoCoder,
    defaultLat,
    defaultLng,
    marker;

var displayDisplay = "";        //route direction display
var routeDirectionsService = new google.maps.DirectionsService();           //direction google map api

//initialize markers
var sourceMarker = '../../Scripts/map_api/icons/red_s.png';                 //marker for source 
var destinationMarker = '../../Scripts/map_api/icons/red_d.png';            //marker for destination

var markers = [];      //array of source and destination markers

var vLatVal = "";
var vLongVal = "";

var marker1 = "";
//========================================== map functionality ============================================//

/**
* Load google map on page.
* @method initMap
* @param {String} id HTML element id where map is loaded.
* @for TicketAdministration
*/
//function initMap(id) {

//    var mapOptions = {
//        center: new google.maps.LatLng(vLatVal, vLongVal),
//        zoom: 12,
//        mapTypeId: google.maps.MapTypeId.ROADMAP
//    };

//    //initialize map
//    ccplMap = new google.maps.Map(document.getElementById(id), mapOptions);
//    var marker = new google.maps.Marker({
//        position: ccplMap.getCenter(),
//        map: ccplMap,
//        draggable: true,
//        title: 'Click to zoom'
//    });
//    var input = /** @type {HTMLInputElement} */(
//    document.getElementById('pac-input'));
//    ccplMap.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

//    var searchBox = new google.maps.places.SearchBox(
//      /** @type {HTMLInputElement} */(input));

//    google.maps.event.addListener(searchBox, 'places_changed', function () {
//        var places = searchBox.getPlaces();

//        if (places.length == 0) {
//            return;
//        }
//        for (var i = 0, marker; marker = markers[i]; i++) {
//            marker.setMap(null);
//        }

//        // For each place, get the icon, place name, and location.

//        var bounds = new google.maps.LatLngBounds();

//        google.maps.event.addListener(ccplMap, 'bounds_changed', function () {
//            var bounds = ccplMap.getBounds();
//            searchBox.setBounds(bounds);
//        });
//        ccplMap.fitBounds(bounds);
//        var mapOptions = {
//            center: bounds.getCenter(),
//            zoom: 12,
//            mapTypeId: google.maps.MapTypeId.ROADMAP
//        };

//        var input = /** @type {HTMLInputElement} */(
//        document.getElementById('pac-input'));
//        ccplMap.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
//        //initialize map
//        ccplMap = new google.maps.Map(document.getElementById("divMapContainer"), mapOptions);
//        marker = new google.maps.Marker({
//            position: ccplMap.getCenter(),
//            map: ccplMap,
//            draggable: true,
//            title: 'Click to zoom'
//        });
//        vLatVal = marker.position.lat();
//        vLongVal = marker.position.lng();
//    });

//    google.maps.event.addListener(ccplMap, 'click', function (e) {
//        window.setTimeout(function () {
//            vLatVal = e.latLng.lat();
//            vLongVal = e.latLng.lng();
//            ccplMap.panTo(marker.getPosition());
//        }, 3000);
//    });

//    google.maps.event.addListener(marker, 'dragend', function (e) {
//        vLatVal = e.latLng.lat();
//        vLongVal = e.latLng.lng();
//    });

//}

/** 
* This function is used to Get dealer Lat long and set it into Hidden field 
* @method initMap
* @param {String} id Id Of Map
* @for ShowDealerMap
*/
function initMap(id) {
    var markers = [];

    ccplMap = new google.maps.Map(document.getElementById(id), {
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        //center: new google.maps.LatLng(vLatVal, vLongVal),
        zoom: 12
    });
    SetDefaultLatAndLong();
   
   
   
    // Create the search box and link it to the UI element.
    //var input = /** @type {HTMLInputElement} */(
    //    document.getElementById('pac-input'));
    //ccplMap.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

    //var searchBox = new google.maps.places.SearchBox(
    //  /** @type {HTMLInputElement} */(input));

    // Listen for the event fired when the user selects an item from the
    // pick list. Retrieve the matching places for that item.
    //google.maps.event.addListener(searchBox, 'places_changed', function () {
    //    var places = searchBox.getPlaces();

    //    if (places.length == 0) {
    //        return;
    //    }
    //    for (var i = 0, marker; marker = markers[i]; i++) {
    //        marker.setMap(null);
    //    }

    //    // For each place, get the icon, place name, and location.
    //    markers = [];
    //    var bounds = new google.maps.LatLngBounds();
    //    for (var i = 0, place; place = places[i]; i++) {
    //        var image = {
    //            url: place.icon,
    //            size: new google.maps.Size(71, 71),
    //            origin: new google.maps.Point(0, 0),
    //            anchor: new google.maps.Point(17, 34),
    //            scaledSize: new google.maps.Size(25, 25)
    //        };

    //        // Create a marker for each place.
    //        var marker = new google.maps.Marker({
    //            map: ccplMap,
    //            icon: image,
    //            title: place.name,
    //            position: place.geometry.location,
    //            draggable: true,
    //        });
    //        vLatVal = marker.position.lat();
    //        vLongVal = marker.position.lng();
    //        markers.push(marker);
    //        bounds.extend(place.geometry.location);
    //    }
    //    console.log(bounds);
    //    var ccplMap = new google.maps.Map(document.getElementById(id), {
    //        mapTypeId: google.maps.MapTypeId.ROADMAP,
    //        center: new google.maps.LatLng(vLatVal, vLongVal),
    //        zoom: 12
    //    });
    //    ccplMap.fitBounds(bounds);
    //    var ccplMap = new google.maps.Map(document.getElementById(id), {
    //        mapTypeId: google.maps.MapTypeId.ROADMAP,
    //        center: new google.maps.LatLng(vLatVal, vLongVal),
    //        zoom: 12
    //    });
    //    var marker = new google.maps.Marker({
    //        position: ccplMap.getCenter(),
    //        map: ccplMap,
    //        draggable: true,
    //        title: 'Click to zoom'
    //    });
    //    //ccplMap.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
    //    google.maps.event.addListener(marker, 'dragend', function (e) {
    //        vLatVal = e.latLng.lat();
    //        vLongVal = e.latLng.lng();
    //    });
    //});


    // Bias the SearchBox results towards places that are within the bounds of the
    // current map's viewport.
    //google.maps.event.addListener(ccplMap, 'bounds_changed', function () {
    //    var bounds = ccplMap.getBounds();
    //    searchBox.setBounds(bounds);
    //    console.log(bounds);
    //});

}

/** 
* This function is used to Get dealer Lat long and set it into Hidden field 
* @method getDelearLatLong
* @for ShowDealerMap
*/
function getDelearLatLong() {
    $("#hdnDealerDefaultLatitude").val(vLatVal);
    $("#hdnDealerDefaultLongitude").val(vLongVal);
    closeWindow("#divShowDealerLocation");
}

//==================================== end map functionality =============================================//
$(document).ready(function () {
    setTimeout(function () {
        initMap("divMapContainer");

    }, 1000);
});

/** 
* This function set marker object and Add Dragend Event in Maps
* @method getSetMarker
* @for ShowDealerMap
*/
function SetDefaultLatAndLong() {
    var DealerState = $("#ddState option:selected").text();
    var DealerCity = $("#ddCity option:selected").val();
    var address = DealerState + "," + DealerCity;
    if ($("#hdnDealerDefaultLatitude").val() == "" || $("#hdnDealerDefaultLatitude").val() == "0") {
        setMapCenterToAddress(address);
    }
    else {
        vLatVal = $("#hdnDealerDefaultLatitude").val();
        vLongVal = $("#hdnDealerDefaultLongitude").val();
        var dealerLatLong = new google.maps.LatLng(vLatVal, vLongVal);
        ccplMap.setCenter(dealerLatLong);
        getSetMarker();
    }
}


/** 
* This function set center and zoom of map when state or city change
* @method setMapCenterToAddress
* @param {String} address address to show on map
* @for ShowDealerMap
*/
function setMapCenterToAddress(address) {
    geoCoder = new google.maps.Geocoder();
    geoCoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            ccplMap.setCenter(results[0].geometry.location);
            defaultLat = results[0].geometry.location.lat();
            defaultLng = results[0].geometry.location.lng();
            vLatVal = defaultLat;
            vLongVal = defaultLng;
            $("#hdnDealerDefaultLatitude").val(vLatVal);
            $("#hdnDealerDefaultLongitude").val(vLongVal);
            getSetMarker();
        }
    });

}

/** 
* This function set marker object and Add Dragend Event in Maps
* @method getSetMarker
* @for ShowDealerMap
*/
function getSetMarker() {
    marker = new google.maps.Marker({
        position: ccplMap.getCenter(),
        map: ccplMap,
        draggable: true,
        title: 'Click to zoom'
    });
    google.maps.event.addListener(marker, 'dragend', function (e) {
        vLatVal = e.latLng.lat();
        vLongVal = e.latLng.lng();
    });
}