XYZ

This example uses OpenLayers v4.0.1. The latest is v.

#### XYZ

Example of a XYZ source.

The XYZ source is used for tile data that is accessed through URLs that include a zoom level and tile grid x/y coordinates.

Related API documentation:

- ol.Map
,
- ol.View
,
- ol.layer.Tile
,
- ol.source.XYZ

Copy Edit
XYZ Example of a XYZ source. var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' + '?apikey=Your API key from http://www.thunderforest.com/docs/apikeys/ here' }) }) ], view: new ol.View({ center: [-472202, 7530279], zoom: 12 }) }); <div id="map" class="map"></div>

    <!DOCTYPE html>
    <html>
      <head>
        <title>XYZ</title>
        <link rel="stylesheet" href="https://openlayers.org/en/v4.0.1/css/ol.css" type="text/css">
        <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
        <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
        <script src="https://openlayers.org/en/v4.0.1/build/ol.js"></script>
      </head>
      <body>
        <div id="map" class="map"></div>
        <script>
          var map = new ol.Map({
            target: 'map',
            layers: [
              new ol.layer.Tile({
                source: new ol.source.XYZ({
                  url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' +
                      '?apikey=Your API key from http://www.thunderforest.com/docs/apikeys/ here'
                })
              })
            ],
            view: new ol.View({
              center: [-472202, 7530279],
              zoom: 12
            })
          });
        </script>
      </body>
    </html>