OpenLayers OpenLayers

Ticket #778 (closed feature: fixed)

Opened 1 year ago

Last modified 10 months ago

Give MousePointer some Display Options

Reported by: euzuro Assigned to:
Priority: minor Milestone: 2.6 Release
Component: Control.MousePosition Version: 2.4
Keywords: Cc: kleptog@gmail.com
State: Complete

Description

As from an email by Lance D. to the dev list (long long time ago):


formatCoords: function (base) {
           var t, t2;
          var degrees = Math.floor(base);
           var minutes = Math.floor(t = ( base - degrees ) * 60);
          var seconds = Math.floor(t2 = ( t - minutes ) * 6000);
           seconds = seconds / 100.00;
           return ("" + degrees + "\u00B0 " + minutes + "\u0027 " +
seconds + "\u0022" );

AND

   if (this.map.units == "degrees") {
         newHtml =  this.formatCoords(lonLat.lon)  + this.separator +
this.formatCoords(lonLat.lat);
       }
   else {
        var digits = parseInt(this.numdigits);
            newHtml =
           this.prefix +
           lonLat.lon.toFixed(digits) +
           this.separator +
           lonLat.lat.toFixed(digits) +
           this.suffix;
       }

As per comment by Jeff D., this should not be the default, but should be a configurable option.

A further idea presented by Lance is "detecting positives and negatives and prepending them as E,W or N,S"

Attachments

mp.patch (1.1 kB) - added by kleptog on 01/26/08 11:50:10.
Patch to seperate formatting out into a seperate overrideable function

Change History

10/10/07 01:01:02 changed by crschmidt

  • milestone set to Future.

I think that we need to consider this as a use case for allowing templating of this particular chunk of data using some templating language (optionally). Alternatively, just passing the data into a callback function and using the return from that rather than trying to implement a bunch of different options.

01/26/08 11:50:10 changed by kleptog

  • attachment mp.patch added.

Patch to seperate formatting out into a seperate overrideable function

01/26/08 11:53:33 changed by kleptog

  • cc set to kleptog@gmail.com.
  • state set to Review.
  • milestone changed from Future to 2.6 Release.

This patch moves the core formatting code of MousePosition into a seperate function called outputFormat. Users can then take the given lonLat (already projected) and format it any way they choose, including the zoom, bounds, number of digits, etc... The returned string is displayed as is.

Tests pass on FF

01/26/08 21:24:34 changed by crschmidt

  • state changed from Review to Commit.

This change:

  • Will not negatively affect users currently overriding the redraw function
  • Will not change any existing behavior
  • Is in the spirit of a comment I made months ago, which means there is at least some validity to it
  • Allows for the development of more complex 'current position' displays more easily
  • Does not require duplicating functional code in applications
  • Allows for easier application overrides

The combination of these features brings me to the conclusion that it is a useful feature to include.

The current tests for MousePosition ensure that this patch does not change any functional behavior (as does looking at the patch itself, which only rearranges things). I believe that this is acceptable for commit.

Martin, thanks again for the patch. It's possible that the contents of the formatOutput function may change in the future -- for example, to use a template, making it easier to override the output if your desired output format is trivial -- but for now, it should be enough to provide this functionality and see what the most commonly used changes are.

01/26/08 21:26:36 changed by crschmidt

  • status changed from new to closed.
  • state changed from Commit to Complete.
  • resolution set to fixed.

(In [5906]) Add a seperate method which actually does the formatting in the MousePosition control in order to allow easier changes in formatting at the application level (with less duplication of code). Patch from Kleptog, r=me. (Closes #778)