Index: trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 8751)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 8752)
@@ -15,4 +15,5 @@
 import java.util.Collection;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -23,7 +24,8 @@
 import java.util.regex.Pattern;
 
-import javax.swing.JList;
 import javax.swing.JPanel;
+import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
+import javax.swing.table.AbstractTableModel;
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
@@ -98,5 +100,5 @@
         private String format;
         private String name;
-        private Map<String, TileMatrixSet> tileMatrixSetByCRS = new ConcurrentHashMap<>();
+        private TileMatrixSet tileMatrixSet;
         private String baseUrl;
         private String style;
@@ -129,12 +131,52 @@
     private static final class SelectLayerDialog extends ExtendedDialog {
         private final Layer[] layers;
-        private final JList<String> list;
+        private final JTable list;
 
         public SelectLayerDialog(Collection<Layer> layers) {
             super(Main.parent, tr("Select WMTS layer"), new String[]{tr("Add layers"), tr("Cancel")});
             this.layers = layers.toArray(new Layer[]{});
-            this.list = new JList<>(getLayerNames(layers));
+            //getLayersTable(layers, Main.getProjection())
+            this.list = new JTable(
+                    new AbstractTableModel() {
+                        @Override
+                        public Object getValueAt(int rowIndex, int columnIndex) {
+                            switch (columnIndex) {
+                            case 0:
+                                return SelectLayerDialog.this.layers[rowIndex].name;
+                            case 1:
+                                return SelectLayerDialog.this.layers[rowIndex].tileMatrixSet.crs;
+                            case 2:
+                                return SelectLayerDialog.this.layers[rowIndex].tileMatrixSet.identifier;
+                            default:
+                                throw new IllegalArgumentException();
+                            }
+                        }
+
+                        @Override
+                        public int getRowCount() {
+                            return SelectLayerDialog.this.layers.length;
+                        }
+
+                        @Override
+                        public int getColumnCount() {
+                            return 3;
+                        }
+                        @Override
+                        public String getColumnName(int column) {
+                            switch (column) {
+                            case 0: return tr("Layer name");
+                            case 1: return tr("Projection");
+                            case 2: return tr("Matrix set identifier");
+                            default:
+                                throw new IllegalArgumentException();
+                            }
+                        }
+                        @Override
+                        public boolean isCellEditable(int row, int column) { return false; }
+                    });
             this.list.setPreferredSize(new Dimension(400, 400));
             this.list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+            this.list.setRowSelectionAllowed(true);
+            this.list.setColumnSelectionAllowed(false);
             JPanel panel = new JPanel(new GridBagLayout());
             panel.add(this.list, GBC.eol().fill());
@@ -142,14 +184,6 @@
         }
 
-        private static String[] getLayerNames(Collection<Layer> layers) {
-            Collection<String> ret = new ArrayList<>();
-            for (Layer layer: layers) {
-                ret.add(layer.name);
-            }
-            return ret.toArray(new String[]{});
-        }
-
         public Layer getSelectedLayer() {
-            int index = list.getSelectedIndex();
+            int index = list.getSelectedRow();
             if (index < 0) {
                 return null; //nothing selected
@@ -175,23 +209,25 @@
         this.baseUrl = normalizeCapabilitiesUrl(handleTemplate(info.getUrl()));
         this.layers = getCapabilities();
-        if (layers.size() > 1) {
-            final SelectLayerDialog layerSelection = new SelectLayerDialog(layers);
-            if (layerSelection.showDialog().getValue() == 1) {
-                this.currentLayer = layerSelection.getSelectedLayer();
-                // TODO: save layer information into ImageryInfo / ImageryPreferences?
-            }
-
-            if (this.currentLayer == null) {
-                // user canceled operation or did not choose any layer
-                throw new IllegalArgumentException(tr("No layer selected"));
-            }
-
-        } else if (layers.size() == 1) {
-            this.currentLayer = this.layers.iterator().next();
-        } else {
+        if (this.layers.isEmpty())
             throw new IllegalArgumentException(tr("No layers defined by getCapabilities document: {0}", info.getUrl()));
-        }
-
-        initProjection();
+
+        // Not needed ? initProjection();
+    }
+
+    private Layer userSelectLayer(Collection<Layer> layers) {
+        if (layers.size() == 1)
+            return layers.iterator().next();
+        Layer ret = null;
+
+        final SelectLayerDialog layerSelection = new SelectLayerDialog(layers);
+        if (layerSelection.showDialog().getValue() == 1) {
+            ret = layerSelection.getSelectedLayer();
+            // TODO: save layer information into ImageryInfo / ImageryPreferences?
+        }
+        if (ret == null) {
+            // user canceled operation or did not choose any layer
+            throw new IllegalArgumentException(tr("No layer selected"));
+        }
+        return ret;
     }
 
@@ -239,5 +275,4 @@
             Map<String, TileMatrixSet> matrixSetById = parseMatrices(getByXpath(document, "/Capabilities/Contents/TileMatrixSet"));
             return parseLayer(layersNodeList, matrixSetById);
-
         } catch (Exception e) {
             throw new IllegalArgumentException(e);
@@ -255,19 +290,21 @@
         for (int layerId = 0; layerId < nodeList.getLength(); layerId++) {
             Node layerNode = nodeList.item(layerId);
-            Layer layer = new Layer();
-            layer.format = getStringByXpath(layerNode, "Format");
-            layer.name = getStringByXpath(layerNode, "Identifier");
-            layer.baseUrl = getStringByXpath(layerNode, "ResourceURL[@resourceType='tile']/@template");
-            layer.style = getStringByXpath(layerNode, "Style[@isDefault='true']/Identifier");
-            if (layer.style == null) {
-                layer.style = "";
-            }
             NodeList tileMatrixSetLinks = getByXpath(layerNode, "TileMatrixSetLink");
+
+            // we add an layer for all matrix sets to allow user to choose, with which tileset he wants to work
             for (int tileMatrixId = 0; tileMatrixId < tileMatrixSetLinks.getLength(); tileMatrixId++) {
+                Layer layer = new Layer();
+                layer.format = getStringByXpath(layerNode, "Format");
+                layer.name = getStringByXpath(layerNode, "Identifier");
+                layer.baseUrl = getStringByXpath(layerNode, "ResourceURL[@resourceType='tile']/@template");
+                layer.style = getStringByXpath(layerNode, "Style[@isDefault='true']/Identifier");
+                if (layer.style == null) {
+                    layer.style = "";
+                }
                 Node tileMatrixLink = tileMatrixSetLinks.item(tileMatrixId);
                 TileMatrixSet tms = matrixSetById.get(getStringByXpath(tileMatrixLink, "TileMatrixSet"));
-                layer.tileMatrixSetByCRS.put(tms.crs, tms);
-            }
-            ret.add(layer);
+                layer.tileMatrixSet = tms;
+                ret.add(layer);
+            }
         }
         return ret;
@@ -357,11 +394,28 @@
      */
     public void initProjection(Projection proj) {
-        this.currentTileMatrixSet = currentLayer.tileMatrixSetByCRS.get(proj.toCode());
-        if (this.currentTileMatrixSet == null) {
-            Main.warn("Unsupported CRS selected");
-            // take first, maybe it will work (if user sets custom projections, codes will not match)
-            this.currentTileMatrixSet = currentLayer.tileMatrixSetByCRS.values().iterator().next();
-        }
+        String layerName = null;
+        if (currentLayer != null) {
+            layerName = currentLayer.name;
+        }
+        Collection<Layer> candidates = getLayers(layerName, proj.toCode());
+        if (!candidates.isEmpty()) {
+            Layer newLayer = userSelectLayer(candidates);
+            if (newLayer != null) {
+                this.currentTileMatrixSet = newLayer.tileMatrixSet;
+                this.currentLayer = newLayer;
+            }
+        }
+
         this.crsScale = getTileSize() * 0.28e-03 / proj.getMetersPerUnit();
+    }
+
+    private Collection<Layer> getLayers(String name, String projectionCode) {
+        Collection<Layer> ret = new ArrayList<>();
+        for (Layer layer: this.layers) {
+            if ((name == null || name.equals(layer.name)) && (projectionCode == null || projectionCode.equals(layer.tileMatrixSet.crs))) {
+                ret.add(layer);
+            }
+        }
+        return ret;
     }
 
@@ -385,4 +439,8 @@
     public String getTileUrl(int zoom, int tilex, int tiley) {
         String url;
+        if (currentLayer == null) {
+            return "";
+        }
+
         switch (transferMode) {
         case KVP:
@@ -619,5 +677,17 @@
      */
     public Set<String> getSupportedProjections() {
-        return this.currentLayer.tileMatrixSetByCRS.keySet();
+        Set<String> ret = new HashSet<>();
+        if (currentLayer == null) {
+            for(Layer layer: this.layers) {
+                ret.add(layer.tileMatrixSet.crs);
+            }
+        } else {
+            for(Layer layer: this.layers) {
+                if (currentLayer.name.equals(layer.name)) {
+                    ret.add(layer.tileMatrixSet.crs);
+                }
+            }
+        }
+        return ret;
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java	(revision 8751)
+++ trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java	(revision 8752)
@@ -3,4 +3,5 @@
 
 import java.io.IOException;
+import java.util.Set;
 
 import org.apache.commons.jcs.access.CacheAccess;
@@ -95,5 +96,6 @@
     @Override
     public boolean isProjectionSupported(Projection proj) {
-        return ((WMTSTileSource) tileSource).getSupportedProjections().contains(proj.toCode());
+        Set<String> supportedProjections = ((WMTSTileSource) tileSource).getSupportedProjections();
+        return supportedProjections.contains(proj.toCode());
     }
 
@@ -104,5 +106,5 @@
             ret.append(e).append(", ");
         }
-        return ret.substring(0, ret.length()-2);
+        return ret.length() > 2 ? ret.substring(0, ret.length()-2) : ret.toString();
     }
 
Index: trunk/test/data/wmts/WMTSCapabilities-Ontario.xml
===================================================================
--- trunk/test/data/wmts/WMTSCapabilities-Ontario.xml	(revision 8752)
+++ trunk/test/data/wmts/WMTSCapabilities-Ontario.xml	(revision 8752)
@@ -0,0 +1,457 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
+  <!-- Service Identification --> 
+ <ows:ServiceIdentification>
+	<ows:Title>Basemap_Imagery_2014</ows:Title>
+	<ows:ServiceType>OGC WMTS</ows:ServiceType>
+	<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
+</ows:ServiceIdentification> <!-- Operations Metadata --> <ows:OperationsMetadata>
+	<ows:Operation name="GetCapabilities">
+		<ows:DCP>
+			<ows:HTTP>
+				<ows:Get xlink:href="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/1.0.0/WMTSCapabilities.xml">
+					<ows:Constraint name="GetEncoding">
+						<ows:AllowedValues>
+							<ows:Value>RESTful</ows:Value>
+						</ows:AllowedValues>
+					</ows:Constraint>
+				</ows:Get>
+                <!-- add KVP binding in 10.1 -->
+                <ows:Get xlink:href="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS?">
+                  <ows:Constraint name="GetEncoding">
+                    <ows:AllowedValues>
+                      <ows:Value>KVP</ows:Value>
+                    </ows:AllowedValues>
+                  </ows:Constraint>
+                </ows:Get>
+    		</ows:HTTP>
+    </ows:DCP>
+	</ows:Operation>
+	<ows:Operation name="GetTile">
+		<ows:DCP>
+			<ows:HTTP>
+				<ows:Get xlink:href="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/">
+					<ows:Constraint name="GetEncoding">
+						<ows:AllowedValues>
+							<ows:Value>RESTful</ows:Value>
+						</ows:AllowedValues>
+					</ows:Constraint>
+				</ows:Get>
+                <ows:Get xlink:href="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS?">
+                  <ows:Constraint name="GetEncoding">
+                    <ows:AllowedValues>
+                      <ows:Value>KVP</ows:Value>
+                    </ows:AllowedValues>
+                  </ows:Constraint>
+                </ows:Get>
+            </ows:HTTP>
+		</ows:DCP>
+	</ows:Operation>
+</ows:OperationsMetadata> 
+<Contents>
+  <!--Layer-->  
+  <Layer>
+    <ows:Title>Basemap_Imagery_2014</ows:Title> 
+    <ows:Identifier>Basemap_Imagery_2014</ows:Identifier>
+    
+      <ows:BoundingBox crs="urn:ogc:def:crs:EPSG::3857">
+	  
+			<ows:LowerCorner>-8507199.652697453 5606950.534040266</ows:LowerCorner>
+			<ows:UpperCorner>-8367322.830222864 5713437.426857653</ows:UpperCorner>
+		
+      </ows:BoundingBox>  
+      
+    <ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
+      <ows:LowerCorner>-76.42147473074407 44.907369851539244</ows:LowerCorner>
+      <ows:UpperCorner>-75.1649398555141 45.580879803959924</ows:UpperCorner>
+    </ows:WGS84BoundingBox>
+    <Style isDefault="true">
+      <ows:Title>Default Style</ows:Title>
+      <ows:Identifier>default</ows:Identifier>
+    </Style>
+    <Format>image/jpg</Format>
+    <TileMatrixSetLink>
+      <TileMatrixSet>default028mm</TileMatrixSet>
+    </TileMatrixSetLink>
+
+      
+        <TileMatrixSetLink>
+          <!--Only show this TileMatrixSet if the tiling scheme is compliant to Google Maps (and that happens with tile width = 256 px)-->
+          <TileMatrixSet>GoogleMapsCompatible</TileMatrixSet>
+        </TileMatrixSetLink>
+        
+    <ResourceURL format="image/jpg" resourceType="tile" template="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/tile/1.0.0/Basemap_Imagery_2014/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.jpg"/>
+  </Layer> 
+   <!--TileMatrixSet-->
+   <TileMatrixSet>
+     <ows:Title>TileMatrix using 0.28mm</ows:Title>
+     <ows:Abstract>The tile matrix set that has scale values calculated based on the dpi defined by OGC specification (dpi assumes 0.28mm as the physical distance of a pixel).</ows:Abstract> 
+     <ows:Identifier>default028mm</ows:Identifier>
+     <ows:SupportedCRS>urn:ogc:def:crs:EPSG::3857</ows:SupportedCRS>
+      
+          <TileMatrix>
+          <ows:Identifier>0</ows:Identifier>
+          
+          <ScaleDenominator>1091957.5469304253</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>150</MatrixWidth> 
+            <MatrixHeight>185</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>1</ows:Identifier>
+          
+          <ScaleDenominator>545978.7734656851</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>299</MatrixWidth> 
+            <MatrixHeight>369</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>2</ows:Identifier>
+          
+          <ScaleDenominator>272989.38673237007</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>597</MatrixWidth> 
+            <MatrixHeight>738</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>3</ows:Identifier>
+          
+          <ScaleDenominator>136494.69336618503</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>1193</MatrixWidth> 
+            <MatrixHeight>1475</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>4</ows:Identifier>
+          
+          <ScaleDenominator>68247.34668309252</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>2386</MatrixWidth> 
+            <MatrixHeight>2950</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>5</ows:Identifier>
+          
+          <ScaleDenominator>34123.67334154626</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>4772</MatrixWidth> 
+            <MatrixHeight>5900</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>6</ows:Identifier>
+          
+          <ScaleDenominator>17061.836671245605</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>9543</MatrixWidth> 
+            <MatrixHeight>11800</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>7</ows:Identifier>
+          
+          <ScaleDenominator>8530.918335622802</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>19085</MatrixWidth> 
+            <MatrixHeight>23599</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>8</ows:Identifier>
+          
+          <ScaleDenominator>4265.459167338929</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>38170</MatrixWidth> 
+            <MatrixHeight>47198</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>9</ows:Identifier>
+          
+          <ScaleDenominator>2132.729584141936</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>76339</MatrixWidth> 
+            <MatrixHeight>94396</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>10</ows:Identifier>
+          
+          <ScaleDenominator>1066.3647915984968</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>152678</MatrixWidth> 
+            <MatrixHeight>188791</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>11</ows:Identifier>
+          
+          <ScaleDenominator>533.1823957992484</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>305355</MatrixWidth> 
+            <MatrixHeight>377581</MatrixHeight>
+          
+          </TileMatrix>
+          
+          <TileMatrix>
+          <ows:Identifier>12</ows:Identifier>
+          
+          <ScaleDenominator>266.5911978996242</ScaleDenominator>
+          
+          <TopLeftCorner>-2.0037508342787E7 2.0037508342787E7</TopLeftCorner>  
+          <TileWidth>256</TileWidth> 
+          <TileHeight>256</TileHeight>
+            
+            <MatrixWidth>610709</MatrixWidth> 
+            <MatrixHeight>755161</MatrixHeight>
+          
+          </TileMatrix>
+          
+   </TileMatrixSet>
+   
+   <TileMatrixSet>
+      <ows:Title>GoogleMapsCompatible</ows:Title>
+      <ows:Abstract>the wellknown 'GoogleMapsCompatible' tile matrix set defined by OGC WMTS specification</ows:Abstract>
+      <ows:Identifier>GoogleMapsCompatible</ows:Identifier>
+      <ows:SupportedCRS>urn:ogc:def:crs:EPSG:6.18.3:3857</ows:SupportedCRS>
+      <WellKnownScaleSet>urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible</WellKnownScaleSet>
+      <TileMatrix>
+        <ows:Identifier>0</ows:Identifier>
+        <ScaleDenominator>559082264.0287178</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>1</MatrixWidth>
+        <MatrixHeight>1</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>1</ows:Identifier>
+        <ScaleDenominator>279541132.0143589</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>2</MatrixWidth>
+        <MatrixHeight>2</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>2</ows:Identifier>
+        <ScaleDenominator>139770566.0071794</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>4</MatrixWidth>
+        <MatrixHeight>4</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>3</ows:Identifier>
+        <ScaleDenominator>69885283.00358972</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>8</MatrixWidth>
+        <MatrixHeight>8</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>4</ows:Identifier>
+        <ScaleDenominator>34942641.50179486</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>16</MatrixWidth>
+        <MatrixHeight>16</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>5</ows:Identifier>
+        <ScaleDenominator>17471320.75089743</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>32</MatrixWidth>
+        <MatrixHeight>32</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>6</ows:Identifier>
+        <ScaleDenominator>8735660.375448715</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>64</MatrixWidth>
+        <MatrixHeight>64</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>7</ows:Identifier>
+        <ScaleDenominator>4367830.187724357</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>128</MatrixWidth>
+        <MatrixHeight>128</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>8</ows:Identifier>
+        <ScaleDenominator>2183915.093862179</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>256</MatrixWidth>
+        <MatrixHeight>256</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>9</ows:Identifier>
+        <ScaleDenominator>1091957.546931089</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>512</MatrixWidth>
+        <MatrixHeight>512</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>10</ows:Identifier>
+        <ScaleDenominator>545978.7734655447</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>1024</MatrixWidth>
+        <MatrixHeight>1024</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>11</ows:Identifier>
+        <ScaleDenominator>272989.3867327723</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>2048</MatrixWidth>
+        <MatrixHeight>2048</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>12</ows:Identifier>
+        <ScaleDenominator>136494.6933663862</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>4096</MatrixWidth>
+        <MatrixHeight>4096</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>13</ows:Identifier>
+        <ScaleDenominator>68247.34668319309</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>8192</MatrixWidth>
+        <MatrixHeight>8192</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>14</ows:Identifier>
+        <ScaleDenominator>34123.67334159654</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>16384</MatrixWidth>
+        <MatrixHeight>16384</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>15</ows:Identifier>
+        <ScaleDenominator>17061.83667079827</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>32768</MatrixWidth>
+        <MatrixHeight>32768</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>16</ows:Identifier>
+        <ScaleDenominator>8530.918335399136</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>65536</MatrixWidth>
+        <MatrixHeight>65536</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>17</ows:Identifier>
+        <ScaleDenominator>4265.459167699568</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>131072</MatrixWidth>
+        <MatrixHeight>131072</MatrixHeight>
+      </TileMatrix>
+      <TileMatrix>
+        <ows:Identifier>18</ows:Identifier>
+        <ScaleDenominator>2132.729583849784</ScaleDenominator>
+        <TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
+        <TileWidth>256</TileWidth>
+        <TileHeight>256</TileHeight>
+        <MatrixWidth>262144</MatrixWidth>
+        <MatrixHeight>262144</MatrixHeight>
+      </TileMatrix>
+      </TileMatrixSet>
+    
+</Contents>
+<ServiceMetadataURL xlink:href="http://maps.ottawa.ca/arcgis/rest/services/Basemap_Imagery_2014/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"/> 
+</Capabilities>
Index: trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java	(revision 8751)
+++ trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java	(revision 8752)
@@ -26,4 +26,5 @@
     private ImageryInfo testImageryWIEN = getImagery("test/data/wmts/getCapabilities-wien.xml");
     private ImageryInfo testImageryWALLONIE = getImagery("test/data/wmts/WMTSCapabilities-Wallonie.xml");
+    private ImageryInfo testImageryOntario = getImagery("test/data/wmts/WMTSCapabilities-Ontario.xml");
 
     @BeforeClass
@@ -48,4 +49,5 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryPSEUDO_MERCATOR);
+        testSource.initProjection();
 
         verifyMercatorTile(testSource, 0, 0, 1);
@@ -78,4 +80,6 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryWALLONIE);
+        testSource.initProjection();
+
         assertEquals("http://geoservices.wallonie.be/arcgis/rest/services/DONNEES_BASE/FOND_PLAN_ANNOTATIONS_2012_RW_NB/"
                 + "MapServer/WMTS/tile/1.0.0/DONNEES_BASE_FOND_PLAN_ANNOTATIONS_2012_RW_NB/default/default028mm/5/1219/1063.png",
@@ -95,4 +99,6 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:31370"));
         WMTSTileSource testSource = new WMTSTileSource(getImagery("test/data/wmts/WMTSCapabilities-Wallonie-nomatrixdimension.xml"));
+        testSource.initProjection();
+
         Bounds wallonieBounds = new Bounds(
                 new LatLon(49.485372459967245, 2.840548314430268),
@@ -117,4 +123,5 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryWIEN);
+        testSource.initProjection();
         int zoomOffset = 9;
 
@@ -158,4 +165,5 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryTOPO_PL);
+        testSource.initProjection();
         verifyTile(new LatLon(56, 12), testSource, 0, 0, 1);
         verifyTile(new LatLon(56, 12), testSource, 0, 0, 2);
@@ -179,4 +187,5 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:4326"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
+        testSource.initProjection();
         verifyTile(new LatLon(53.5993712684958, 19.560669777688176), testSource, 12412, 3941, 14);
         verifyTile(new LatLon(49.783096954497786, 22.79034127751704), testSource, 17714, 10206, 14);
@@ -187,7 +196,19 @@
         Main.setProjection(Projections.getProjectionByCode("EPSG:2180"));
         WMTSTileSource testSource = new WMTSTileSource(testImageryORTO_PL);
+        testSource.initProjection();
 
         verifyTile(new LatLon(53.59940948387726, 19.560544913270064), testSource, 6453, 3140, 14);
         verifyTile(new LatLon(49.782984840526055, 22.790064966993445), testSource, 9932, 9305, 14);
+    }
+
+    // disabled as this needs user action
+    // @Test
+    public void testTwoTileSetsForOneProjection() throws Exception {
+        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
+        WMTSTileSource testSource = new WMTSTileSource(testImageryOntario);
+        testSource.initProjection();
+        verifyTile(new LatLon(45.4105023, -75.7153702), testSource, 303751, 375502, 12);
+        verifyTile(new LatLon(45.4601306, -75.7617187), testSource, 1186, 1466, 4);
+
     }
 
