[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/osm 6df17a6a84: osm-server-list: Add support for api ke
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/osm 6df17a6a84: osm-server-list: Add support for api keys |
|
Date: |
Thu, 18 May 2023 11:58:46 -0400 (EDT) |
branch: externals/osm
commit 6df17a6a84a242e3a9a45a0677fe6a0fc42657c2
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
osm-server-list: Add support for api keys
---
CHANGELOG.org | 1 +
osm.el | 25 +++++++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 82345b4a16..9880062d0f 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -5,6 +5,7 @@
* Development
- Provide =osm-prefix-map=.
+- =osm-server-list=: Add support for an api-key placeholder =%k= in the server
=:url=.
* Version 0.12 (2023-05-01)
diff --git a/osm.el b/osm.el
index 81d6167ca5..33652243fb 100644
--- a/osm.el
+++ b/osm.el
@@ -164,7 +164,11 @@ A comma-separated specifies descending order of
preference. See also
:group "Artistic"
:copyright ("Map data ©
{OpenStreetMap|https://www.openstreetmap.org/copyright} contributors"
"Map style © {Stamen Design|http://maps.stamen.com/}
({CC-BY|https://creativecommons.org/licenses/by/3.0/})")))
- "List of tile servers."
+ "List of tile servers.
+The :url of each server should specify %x, %y and %z placeholders
+for the map coordinates. It can optionally use an %s placeholder
+for the subdomain and a %k placeholder for an api-key, which will
+be retrieved via `auth-source-search'."
:type '(alist :key-type symbol :value-type plist))
(defcustom osm-copyright t
@@ -480,8 +484,25 @@ Should be at least 7 days according to the server usage
policies."
(defun osm--tile-url (x y zoom)
"Return tile url for coordinate X, Y and ZOOM."
(let ((url (osm--server-property :url))
- (sub (osm--server-property :subdomains)))
+ (sub (osm--server-property :subdomains))
+ (key (osm--server-property :key)))
+ (when (and (string-search "%k" url) (not key))
+ (require 'auth-source)
+ (declare-function auth-source-search "auth-source")
+ (let ((host (string-join
+ (last (split-string (cadr (split-string url "/" t)) "\\.")
2)
+ ".")))
+ (setq key (plist-get
+ (car (auth-source-search :require '(:user :host :secret)
+ :host host
+ :user "apikey"))
+ :secret))
+ (unless key
+ (warn "No auth source secret found for apikey@%s" host)
+ (setq key ""))
+ (setf (plist-get (alist-get osm-server osm-server-list) :key) key)))
(format-spec url `((?z . ,zoom) (?x . ,x) (?y . ,y)
+ (?k . ,(if (functionp key) (funcall key) key))
(?s . ,(nth (mod osm--subdomain-index (length sub))
sub))))))
(defun osm--tile-file (x y zoom)
| [Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/osm 6df17a6a84: osm-server-list: Add support for api keys,
ELPA Syncer <=