XYZ Retina tiles example

Example of Retina / HiDPI mercator tiles (512x512px) available as XYZ.

The ol.source.XYZ must contain tilePixelRatio parameter. The tiles were prepared from a GeoTIFF file with MapTiler.

retina, hidpi, xyz, maptiler, @2x, devicePixelRatio
<!DOCTYPE html>
<html>
<head>
<title>XYZ Retina tiles example</title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.9.0/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.9.0/build/ol.js"></script>

</head>
<body>
<div class="container-fluid">

<div class="row-fluid">
  <div class="span12">
    <div id="map" class="map"></div>
  </div>
</div>

</div>
<script>
var attribution = new ol.Attribution({
  html: 'Tiles &copy; USGS, rendered with ' +
      '<a href="http://www.maptiler.com/">MapTiler</a>'
});

var mapMinZoom = 1;
var mapMaxZoom = 15;
var mapExtent = [-112.261791, 35.983744, -112.113981, 36.132062];

var map = new ol.Map({
  target: 'map',
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),
    new ol.layer.Tile({
      extent: ol.proj.transformExtent(mapExtent, 'EPSG:4326', 'EPSG:3857'),
      source: new ol.source.XYZ({
        attributions: [attribution],
        url: 'http://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png',
        tilePixelRatio: 2, // THIS IS IMPORTANT
        minZoom: mapMinZoom,
        maxZoom: mapMaxZoom
      })
    })
  ],
  view: new ol.View({
    projection: 'EPSG:3857',
    center: ol.proj.transform([-112.18688965, 36.057944835],
        'EPSG:4326', 'EPSG:3857'),
    zoom: 12
  })
});

</script>
</body>
</html>