aboutsummaryrefslogtreecommitdiffstats
path: root/view/theme/diabook/js/jquery.mapquery.mqZoomSlider.js
blob: ebdce3bf34be4d25bce79a4df631d0b7a1c665ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
 * full list of contributors). Published under the MIT license.
 * See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
 * full text of the license. */


/**
#jquery.mapquery.mqZoomSlider.js
The file containing the mqZoomSlider Widget

### *$('selector')*.`mqZoomSlider([options])`
_version added 0.1_
####**Description**: create a widget to show a zoom slider

 + **options**:
  - **map**: the mapquery instance

>Returns: widget


The mqZoomSlider widget allows us to display a vertical zoom slider.


     $('#zoomslider').mqZoomSlider({
        map: '#map'
     });

 */
(function($) {
$.template('mqZoomSlider',
    '<div class="mq-zoomslider ui-widget ui-helper-clearfix ">'+
    '<div class="mq-zoomslider-slider"></div>'+
    '</div>');

$.widget("mapQuery.mqZoomSlider", {
    options: {
        // The MapQuery instance
        map: undefined

    },
    _create: function() {
        var map;
        var zoom;
        var numzoomlevels;
        var self = this;
        var element = this.element;

        //get the mapquery object
        map = $(this.options.map).data('mapQuery');

        $.tmpl('mqZoomSlider').appendTo(element);

        numzoomlevels = map.options.numZoomLevels;
        $(".mq-zoomslider-slider", element).slider({
           max: numzoomlevels,
           min:2,
           orientation: 'vertical',
           step: 1,
           value: numzoomlevels - map.center().zoom,
           slide: function(event, ui) {
               map.center({zoom:numzoomlevels-ui.value});
           },
           change: function(event, ui) {
               map.center({zoom:numzoomlevels-ui.value});
           }
       });
       map.bind("zoomend",
            {widget:self,map:map,control:element},
            self._onZoomEnd);

    },
    _destroy: function() {
        this.element.removeClass(' ui-widget ui-helper-clearfix ' +
                                 'ui-corner-all')
            .empty();
    },
    _zoomEnd: function (element,map) {
        var slider = element.find('.mq-zoomslider-slider');
        slider.slider('value',map.options.numZoomLevels-map.center().zoom);
    },
    _onZoomEnd: function(evt) {
        evt.data.widget._zoomEnd(evt.data.control,evt.data.map);
    }
});
})(jQuery);