leaflet加载离线瓦片地图,EPSG:4326
import proj4 from 'proj4';
import 'proj4leaflet';
const resolutions = [
1.40625, 0.703125, 0.3515625, 0.17578125, 0.087890625,
0.0439453125, 0.02197265625, 0.010986328125, 0.0054931640625,
0.00274658203125, 0.001373291015625, 0.0006866455078125,
0.00034332275390625, 0.000171661376953125, 0.0000858306884765625,
0.00004291534423828125, 0.000021457672119140625,
0.000010728836059570312, 0.000005364418029785156,
0.000002682209014892578, 0.000001341104507446289
];
const crs = new L.Proj.CRS(
'EPSG:4326',
'+proj=longlat +datum=WGS84 +no_defs',
{
resolutions: resolutions,
origin: [-180, -90],
transformation: new L.Transformation(
1/360,
0.5,
1/180,
0.5
)
}
);
const customLayer = L.TileLayer.extend({
getTileUrl: function(coords) {
const z = coords.z;
const x = coords.x;
const y = -1 - coords.y;
return `http://127.0.0.1:8080/test/${z}/${x}/${y}.png`;
}
});
const map = L.map('map',{
center: mapCenter.value,
zoom: 18,
zoomControl: true,
scrollWheelZoom: true,
attributionControl: false,
crs: crs
});
const layer = new customLayer('', {
tms: true,
maxZoom: 20,
tileSize: 256,
bounds: [[-90, -180], [90, 180]]
});
layer.addTo(map);