minad/osm

feature request: view a list of pins

Closed this issue · 0 comments

Hello! I love the package. It's wonderful

I was wondering if a feature could be added to view a list of pins. Currently we simply pull in all the bookmarks + home and put pins there.

An example use case: I want to plan a fun itinerary of events so I made a list of locations. Now I want to see them all on a map so I can plan the order and travel of the outing.

I could of course just bookmark all those locations but then they'd get mixed in with my global bookmarks and if I already had some other bookmarks that would clutter the map.

I have sort of already coded a snippet to enable this feature but it is not very good and has weird issues. It overrides the bookmarks with the geo links in the current buffer.

This is actually good enough for me and I don't have a reason to go further with this but I thought I'd share my code with you. I'd also be willing to put in some effort to integrate this feature into the code-base but I thought I'd see what you had to say before getting to work.

(defun osm-override-bookmarks ()
  "Override bookmarks with links in current org buffer."
  (when (eq (with-current-buffer (window-buffer) major-mode) 'org-mode)
    (make-local-variable 'bookmark-alist)
    (setq bookmark-alist '())
    (let ((bookmark-save-flag nil))
      (org-element-map (with-current-buffer (window-buffer) (org-element-parse-buffer))
          '(link)
        (lambda (elem)
          (let ((url (org-element-property :path elem)))
            (if (and (string-equal "geo" (org-element-property :type elem))
                     ;; string-match bit copied from osm.el
                     (string-match
                      "\\`\\([0-9.-]+\\),\\([0-9.-]+\\)\\(?:,[0-9.-]+\\)?\\(;.+\\'\\|\\'\\)" url))
                (let* ((lat (string-to-number (match-string 1 url)))
                       (lon (string-to-number (match-string 2 url)))
                       (args (url-parse-args (match-string 3 url) ""))
                       (osm--zoom (cdr (assoc "z" args)))
                       ;; (server (cdr (assoc "s" args)))
                       (name (car (org-element-contents elem)))
                       (bookmark-make-record-function
                        (lambda () (osm--bookmark-record name lat lon name))))
                  (bookmark-set
                   (osm--bookmark-name lat lon name))))))))))

(add-hook 'osm-mode-hook 'osm-override-bookmarks)