Index: applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java
===================================================================
--- applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java	(revision 35321)
+++ applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/tilesources/TemplatedTMSTileSource.java	(revision 35322)
@@ -52,4 +52,11 @@
     private static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apiKey\\}");
     private static final Pattern PATTERN_PARAM  = Pattern.compile("\\{((?:\\d+-)?z(?:oom)?(:?[+-]\\d+)?|x|y|!y|-y|switch:([^}]+))\\}");
+
+    /**
+     * Pattern used only for compatibility with older JOSM clients. To remove end of 2020, with an update of JOSM wiki
+     * @deprecated to remove end of 2020
+     */
+    @Deprecated
+    private static final Pattern PATTERN_API_KEY_COMPATIBILITY = Pattern.compile("_apiKey_");
     // CHECKSTYLE.ON: SingleSpaceSeparator
 
@@ -71,12 +78,14 @@
     }
 
-    private void replacePattern(Pattern p, BiConsumer<Matcher, StringBuffer> replaceAction) {
-        StringBuffer output = new StringBuffer();
-        Matcher m = p.matcher(baseUrl);
-        while (m.find()) {
-            replaceAction.accept(m, output);
+    private void replacePattern(BiConsumer<Matcher, StringBuffer> replaceAction, Pattern... patterns) {
+        for (Pattern p : patterns) {
+            StringBuffer output = new StringBuffer();
+            Matcher m = p.matcher(baseUrl);
+            while (m.find()) {
+                replaceAction.accept(m, output);
+            }
+            m.appendTail(output);
+            baseUrl = output.toString();
         }
-        m.appendTail(output);
-        baseUrl = output.toString();
     }
 
@@ -89,16 +98,18 @@
         }
         // Capturing group pattern on header values
-        replacePattern(PATTERN_HEADER, (matcher, output) -> {
+        replacePattern((matcher, output) -> {
             headers.put(matcher.group(1), matcher.group(2));
             matcher.appendReplacement(output, "");
-        });
+        }, PATTERN_HEADER);
         // Capturing group pattern on API key values
-        replacePattern(PATTERN_API_KEY, (matcher, output) -> {
-            try {
-                matcher.appendReplacement(output, FeatureAdapter.retrieveApiKey(imageryId));
-            } catch (IOException e) {
-                throw new IllegalArgumentException(e);
-            }
-        });
+        if (imageryId != null) {
+            replacePattern((matcher, output) -> {
+                try {
+                    matcher.appendReplacement(output, FeatureAdapter.retrieveApiKey(imageryId));
+                } catch (IOException e) {
+                    throw new IllegalArgumentException(e);
+                }
+            }, PATTERN_API_KEY, PATTERN_API_KEY_COMPATIBILITY);
+        }
         // Capturing group pattern on zoom values
         m = PATTERN_ZOOM.matcher(baseUrl);
