function onLatLngChange(event, mapData) {
      if (!vm.map) {
        eventQ.unshift(mapData);
        return;
      }

      if (angular.isObject(mapData.locations) && Object.keys(mapData.locations).length === 0) {
        return;
      }


      if (mapData.clearMarkers) {
        Object.keys(markers).map(function (m) {
          markers[m].setMap(null);
          delete markers[m];
        });
      }

      var id, locations = {};
      for (id in mapData.locations) {
        var state = mapData.locations[id];
        locations[id] = {};
        locations[id].latLng = new google.maps.LatLng(state.lat, state.lng);
        locations[id].markerProperties = {
          position: locations[id].latLng,
          map: vm.map,
          label: state.label,
          icon: {
            labelOrigin: new google.maps.Point(60, 0)
          }
        };

        if (state.direction) {
          locations[id].markerProperties.icon = {
            path : google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
            scale: 4,
            rotation: state.direction,
            labelOrigin: new google.maps.Point(5, 5)
          };
        } else if (state.icon) {
          var icon = state.icon;
          icon.scaledSize = new google.maps.Size(35, 35);
          icon.labelOrigin =  new google.maps.Point(60, 0);
          angular.extend(locations[id].markerProperties.icon, icon);
        }
      }

      if (mapData.zoom) {
        vm.map.setZoom(mapData.zoom);
      }

      if (mapData.pan) {
        var k = Object.keys(locations)[0];
        vm.map.panTo(locations[k].latLng);
      }

      for (id in mapData.locations) {
        var currentLatLng = locations[id].latLng;
        var currentMarkerProperties = locations[id].markerProperties;
        var currentMarker = markers[id];

        if (!currentMarker) {
          markers[id] = new google.maps.Marker(currentMarkerProperties);
          markers[id].addListener('click', getMarkerOnClickHandler(mapData, mapData.locations[id]));
        } else {
          currentMarker.setPosition(currentLatLng);
          if (currentMarkerProperties && currentMarkerProperties.icon) {
            currentMarker.setIcon(currentMarkerProperties.icon);
          }
        }
      }
    }
/**
     * if lat-lng-change event broadcasted before map load, push event to eventQ
     */
if lat-lng-change event broadcasted before map load, push event to eventQ
if lat - lng - change event broadcasted before map load push event to eventQ
function onLatLngChange(event, mapData) {
      if (!vm.map) {
        eventQ.unshift(mapData);
        return;
      }
      if (angular.isObject(mapData.locations) && Object.keys(mapData.locations).length === 0) {
        return;
      }
      if (mapData.clearMarkers) {
        Object.keys(markers).map(function (m) {
          markers[m].setMap(null);
          delete markers[m];
        });
      }
      var id, locations = {};
      for (id in mapData.locations) {
        var state = mapData.locations[id];
        locations[id] = {};
        locations[id].latLng = new google.maps.LatLng(state.lat, state.lng);
        locations[id].markerProperties = {
          position: locations[id].latLng,
          map: vm.map,
          label: state.label,
          icon: {
            labelOrigin: new google.maps.Point(60, 0)
          }
        };
        if (state.direction) {
          locations[id].markerProperties.icon = {
            path : google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
            scale: 4,
            rotation: state.direction,
            labelOrigin: new google.maps.Point(5, 5)
          };
        } else if (state.icon) {
          var icon = state.icon;
          icon.scaledSize = new google.maps.Size(35, 35);
          icon.labelOrigin =  new google.maps.Point(60, 0);
          angular.extend(locations[id].markerProperties.icon, icon);
        }
      }
      if (mapData.zoom) {
        vm.map.setZoom(mapData.zoom);
      }
      if (mapData.pan) {
        var k = Object.keys(locations)[0];
        vm.map.panTo(locations[k].latLng);
      }
      for (id in mapData.locations) {
        var currentLatLng = locations[id].latLng;
        var currentMarkerProperties = locations[id].markerProperties;
        var currentMarker = markers[id];
        if (!currentMarker) {
          markers[id] = new google.maps.Marker(currentMarkerProperties);
          markers[id].addListener('click', getMarkerOnClickHandler(mapData, mapData.locations[id]));
        } else {
          currentMarker.setPosition(currentLatLng);
          if (currentMarkerProperties && currentMarkerProperties.icon) {
            currentMarker.setIcon(currentMarkerProperties.icon);
          }
        }
      }
    }
function onLatLngChange ( event , mapData ) { if ( ! vm . map ) { eventQ . unshift ( mapData ) ; return ; } if ( angular . isObject ( mapData . locations ) && Object . keys ( mapData . locations ) . length === 0 ) { return ; } if ( mapData . clearMarkers ) { Object . keys ( markers ) . map ( function ( m ) { markers [ m ] . setMap ( null ) ; delete markers [ m ] ; } ) ; } var id , locations = { } ; for ( id in mapData . locations ) { var state = mapData . locations [ id ] ; locations [ id ] = { } ; locations [ id ] . latLng = new google . maps . LatLng ( state . lat , state . lng ) ; locations [ id ] . markerProperties = { position : locations [ id ] . latLng , map : vm . map , label : state . label , icon : { labelOrigin : new google . maps . Point ( 60 , 0 ) } } ; if ( state . direction ) { locations [ id ] . markerProperties . icon = { path : google . maps . SymbolPath . FORWARD_CLOSED_ARROW , scale : 4 , rotation : state . direction , labelOrigin : new google . maps . Point ( 5 , 5 ) } ; } else if ( state . icon ) { var icon = state . icon ; icon . scaledSize = new google . maps . Size ( 35 , 35 ) ; icon . labelOrigin = new google . maps . Point ( 60 , 0 ) ; angular . extend ( locations [ id ] . markerProperties . icon , icon ) ; } } if ( mapData . zoom ) { vm . map . setZoom ( mapData . zoom ) ; } if ( mapData . pan ) { var k = Object . keys ( locations ) [ 0 ] ; vm . map . panTo ( locations [ k ] . latLng ) ; } for ( id in mapData . locations ) { var currentLatLng = locations [ id ] . latLng ; var currentMarkerProperties = locations [ id ] . markerProperties ; var currentMarker = markers [ id ] ; if ( ! currentMarker ) { markers [ id ] = new google . maps . Marker ( currentMarkerProperties ) ; markers [ id ] . addListener ( 'click' , getMarkerOnClickHandler ( mapData , mapData . locations [ id ] ) ) ; } else { currentMarker . setPosition ( currentLatLng ) ; if ( currentMarkerProperties && currentMarkerProperties . icon ) { currentMarker . setIcon ( currentMarkerProperties . icon ) ; } } } }
if lat-lng-change event broadcasted before map load, push event to eventQ
if lat - lng - change event broadcasted before map load push event to eventQ