I have a web app powered on the backend by PyGMT which allows the user to position labels for markers however they want. I have implemented this successfully by tracking the final latitude/longitude of the label as positioned by the user, and using that as the X/Y in the call to figure.text
This works great, as long as I don’t want a line back to the original location. Of course, the figure.text
command makes it easy to draw said line using the “offset” parameter, but there’s two problems at the moment:
-
While I know the original location, and the “new” location, I don’t know how to figure out what offset would place the label in the desired location - to the best of my knowledge (correct me if I am wrong), the offset has to be in “measurement” units such as points, in, or cm, not map units of latitude/longitude.
-
The new location is provided as the top-left corner of the label, however depending on the label location relative to the original location, that may not be an appropriate anchor point for the line.
So, basically the challenge I have given myself here is to first figure out the most appropriate anchor point to use for each label, and then to figure out an appropriate offset to place the label at the proper point.
I have an idea as to how I can solve #2 on the front end, if needed, and provide a) the proper anchor point, and b) the latitude/longitude of said anchor point to PyGMT for plotting, but that still leaves problem #1 - how to figure out the offset needed to position the text at the desired latitude/longitude.
Any thoughts/suggestions?