0

In this question I was able to align some labels with polylines representing hectometer points along a railroad. I did this using custom expressions in the "data defined" portion of the labelling tab in the layer properties:

enter image description here

The problem now is that the label spacing with respect to the line end points is zoom dependent. Here's a zoomed in portion of the map:

enter image description here

Here's the same portion of the map, zoomed out:

enter image description here

This is kind of a problem when it comes to making layouts, as usually you want to have separate layouts coming from the same canvas to have slightly different zoom labels but to be consistent when it comes to symbology.

Perhaps one way to overcome this issue is by specifying canvas units for the offset rather than map units in the X and Y portions of the data defined section in the Layer Properties Dialog:

X: x(end_point($geometry))+5*canvas_units
Y: y(end_point($geometry))+3*canvas_units

But I'm not sure whether this is possible. If anyone has any idea how to do this please let me know. Thanks.

user32882
  • 3,514
  • 2
  • 31
  • 67

1 Answers1

2

you could use the "@map_scale" variable in your expression like : x(end_point($geometry))+(0.005*@map_scale) (adjust the 0.005 to your need, dont forget the parenthesis)

this way the offset is calculated using the actual scale and should stay the same at all scale.

If your lines are not all at the same angle just using an offset wont work (as the x and y offset will need to be different for different angle), look at this answer for some more complete solution)

J.R
  • 16,090
  • 1
  • 19
  • 52