Slovenia EPSG 3912 Leaflet map with custom tiling

by Mitja Tomažič

HTML

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css">
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://kartena.github.io/Proj4Leaflet/lib/proj4-compressed.js"></script>
<script src="https://kartena.github.io/Proj4Leaflet/src/proj4leaflet.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/MrMufflon/Leaflet.Coordinates/master/dist/Leaflet.Coordinates-0.1.5.css">
<script src="https://cdn.rawgit.com/MrMufflon/Leaflet.Coordinates/master/dist/Leaflet.Coordinates-0.1.5.min.js"></script>
<div id="map"></div>

CSS

html,
			body {
			  height: 100%;
			  padding: 0;
			  margin: 0;
			}
			
			#map {
			  width: 100%;
			  height: 100%;
			}
			
			.leaflet-tile {
			  border: solid red 1px;
			}

JavaScript

L.TileLayer.MyCustomLayerClass = L.TileLayer.extend({
			  getTileUrl: function(coords) {
			    var tileS;
			    var tileX;
			    var tileY;
			    var tileZ;
			    var tileName;
			    var hexX;
			    var hexY;
			    var hexXhexY;

			    tileS = this._getSubdomain(coords);
			    tileX = coords.x;
			    tileY = (2048 / Math.pow(2, 11 - coords.z)) - coords.y - 1;
			    tileZ = 'S' + '789ABCDEFGHI'.charAt(coords.z);
			    switch (Math.ceil(coords.z / 4)) {
			      case 3:
			        var hexX = ('00' + (tileX.toString(16)).toUpperCase()).slice(-3);
			        var hexY = ('00' + (tileY.toString(16)).toUpperCase()).slice(-3);
			        var hexXhexY = hexX + hexY;
			        var tileName = hexXhexY.substr(0, 2) + '/' + hexXhexY.substr(2, 2) + '/' + tileZ + hexXhexY + '.jpg';
			        break;
			      case 2:
			        var hexX = ('0' + (tileX.toString(16)).toUpperCase()).slice(-2);
			        var hexY = ('0' + (tileY.toString(16)).toUpperCase()).slice(-2);
			        var hexXhexY = hexX + hexY;
			        var tileName = hexXhexY.substr(0, 2) + '/' + tileZ + hexXhexY + '.jpg';
			        break;
			      default:
			        var hexX = (tileX.toString(16)).toUpperCase();
			        var hexY = (tileY.toString(16)).toUpperCase();
			        var tileName = tileZ + hexX + hexY + '.jpg';
			    }
			    return 'http://gpcl' + tileS + '.geopedia.si/v1/AUTH_d7e1266c-6b4e-4629-91e6-17d4b370846d/gurs.dof.50cm.2011.epsg:3912/' + tileZ + '/' + tileName;
			  }
			});

			L.tileLayer.myCustomLayer = function(templateUrl, options) {
			  return new L.TileLayer.MyCustomLayerClass(templateUrl, options);
			}

			var crs3912 = new L.Proj.CRS('EPSG:3912',
			  '+proj=tmerc +lat_0=0 +lon_0=15 +k=0.9999 +x_0=500000 +y_0=-5000000 +ellps=bessel +towgs84=682,-203,480,0,0,0,0 +units=m +no_defs', {
			    origin: [368000, 243144],
			    resolutions: [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 0.5],
			  });

			var map = L.map('map', {
			  crs: crs3912,
			});

			var myLayer...