Skip to content

Instantly share code, notes, and snippets.

@moklick
Created April 18, 2016 15:09
Show Gist options
  • Save moklick/2ac7735584fdcf74c84cbbc5f79ce044 to your computer and use it in GitHub Desktop.
Save moklick/2ac7735584fdcf74c84cbbc5f79ce044 to your computer and use it in GitHub Desktop.

Revisions

  1. moklick created this gist Apr 18, 2016.
    21 changes: 21 additions & 0 deletions leaflet-crs-mapbox.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    const customCRS = L.extend({}, L.CRS.Earth, {
    projection: L.Projection.SphericalMercator,
    transformation: (function () {
    var scale = 0.5 / (Math.PI * L.Projection.SphericalMercator.R);
    return new L.Transformation(scale, 0.5, -scale, 0.5);
    }()),
    scale: function (zoom) {
    return 512 * Math.pow(2, zoom);
    }
    });

    const map = L.map('map', {
    crs: customCRS,
    center: config.map.center
    });

    const tileLayer = L.tileLayer(config.map.tileLayer, {
    attribution: config.map.attribution,
    accessToken: config.map.accessToken,
    tileSize: 512
    }).addTo(map);