]> git.mxchange.org Git - friendica.git/blob - view/theme/diabook/js/jquery.mapquery.mqMousePosition.js
Merge remote-tracking branch 'upstream/master'
[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         //get the mapquery object
61         this.map = $(this.options.map).data('mapQuery');
62
63         this.map.element.bind('mousemove', {widget: this}, this._onMousemove);
64         $.tmpl('mqMousePosition', {}).appendTo(this.element);
65
66     },
67     _destroy: function() {
68         this.element.removeClass('ui-widget ui-helper-clearfix ' +
69                                  'ui-corner-all')
70             .empty();
71     },
72     _onMousemove: function(evt) {
73         var self = evt.data.widget;
74         var x = evt.pageX;
75         var y = evt.pageY;
76         var mapProjection = new OpenLayers.Projection(self.map.projection);
77         var displayProjection = new OpenLayers.Projection(
78             self.map.displayProjection);
79         var pos = self.map.olMap.getLonLatFromLayerPx(
80             new OpenLayers.Pixel(x, y));
81         //if the coordinates should be displayed in something else,
82         //set them via the map displayProjection option
83         if(!mapProjection.equals(self.map.displayProjection)) {
84             pos = pos.transform(mapProjection, displayProjection);
85         }
86         $("#id_diabook_ELPosX", document.element).val(
87             self.options.x + pos.lon.toFixed(self.options.precision));
88         $("#id_diabook_ELPosY", document.element).val(
89             self.options.y + pos.lat.toFixed(self.options.precision));
90     }
91 });
92 })(jQuery);