| Current Path : /var/www/iplanru/data/www/i-plan.ru/media/zoo/elements/googlemaps/ |
| Current File : /var/www/iplanru/data/www/i-plan.ru/media/zoo/elements/googlemaps/googlemaps.js |
/* Copyright (C) YOOtheme GmbH, http://www.gnu.org/licenses/gpl.html GNU/GPL */
(function(t){var o=function(){};t.extend(o.prototype,{name:"Googlemaps",options:{lat:53.553407,lng:9.992196,marker:true,popup:false,text:"",zoom:13,mapCtrl:2,zoomWhl:true,mapType:0,typeCtrl:true,overviewCtrl:true,directions:true,directionsDestUpdate:false,directionsTravelMode:0,locale:"en",mainIcon:"red-dot",otherIcon:"blue-dot",iconUrl:"http://maps.google.com/mapfiles/ms/micons/",msgFromAddress:"From address: ",msgGetDirections:"Get directions",msgEmpty:"Please fill in your address.",msgNotFound:"Sorry, address not found!",msgAddressNotFound:", not found!"},initialize:function(o,e){this.options=t.extend({},this.options,e);this.container=o;this.setupMap();if(this.options.directions){this.setupDirections()}},setupMap:function(){this.map=new google.maps.Map(this.container.get(0),{mapTypeId:google.maps.MapTypeId.ROADMAP});this.map.setOptions({navigationControl:this.options.mapCtrl==1||this.options.mapCtrl==2?true:false});this.map.setOptions({navigationControlOptions:{style:this.options.mapCtrl==1?google.maps.NavigationControlStyle.SMALL:google.maps.NavigationControlStyle.DEFAULT}});this.map.setOptions({scrollwheel:this.options.zoomWhl?true:false});if(this.options.mapType==1)this.map.setOptions({mapTypeId:google.maps.MapTypeId.SATELLITE});if(this.options.mapType==2)this.map.setOptions({mapTypeId:google.maps.MapTypeId.HYBRID});if(this.options.mapType==3)this.map.setOptions({mapTypeId:google.maps.MapTypeId.TERRAIN});this.map.setOptions({mapTypeControl:this.options.typeCtrl?true:false});this.infowindow=new google.maps.InfoWindow;if(this.options.marker){this.addMarkerLatLng(this.options.lat,this.options.lng,this.options.text,true)}else{this.centerMap(this.options.lat,this.options.lng)}},createMarker:function(t,o,e){var i=this;var s=this.map;var n=this.infowindow;var a=new google.maps.MarkerImage(this.options.iconUrl+e+".png",new google.maps.Size(32,32),new google.maps.Point(0,0),new google.maps.Point(16,32));var p=e.match("pushpin")?this.options.iconUrl+"pushpin_shadow.png":this.options.iconUrl+"msmarker.shadow.png";var r=new google.maps.MarkerImage(p,new google.maps.Size(56,32),new google.maps.Point(0,0),new google.maps.Point(16,32));var l=new google.maps.Marker({position:t,icon:a,shadow:r,map:this.map});if(o||this.options.directionsDestUpdate){google.maps.event.addListener(l,"click",function(){if(o){n.setContent(o);n.open(s,l)}if(i.options.directionsDestUpdate){i.options.lat=l.getPosition().lat();i.options.lng=l.getPosition().lng()}})}return l},centerMap:function(t,o){var e=new google.maps.LatLng(t,o);this.map.setCenter(e);this.map.setZoom(this.options.zoom)},addMarkerLatLng:function(t,o,e,i){var s=this.options.otherIcon;if(i)s=this.options.mainIcon;var n=new google.maps.LatLng(t,o);var a=this.createMarker(n,e,s);if(i){this.map.setCenter(n);this.map.setZoom(this.options.zoom)}if(i&&e&&this.options.popup){this.infowindow.setContent(e);this.infowindow.open(this.map,a)}},setupDirections:function(){var o=this;this.directionsService=new google.maps.DirectionsService;this.directionsDisplay=new google.maps.DirectionsRenderer;this.directionsDisplay.setMap(this.map);this.directionsDisplay.setPanel(t("<div>").addClass("directions").css("position","relative").insertAfter(this.container).get(0));var e=t("<p>").append('<label for="from-address">'+this.options.msgFromAddress+"</label>").append('<input type="text" name="address" style="margin:0 5px;" />').append('<button type="submit">'+this.options.msgGetDirections+"</button>");t('<form method="get" action="#"></form>').append(e).insertAfter(this.container).bind("submit",function(e){e.preventDefault();e.stopPropagation();o.setDirections(t(this))})},setDirections:function(t){var o=this;this.container.parent().find("div.alert").remove();var e=t.find('input[name="address"]').val();if(e===""){this.showAlert(this.options.msgEmpty)}else{var i={origin:e,destination:new google.maps.LatLng(this.options.lat,this.options.lng),travelMode:google.maps.DirectionsTravelMode.DRIVING,region:this.options.locale};this.directionsService.route(i,function(t,e){if(e==google.maps.DirectionsStatus.OK){o.directionsDisplay.setDirections(t)}else{o.showAlert(o.options.msgNotFound)}})}},showAlert:function(o){t("<div>").addClass("alert").append(t("<strong>").text(o)).insertAfter(this.container)},refresh:function(){google.maps.event.trigger(this.map,"resize");this.centerMap(this.options.lat,this.options.lng)}});t.fn[o.prototype.name]=function(){var e=arguments;var i=e[0]?e[0]:null;return this.each(function(){var s=t(this);if(o.prototype[i]&&s.data(o.prototype.name)&&i!="initialize"){s.data(o.prototype.name)[i].apply(s.data(o.prototype.name),Array.prototype.slice.call(e,1))}else if(!i||t.isPlainObject(i)){var n=new o;if(o.prototype["initialize"]){n.initialize.apply(n,t.merge([s],e))}s.data(o.prototype.name,n)}else{t.error("Method "+i+" does not exist on jQuery."+o.name)}})}})(jQuery);