Skip to content

Instantly share code, notes, and snippets.

@iljya
Created February 17, 2021 18:57
Show Gist options
  • Save iljya/b1d58f250be11e8972ea6e5628f84b2a to your computer and use it in GitHub Desktop.
Save iljya/b1d58f250be11e8972ea6e5628f84b2a to your computer and use it in GitHub Desktop.
Mapserver: Symbol and Label collisions
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
MAP
NAME SYMBOL_LABEL_COLLISION_TEST
SIZE 500 500
EXTENT 0 0 1 1
IMAGECOLOR 255 255 255
IMAGETYPE svg
CONFIG "MS_ERRORFILE" "stderr"
SYMBOL
NAME "square_05_05"
TYPE svg
IMAGE "./square.svg"
ANCHORPOINT 0.5 0.5
END
LAYER
TYPE LINE
STATUS ON
FEATURE
POINTS
0 0
0.5 0.5
1 1
END
TEXT "HELLO"
END
CLASS
STYLE
COLOR 255 0 0
END
LABEL
COLOR 150 150 150
SIZE 50
ANGLE AUTO
POSITION CC
#FORCE TRUE
END
END
END
LAYER
TYPE POINT
STATUS ON
FEATURE
POINTS
0.25 0.25
END
END
CLASS
STYLE
SIZE 150
SYMBOL "square_05_05"
END
END
END
END
@iljya
Copy link
Author

iljya commented Feb 17, 2021

Here is the result of rendering this map file with:
shp2img -o ~/Desktop/collision.svg -m collision.map

collision

I expected to see the label in the top-right corner, avoiding the square symbol.

@LarsSchy
Copy link

LarsSchy commented Feb 18, 2021

I have modified your example a little bit.

I You add REPEATDISTANCE for the text and then a fake label with transparent text above the svg symbol
I think that You get something that is close to what you are looking for.

If You remove the last fake label block You get the old behavior that the text is written above the symbol.


`MAP
NAME SYMBOL_LABEL_COLLISION_TEST
SIZE 500 500
EXTENT 0 0 1 1
IMAGECOLOR 255 255 255

IMAGETYPE svg

CONFIG "MS_ERRORFILE" "stderr"

SYMBOL
NAME "square_05_05"
TYPE svg
IMAGE "./square.svg"
ANCHORPOINT 0.5 0.5
END

LAYER
TYPE LINE
STATUS ON
FEATURE
POINTS
0 0
0.5 0.5
1 1
END
TEXT "HELLO"
END
CLASS
STYLE
COLOR 255 0 0
END
LABEL
COLOR 150 150 150
SIZE 15
ANGLE FOLLOW
POSITION AUTO
REPEATDISTANCE 200
END
END
END

LAYER
TYPE POINT
STATUS ON
FEATURE
POINTS
0.5 0.5
END
END
CLASS
STYLE
SIZE 50
SYMBOL "square_05_05"
END
LABEL
TEXT "X"
COLOR "#00000000"
SIZE 8
POSITION CC
END
END
END

END
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment