[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/osm e546671a0e 38/77: Minor cleanup
From: |
ELPA Syncer |
Subject: |
[elpa] externals/osm e546671a0e 38/77: Minor cleanup |
Date: |
Mon, 7 Mar 2022 08:58:06 -0500 (EST) |
branch: externals/osm
commit e546671a0ed87cae748ced499442b98980d3a0e1
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Minor cleanup
---
osm.el | 52 +++++++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 27 deletions(-)
diff --git a/osm.el b/osm.el
index aee90ed706..3da392f61d 100644
--- a/osm.el
+++ b/osm.el
@@ -276,9 +276,10 @@ 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 (or (member job osm--queue) (member job osm--active))
- (setq osm--queue (nconc osm--queue (list job))))))
+ (when (let ((n (expt 2 osm--zoom))) (and (>= x 0) (>= y 0) (< x n) (< y n)))
+ (let ((job `(,x ,y . ,osm--zoom)))
+ (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."
@@ -311,7 +312,7 @@ We need two distinct images which are not `eq' for the
display properties.")
(when (and (string-match-p "finished" status)
(eq osm--zoom zoom))
(ignore-errors (rename-file tmp dst t))
- (osm--display-tile x y))
+ (osm--display-tile x y (osm--get-tile x y)))
(delete-file tmp)
(force-mode-line-update)
(setq osm--active (delq job osm--active))
@@ -451,30 +452,29 @@ We need two distinct images which are not `eq' for the
display properties.")
bookmark-make-record-function #'osm--make-bookmark)
(add-hook 'window-size-change-functions #'osm--revert nil 'local))
-(defun osm--display-tile (x y)
- "Display tile at X/Y."
+(defun osm--get-tile (x y)
+ "Get tile at X/Y."
+ (let ((file (osm--tile-file x y osm--zoom)))
+ (when (file-exists-p file)
+ `(image :type ,(if (member (file-name-extension file) '("jpg" "jpeg"))
'jpeg 'png)
+ :width 256 :height 256 :file ,file))))
+
+(defun osm--display-tile (x y tile)
+ "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))
(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))))
+ (pos (+ (point-min) (* j (1+ osm--nx)) i)))
+ (unless tile
+ (setq tile (if (= 0 (mod i 2)) osm--placeholder1 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)))))))
+ `((slice ,mx ,my ,(- 256 mx) ,(- 256 my)) ,tile)
+ tile)))))))
;;;###autoload
(defun osm-home ()
@@ -498,8 +498,7 @@ We need two distinct images which are not `eq' for the
display properties.")
(unless (eq major-mode #'osm-mode)
(error "Not an osm-mode buffer"))
(with-silent-modifications
- (let* ((size (expt 2 osm--zoom))
- (meter-per-pixel (/ (* 156543.03 (cos (/ (osm--lat) (/ 180.0
float-pi)))) size))
+ (let* ((meter-per-pixel (/ (* 156543.03 (cos (/ (osm--lat) (/ 180.0
float-pi)))) (expt 2 osm--zoom)))
(meter '(1 5 10 50 100 500 1000 5000 10000 50000 100000 500000
1000000 5000000 10000000))
(windows (or (get-buffer-window-list) (list (frame-root-window))))
(win-width (cl-loop for w in windows maximize (window-pixel-width
w)))
@@ -535,12 +534,11 @@ We need two distinct images which are not `eq' for the
display properties.")
(goto-char (point-min))
(dotimes (j osm--ny)
(dotimes (i osm--nx)
- (let ((x (+ i (/ (- osm--x osm--wx) 256)))
- (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)))))
+ (let* ((x (+ i (/ (- osm--x osm--wx) 256)))
+ (y (+ j (/ (- osm--y osm--wy) 256)))
+ (tile (osm--get-tile x y)))
+ (osm--display-tile x y tile)
+ (unless tile (osm--enqueue x y)))))
(setq osm--queue
(seq-sort-by
(pcase-lambda (`(,x ,y . ,_z))
- [elpa] externals/osm 7ac6f60b90 39/77: README update, (continued)
- [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
- [elpa] externals/osm 162f883f80 35/77: Reuse existing buffer, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 9053d8a930 16/77: Indentation, ELPA Syncer, 2022/03/07
- [elpa] externals/osm f2fba2ebdf 43/77: Auto rename the buffers, ELPA Syncer, 2022/03/07
- [elpa] externals/osm b991de6e89 54/77: Rename server, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 03d4ceb553 57/77: Add tile memory cache, ELPA Syncer, 2022/03/07
- [elpa] externals/osm f6c16a4cc4 63/77: Improve keybindings, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 2a0bd8c7eb 50/77: Improve header line, ELPA Syncer, 2022/03/07
- [elpa] externals/osm e546671a0e 38/77: Minor cleanup,
ELPA Syncer <=
- [elpa] externals/osm 7657cb1b3b 71/77: Add check for image format support, ELPA Syncer, 2022/03/07
- [elpa] externals/osm e78a337477 44/77: Rename commands, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 1b7f4020b3 73/77: Fix caching, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d27892f63a 40/77: Add some utility functions, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 3c0950a24b 31/77: Simplify bookmark handling, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 11a04bb5b9 66/77: osm-server: Improve completion command, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 88e7e36e43 49/77: Rename function, ELPA Syncer, 2022/03/07
- [elpa] externals/osm a9d0ec74e3 07/77: Simplify placeholder, ELPA Syncer, 2022/03/07
- [elpa] externals/osm db20223911 27/77: Minor cleanup, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 92fb0c72dd 62/77: Add osm-bookmark-delete, ELPA Syncer, 2022/03/07