marker-animations-iteration.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  5. <script src="https://maps.google.com/maps/api/js?sensor=false"></script>
  6. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
  7. <script src="scripts/app.js"></script>
  8. <!-- build:js scripts/ng-map.min.js -->
  9. <script src="../app/scripts/app.js"></script>
  10. <script src="../app/scripts/directives/map_controller.js"></script>
  11. <script src="../app/scripts/directives/map.js"></script>
  12. <script src="../app/scripts/directives/marker.js"></script>
  13. <script src="../app/scripts/directives/shape.js"></script>
  14. <script src="../app/scripts/services/geo_coder.js"></script>
  15. <script src="../app/scripts/services/navigator_geolocation.js"></script>
  16. <script src="../app/scripts/services/attr2_options.js"></script>
  17. <!-- endbuild -->
  18. <script>
  19. var app = angular.module('myApp', ['ngMap']);
  20. app.controller('MarkerAnimationCtrl', function($scope, $timeout) {
  21. $scope.neighborhoods = [
  22. new google.maps.LatLng(52.511467, 13.447179),
  23. new google.maps.LatLng(52.549061, 13.422975),
  24. new google.maps.LatLng(52.497622, 13.396110),
  25. new google.maps.LatLng(52.517683, 13.394393)
  26. ];
  27. $scope.toggleBounce = function() {
  28. if (this.getAnimation() != null) {
  29. this.setAnimation(null);
  30. } else {
  31. this.setAnimation(google.maps.Animation.BOUNCE);
  32. }
  33. };
  34. var iterator=0;
  35. $scope.addMarker = function() {
  36. for (var i=0; i<$scope.neighborhoods.length; i++) {
  37. $timeout(function() {
  38. // add a marker this way does not sync. marker with <marker> tag
  39. new google.maps.Marker({
  40. position: $scope.neighborhoods[iterator++],
  41. map: $scope.map,
  42. draggable: false,
  43. animation: google.maps.Animation.DROP
  44. });
  45. }, i * 200);
  46. }
  47. }
  48. });
  49. </script>
  50. </head>
  51. <body>
  52. Marker animations with setTimeout()<br/>
  53. If you're adding a number of markers, you may want to
  54. drop them on the map consecutively rather than all at once.
  55. This example shows how to use setTimeout() to space
  56. your markers' animation.
  57. <style>
  58. div[ng-controller] {
  59. position: relative;
  60. }
  61. #panel {
  62. position: absolute;
  63. top: 10px;
  64. left: 50%;
  65. margin-left: -180px;
  66. z-index: 5;
  67. background-color: #fff;
  68. padding: 5px;
  69. border: 1px solid #999;
  70. }
  71. </style>
  72. <div ng-controller="MarkerAnimationCtrl">
  73. <div id="panel">
  74. <button id="drop" ng-click="addMarker()">Drop Markers</button>
  75. </div>
  76. <map center="52.520816, 13.410186" zoom="12">
  77. </map>
  78. </div>
  79. </body>
  80. </html>