Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.85 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. html,
  6. body {
  7. font-family: Arial, sans-serif;
  8. height: 100%;
  9. margin: 0;
  10. padding: 0;
  11. }
  12.  
  13. .container {
  14. height: 100%;
  15. position: relative;
  16. }
  17. input {
  18. font-size: 12px;
  19. }
  20. h1 {
  21. color: #525454;
  22. font-size: 22px;
  23. margin: 0 0 10px 0;
  24. text-align: center;
  25. }
  26. #hide-listings,
  27. #show-listings {
  28. width: 48%;
  29. }
  30.  
  31. #map {
  32. bottom:0px;
  33. height: 100%;
  34. left: 362px;
  35. position: absolute;
  36. right: 0px;
  37. }
  38.  
  39. .options-box {
  40. background: #fff;
  41. border: 1px solid #999;
  42. border-radius: 3px;
  43. height: 100%;
  44. line-height: 35px;
  45. padding: 10px 10px 30px 10px;
  46. text-align: left;
  47. width: 340px;
  48. }
  49.  
  50. #pano {
  51. width: 200px;
  52. height: 200px;
  53. }
  54.  
  55. .text {
  56. font-size: 12px;
  57. }
  58.  
  59. #zoom-to-area-text {
  60. position: relative;
  61. width: 70%;
  62. }
  63.  
  64. #zoom-to-area {
  65. width: 24%;
  66. }
  67.  
  68. </style>
  69. </head>
  70. <body>
  71. <div class="container">
  72. <div class="options-box">
  73. <h1>Find Your New NYC Home</h1>
  74. <div>
  75. <input id="show-listings" type="button" value="Show Listings">
  76. <input id="hide-listings" type="button" value="Hide Listings">
  77. </div>
  78. <div>
  79. <input id="zoom-to-area-text" type="text" placeholder="Enter your favourite area!">
  80. <input id="zoom-to-area" type="button" value="Zoom">
  81. </div>
  82. </div>
  83.  
  84. <div id="map"></div>
  85. </div>
  86. <script>
  87. var map;
  88.  
  89. // Create a new blank array for all the listing markers.
  90. var markers = [];
  91.  
  92. function initMap() {
  93. // Create a styles array to use with the map.
  94. var styles = [
  95. {
  96. featureType: 'water',
  97. stylers: [
  98. { color: '#19a0d8' }
  99. ]
  100. },{
  101. featureType: 'administrative',
  102. elementType: 'labels.text.stroke',
  103. stylers: [
  104. { color: '#ffffff' },
  105. { weight: 6 }
  106. ]
  107. },{
  108. featureType: 'administrative',
  109. elementType: 'labels.text.fill',
  110. stylers: [
  111. { color: '#e85113' }
  112. ]
  113. },{
  114. featureType: 'road.highway',
  115. elementType: 'geometry.stroke',
  116. stylers: [
  117. { color: '#efe9e4' },
  118. { lightness: -40 }
  119. ]
  120. },{
  121. featureType: 'transit.station',
  122. stylers: [
  123. { weight: 9 },
  124. { hue: '#e85113' }
  125. ]
  126. },{
  127. featureType: 'road.highway',
  128. elementType: 'labels.icon',
  129. stylers: [
  130. { visibility: 'off' }
  131. ]
  132. },{
  133. featureType: 'water',
  134. elementType: 'labels.text.stroke',
  135. stylers: [
  136. { lightness: 100 }
  137. ]
  138. },{
  139. featureType: 'water',
  140. elementType: 'labels.text.fill',
  141. stylers: [
  142. { lightness: -100 }
  143. ]
  144. },{
  145. featureType: 'poi',
  146. elementType: 'geometry',
  147. stylers: [
  148. { visibility: 'on' },
  149. { color: '#f0e4d3' }
  150. ]
  151. },{
  152. featureType: 'road.highway',
  153. elementType: 'geometry.fill',
  154. stylers: [
  155. { color: '#efe9e4' },
  156. { lightness: -25 }
  157. ]
  158. }
  159. ];
  160.  
  161. // Constructor creates a new map - only center and zoom are required.
  162. map = new google.maps.Map(document.getElementById('map'), {
  163. center: {lat: 40.7413549, lng: -73.9980244},
  164. zoom: 13,
  165. styles: styles,
  166. mapTypeControl: false
  167. });
  168.  
  169. var locations = [
  170. {title: 'Park Ave Penthouse', location: {lat: 40.7713024, lng: -73.9632393}},
  171. {title: 'Chelsea Loft', location: {lat: 40.7444883, lng: -73.9949465}},
  172. {title: 'Union Square Open Floor Plan', location: {lat: 40.7347062, lng: -73.9895759}},
  173. {title: 'East Village Hip Studio', location: {lat: 40.7281777, lng: -73.984377}},
  174. {title: 'TriBeCa Artsy Bachelor Pad', location: {lat: 40.7195264, lng: -74.0089934}},
  175. {title: 'Chinatown Homey Space', location: {lat: 40.7180628, lng: -73.9961237}}
  176. ];
  177.  
  178. var largeInfoWindow = new google.maps.InfoWindow();
  179.  
  180. var defaultIcon = makeMarkerIcon('0091ff');
  181.  
  182. var highlightedIcon = makeMarkerIcon('FFFF24');
  183.  
  184.  
  185. // The following group uses the location array to create an array of markers on initialize.
  186. for (var i = 0; i < locations.length; i++) {
  187. // Get the position from the location array.
  188. var position = locations[i].location;
  189. var title = locations[i].title;
  190. // Create a marker per location, and put into markers array.
  191. var marker = new google.maps.Marker({
  192. position: position,
  193. title: title,
  194. animation: google.maps.Animation.DROP,
  195. icon: defaultIcon,
  196. id: i
  197. });
  198. // Push the marker to our array of markers.
  199. markers.push(marker);
  200. // Create an onclick event to open an infowindow at each marker.
  201. marker.addListener('click', function() {
  202. populateInfoWindow(this, largeInfoWindow);
  203. });
  204. marker.addListener('mouseover', function() {
  205. this.setIcon(highlightedIcon);
  206.  
  207. });
  208. marker.addListener('mouseout', function() {
  209. this.setIcon(defaultIcon);
  210. });
  211. }
  212.  
  213. document.getElementById('show-listings').addEventListener('click', showListings);
  214. document.getElementById('hide-listings').addEventListener('click', hideListings);
  215.  
  216. document.getElementById('zoom-to-area').addEventListener('click', function() {
  217. zoomToArea();
  218. });
  219. }
  220. // This function populates the infowindow when the marker is clicked. We'll only allow
  221. // one infowindow which will open at the marker that is clicked, and populate based
  222. // on that markers position.
  223. function populateInfoWindow(marker, infowindow) {
  224. // Check to make sure the infowindow is not already opened on this marker.
  225. if (infowindow.marker != marker) {
  226. infowindow.marker = marker;
  227. infowindow.setContent('<div>' + marker.title + '</div>');
  228. infowindow.open(map, marker);
  229. // Make sure the marker property is cleared if the infowindow is closed.
  230. infowindow.addListener('closeclick', function(){
  231. infowindow.setMarker = null;
  232. });
  233. var streetViewService = new google.maps.StreetViewService();
  234. var radius = 50;
  235. // In case the status is OK, which means the pano was found, compute the
  236. // position of the streetview image, then calculate the heading, then get a
  237. // panorama from that and set the options
  238. function getStreetView(data, status) {
  239. if (status == google.maps.StreetViewStatus.OK) {
  240. var nearStreetViewLocation = data.location.latLng;
  241. var heading = google.maps.geometry.spherical.computeHeading(
  242. nearStreetViewLocation, marker.position);
  243. infowindow.setContent('<div>' + marker.title + '</div><div id="pano"></div>');
  244. var panoramaOptions = {
  245. position: nearStreetViewLocation,
  246. pov: {
  247. heading: heading,
  248. pitch: 30
  249. }
  250. };
  251. var panorama = new google.maps.StreetViewPanorama(
  252. document.getElementById('pano'), panoramaOptions);
  253. } else {
  254. infowindow.setContent('<div>' + marker.title + '</div>' +
  255. '<div>No Street View Found</div>');
  256. }
  257. }
  258. // Use streetview service to get the closest streetview image within
  259. // 50 meters of the markers position
  260. streetViewService.getPanoramaByLocation(marker.position, radius, getStreetView);
  261. infowindow.open(map, marker);
  262. }
  263. }
  264.  
  265. // This function will loop through the markers array and display them all.
  266. function showListings() {
  267. var bounds = new google.maps.LatLngBounds();
  268. // Extend the boundaries of the map for each marker and display the marker
  269. for (var i = 0; i < markers.length; i++) {
  270. markers[i].setMap(map);
  271. bounds.extend(markers[i].position);
  272. }
  273. map.fitBounds(bounds);
  274. }
  275.  
  276. // This function will loop through the listings and hide them all.
  277. function hideListings() {
  278. for (var i =0; i < markers.length; i++) {
  279. markers[i].setMap(null);
  280. }
  281. }
  282.  
  283. function makeMarkerIcon(markerColor) {
  284. var markerImage = new google.maps.MarkerImage(
  285. 'http://chart.googleapis.com/chart?chst=d_map_spin&chld=1.15|0|'+ markerColor +
  286. '|40|_|%E2%80%A2',
  287. new google.maps.Size(21, 34),
  288. new google.maps.Point(0, 0),
  289. new google.maps.Point(10, 34),
  290. new google.maps.Size(21, 34));
  291. return markerImage;
  292. }
  293.  
  294. // This function takes the input value in the find nearby area text input
  295. // locates it, and then zooms into that area. This is so that the user can
  296. // show all listings, then decide to focus on one area of the map.
  297. function zoomToArea() {
  298. var geocoder = new google.maps.Geocoder();
  299. var address = document.getElementById('zoom-to-area-text').value;
  300. if (address == '') {
  301. window.alert('You must enter an area, or address.');
  302. } else {
  303. // Geocode the address/area entered to get the center. Then, center the map
  304. // on it and zoom in
  305. geocoder.geocode(
  306. { address: address,
  307. componentRestrictions: {locality: 'New York'}
  308. }, function(results, status) {
  309. if (status == google.maps.GeocoderStatus.OK) {
  310. map.setCenter(results[0].geometry.location);
  311. map.setZoom(15);
  312. } else {
  313. window.alert('We could not find that location - try entering a more' + ' specific place.');
  314. }
  315.  
  316. });
  317. }
  318.  
  319. }
  320.  
  321.  
  322.  
  323. </script>
  324.  
  325. <script async defer
  326. src="https://maps.googleapis.com/maps/api/js?libraries=drawing,geometry&key=MYKEY=3&callback=initMap">
  327. </script>
  328.  
  329. </body>
  330. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement