|
25 | 25 | createTile: function (coords) {
|
26 | 26 | var tile = L.DomUtil.create('div', 'leaflet-tile');
|
27 | 27 | tile.style['box-shadow'] = 'inset 0 0 2px #f00';
|
28 |
| - var url = L.Util.template(this.url, coords); |
| 28 | + var url = this._expandUrl(this.url, coords); |
29 | 29 | if (this.cache[url]) {
|
30 | 30 | this._updateLayers(url, this.cache[url]);
|
31 | 31 | } else {
|
|
51 | 51 | //
|
52 | 52 | // Custom methods
|
53 | 53 | //
|
| 54 | + _expandUrl: function(template, coords) { |
| 55 | + // from: https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Implementations |
| 56 | + var tile2lon = function(x,z) { |
| 57 | + return (x/Math.pow(2,z)*360-180); |
| 58 | + }; |
| 59 | + var tile2lat = function(y,z) { |
| 60 | + var n=Math.PI-2*Math.PI*y/Math.pow(2,z); |
| 61 | + return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n)))); |
| 62 | + }; |
| 63 | + // from: https://leafletjs.com/reference-1.5.0.html#map-methods-for-getting-map-state |
| 64 | + var southWest = L.latLng( |
| 65 | + tile2lat(coords.y+1, coords.z), |
| 66 | + tile2lon(coords.x+1, coords.z) |
| 67 | + ); |
| 68 | + var northEast = L.latLng( |
| 69 | + tile2lat(coords.y, coords.z), |
| 70 | + tile2lon(coords.x, coords.z) |
| 71 | + ); |
| 72 | + // from: "toBBoxString()" on https://leafletjs.com/reference-1.5.0.html#latlngbounds |
| 73 | + var bboxStr = [southWest.lng,southWest.lat,northEast.lng,northEast.lat].join(','); |
| 74 | + coords = Object.assign(coords, { |
| 75 | + lat1: southWest.lat, |
| 76 | + lon1: southWest.lng, |
| 77 | + lat2: northEast.lat, |
| 78 | + lon2: northEast.lng, |
| 79 | + bbox: bboxStr |
| 80 | + }); |
| 81 | + return L.Util.template(template, coords); |
| 82 | + }, |
| 83 | + |
54 | 84 | _updateLayers: function(url, geoData) {
|
55 | 85 | if (geoData.type == 'FeatureCollection'){
|
56 | 86 | geoData = geoData.features;
|
|
0 commit comments