map-custom-script.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // google map scripts
  2. var map;
  3. function initMap() {
  4. // Basic map
  5. map = new google.maps.Map(document.getElementById('simple-map'), {
  6. center: {
  7. lat: -34.397,
  8. lng: 150.644
  9. },
  10. zoom: 8
  11. });
  12. // marker map
  13. var myLatLng = {
  14. lat: -25.363,
  15. lng: 131.044
  16. };
  17. var map = new google.maps.Map(document.getElementById('marker-map'), {
  18. zoom: 4,
  19. center: myLatLng
  20. });
  21. var marker = new google.maps.Marker({
  22. position: myLatLng,
  23. map: map,
  24. title: 'Hello World!'
  25. });
  26. // overlays map
  27. var overlay;
  28. USGSOverlay.prototype = new google.maps.OverlayView();
  29. // Initialize the map and the custom overlay.
  30. function initMap() {
  31. var map = new google.maps.Map(document.getElementById('overlay-map'), {
  32. zoom: 11,
  33. center: {
  34. lat: 62.323907,
  35. lng: -150.109291
  36. },
  37. mapTypeId: 'satellite'
  38. });
  39. var bounds = new google.maps.LatLngBounds(new google.maps.LatLng(62.281819, -150.287132), new google.maps.LatLng(62.400471, -150.005608));
  40. // The photograph is courtesy of the U.S. Geological Survey.
  41. var srcImage = 'https://developers.google.com/maps/documentation/' + 'javascript/examples/full/images/talkeetna.png';
  42. // The custom USGSOverlay object contains the USGS image,
  43. // the bounds of the image, and a reference to the map.
  44. overlay = new USGSOverlay(bounds, srcImage, map);
  45. }
  46. /** @constructor */
  47. function USGSOverlay(bounds, image, map) {
  48. // Initialize all properties.
  49. this.bounds_ = bounds;
  50. this.image_ = image;
  51. this.map_ = map;
  52. // Define a property to hold the image's div. We'll
  53. // actually create this div upon receipt of the onAdd()
  54. // method so we'll leave it null for now.
  55. this.div_ = null;
  56. // Explicitly call setMap on this overlay.
  57. this.setMap(map);
  58. }
  59. /**
  60. * onAdd is called when the map's panes are ready and the overlay has been
  61. * added to the map.
  62. */
  63. USGSOverlay.prototype.onAdd = function () {
  64. var div = document.createElement('div');
  65. div.style.borderStyle = 'none';
  66. div.style.borderWidth = '0px';
  67. div.style.position = 'absolute';
  68. // Create the img element and attach it to the div.
  69. var img = document.createElement('img');
  70. img.src = this.image_;
  71. img.style.width = '100%';
  72. img.style.height = '100%';
  73. img.style.position = 'absolute';
  74. div.appendChild(img);
  75. this.div_ = div;
  76. // Add the element to the "overlayLayer" pane.
  77. var panes = this.getPanes();
  78. panes.overlayLayer.appendChild(div);
  79. };
  80. USGSOverlay.prototype.draw = function () {
  81. // We use the south-west and north-east
  82. // coordinates of the overlay to peg it to the correct position and size.
  83. // To do this, we need to retrieve the projection from the overlay.
  84. var overlayProjection = this.getProjection();
  85. // Retrieve the south-west and north-east coordinates of this overlay
  86. // in LatLngs and convert them to pixel coordinates.
  87. // We'll use these coordinates to resize the div.
  88. var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
  89. var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
  90. // Resize the image's div to fit the indicated dimensions.
  91. var div = this.div_;
  92. div.style.left = sw.x + 'px';
  93. div.style.top = ne.y + 'px';
  94. div.style.width = (ne.x - sw.x) + 'px';
  95. div.style.height = (sw.y - ne.y) + 'px';
  96. };
  97. // The onRemove() method will be called automatically from the API if
  98. // we ever set the overlay's map property to 'null'.
  99. USGSOverlay.prototype.onRemove = function () {
  100. this.div_.parentNode.removeChild(this.div_);
  101. this.div_ = null;
  102. };
  103. google.maps.event.addDomListener(window, 'load', initMap);
  104. // polygons
  105. var map = new google.maps.Map(document.getElementById('polygons-map'), {
  106. zoom: 5,
  107. center: {
  108. lat: 24.886,
  109. lng: -70.268
  110. },
  111. mapTypeId: 'terrain'
  112. });
  113. // Define the LatLng coordinates for the polygon's path.
  114. var triangleCoords = [{
  115. lat: 25.774,
  116. lng: -80.190
  117. }, {
  118. lat: 18.466,
  119. lng: -66.118
  120. }, {
  121. lat: 32.321,
  122. lng: -64.757
  123. }, {
  124. lat: 25.774,
  125. lng: -80.190
  126. }];
  127. // Construct the polygon.
  128. var bermudaTriangle = new google.maps.Polygon({
  129. paths: triangleCoords,
  130. strokeColor: '#FF0000',
  131. strokeOpacity: 0.8,
  132. strokeWeight: 2,
  133. fillColor: '#FF0000',
  134. fillOpacity: 0.35
  135. });
  136. bermudaTriangle.setMap(map);
  137. // Styles a map in night mode.
  138. var map = new google.maps.Map(document.getElementById('style-map'), {
  139. center: {
  140. lat: 40.674,
  141. lng: -73.945
  142. },
  143. zoom: 12,
  144. styles: [{
  145. elementType: 'geometry',
  146. stylers: [{
  147. color: '#242f3e'
  148. }]
  149. }, {
  150. elementType: 'labels.text.stroke',
  151. stylers: [{
  152. color: '#242f3e'
  153. }]
  154. }, {
  155. elementType: 'labels.text.fill',
  156. stylers: [{
  157. color: '#746855'
  158. }]
  159. }, {
  160. featureType: 'administrative.locality',
  161. elementType: 'labels.text.fill',
  162. stylers: [{
  163. color: '#d59563'
  164. }]
  165. }, {
  166. featureType: 'poi',
  167. elementType: 'labels.text.fill',
  168. stylers: [{
  169. color: '#d59563'
  170. }]
  171. }, {
  172. featureType: 'poi.park',
  173. elementType: 'geometry',
  174. stylers: [{
  175. color: '#263c3f'
  176. }]
  177. }, {
  178. featureType: 'poi.park',
  179. elementType: 'labels.text.fill',
  180. stylers: [{
  181. color: '#6b9a76'
  182. }]
  183. }, {
  184. featureType: 'road',
  185. elementType: 'geometry',
  186. stylers: [{
  187. color: '#38414e'
  188. }]
  189. }, {
  190. featureType: 'road',
  191. elementType: 'geometry.stroke',
  192. stylers: [{
  193. color: '#212a37'
  194. }]
  195. }, {
  196. featureType: 'road',
  197. elementType: 'labels.text.fill',
  198. stylers: [{
  199. color: '#9ca5b3'
  200. }]
  201. }, {
  202. featureType: 'road.highway',
  203. elementType: 'geometry',
  204. stylers: [{
  205. color: '#746855'
  206. }]
  207. }, {
  208. featureType: 'road.highway',
  209. elementType: 'geometry.stroke',
  210. stylers: [{
  211. color: '#1f2835'
  212. }]
  213. }, {
  214. featureType: 'road.highway',
  215. elementType: 'labels.text.fill',
  216. stylers: [{
  217. color: '#f3d19c'
  218. }]
  219. }, {
  220. featureType: 'transit',
  221. elementType: 'geometry',
  222. stylers: [{
  223. color: '#2f3948'
  224. }]
  225. }, {
  226. featureType: 'transit.station',
  227. elementType: 'labels.text.fill',
  228. stylers: [{
  229. color: '#d59563'
  230. }]
  231. }, {
  232. featureType: 'water',
  233. elementType: 'geometry',
  234. stylers: [{
  235. color: '#17263c'
  236. }]
  237. }, {
  238. featureType: 'water',
  239. elementType: 'labels.text.fill',
  240. stylers: [{
  241. color: '#515c6d'
  242. }]
  243. }, {
  244. featureType: 'water',
  245. elementType: 'labels.text.stroke',
  246. stylers: [{
  247. color: '#17263c'
  248. }]
  249. }]
  250. });
  251. }
  252. // routes map
  253. // style map