]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/js/jquery.mapquery.mqMousePosition.js
diabook-themes: state of the boxes at right_aside are now stored in db, instead of...
[friendica.git] / view / theme / diabook / js / jquery.mapquery.mqMousePosition.js
1 /* Copyright (c) 2011 by MapQuery Contributors (see AUTHORS for
2  * full list of contributors). Published under the MIT license.
3  * See https://github.com/mapquery/mapquery/blob/master/LICENSE for the
4  * full text of the license. */
5
6 /**
7 #jquery.mapquery.mqMousePosition.js
8 The file containing the mqMousePosition Widget
9
10 ### *$('selector')*.`mqMousePosition([options])`
11 _version added 0.1_
12 ####**Description**: create a widget to show the location under the mouse pointer
13
14  + **options**
15   - **map**: the mapquery instance
16   - **precision**: the number of decimals (default 2)
17   - **x**: the label for the x-coordinate (default x)
18   - **y**: the label for the y-coordinate (default y)
19
20
21 >Returns: widget
22
23
24 The mqMousePosition allows us to show the coordinates under the mouse pointer
25
26
27      $('#mousepointer').mqMousePointer({
28         map: '#map'
29      });
30
31  */
32 (function($) {
33 $.template('mqMousePosition',
34     '<div class="mq-mouseposition ui-widget ui-helper-clearfix ">'+
35     '<span class="ui-widget-content ui-helper-clearfix ui-corner-all ui-corner-all">'+
36     '<div id="mq-mouseposition-x" class="mq-mouseposition-coordinate">'+
37     '</div><div id="mq-mouseposition-y" class="mq-mouseposition-coordinate">'+
38     '</div></div></span>');
39
40 $.widget("mapQuery.mqMousePosition", {
41     options: {
42         // The MapQuery instance
43         map: undefined,
44
45         // The number of decimals for the coordinates
46         // default: 2
47     // TODO: JCB20110630 use dynamic precision based on the pixel
48     // resolution, no need to configure precision
49         precision: 2,
50
51         // The label of the x-value
52         // default: 'x'
53         x: 'x',
54         // The label of the y-value
55         // default: 'y'
56         y: 'y'
57
58     },
59     _create: function() {
60         var map;
61         var self = this;
62         var element = this.element;
63         var mousepos;
64
65         //get the mapquery object
66         map = $(this.options.map).data('mapQuery');
67
68         map.bind("mousemove",
69             {widget:self,map:map},
70             self._onMouseMove);
71
72
73         $.tmpl('mqMousePosition',{
74             mouseposition:mousepos
75         }).appendTo(element);
76
77     },
78     _destroy: function() {
79         this.element.removeClass(' ui-widget ui-helper-clearfix ' +
80                                  'ui-corner-all')
81             .empty();
82     },
83     _mouseMoved: function(data, element, map) {
84         var x = data.layerX;
85         var y = data.layerY;
86         var mapProjection = map.options.projection;
87         var displayProjection = map.options.projection;
88         //if the coordinates should be displayed in something else,
89     //set them via the map displayProjection option
90         var pos = map.olMap.getLonLatFromLayerPx(new OpenLayers.Pixel(x,y));
91         if(map.options.displayProjection) {
92             displayProjection = map.options.displayProjection;
93             pos=pos.transform(
94         new OpenLayers.Projection(mapProjection),
95         new OpenLayers.Projection(displayProjection));
96         }
97         $("#id_diabook_ELPosX", element).val(
98         this.options.x+pos.lon.toFixed(this.options.precision));
99         $("#id_diabook_ELPosY", element).val(
100         this.options.y+pos.lat.toFixed(this.options.precision));
101     },
102
103     _onMouseMove: function(evt, data) {
104         evt.data.widget._mouseMoved(data,evt.data.control,evt.data.map);
105     }
106 });
107 })(jQuery);