Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="cs">
  3. <head>
  4. <meta charset="UTF-8">
  5. <style>
  6. #map {
  7. height: 400px;
  8. width: 100%;
  9. }
  10.  
  11. </style>
  12.  
  13. </head>
  14.  
  15. <body>
  16. <div id="floating-panel">
  17. <input onclick="clearMarkers();" type=button value="Hide Markers">
  18. <input onclick="showMarkers();" type=button value="Show All Markers">
  19. <input onclick="deleteMarkers();" type=button value="Delete Markers">
  20. </div>
  21. <div id="map"></div>
  22. <p>Click on the map to add markers.</p>
  23. <script>
  24.  
  25. // In the following example, markers appear when the user clicks on the map.
  26. // The markers are stored in an array.
  27. // The user can then click an option to hide, show or delete the markers.
  28. var map;
  29. var markers = [];
  30. var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  31. var labelIndex = 0;
  32.  
  33.  
  34. function initMap() {
  35. var haightAshbury = {lat: 37.769, lng: -122.446};
  36.  
  37. map = new google.maps.Map(document.getElementById('map'), {
  38. zoom: 12,
  39. center: haightAshbury,
  40. mapTypeId: 'terrain'
  41. });
  42.  
  43. // This event listener will call addMarker() when the map is clicked.
  44. map.addListener('click', function(event) {
  45. addMarker(event.latLng);
  46. });
  47. }
  48.  
  49. // Adds a marker to the map and push to the array.
  50. function addMarker(location) {
  51. var marker = new google.maps.Marker({
  52. position: location,
  53. map: map,
  54. label: labels[labelIndex++ % labels.length]
  55. });
  56. markers.push(marker);
  57. }
  58.  
  59. marker.addListener('click', function() {
  60. var lable = prompt("Změňte popis.", "labelIndex");
  61.  
  62. });
  63. }
  64.  
  65. // Sets the map on all markers in the array.
  66. function setMapOnAll(map) {
  67. for (var i = 0; i < markers.length; i++) {
  68. markers[i].setMap(map);
  69. }
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. // Removes the markers from the map, but keeps them in the array.
  78. function clearMarkers() {
  79. setMapOnAll(null);
  80. }
  81.  
  82. // Shows any markers currently in the array.
  83. function showMarkers() {
  84. setMapOnAll(map);
  85. }
  86.  
  87. // Deletes all markers in the array by removing references to them.
  88. function deleteMarkers() {
  89. clearMarkers();
  90. markers = [];
  91. }
  92. </script>
  93. <script async defer
  94. src="https://maps.googleapis.com/maps/api/js?key= AIzaSyBTPNGyLAdaD6-kvTTjrUH7yjrwyzN_Z10 &region=CZ &language=cs-CZ &callback=initMap">
  95. </script>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement