Permalink
Browse files

Add an offset to the scalebar

The scalebar is "stuck" to the edges of the map. This can make the
scalebar difficult to read when it is embedded in some mapping applications.

This PR adds the "OFFSET" key word to the scalebar object. The OFFSET X and Y
moves the scalebar away from the map a set number of pixels.
  • Loading branch information...
theduckylittle committed Oct 4, 2017
1 parent 69da69c commit a6d174902bff1aea11277eb7d8667470e6efe432
@@ -5536,6 +5536,8 @@ void initScalebar(scalebarObj *scalebar)
scalebar->interlace = MS_NOOVERRIDE;
scalebar->postlabelcache = MS_FALSE; /* draw with labels */
scalebar->align = MS_ALIGN_CENTER;
scalebar->offsetx = 0;
scalebar->offsety = 0;
}
void freeScalebar(scalebarObj *scalebar)
@@ -5603,6 +5605,10 @@ int loadScalebar(scalebarObj *scalebar)
case(UNITS):
if((scalebar->units = getSymbol(6, MS_INCHES,MS_FEET,MS_MILES,MS_METERS,MS_KILOMETERS,MS_NAUTICALMILES)) == -1) return(-1);
break;
case(OFFSET):
if(getInteger(&(scalebar->offsetx)) == -1) return(-1);
if(getInteger(&(scalebar->offsety)) == -1) return(-1);
break;
default:
if(strlen(msyystring_buffer) > 0) {
msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadScalebar()", msyystring_buffer, msyylineno);
@@ -428,28 +428,28 @@ int msEmbedScalebar(mapObj *map, imageObj *img)
switch(map->scalebar.position) {
case(MS_LL):
point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0) + map->scalebar.offsetx;
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0) - map->scalebar.offsety;
break;
case(MS_LR):
point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0) - map->scalebar.offsetx;
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0) - map->scalebar.offsety;
break;
case(MS_LC):
point.x = MS_NINT(map->width/2.0);
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = MS_NINT(map->width/2.0) + map->scalebar.offsetx;
point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0) - map->scalebar.offsety;
break;
case(MS_UR):
point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0) - map->scalebar.offsetx;
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0) + map->scalebar.offsety;
break;
case(MS_UL):
point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0) + map->scalebar.offsetx;
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0) + map->scalebar.offsety;
break;
case(MS_UC):
point.x = MS_NINT(map->width/2.0);
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
point.x = MS_NINT(map->width/2.0) + map->scalebar.offsetx;
point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0) + map->scalebar.offsety;
break;
}
@@ -1422,6 +1422,8 @@ typedef struct labelObj labelObj;
#endif /* not SWIG */
int postlabelcache;
int align;
int offsetx;
int offsety;
} scalebarObj;
/************************************************************************/
@@ -0,0 +1,42 @@
# RUN_PARMS: embed_sb_rgba_offset.png [SHP2IMG] -m [MAPFILE] -i png -o [RESULT]
# RUN_PARMS: embed_sb_rgba_offset.cairo.png [SHP2IMG] -m [MAPFILE] -i cairopng -o [RESULT]
#
#
# Test embedded scalebar with an offset.
#
# REQUIRES: OUTPUT=PNG
#
MAP
EXTENT -180 -90 180 90
SIZE 160 40
IMAGECOLOR 0 0 0
fontset "../misc/fonts.lst"
TRANSPARENT ON
IMAGETYPE png
SCALEBAR
TRANSPARENT OFF
LABEL
COLOR 0 0 0
size 9
type truetype
font "default"
END
SIZE 150 3
COLOR 0 0 0
BACKGROUNDCOLOR 255 255 255
OUTLINECOLOR 0 0 0
UNITS kilometers
INTERVALS 3
STATUS EMBED
OFFSET
5 5
END
END
END
Binary file not shown.
Binary file not shown.

0 comments on commit a6d1749

Please sign in to comment.