index.js (2453B)
1 import L from 'leaflet'; 2 import './style.css'; 3 4 const yandexCrs = L.CRS.EPSG3395; 5 6 L.Layer.Yandex = L.TileLayer.extend({ 7 options: { 8 className: L.Browser.retina ? '' : 'yandex-tile-layer', 9 yandexScale: L.Browser.retina ? 2 : 1 10 }, 11 12 _getTilePos: function(coords) { 13 const tilePosLatLng = yandexCrs.pointToLatLng(coords.scaleBy(this.getTileSize()), coords.z); 14 return this._map.project(tilePosLatLng, coords.z).subtract(this._level.origin).round(); 15 }, 16 17 _pxBoundsToTileRange: function(bounds) { 18 const zoom = this._tileZoom; 19 const bounds2 = new L.Bounds( 20 yandexCrs.latLngToPoint(this._map.unproject(bounds.min, zoom), zoom), 21 yandexCrs.latLngToPoint(this._map.unproject(bounds.max, zoom), zoom)); 22 return L.TileLayer.prototype._pxBoundsToTileRange.call(this, bounds2); 23 }, 24 25 createTile: function(coords, done) { 26 const tile = L.TileLayer.prototype.createTile.call(this, coords, done); 27 const coordsBelow = L.point(coords).add([0, 1]); 28 coordsBelow.z = coords.z; 29 tile._adjustHeight = this._getTilePos(coordsBelow).y - this._getTilePos(coords).y; 30 return tile; 31 }, 32 33 _initTile: function(tile) { 34 L.TileLayer.prototype._initTile.call(this, tile); 35 tile.style.height = `${tile._adjustHeight}px`; 36 } 37 } 38 ); 39 40 L.Layer.Yandex.Map = L.Layer.Yandex.extend({ 41 initialize: function(options) { 42 let url = 'https://core-renderer-tiles.maps.yandex.net/tiles?l=map&x={x}&y={y}&z={z}&scale={yandexScale}'; 43 if (navigator.language) { 44 url += `&lang=${navigator.language}`; 45 } 46 L.Layer.Yandex.prototype.initialize.call(this, url, options); 47 }, 48 }); 49 50 L.Layer.Yandex.Sat = L.Layer.Yandex.extend({ 51 initialize: function(options) { 52 L.Layer.Yandex.prototype.initialize.call( 53 this, 54 'https://core-sat.maps.yandex.net/tiles?l=sat&x={x}&y={y}&z={z}', 55 options 56 ); 57 }, 58 }); 59 60 L.Layer.Yandex.Tracks = L.Layer.Yandex.extend({ 61 initialize: function(options) { 62 options = {minZoom: 10, maxNativeZoom: 16, ...options}; 63 L.Layer.Yandex.prototype.initialize.call( 64 this, 65 'https://core-gpstiles.maps.yandex.net/tiles?style=point&x={x}&y={y}&z={z}', 66 options 67 ); 68 }, 69 });