All pastes #936658 Raw Edit

Unnamed

public javascript v1 · immutable
·published 2008-03-10 15:42 UTC
rendered paste body
var mapper=new Class({  Implements:[Events,Options],  options:{zoomLevel:12,mapControls:new GLargeMapControl(),addMapTypeControls:false,customIcon:new GIcon(G_DEFAULT_ICON),centerOnDefaultLocation:true,defaultLocationCoord:false,defaultLocationText:"Paris, France",tooltipClass:"map-tips",tooltipOpacity:0.8,clickableAfterExpand:false,markerPrefix:"/static/images/",markers:{bar:"map1-drink",restaurant:"map1-eat","bar-restaurant":"map1-eatdrink",select:"map1-select"},fixFloat:false},    initialize:function(B,A){        this.element=$(B);    this.addresses=[];    this.setOptions(A);    this.geocoder=new GClientGeocoder();    this.map=new GMap2(this.element);    this.map.addControl(this.options.mapControls);    this.markerOptions={icon:this.options.customIcon};        if(this.options.centerOnDefaultLocation){      if(!this.options.defaultLocationCoord){        this.geocoder.getLatLng(this.options.defaultLocationText,function(C){          if(!C){            //empty?          } else {            this.map.setCenter(C,this.options.zoomLevel)          }        }.bind(this))      } else {        this.map.setCenter(new GLatLng(this.options.defaultLocationCoord[0],this.options.defaultLocationCoord[1]),this.options.zoomLevel)      }    }        this.fireEvent("onInitialized")      },    addAddress:function(B){var A=this.addMarker(new GLatLng(B.lat,B.lng),B);A.markerType=B.type;if(window.ie){markerSuffix=".gif"}else{markerSuffix=".png"}if(B.type){A.defaultImage=this.options.markerPrefix+this.options.markers[B.type]+markerSuffix;A.selectImage=this.options.markerPrefix+this.options.markers.select+markerSuffix;A.setImage(A.defaultImage);A.select=function(C){C.setImage(C.selectImage);C.showTip()}.pass(A,this);A.unselect=function(C){C.setImage(C.defaultImage);C.hideTip()}.pass(A,this)}this.addresses.push($H(B).extend({marker:A}))  },    clearAddresses:function(){this.addresses.each(function(A){this.map.removeOverlay(A.marker)}.bind(this));this.addresses=[]},    addMarker:function(A,C){var B=new GMarker(A,this.markerOptions);this.map.addOverlay(B);this.initToolTip(B,C);return B},    initToolTip:function(A,B){        A.toolTip=new Element("div",{"class":this.options.tooltipClass,styles:{position:"absolute",bottom:"0",left:"0",visibility:"hidden",opacity:0}},document).inject(document.body);    A.toolTipWrapper=new Element("div").inject(A.toolTip);    A.toolTipEffect=new Fx.Styles(A.toolTip);    lastmarker=A;    A.linkUrl=B.link;        A.showTip=function(C){      tooltipSize=C.toolTip.getSize().size;      markerDomObject=$(C.am);      markerSize=markerDomObject.getSize().size;      markerPosition=markerDomObject.getPosition();      addX=0;      addY=0;            if(Browser.Engine.trident4){        addY+=document.getScroll().y      }            if(this.options.fixFloat&&window.ie){        addX=-40      }            C.toolTip.setStyles({        bottom:(document.window.getHeight()-markerPosition.y-markerSize.y+addY)+"px",        left:(markerPosition.x-tooltipSize.x+markerSize.x+addX)+"px"      });            C.toolTip.setHTML(this.formatTip(B));            moreinfo=C.toolTip.getElement("p.moreinfo");            C.slider=new Fx.Slide(moreinfo,{duration:500});      C.slider.hide();C.btnslider=new Fx.Slide(C.toolTip.getElement("p.seemore"),{duration:500});      C.toolTip.getElement("a.seemore").addEvent("click",function(D){        D.btnslider.slideOut("vertical");        D.slider.slideIn("vertical");                if(this.options.clickableAfterExpand){          targetElement=D.toolTip.getElement("p.moreinfo");          targetElement.setStyle("cursor","pointer");          targetElement.addEvent("click",function(E){            window.location.href=E          }.pass(D.linkUrl,this))        }              }.pass(C,this));            C.toolTipEffect.clearChain();      C.toolTip.setStyles({visibility:"visible"});      C.toolTipEffect.start({opacity:this.options.tooltipOpacity})}.bind(this,A);      A.hideTip=function(C){        C.toolTipEffect.start({opacity:0}).chain(function(D){          D.toolTip.setStyle("visibility","hidden")        }.pass(C,this))      }.pass(A,this);      $(A.Zk[0]).addEvent("mouseenter",A.showTip);      A.toolTip.addEvent("mouseleave",A.hideTip);  },    formatTip:function(A){    return'<h4><a href="'+A.link+'">'+A.label+'</a></h4><div class="tipcontent"><p class="moreinfo">'+A.address+'</p><p class="seemore"><a class="seemore">'+_("click to get more info >>")+"</a></p></div>";  },    getLatLngRange:function(){    bounds=this.map.getBounds();    sw=bounds.getSouthWest();    ne=bounds.getNorthEast();    range={lat:[sw.lat(),ne.lat()],lng:[sw.lng(),ne.lng()]};    return range  },    setCenter:function(B,A){    this.map.setCenter(new GLatLng(parseFloat(B),parseFloat(A)))  },    setZoom:function(A){    this.map.setZoom(A)  },    setCenterAndZoom:function(B,A,C){this.map.setCenter(new GLatLng(parseFloat(B),parseFloat(A)),C)  }  });  var parisEnviesMapper=mapper.extend({        initialize:function(B,A){      this.initIcons();      this.setOptions({        url:"/lieux/get_popular",        itemUrl:"/lieux/lieu/",        thumbUrl:"/lieux/lieu/thumbnail/40/",        customIcon:this.locIcon,        autoLoad:true,        clickableAfterExpand:true,        infoPane:false,        autoZoom:false      });            this.setOptions(A);            if(this.options.autoLoad){        this.addEvent("onInitialized",this.loadData.bind(this))      }            this.parent(B,this.options);    },            loadData:function(){        var A=new Request.JSON({url:this.options.url,method:"get",onComplete:function(B){this.jsonData=B;if(this.jsonData){this.addAddresses()}}.bind(this)}).send()      },            changeDataSet:function(B){        this.options.url=B;        var A=new Request.JSON({url:this.options.url,method:"get",onComplete:function(C){          this.jsonData=C;          if(this.jsonData){            this.clearAddresses();            if(this.jsonData.position){              this.setCenterAndZoom(this.jsonData.position.lat,this.jsonData.position.lng,this.jsonData.position.zoom_level)            }            this.addAddresses();            this.fireEvent("onMarkersReceived",10)          }        }.bind(this)}).send()      },            addAddresses:function(){        this.jsonData.lieux.each(function(E,F){          this.addAddress({            lat:E.lat,            lng:E.lng,            formated_address:E.adresse+"<br />"+E.codepostal+" "+E.nom_ville,            label:E.nom,            note:E.note,            number_reviews:E.nombre_avis,            link:this.options.itemUrl+E.slug,            thumbnail:this.options.thumbUrl+E.slug,            type:E.typelieu          })        },this);                if(this.options.autoZoom){          bounds=new GLatLngBounds();          this.addresses.each(function(E){            if(E.lat>0){              bounds.extend(new GLatLng(E.lat,E.lng))            }          });                    var A=bounds.getSouthWest();          var D=bounds.getNorthEast();          var C=D.lng()-A.lng();          var B=D.lat()-A.lat();          if(C>0&&B>0){            C*=0.05;            B*=0.05;            bounds=new GLatLngBounds(new GLatLng(A.lat()-B,A.lng()-C),new GLatLng(D.lat()+B,D.lng()+C))          }          zoom_level=this.map.getBoundsZoomLevel(bounds);          this.setCenterAndZoom(bounds.getCenter().lat(),bounds.getCenter().lng(),zoom_level)        }                if(this.jsonData.total!=undefined){          this.totalAddresses=this.jsonData.total        }      },            initIcons:function(){        var A=new GIcon();        A.iconSize=new GSize(30,30);        A.shadowSize=new GSize(0,0);        A.iconAnchor=new GPoint(1,27);        A.infoWindowAnchor=new GPoint(27,3);        A.infoShadowAnchor=new GPoint(1,27);                if(window.ie){          A.image="/static/images/map1-select.gif"        } else {          A.image="/static/images/map1-select.png"        }                this.locIcon=A      },            formatTip:function(A){        tipHTML='<h4><a href="'+A.link+'">'+A.label+'</a></h4><div class="tipcontent"><p class="moreinfo">';        if(A.thumbnail){          tipHTML+='<img src="'+A.thumbnail+'" />'        }        tipHTML+=A.formated_address+'<br /><img src="/static/images/star_small_black-'+Math.round(A.note)+'.gif" /> '+A.number_reviews+" "+_("Reviews.")+'</p><p class="seemore"><a class="seemore">'+_("click to get more info >>")+"</a></p></div>";        return tipHTML      }        });