[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/osm 458257fa1f 19/77: Improve tile loading
From: |
ELPA Syncer |
Subject: |
[elpa] externals/osm 458257fa1f 19/77: Improve tile loading |
Date: |
Mon, 7 Mar 2022 08:58:05 -0500 (EST) |
branch: externals/osm
commit 458257fa1f402bb5398073f0e5cd74745fd20b78
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Improve tile loading
---
osm.el | 122 ++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 61 insertions(+), 61 deletions(-)
diff --git a/osm.el b/osm.el
index e5a6c14e8f..11eece996b 100644
--- a/osm.el
+++ b/osm.el
@@ -274,41 +274,40 @@ We need two distinct images which are not `eq' for the
display properties.")
(defun osm--enqueue (x y)
"Enqueue tile X/Y for download."
(let ((job `(,x ,y . ,osm--zoom)))
- (unless (member job osm--queue)
+ (unless (or (member job osm--queue) (member job osm--active))
(setq osm--queue (nconc osm--queue (list job))))))
(defun osm--download ()
"Download next tile in queue."
- (pcase (and (< (length osm--active)
- (* (length (osm--server-property :url))
- (osm--server-property :max-connections)))
- (pop osm--queue))
- (`(,x ,y . ,zoom)
- (let* ((buffer (current-buffer))
- (dst (osm--tile-file x y zoom))
- (tmp (concat dst ".tmp")))
- (push
- (make-process
- :name (format "osm %s %s %s" x y zoom)
- :connection-type 'pipe
- :noquery t
- :command
- (list "curl" "-s" "-o" tmp (osm--tile-url x y zoom))
- :filter #'ignore
- :sentinel
- (lambda (proc status)
- (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (when (and (string-match-p "finished" status)
- (eq osm--zoom zoom))
- (ignore-errors (rename-file tmp dst t))
- (osm--put x y))
- (delete-file tmp)
- (force-mode-line-update)
- (setq osm--active (delq proc osm--active))
- (osm--download)))))
- osm--active)
- (osm--download)))))
+ (when-let (job (and (< (length osm--active)
+ (* (length (osm--server-property :url))
+ (osm--server-property :max-connections)))
+ (pop osm--queue)))
+ (push job osm--active)
+ (pcase-let* ((`(,x ,y . ,zoom) job)
+ (buffer (current-buffer))
+ (dst (osm--tile-file x y zoom))
+ (tmp (concat dst ".tmp")))
+ (make-process
+ :name (format "osm %s %s %s" x y zoom)
+ :connection-type 'pipe
+ :noquery t
+ :command
+ (list "curl" "-s" "-o" tmp (osm--tile-url x y zoom))
+ :filter #'ignore
+ :sentinel
+ (lambda (_proc status)
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (when (and (string-match-p "finished" status)
+ (eq osm--zoom zoom))
+ (ignore-errors (rename-file tmp dst t))
+ (osm--display-tile x y))
+ (delete-file tmp)
+ (force-mode-line-update)
+ (setq osm--active (delq job osm--active))
+ (osm--download)))))
+ (osm--download))))
(defun osm-click (event)
"Handle click EVENT."
@@ -439,28 +438,30 @@ We need two distinct images which are not `eq' for the
display properties.")
fringe-indicator-alist '((truncation . nil)))
(add-hook 'window-size-change-functions #'osm--update nil 'local))
-(defun osm--put (x y &optional image)
- "Put tile IMAGE at X/Y."
- (let* ((i (- x (/ (- osm--x osm--wx) 256)))
- (j (- y (/ (- osm--y osm--wy) 256)))
- (mx (if (= 0 i) (mod (- osm--x osm--wx) 256) 0))
- (my (if (= 0 j) (mod (- osm--y osm--wy) 256) 0))
- (pos (+ (point-min) (* j (1+ osm--nx)) i)))
+(defun osm--display-tile (x y)
+ "Display tile at X/Y."
+ (let ((i (- x (/ (- osm--x osm--wx) 256)))
+ (j (- y (/ (- osm--y osm--wy) 256))))
(when (and (>= i 0) (< i osm--nx) (>= j 0) (< j osm--ny))
- (unless image
- (let ((file (osm--tile-file x y osm--zoom)))
- (setq image
- `(image :type
- ,(if (member (file-name-extension file) '("jpg"
"jpeg"))
- 'jpeg 'png)
- :file ,file
- :width 256 :height 256))))
- (with-silent-modifications
- (put-text-property
- pos (1+ pos) 'display
- (if (or (/= 0 mx) (/= 0 my))
- `((slice ,mx ,my ,(- 256 mx) ,(- 256 my)) ,image)
- image))))))
+ (let* ((mx (if (= 0 i) (mod (- osm--x osm--wx) 256) 0))
+ (my (if (= 0 j) (mod (- osm--y osm--wy) 256) 0))
+ (pos (+ (point-min) (* j (1+ osm--nx)) i))
+ (file (osm--tile-file x y osm--zoom))
+ (image (cond
+ ((file-exists-p file)
+ `(image :type
+ ,(if (member (file-name-extension file) '("jpg"
"jpeg"))
+ 'jpeg 'png)
+ :file ,file
+ :width 256 :height 256))
+ ((= 0 (mod i 2)) osm--placeholder1)
+ (t osm--placeholder2))))
+ (with-silent-modifications
+ (put-text-property
+ pos (1+ pos) 'display
+ (if (or (/= 0 mx) (/= 0 my))
+ `((slice ,mx ,my ,(- 256 mx) ,(- 256 my)) ,image)
+ image)))))))
;;;###autoload
(defun osm-new (&optional unique)
@@ -520,14 +521,11 @@ We need two distinct images which are not `eq' for the
display properties.")
(dotimes (j osm--ny)
(dotimes (i osm--nx)
(let ((x (+ i (/ (- osm--x osm--wx) 256)))
- (y (+ j (/ (- osm--y osm--wy) 256)))
- (placeholder (if (= 0 (mod i 2)) osm--placeholder1
osm--placeholder2)))
- (if (and (>= x 0) (>= y 0) (< x size) (< y size))
- (if (file-exists-p (osm--tile-file x y osm--zoom))
- (osm--put x y)
- (osm--put x y placeholder)
- (osm--enqueue x y))
- (osm--put x y placeholder)))))
+ (y (+ j (/ (- osm--y osm--wy) 256))))
+ (osm--display-tile x y)
+ (when (and (>= x 0) (>= y 0) (< x size) (< y size)
+ (not (file-exists-p (osm--tile-file x y osm--zoom))))
+ (osm--enqueue x y)))))
(setq osm--queue
(seq-sort-by
(pcase-lambda (`(,x ,y . ,_z))
@@ -669,7 +667,9 @@ The buffer is optionally assigned a UNIQUE name."
(format "\\`\\*osm: %s\\*\\(?:<[0-9]+>\\)?\\'"
(regexp-quote (osm--server-property :name)))
(buffer-name))))
- (setq-local osm-server server)
+ (setq-local osm-server server
+ osm--active nil
+ osm--queue nil)
(when rename (rename-buffer (osm--buffer-name) 'unique)))
(osm--update))))
- [elpa] externals/osm 2fbf12f0ef 46/77: seq is not needed, (continued)
- [elpa] externals/osm 2fbf12f0ef 46/77: seq is not needed, ELPA Syncer, 2022/03/07
- [elpa] externals/osm c2c7dff887 22/77: Compact server configuration, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 7ce1d26c88 67/77: Extract osm--make-tile, ELPA Syncer, 2022/03/07
- [elpa] externals/osm ff8ff68b4d 65/77: Check if bookmarks are present, ELPA Syncer, 2022/03/07
- [elpa] externals/osm cb191d426f 76/77: Version 0.2, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 8e8e4583f5 74/77: More robust mouse dragging, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d776cdb343 42/77: Fix melpa issues (See https://github.com/melpa/melpa/pull/7936), ELPA Syncer, 2022/03/07
- [elpa] externals/osm 5b82b32201 28/77: Add server descriptions, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 832bce78f8 72/77: Implement proper map dragging with the mouse, ELPA Syncer, 2022/03/07
- [elpa] externals/osm df844cd56b 30/77: Add osm-rename command, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 458257fa1f 19/77: Improve tile loading,
ELPA Syncer <=
- [elpa] externals/osm 699aae27b1 20/77: Rename osm-new to osm-home, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d830691585 61/77: README: Remove wishlist, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 25621bb80e 41/77: curl add --fail argument, ELPA Syncer, 2022/03/07
- [elpa] externals/osm b300e42d9f 68/77: Add transient pin, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 28d3305bef 32/77: Improve handling of generated names, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 833793ed6c 77/77: Use grid placeholder, ELPA Syncer, 2022/03/07
- [elpa] externals/osm adc8156a70 37/77: README: Add more examples, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 7ac6f60b90 39/77: README update, ELPA Syncer, 2022/03/07
- [elpa] externals/osm ff5c089087 52/77: Update completion predicates, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d5c5dc6ffd 75/77: Mouse dragging: Check window, ELPA Syncer, 2022/03/07