Index: trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java	(revision 14398)
+++ trunk/src/org/openstreetmap/josm/data/imagery/AbstractWMSTileSource.java	(revision 14399)
@@ -226,13 +226,19 @@
         double e = se.getX();
 
-        return (
-                switchLatLon ?
-                        String.format("%s,%s,%s,%s",
-                                LATLON_FORMAT.format(s), LATLON_FORMAT.format(w), LATLON_FORMAT.format(n), LATLON_FORMAT.format(e))
-                        :
-                        String.format("%s,%s,%s,%s",
-                                LATLON_FORMAT.format(w), LATLON_FORMAT.format(s), LATLON_FORMAT.format(e), LATLON_FORMAT.format(n))
-
-                );
+        return switchLatLon ?
+                getBboxstr(s, w, n, e)
+                : getBboxstr(w, s, e, n);
+    }
+
+    private final String getBboxstr(double x1, double x2, double x3, double x4) {
+        return new StringBuilder(64)
+                .append(LATLON_FORMAT.format(x1))
+                .append(',')
+                .append(LATLON_FORMAT.format(x2))
+                .append(',')
+                .append(LATLON_FORMAT.format(x3))
+                .append(',')
+                .append(LATLON_FORMAT.format(x4))
+                .toString();
     }
 }
Index: trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 14398)
+++ trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java	(revision 14399)
@@ -51,4 +51,5 @@
     };
 
+    private final boolean switchLatLon;
     /**
      * Creates a tile source based on imagery info
@@ -62,4 +63,29 @@
         handleTemplate();
         initProjection();
+        // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326.
+        //
+        // Background:
+        //
+        // bbox=x_min,y_min,x_max,y_max
+        //
+        //      SRS=... is WMS 1.1.1
+        //      CRS=... is WMS 1.3.0
+        //
+        // The difference:
+        //      For SRS x is east-west and y is north-south
+        //      For CRS x and y are as specified by the EPSG
+        //          E.g. [1] lists lat as first coordinate axis and lot as second, so it is switched for EPSG:4326.
+        //          For most other EPSG code there seems to be no difference.
+        // CHECKSTYLE.OFF: LineLength
+        // [1] https://www.epsg-registry.org/report.htm?type=selection&entity=urn:ogc:def:crs:EPSG::4326&reportDetail=short&style=urn:uuid:report-style:default-with-code&style_name=OGP%20Default%20With%20Code&title=EPSG:4326
+        // CHECKSTYLE.ON: LineLength
+        if (baseUrl.toLowerCase(Locale.US).contains("crs=epsg:4326")) {
+            switchLatLon = true;
+        } else if (baseUrl.toLowerCase(Locale.US).contains("crs=")) {
+            // assume WMS 1.3.0
+            switchLatLon = ProjectionRegistry.getProjection().switchXY();
+        } else {
+            switchLatLon = false;
+        }
     }
 
@@ -86,30 +112,4 @@
         }
 
-        // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326.
-        //
-        // Background:
-        //
-        // bbox=x_min,y_min,x_max,y_max
-        //
-        //      SRS=... is WMS 1.1.1
-        //      CRS=... is WMS 1.3.0
-        //
-        // The difference:
-        //      For SRS x is east-west and y is north-south
-        //      For CRS x and y are as specified by the EPSG
-        //          E.g. [1] lists lat as first coordinate axis and lot as second, so it is switched for EPSG:4326.
-        //          For most other EPSG code there seems to be no difference.
-        // CHECKSTYLE.OFF: LineLength
-        // [1] https://www.epsg-registry.org/report.htm?type=selection&entity=urn:ogc:def:crs:EPSG::4326&reportDetail=short&style=urn:uuid:report-style:default-with-code&style_name=OGP%20Default%20With%20Code&title=EPSG:4326
-        // CHECKSTYLE.ON: LineLength
-        boolean switchLatLon = false;
-        if (baseUrl.toLowerCase(Locale.US).contains("crs=epsg:4326")) {
-            switchLatLon = true;
-        } else if (baseUrl.toLowerCase(Locale.US).contains("crs=")) {
-            // assume WMS 1.3.0
-            switchLatLon = ProjectionRegistry.getProjection().switchXY();
-        }
-        String bbox = getBbox(zoom, tilex, tiley, switchLatLon);
-
         // Using StringBuffer and generic PATTERN_PARAM matcher gives 2x performance improvement over replaceAll
         StringBuffer url = new StringBuffer(baseUrl.length());
@@ -125,5 +125,5 @@
                 break;
             case "bbox":
-                replacement = bbox;
+                replacement = getBbox(zoom, tilex, tiley, switchLatLon);
                 break;
             case "w":
Index: trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java	(revision 14398)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java	(revision 14399)
@@ -60,6 +60,4 @@
     @Override
     public String getTileUrl(int zoom, int tilex, int tiley) {
-        String bbox = getBbox(zoom, tilex, tiley, !wmsi.belowWMS130() && getTileProjection().switchXY());
-
         // Using StringBuffer and generic PATTERN_PARAM matcher gives 2x performance improvement over replaceAll
         StringBuffer url = new StringBuffer(urlPattern.length());
@@ -72,5 +70,5 @@
                 break;
             case "bbox":
-                replacement = bbox;
+                replacement = getBbox(zoom, tilex, tiley, !wmsi.belowWMS130() && getTileProjection().switchXY());
                 break;
             case "width":
Index: trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java	(revision 14398)
+++ trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java	(revision 14399)
@@ -152,4 +152,45 @@
     }
 
+    /**
+     * Test getTileUrl
+     */
+    @Test
+    public void testGetTileUrl() {
+        // "https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
+        Projection projection = Projections.getProjectionByCode("EPSG:4326");
+        ProjectionRegistry.setProjection(projection);
+        ImageryInfo testImageryWMS = new ImageryInfo("test imagery",
+                "https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&"
+                + "REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&"
+                + "MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
+                "wms",
+                null,
+                null);
+        TemplatedWMSTileSource ts = new TemplatedWMSTileSource(testImageryWMS, projection);
+        assertEquals("https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&"
+                + "VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=-1349.9999381,539.9999691,-989.9999536,899.9999536&WIDTH=512&"
+                + "HEIGHT=512&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
+                ts.getTileUrl(1, 2, 3));
+        assertEquals("https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&"
+                + "VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=-89.9999923,-0.0000077,0.0000039,89.9999884&WIDTH=512&HEIGHT=512&"
+                + "LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
+                ts.getTileUrl(3, 2, 1));
+        testImageryWMS = new ImageryInfo("test imagery",
+                "https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
+                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS={proj}&BBOX={bbox}&"
+                + "WIDTH={width}&HEIGHT={height}",
+                "wms",
+                null,
+                null);
+        ts = new TemplatedWMSTileSource(testImageryWMS, projection);
+        assertEquals("https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
+                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG:4326&"
+                + "BBOX=539.9999691,-1349.9999381,899.9999536,-989.9999536&WIDTH=512&HEIGHT=512",
+                ts.getTileUrl(1, 2, 3));
+        assertEquals("https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
+                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG:4326&"
+                + "BBOX=-0.0000077,-89.9999923,89.9999884,0.0000039&WIDTH=512&HEIGHT=512", ts.getTileUrl(3, 2, 1));
+    }
+
     private void verifyMercatorTile(TemplatedWMSTileSource source, int x, int y, int z) {
         TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
