LOD and custom TileLayer

Each tile service has a tiling rule : different tile origin and different numbering rule. TileLayer uses TileSystem to define such tiling rule (tile origin and numbering rule).

You can refer to this doc for more details.

index.html
<!DOCTYPE html>
<html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>TileLayer and Geo-Projections - LOD and custom TileLayer</title>
  <style type="text/css">
    html,body{margin:0px;height:100%;width:100%}
    .container{width:100%;height:100%}
  </style>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.css">
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
  <body>
    <div id="map" class="container"></div>

    <script>
      // A complete customized TileLayer
      var resolutions = [];
      var d = 2 * 6378137 * Math.PI;
      for (var i = 0; i < 21; i++) {
        resolutions[i] = d / (256 * Math.pow(2, i));
      }

      var map = new maptalks.Map('map', {
        center:     [-0.113049,51.498568],
        zoom:  13,
        // a custom version of default web-mercator spatial reference
        // map's spatial reference definition
        spatialReference : {
          projection : 'EPSG:3857', // geo projection, can be a string or a function
          resolutions : resolutions,
          fullExtent : {         // map's full extent
            'top': 6378137 * Math.PI,
            'left': -6378137 * Math.PI,
            'bottom': -6378137 * Math.PI,
            'right': 6378137 * Math.PI
          }
        },
        baseLayer : new maptalks.TileLayer('base',{
          urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
          subdomains: ['a','b','c','d'],
          attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>',
          tileSystem : [1, -1, -20037508.34, 20037508.34], // tile system
          minZoom : 1,
          maxZoom : 20
        })
      });

    </script>
  </body>
</html>
Copied!