-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.easymap.min.js
1 lines (1 loc) · 1.94 KB
/
jquery.easymap.min.js
1
(function(e){"use strict";function r(t,r){this.element=t;this.$element=e(this.element);this.options=r;this.metadata=this.$element.data("options");this.settings=e.extend({},n,this.options,this.metadata);this.map=null;this.init()}var t="easyMap",n={lat:1.276816,lng:103.848346,zoom:13,randomId:true,markerIcon:"",tooltip:false,styles:false};r.prototype={init:function(){var t=this;t.prepareHTML();if(typeof google!=="object"||typeof google.maps!=="object"){e.getScript(("https:"===document.location.protocol?"https:":"http:")+"//www.google.com/jsapi",function(){google.load("maps",3,{other_params:"sensor=false",callback:function(){t.render()}})})}else{t.render()}},prepareHTML:function(){if(this.settings.randomId){this.$element.attr("id",this.getRandomId())}if(this.$element.height()===0){this.$element.height("100%")}},render:function(){this.renderMap();this.enableTooltips();this.addMarker()},renderMap:function(){var t={zoom:this.settings.zoom,mapTypeId:google.maps.MapTypeId.ROADMAP,navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL},streetViewControl:false,mapTypeControl:false,scrollwheel:false,styles:this.settings.styles};this.mapLocation=new google.maps.LatLng(this.settings.lat,this.settings.lng);this.map=new google.maps.Map(document.getElementById(this.element.id),e.extend(t,{center:this.mapLocation}))},enableTooltips:function(){if(this.settings.tooltip){var e=this;this.infowindow=new google.maps.InfoWindow({content:e.settings.tooltip})}},addMarker:function(){this.marker=new google.maps.Marker({position:this.mapLocation,icon:this.settings.markerIcon,map:this.map});if(this.settings.tooltip){var e=this;google.maps.event.addListener(this.marker,"click",function(){e.infowindow.open(e.map,e.marker)})}},getRandomId:function(){var e=String.fromCharCode(65+Math.floor(Math.random()*26)),t=Date.now();return e+"-"+t}};e.fn[t]=function(n){return this.each(function(){if(!e.data(this,"plugin_"+t)){e.data(this,"plugin_"+t,new r(this,n))}})}})(jQuery)