Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function YaZoomSlider(){
- this.YSLIDERLENGTH = 60;
- this.MAXZOOM = 17;
- this.onAddToMap = function (map, position){
- var that=this;
- this.map = map;
- this.position = position || new YMaps.ControlPosition(YMaps.ControlPosition.TOP_RIGHT, new YMaps.Size(10, 10));
- this.container = document.createElement("div");
- this.container.className = 'mg-map-plugin-scale';
- this.plusbtn = document.createElement("div");
- this.plusbtn.className = 'mg-map-plugin-scale-plus';
- this.plusbtn.onclick = function(){
- that.map.setZoom(that.map.getZoom() + 1);
- }
- this.container.appendChild(this.plusbtn);
- this.knobcont = document.createElement("div");
- this.knobcont.className = 'mg-map-plugin-scale-runnerPlace';
- this.knobcont.id = 'ya-mg-map-plugin-scale-runnerPlace-id';
- this.container.appendChild(this.knobcont);
- this.knob = document.createElement("div");
- this.knob.className = 'mg-map-plugin-scale-runner';
- this.knobcont.appendChild(this.knob);
- this.minusbtn = document.createElement("div");
- this.minusbtn.className = 'mg-map-plugin-scale-minus';
- this.minusbtn.onclick = function(){
- that.map.setZoom(that.map.getZoom() - 1);
- }
- this.container.appendChild(this.minusbtn);
- this.position.apply(this.container);
- YMaps.Events.observe(map, map.Events.Update, function(a) {that.setSlider(a.getZoom())});
- this.setSlider(map.getZoom())
- jQuery(this.container).appendTo(this.map.getContainer());
- jQuery( this.knob ).draggable({ containment: jQuery("#ya-mg-map-plugin-scale-runnerPlace-id"), drag : function(event, ui){ that.setZoom(ui.position.top); } });
- }
- this.onRemoveFromMap = function () {
- this.container.remove();
- this.container = this.map = null;
- }
- this.setSlider = function(zoom) {
- if(zoom > 0){
- var top = (this.YSLIDERLENGTH) - Math.round((this.YSLIDERLENGTH/this.MAXZOOM*zoom));
- } else {
- var top = (this.YSLIDERLENGTH);
- }
- this.knob.style.top = top+"px";
- }
- this.setZoom = function(top) {
- var z=this.MAXZOOM - Math.round(top*this.MAXZOOM/this.YSLIDERLENGTH);
- this.map.setZoom(z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement