map-helper.js 4.4 KB

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