marker.setPosition блокирует все события на карте - PullRequest
0 голосов
/ 31 августа 2018

спустя после маркер мой код:

var refreshMarkers = function (vehicules, mapMarkers, showVehiculeFct, map, registrationNbr) {
    return $q(function (resolve, reject) {
      try {
        if (mapMarkers) {
          for (var j = 0; j < $rootScope.vehicules.length; j++) {
            if (moment().diff(moment($rootScope.vehicules[j].date)) > 3600000 && $rootScope.vehicules[j].speed <= 30) {
              $rootScope.vehicules[j].speed = 0;
              $rootScope.vehicules[j].engine = 0;
            }
            var vehicule = $rootScope.vehicules[j];
            var marker = mapMarkers[vehicule.registrationNbr];
            var latLng = new google.maps.LatLng(
              vehicule.lat,
              vehicule.lng);
            if (map.getBounds().contains(marker.getPosition()) && !$rootScope.isCluster)
              marker.setMap(map);
            else if (!map.getBounds().contains(marker.getPosition()))
              marker.setMap(null);
            if (marker) {
              setMarkerStyle(vehicule, marker, rotationSetting(vehicule), map);
            }
            if (registrationNbr && registrationNbr === vehicule.registrationNbr) {
              if (marker) {
                marker.setPositionNotAnimated(latLng);
              }
            }
            else {
              if(marker)
              {
              //this is the line who bloque map zoom and move
                marker.setPosition(latLng);

              }
            }

          if (marker)
            if (marker.selected === true && !$rootScope.isSuivi) {
              map.panTo(latLng);
              $rootScope.suivreVehicule();
              if ($rootScope.markerListener[marker.customInfo]) {
                google.maps.event.removeListener($rootScope.markerListener[marker.customInfo]);
              }

              $rootScope.markerListener[marker.customInfo] = google.maps.event.addListener(marker, 'click', function () {
                showVehiculeFct(vehicule);
              });
              selectMarker(marker, map);
              hideLabels(mapMarkers);

              break;
            }
            else if (marker.selected === true && $rootScope.isSuivi) {
              var options = {
                timeout: 10000,
                enableHighAccuracy: true
              }
              $cordovaGeolocation.getCurrentPosition(options)
                .then(function (position) {
                  if ($rootScope.selectedMarkerListener) {
                    google.maps.event.removeListener($rootScope.selectedMarkerListener);
                  }
                  myPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                  $rootScope.myPositionMarker.setPositionNotAnimated(myPosition)
                  var start = myPosition;
                  var end = latLng;
                  var request = {
                    origin: start,
                    destination: end,
                    travelMode: google.maps.TravelMode.DRIVING
                  };
                  directionsService.route(request, function (result, status) {
                    if (status == google.maps.DirectionsStatus.OK) {
                      $scope.directionsDisplay.setDirections(result);

                      var service = new google.maps.DistanceMatrixService;
                      service.getDistanceMatrix({
                        origins: [start],
                        destinations: [end],
                        travelMode: google.maps.TravelMode.DRIVING,
                        unitSystem: google.maps.UnitSystem.METRIC,
                        avoidHighways: false,
                        avoidTolls: false
                      }, function (response, status) {
                        if (status !== google.maps.DistanceMatrixStatus.OK) {
                          alert('Error was: ' + status);
                        } else {
                          $scope.durationWithCar = response.rows[0].elements[0].duration.text;
                          $scope.distanceGoto = response.rows[0].elements[0].distance.text;
                        }
                      });
                      service.getDistanceMatrix({
                        origins: [start],
                        destinations: [end],
                        travelMode: google.maps.TravelMode.WALKING,
                        unitSystem: google.maps.UnitSystem.METRIC,
                        avoidHighways: false,
                        avoidTolls: false
                      }, function (response, status) {
                        if (status !== google.maps.DistanceMatrixStatus.OK) {
                          alert('Error was: ' + status);
                        } else {
                          $scope.durationByWalking = response.rows[0].elements[0].duration.text;
                        }
                      });
                    }
                    resolve('goto vehicule succ');
                  });
                }, function (err) {
                  reject('goto vehicule err');
                  console.log(err);
                });
            }
        }
      }
      resolve('markers actualisé');
    }
    catch
    (e)
    {
      console.log(e);
      //$rootScope.isConnected=false
      reject('probleme avec l\'actualisation des markers');
    }
  }
  );
}

введите описание изображения здесь

У меня есть changer marker.setPosition с marker.setAnimation, но та же проблема, но когда я делаю marker.setPositionNotAnimated, маркер перемещается не плавно, но я могу масштабировать и перемещать карту без каких-либо проблем, но я хочу плавно перемещать маркер и масштабировать или переместить карту одновременно.

...