Last active
February 12, 2021 14:13
-
-
Save iljya/e67a2a245c6968e685c11498a8361fe0 to your computer and use it in GitHub Desktop.
Mapserver ANCHORPOINTS with SVG symbols, SVG output - What's going on?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAP | |
NAME SVG_ICON_ANCHORPOINT_TEST | |
STATUS ON | |
SIZE 100 100 | |
EXTENT 0 0 0.001 0.001 | |
IMAGECOLOR 255 255 255 | |
IMAGETYPE svg | |
CONFIG "MS_ERRORFILE" "stderr" | |
SYMBOL | |
NAME "square_0_0" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 0 0 | |
END | |
SYMBOL | |
NAME "square_05_05" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 0.5 0.5 | |
END | |
SYMBOL | |
NAME "square_1_1" | |
TYPE svg | |
IMAGE "./square.svg" | |
ANCHORPOINT 1 1 | |
END | |
SYMBOL | |
NAME "DEBUG" | |
TYPE ellipse | |
FILLED true | |
POINTS | |
1 1 | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0004 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_0_0" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0005 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_05_05" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
LAYER | |
TYPE POINT | |
STATUS ON | |
FEATURE | |
POINTS | |
0.0006 0.0005 | |
END | |
TEXT "P" | |
END | |
CLASS | |
STYLE | |
SYMBOL "square_1_1" | |
END | |
STYLE | |
COLOR 255 0 0 | |
SYMBOL "DEBUG" | |
END | |
END | |
END | |
END |
I found the issue! The SVG symbol (square.svg) does not have a width/height set. If the width/height is set, the symbol is correctly anchored at the set anchorpoints.
The reason the results are so strange seems to be related to the fractional maxx/maxy set in the viewbox: they are apparently being cast to ints! I verified this by adding a print statement in mapcairo.c::msPreloadSVGSymbol() [0]:
rsvg_handle_get_dimensions_sub (cache->svgc, &dim, NULL);
symbol->sizex = dim.width;
symbol->sizey = dim.height;
fprintf( stderr, "width: %d height: %d\n", dim.width, dim.height);
The dimensions returned by rsvg_handle_get_dimensions_sub(...) are always ints [1].
[0] https://github.com/MapServer/MapServer/blob/main/mapcairo.c#L1000
[1] https://github.com/ImageMagick/librsvg/blob/main/rsvg-base.c#L1458
Thanks for all of this research. Added to docs as a note (MapServer/MapServer-documentation#446)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also doesn't work with 7.6.2.
MapServer version 7.6.2 OUTPUT=PNG OUTPUT=JPEG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WFS_SERVER SUPPORTS=WCS_SERVER SUPPORTS=FASTCGI SUPPORTS=GEOS SUPPORTS=POINT_Z_M INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE