Advertisement
Guest User

Untitled

a guest
Dec 7th, 2010
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function YaZoomSlider(){
  2.     this.YSLIDERLENGTH = 60;
  3.     this.MAXZOOM = 17;
  4.    
  5.     this.onAddToMap = function (map, position){
  6.         var that=this;
  7.         this.map = map;
  8.         this.position = position || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(10, 10));
  9.        
  10.         this.container = document.createElement("div");
  11.         this.container.className = 'mg-map-plugin-scale';
  12.        
  13.         this.plusbtn = document.createElement("div");
  14.         this.plusbtn.className = 'mg-map-plugin-scale-plus';
  15.         this.plusbtn.onclick = function(){
  16.             that.map.setZoom(that.map.getZoom() + 1);
  17.         }
  18.         this.container.appendChild(this.plusbtn);
  19.        
  20.         this.knobcont = document.createElement("div");
  21.         this.knobcont.className = 'mg-map-plugin-scale-runnerPlace';
  22.         this.knobcont.id = 'ya-mg-map-plugin-scale-runnerPlace-id';
  23.         this.container.appendChild(this.knobcont);
  24.        
  25.         this.knob = document.createElement("div");
  26.         this.knob.className = 'mg-map-plugin-scale-runner';
  27.         this.knobcont.appendChild(this.knob);
  28.        
  29.         this.minusbtn = document.createElement("div");
  30.         this.minusbtn.className = 'mg-map-plugin-scale-minus';
  31.         this.minusbtn.onclick = function(){
  32.             that.map.setZoom(that.map.getZoom() - 1);
  33.         }
  34.         this.container.appendChild(this.minusbtn);
  35.        
  36.         this.position.apply(this.container);
  37.        
  38.         YMaps.Events.observe(map, map.Events.Update, function(a) {that.setSlider(a.getZoom())});
  39.        
  40.         this.setSlider(map.getZoom())
  41.        
  42.         jQuery(this.container).appendTo(this.map.getContainer());
  43.        
  44.         jQuery( this.knob ).draggable({ containment: jQuery("#ya-mg-map-plugin-scale-runnerPlace-id"), drag : function(event, ui){ that.setZoom(ui.position.top); } });
  45.     }
  46.    
  47.     this.onRemoveFromMap = function () {
  48.         this.container.remove();
  49.         this.container = this.map = null;
  50.     }
  51.    
  52.     this.setSlider = function(zoom) {
  53.         if(zoom > 0){
  54.             var top = (this.YSLIDERLENGTH) - Math.round((this.YSLIDERLENGTH/this.MAXZOOM*zoom));
  55.         } else {
  56.             var top = (this.YSLIDERLENGTH);
  57.         }
  58.         this.knob.style.top = top+"px";
  59.     }
  60.    
  61.     this.setZoom = function(top) {
  62.         var z=this.MAXZOOM - Math.round(top*this.MAXZOOM/this.YSLIDERLENGTH);
  63.         this.map.setZoom(z);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement