map_app.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <title>GoogleMap-Based App</title>
  5. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
  6. <script src="https://maps.google.com/maps/api/js?sensor=false"></script>
  7. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.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/street_view.js"></script>
  17. <script src="../app/scripts/services/attr2_options.js"></script>
  18. <!-- endbuild -->
  19. <script src="scripts/markerclusterer.js"></script>
  20. <script>
  21. var app = angular.module('myApp', ['ngMap']);
  22. app.controller('mapController', function($scope, $http, StreetView) {
  23. $scope.map;
  24. $scope.stores = [];
  25. $scope.$on('mapInitialized', function(event, evtMap) {
  26. map = evtMap;
  27. $scope.map = map;
  28. console.log('loading scripts/starbucks.json');
  29. $http.get('scripts/starbucks.json').success( function(stores) {
  30. for (var i=0; i<stores.length; i++) {
  31. var store = stores[i];
  32. store.position = new google.maps.LatLng(store.latitude,store.longitude);
  33. store.title = store.name;
  34. var marker = new google.maps.Marker(store);
  35. google.maps.event.addListener(marker, 'click', function() {
  36. $scope.store = this;
  37. StreetView.getPanorama(map).then(function(panoId) {
  38. $scope.panoId = panoId;
  39. });
  40. map.setZoom(18);
  41. map.setCenter(this.getPosition());
  42. $scope.storeInfo.show();
  43. });
  44. google.maps.event.addListener(map, 'click', function() {
  45. $scope.storeInfo.hide();
  46. });
  47. $scope.stores.push(marker);
  48. }
  49. console.log('finished loading scripts/starbucks.json', '$scope.stores', $scope.stores.length);
  50. $scope.markerClusterer = new MarkerClusterer(map, $scope.stores, {});
  51. $scope.fullScreenToggle.click();
  52. });
  53. });
  54. $scope.showStreetView = function() {
  55. StreetView.setPanorama(map, $scope.panoId);
  56. $scope.storeInfo.hide();
  57. };
  58. $scope.showHybridView = function() {
  59. map.setMapTypeId(google.maps.MapTypeId.HYBRID);
  60. map.setTilt(45);
  61. $scope.storeInfo.hide();
  62. }
  63. });
  64. app.directive('fullScreenToggle', function() {
  65. return {
  66. link: function(scope, e, a) {
  67. this.click = function() {
  68. e.parent().toggleClass('full-screen');
  69. e.text( e.parent().hasClass('full-screen') ? 'Exit Full Screen' : 'Full Screen' );
  70. google.maps.event.trigger(scope.map, 'resize');
  71. };
  72. e.on('click', this.click);
  73. scope.fullScreenToggle = this;
  74. }
  75. }
  76. });
  77. app.directive('storeInfo', function() {
  78. var StoreInfo = function(s, e, a) {
  79. this.scope = s;
  80. this.element = e;
  81. this.attrs = a;
  82. this.show = function() {
  83. this.element.css('display', 'block');
  84. this.scope.$apply();
  85. }
  86. this.hide = function() {
  87. this.element.css('display', 'none');
  88. }
  89. };
  90. return {
  91. templateUrl: 'store-info.html',
  92. link: function(scope, e, a) {
  93. scope.storeInfo= new StoreInfo(scope, e, a);
  94. }
  95. }
  96. });
  97. </script>
  98. <style>
  99. html, body {width:100%; height: 100%; margin: 0}
  100. div#map-container {width: 600px; height: 400px; position: relative; color: rgb(86, 86, 86); font-family: Roboto, Arial, sans-serif; -webkit-user-select: none; font-size: 11px; }
  101. div#map-container div.custom-control { z-index: 1; direction: ltr; overflow: hidden; text-align: center; padding: 1px 6px; border-bottom-right-radius: 2px; border-top-right-radius: 2px; -webkit-background-clip: padding-box; border-width: 1px 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-top-color: rgba(0, 0, 0, 0.14902); border-right-color: rgba(0, 0, 0, 0.14902); border-bottom-color: rgba(0, 0, 0, 0.14902); -webkit-box-shadow: rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px; box-shadow: rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px; min-width: 41px; background-color: rgb(255, 255, 255); background-clip: padding-box; }
  102. div#map-container.full-screen {position:absolute; display:block; width:100%; height:100%; top: 0; left: 0}
  103. div#map-container div[full-screen-toggle] { cursor: pointer; position: absolute; top: 5px; right: 100px; }
  104. div#map-container div[store-info] { position: absolute; display: none; top: 5px; right: 5px; bottom: 5px; width: 40% }
  105. div#map-container div[store-info] a.hide-link { float:right }
  106. div#map-container div[store-info] table { width: 100% }
  107. div#map-container div[store-info] table td { text-align: left; padding: 5px; border: 1px solid #ccc }
  108. map {display:block; width:100%; height:100%;}
  109. </style>
  110. <script type="text/ng-template" id="store-info.html">
  111. <a class="hide-link" ng-click="storeInfo.hide()" href="">x</a>
  112. <h3> {{store.name}} </h3>
  113. <table>
  114. <tr>
  115. <td> Address </td>
  116. <td> {{store.street_combined}} <br/>
  117. {{store.city}} {{store.postal_code}} {{store.country}} <br/>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td> Coordinates </td>
  122. <td>
  123. Latitude: {{store.latitude}} <br/>
  124. Longitude: {{store.longitude}}
  125. </td>
  126. </tr>
  127. </table>
  128. <a ng-show="panoId" href="" ng-click="showStreetView()">Street View</a>
  129. <a href="" ng-click="showHybridView()">Satellite View</a>
  130. </script>
  131. </head>
  132. <body>
  133. <h1>GoogleMap-Based App</h1>
  134. <hr />
  135. <div id="map-container" ng-controller="mapController">
  136. <map zoom="2" center="[45.518970, -122.672899]"></map>
  137. <div full-screen-toggle class="custom-control">Full Screen</div>
  138. <div store-info class="custom-control">Store Info</div>
  139. </div>
  140. </body>
  141. </html>