I know this have been touched upon before, but the other posts did not entirely do it for me.
I'm trying to make a minimal Leaflet .html page with a map, containing a WMTS map. The code looks like this:
<html>
<head>
<title>TEST leaflet.TileLayer.WMTS</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="https://rawgithub.com/mylen/leaflet.TileLayer.WMTS/master/leaflet-tilelayer-wmts.js"></script>
</head>
<body>
<div id="map" style="height: 100%; width: 80%"></div>
<script> // based on https://github.com/mylen/leaflet.TileLayer.WMTS
var map = L.map('map', {CRS: L.CRS.EPSG25832});
// http://jordbrugsanalyser.dk/geoserver/gwc/service/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetCapabilities
var markWMTSlayer = new L.TileLayer.WMTS('http://jordbrugsanalyser.dk/geoserver/gwc/service/wmts', {
layer: "Marker13",
format: "image/png",
style: "default",
tilematrixSet: "GST"});
map.addLayer(markWMTSlayer);
// http://data.geus.dk/arcgis/rest/services/GtW/S035_Jordartskort_25000/MapServer/WMTS/1.0.0/WMTSCapabilities.xml
var jordWMTSlayer = new L.TileLayer.WMTS('data.geus.dk/arcgis/rest/services/GtW/S035_Jordartskort_25000/MapServer/WMTS', {
layer: "GtW_S035_Jordartskort_25000",
format: "image/png",
style: "default",
tilematrixSet: "default028mm"});
//map.addLayer(jordWMTSlayer);
L.control.scale({'position':'bottomleft','metric':true,'imperial':false}).addTo(map);
var baseLayers = {"jord": jordWMTSlayer, "mark": markWMTSlayer};
L.control.layers(baseLayers, {}).addTo(map);
</script>
</body>
The resulting page can be seen live here: http://snapseatlas.dk/daftest/daf.html
Not that there is much to see, because only a grey background is shown.
I suspect my problem can be either:
1) I missed something fundamental, because I'm an Leaflet amateur, or
2) Something with the projection (EPSG:25832, is common in Denmark).
So please – Can somebody with a bit more Leaflet/WMTS experience have a look, and tell me what I'm doing wrong.
/M
Best Answer
There are quite a few reasons your code does not work.
First, there is
map.setView
call missing. Even everything else would be ok, map wouldn't show without this call.Second, your WMTS service is using CRS EPSG 25832 projection, which is not natively supported in Leaflet. To use it, you must use
Proj4Leaflet
plugin.Third, if you use
Proj4Leaflet
plugin, thenleaflet.TileLayer.WMTS
plugin won't work. You have to construct WMTS call yourself.Fourth, the right name for your
markWMTSlayer
layer in WMTS service isJordbrugsanalyser:Marker13
.Below is code, where I took CRS definition from somwhere else, so resolutions and origin are debatable. I also could not find any such data in WMTS GetCapabilites info.