Bez popisu

map-helper.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. "use strict"; // Start of use strict
  2. // 7. google map
  3. function gMap () {
  4. if ($('.google-map').length) {
  5. $('.google-map').each(function () {
  6. // getting options from html
  7. var Self = $(this);
  8. var mapName = Self.attr('id');
  9. var mapLat = Self.data('map-lat');
  10. var mapLng = Self.data('map-lng');
  11. var iconPath = Self.data('icon-path');
  12. var mapZoom = Self.data('map-zoom');
  13. var mapTitle = Self.data('map-title');
  14. var markers = Self.data('markers');
  15. // defined default style
  16. var styles = [
  17. {
  18. "featureType": "administrative",
  19. "elementType": "labels.text.fill",
  20. "stylers": [
  21. {
  22. "color": "#444444"
  23. }
  24. ]
  25. },
  26. {
  27. "featureType": "landscape",
  28. "elementType": "all",
  29. "stylers": [
  30. {
  31. "color": "#f2f2f2"
  32. }
  33. ]
  34. },
  35. {
  36. "featureType": "poi",
  37. "elementType": "all",
  38. "stylers": [
  39. {
  40. "visibility": "off"
  41. }
  42. ]
  43. },
  44. {
  45. "featureType": "road",
  46. "elementType": "all",
  47. "stylers": [
  48. {
  49. "saturation": -100
  50. },
  51. {
  52. "color": "#ffffff"
  53. },
  54. {
  55. "lightness": 45
  56. }
  57. ]
  58. },
  59. {
  60. "featureType": "road.highway",
  61. "elementType": "all",
  62. "stylers": [
  63. {
  64. "color": "#c1decd"
  65. },
  66. {
  67. "visibility": "simplified"
  68. }
  69. ]
  70. },
  71. {
  72. "featureType": "road.arterial",
  73. "elementType": "labels.icon",
  74. "stylers": [
  75. {
  76. "visibility": "off"
  77. }
  78. ]
  79. },
  80. {
  81. "featureType": "transit",
  82. "elementType": "all",
  83. "stylers": [
  84. {
  85. "visibility": "off"
  86. }
  87. ]
  88. },
  89. {
  90. "featureType": "water",
  91. "elementType": "all",
  92. "stylers": [
  93. {
  94. "color": "#c1decd"
  95. },
  96. {
  97. "visibility": "on"
  98. }
  99. ]
  100. }
  101. ];
  102. // if zoom not defined the zoom value will be 15;
  103. if (mapZoom) {
  104. var mapZoom = 8;
  105. };
  106. // init map
  107. var map;
  108. map = new GMaps({
  109. div: '#'+mapName,
  110. scrollwheel: false,
  111. lat: mapLat,
  112. lng: mapLng,
  113. styles: styles,
  114. zoom: mapZoom
  115. });
  116. // if icon path setted then show marker
  117. if(iconPath) {
  118. $.each(markers, function (index, value) {
  119. var index = value;
  120. var html;
  121. if (index[2]) {
  122. html = index[2];
  123. };
  124. if (!index[3]) {
  125. index[3] = iconPath;
  126. };
  127. map.addMarker({
  128. icon: index[3],
  129. lat: index[0],
  130. lng: index[1],
  131. infoWindow: {
  132. content: html
  133. }
  134. });
  135. });
  136. }
  137. });
  138. };
  139. }
  140. // instance of fuction while Document ready event
  141. jQuery(document).on('ready', function () {
  142. (function ($) {
  143. gMap();
  144. })(jQuery);
  145. });