prettymaps.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * prettyMaps 1.0.0
  3. *
  4. * Copyright 2014, Jean-Marc Goefpert - http://omgogepfert.com
  5. * Released under the WTFPL license - http://www.wtfpl.net/
  6. *
  7. * Date: Sun Jan 12 18:00:00 2014 -0500
  8. */
  9. (function($) {
  10. function prettyMaps(el, options) {
  11. options = options || {};
  12. this.defaults = {
  13. address: 'Melbourne, Australia',
  14. zoom: 13,
  15. panControl: false,
  16. zoomControl: false,
  17. mapTypeControl: false,
  18. scaleControl: false,
  19. streetViewControl: false,
  20. overviewMapControl: false,
  21. scrollwheel: true,
  22. image: '',
  23. styles: [
  24. {
  25. stylers: [
  26. { hue: options.hue },
  27. { saturation: options.saturation },
  28. { lightness: options.lightness }
  29. ]
  30. }
  31. ]
  32. };
  33. this.options = $.extend({}, this.defaults, options);
  34. this.$el = $(el);
  35. }
  36. prettyMaps.prototype = {
  37. init: function() {
  38. var that = this,
  39. geocoder = new google.maps.Geocoder();
  40. geocoder.geocode({
  41. 'address': this.options.address
  42. }, function(results, status) {
  43. if ( status === google.maps.GeocoderStatus.OK ) {
  44. var map = that.drawMap(results),
  45. marker = that.placeMarker(map, results);
  46. }
  47. });
  48. },
  49. drawMap: function(results) {
  50. var mapDetails = { center: results[0].geometry.location },
  51. finalOptions = $.extend({}, this.options, mapDetails),
  52. map = new google.maps.Map(this.$el[0], finalOptions);
  53. return map;
  54. },
  55. placeMarker: function(map, results) {
  56. var marker = new google.maps.Marker({
  57. map: map,
  58. position: results[0].geometry.location,
  59. icon: this.options.image,
  60. animation: google.maps.Animation.DROP
  61. });
  62. }
  63. };
  64. $.fn.prettyMaps = function(options) {
  65. if ( this.length ) {
  66. this.each(function() {
  67. var rev = new prettyMaps(this, options);
  68. rev.init();
  69. $(this).data('prettyMaps', rev);
  70. });
  71. }
  72. };
  73. })(jQuery);