1/* 2 * L.TileLayer.Zoomify display Zoomify tiles with Leaflet 3 */ 4 5L.TileLayer.Zoomify = L.TileLayer.extend({ 6 options: { 7 continuousWorld: true, 8 tolerance: 0.8 9 }, 10 11 initialize: function (url, options) { 12 options = L.setOptions(this, options); 13 this._url = url; 14 15 var imageSize = L.point(options.width, options.height), 16 tileSize = options.tileSize; 17 18 this._imageSize = [imageSize]; 19 this._gridSize = [this._getGridSize(imageSize)]; 20 21 while (parseInt(imageSize.x) > tileSize || parseInt(imageSize.y) > tileSize) { 22 imageSize = imageSize.divideBy(2).floor(); 23 this._imageSize.push(imageSize); 24 this._gridSize.push(this._getGridSize(imageSize)); 25 } 26 27 this._imageSize.reverse(); 28 this._gridSize.reverse(); 29 30 this.options.maxZoom = this._gridSize.length - 1; 31 }, 32 33 onAdd: function (map) { 34 L.TileLayer.prototype.onAdd.call(this, map); 35 36 var mapSize = map.getSize(), 37 zoom = this._getBestFitZoom(mapSize), 38 imageSize = this._imageSize[zoom], 39 center = map.options.crs.pointToLatLng(L.point(imageSize.x / 2, imageSize.y / 2), zoom); 40 41 map.setView(center, zoom, true); 42 }, 43 44 _getGridSize: function (imageSize) { 45 var tileSize = this.options.tileSize; 46 return L.point(Math.ceil(imageSize.x / tileSize), Math.ceil(imageSize.y / tileSize)); 47 }, 48 49 _getBestFitZoom: function (mapSize) { 50 var tolerance = this.options.tolerance, 51 zoom = this._imageSize.length - 1, 52 imageSize, zoom; 53 54 while (zoom) { 55 imageSize = this._imageSize[zoom]; 56 if (imageSize.x * tolerance < mapSize.x && imageSize.y * tolerance < mapSize.y) { 57 return zoom; 58 } 59 zoom--; 60 } 61 62 return zoom; 63 }, 64 65 _tileShouldBeLoaded: function (tilePoint) { 66 var gridSize = this._gridSize[this._map.getZoom()]; 67 return (tilePoint.x >= 0 && tilePoint.x < gridSize.x && tilePoint.y >= 0 && tilePoint.y < gridSize.y); 68 }, 69 70 _addTile: function (tilePoint, container) { 71 var tilePos = this._getTilePos(tilePoint), 72 tile = this._getTile(), 73 zoom = this._map.getZoom(), 74 imageSize = this._imageSize[zoom], 75 gridSize = this._gridSize[zoom], 76 tileSize = this.options.tileSize; 77 78 if (tilePoint.x === gridSize.x - 1) { 79 tile.style.width = imageSize.x - (tileSize * (gridSize.x - 1)) + 'px'; 80 } 81 82 if (tilePoint.y === gridSize.y - 1) { 83 tile.style.height = imageSize.y - (tileSize * (gridSize.y - 1)) + 'px'; 84 } 85 86 L.DomUtil.setPosition(tile, tilePos, L.Browser.chrome || L.Browser.android23); 87 88 this._tiles[tilePoint.x + ':' + tilePoint.y] = tile; 89 this._loadTile(tile, tilePoint); 90 91 if (tile.parentNode !== this._tileContainer) { 92 container.appendChild(tile); 93 } 94 }, 95 96 getTileUrl: function (tilePoint) { 97 return this._url + 'TileGroup' + this._getTileGroup(tilePoint) + '/' + this._map.getZoom() + '-' + tilePoint.x + '-' + tilePoint.y + '.jpg'; 98 }, 99 100 _getTileGroup: function (tilePoint) { 101 var zoom = this._map.getZoom(), 102 num = 0, 103 gridSize; 104 105 for (z = 0; z < zoom; z++) { 106 gridSize = this._gridSize[z]; 107 num += gridSize.x * gridSize.y; 108 } 109 110 num += tilePoint.y * this._gridSize[zoom].x + tilePoint.x; 111 return Math.floor(num / 256);; 112 } 113 114}); 115 116L.tileLayer.zoomify = function (url, options) { 117 return new L.TileLayer.Zoomify(url, options); 118};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.