minad/osm

Getting detailed coordinates

hmelman opened this issue · 7 comments

The first thing I wanted to do was set osm-home.

I found I wanted to set it to a building and I needed zoom level 17 and 4 decimal places of precision. But while I could find the building on a map I couldn't get those numbers easily. While I could click on a building and create a blue location marker, I didn't see a way to get the coordinates of the marker, it would be nice if a key could do that (not just save a bookmark). And the header showed just 2 decimal places. I changed header-line-format in osm--update-header to show four places. Perhaps that would be a better default than two places?

minad commented

You can also use org-store-link bound to l in osm-mode. Then you can paste the link into an org mode buffer with C-c C-l. This way you get the precise coordinates with a description. However it may make sense to add a feature to capture coordinates in another format, e.g., as a lisp expression. See also the issue #4 by @edrx. We could add a command osm-store-coordinates which stores (osm-goto lat lon zoom) in the kill ring. Then one could paste this into a buffer, edit it or directly execute it with C-x e.

minad commented

I added a command osm-elisp-link in a separate branch. I still have have to think about this. Please let me know your thoughts. It would also be interesting to hear what @edrx has to say about this command. I like the idea of saving an executable elisp expression as link in the kill ring. I think that's central idea of @edrx eev project. We can also support this here. I could even add a function osm to make the link a bit shorter.

edrx commented

@hmelman, the code that does this in eev is here:
http://angg.twu.net/eev-current/eev-tlinks.el.html#find-osm-links
Here is a version that doesn't need eev:

(defun ee-osm-sexp (lat lon zoom)
  (format "(osm-goto %2.4f %2.4f %d)" lat lon zoom))

(defun ee-osm-kill ()
  (interactive)
  (if (not (eq major-mode 'osm-mode)) (error "Not in osm-mode"))
  (let ((str (ee-osm-sexp (osm--lat) (osm--lon) osm--zoom)))
    (message "Killing: %s" str)
    (kill-new str)))

Let me check Daniel's code...

edrx commented

@minad, I took a look at your code and I have two suggestions: 1) it would be nice if you could factor it into smaller functions that people would find easier to understand, test, and call from their own functions, 2) you need a way to specify of decimal places...

I know that eev has some users who know Lisp very well, but 99% of the feedback that I get on it is from people who are learning Lisp and who find backquotes hard and pcase very very magic, so I'm probably going to keep the support for osm in eev in a style that those people feel that is clear...

minad commented

@edrx I merged the osm link support in #8. I like to have this here since it gives another Emacs touch to the whole thing.

  1. Maybe. I think the code is quite readable and robust, but there are maybe a few offending functions in particular from the display code. Not a priority though.

  2. Do you mean a configuration option? I think it is okay to capture them with a fixed reasonably large precision. Currently I use full precision which is too much. I will add some truncation.

I'll have to wait until this makes elpa to try it, but it seems reasonable. A few quick thoughts:

  1. I think I'd still like more precision in the header line or make it configurable with a user option for the format string.
  2. My first thought for a key to "kill" a location was w. This matches dired and embark. I know of org-link though I'm not really an org user. Having several single key bindings for similar things (e, l, b) gives me pause but such is emacs. Until you run out of keys, it's probably fine :)
  3. I like the idea of an executable data format for the link, but the tag name osm seems a bit generic. Maybe osm-location? I'm not sure what future growth to leave room for, maybe there's no need. I assume you've considered this, but it jumped out to me. It also reads a little better if someone comes across one without knowing what osm is. Something like osm-location would tell them it's a location associated with a package called osm.
  4. It would be nice if the variable osm-home accepted one of these. Maybe it should be osm-home-location (or I'm just pointlessly bikeshedding). I found while using the custom interface, setting osm-home had ugly prompts for the 3 numbers, just "Number:", perhaps a custom format could address that.
minad commented