Opened 17 years ago

Last modified 15 years ago

#2468 assigned enhancement

Allow for specifying scalebar alignment (within the scalebar image)

Reported by: sdlime Owned by: sdlime
Priority: normal Milestone: 5.6 release
Component: MapServer C Library Version: svn-trunk (development)
Severity: minor Keywords: scalebar, align
Cc: dmorissette, assefa, jmckenna


Currently, MapServer scalebars are fit to a fixed with specified by the size parameter in the scalebar object. Depending on how the math works the scalebar won't always fit the width perfectly (this is most often the case) so the code centers the scalebar in the allotted space. This can leave a good deal of white space around the graphic that doesn't look great depending on the interface design. So, it would be desirable to be able to align the scalebar within the image (right, left or center=default).

This ticket tracks the addition of a ALIGN keyword to the scalebar object.


Attachments (1)

scalebar_align.png (4.8 KB ) - added by dmorissette 16 years ago.
Scalebar examples showing truncated 'km' label

Download all attachments as: .zip

Change History (11)

comment:1 by sdlime, 17 years ago

Status: newassigned


  • mapserver.h: add enum
  • mapfile.h: add ALIGN keyword
  • mapfile.c: add ALIGN to scalebar initialization, read and write routines
  • mapcopy.c: update scalebar copy function
  • mapscale.c: add switch statement (based on ALIGN) to set x offset value
  • maplexer.l: detect ALIGN keyword
  • php/MapScript: allow get/set ALIGN for a scalebar

Lot's of files but the changes are tiny in each.


comment:2 by sdlime, 17 years ago

Type: defectenhancement

Added base code to trunk, need to document and update php...


comment:3 by dmorissette, 17 years ago

Cc: dmorissette added

comment:4 by sdlime, 16 years ago

Documentation (by Jeff I think) and HISTORY.TXT have been updated. Just PHP remains.


comment:5 by sdlime, 16 years ago

Component: MapServer C LibraryMapScript-PHP

Changing component to PHP/MapScript. Should be a relatively easy addition.


comment:6 by dmorissette, 16 years ago

Cc: assefa added

Taking care of the PHP MapScript bits now.

comment:7 by dmorissette, 16 years ago

Cc: jmckenna added

I have committed the required changes for PHP MapScript in r7598 (trunk). Adding Jeff to CC since that includes an update to the PHP MapScript README.

In my testing I was never able to produce a scalebar with enough whitespace around it to justify this change. However I did notice that with MS_ALIGN_RIGHT the 'km' label in my scalebar is always truncated. I'll attach an image showing the problem. Here is my scalebar definition:

  IMAGECOLOR 150 150 150
    COLOR 0 0 0 
  SIZE 150 5
  COLOR 255 255 255
  UNITS kilometers

by dmorissette, 16 years ago

Attachment: scalebar_align.png added

Scalebar examples showing truncated 'km' label

comment:8 by sdlime, 16 years ago

Must be off by 1/2 a character or something like that. I typically use miles but have had no problem with the 'i' getting truncated. Will look...


comment:9 by sdlime, 16 years ago

Component: MapScript-PHPMapServer C Library
Milestone: 5.2 release5.4 release
Severity: normalminor

Will try to fix rounding problems in 5.4. Reclassifying as minor since this is a lightly used option...


comment:10 by sdlime, 15 years ago

Working on the alignment issue (I hope in time for 5.6). Problem is that the math used was based on a approximation of truetype font width per character and that's not precise enough. Solution is to use actual string sizes via the functions found in maplabel.c and not rely on the direct GD calls. This should allow for exact placement AND make this much easier to port to use the rendering API.


Note: See TracTickets for help on using tickets.