Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

uiGmapIsReady work only once? #1224

Open
@Grandiz

Description

@Grandiz

Hi. I tryed to write directive for route direction.
I use directive on location /order/create/step1. When i went to another location, for example /order/create/step2 and back to the step1, it didn't show routes and didnts;t print console.log('uiGmapIsReady');

.directive('uiGmapRoutes', function(uiGmapIsReady, GoogleError){

    var directionsDisplay, directionsService;

    uiGmapIsReady.promise(1).then(function(instances) {
      console.log('uiGmapIsReady');
      directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers : true});
      directionsService = new google.maps.DirectionsService();
      directionsDisplay.setMap(instances[0].map);
    });


      return {
        scope: {
          points: '='
        },
        controller: function($scope){
          //watch when points changed
          $scope.$watchCollection('points', function(newPoints){
            if(_.size(newPoints) >= 2 && _.last(newPoints).coords){

              var request = {
                origin: new google.maps.LatLng(_.first(newPoints).coords.latitude, _.first(newPoints).coords.longitude),
                destination: new google.maps.LatLng(_.last(newPoints).coords.latitude, _.last(newPoints).coords.longitude),
                travelMode: google.maps.TravelMode.DRIVING
              };

              if(_.size(newPoints) > 2){
                request.waypoints = [];
                _.each(newPoints, function(point, index){
                  if(index != 0 && index < _.size(newPoints) - 1){
                    request.waypoints.push({
                      location: new google.maps.LatLng(point.coords.latitude, point.coords.longitude),
                      stopover:true
                    })
                  }
                });
              }

              directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                  directionsDisplay.setDirections(response);
                }else{
                  GoogleError.direction(status);
                }
              });
            }
          })
        }
      };
  })

and by the way, in this case

if (status == google.maps.DirectionsStatus.OK) {
                  directionsDisplay.setDirections(response);
                }

i print directionDisplay and reponse, and it wasn't empty

the same issue if open page on / and click on url with is reffer to /order/create/step1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions