0

I am new to web mapping and web in general.

I am trying to add the default WMTS Italy mosaic that can be found in GeoServer by default (nurc:mosaic, namely) to my map via Leaflet.

I tried to tweak following code: https://github.com/mylen/leaflet.TileLayer.WMTS

I get the WMTS link simply right clicking on GeoServer's Web Admin page WMTS 1.0.0 and copy the link location. Here it is: http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities

And here is my code: Demo leaflet.TileLayer.WMTS

// The WMTS URL
var url = "http://localhost:8081/geoserver/gwc/service/wmts?REQUEST=GetCapabilities";

var italy = new L.TileLayer.WMTS( url ,
    {
        layer: 'nurc:mosaic',
        style: "",
        tilematrixSet: "EPSG:4326",
        format: "image/png"
    }
);
var map = L.map('map').setView([37, 24], 4);

L.control.scale({'position':'bottomleft','metric':true,'imperial':false}).addTo(map);



var osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);


var baseLayers = {
    "ItalyWMTS" : italy,
    "OpenStreetMap": osm
};

L.control.layers(baseLayers).addTo(map);

And this is my result: WMTS getCapabilities link from GeoServer inclusion with Leaflet

What am I missing ?

1 Answer 1

1

I think the issue is projections. You are trying to add an EPSG:4326 tileset (in degrees of latitude and longitude) to a map that is in metres (EPSG:3587). if you zoom in (a lot) near Null Island you should see Italy.

Change the projection of the TileSet to match your map to EPSG:900913, which for historical reasons is what GeoServer calls Web Mercator.

 tilematrixSet: "EPSG:900913",
1
  • var italy = new L.TileLayer.WMTS( url , { layer: 'nurc:mosaic', style: '', tilematrixset: 'EPSG:900913', format:'image/png' } ); This didn't solve the problem. I also checked if the nurc:mosaic has the EPSG:900913 defined, it has. ( I checked it from the GeoServer's Web Admin Page - Tile Layers - Tile Caching - Gridset, there are gridsets for both EPSG 4326 and EPSG 900913). Commented Feb 15, 2018 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.