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. */
7 #jquery.mapquery.mqMousePosition.js
8 The file containing the mqMousePosition Widget
10 ### *$('selector')*.`mqMousePosition([options])`
12 ####**Description**: create a widget to show the location under the mouse pointer
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)
24 The mqMousePosition allows us to show the coordinates under the mouse pointer
27 $('#mousepointer').mqMousePointer({
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>');
40 $.widget("mapQuery.mqMousePosition", {
42 // The MapQuery instance
45 // The number of decimals for the coordinates
47 // TODO: JCB20110630 use dynamic precision based on the pixel
48 // resolution, no need to configure precision
51 // The label of the x-value
54 // The label of the y-value
62 var element = this.element;
65 //get the mapquery object
66 map = $(this.options.map).data('mapQuery');
69 {widget:self,map:map},
73 $.tmpl('mqMousePosition',{
74 mouseposition:mousepos
78 _destroy: function() {
79 this.element.removeClass(' ui-widget ui-helper-clearfix ' +
83 _mouseMoved: function(data, element, map) {
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;
94 new OpenLayers.Projection(mapProjection),
95 new OpenLayers.Projection(displayProjection));
97 $("#mq-mouseposition-x", element).html(
98 this.options.x+': '+pos.lon.toFixed(this.options.precision));
99 $("#mq-mouseposition-y", element).html(
100 this.options.y+': '+pos.lat.toFixed(this.options.precision));
103 _onMouseMove: function(evt, data) {
104 evt.data.widget._mouseMoved(data,evt.data.control,evt.data.map);