I do not know a direct solution or plugin to load the images in, but i can provide you with a minimal samplecode:
HTML: <div id="leafletMap" class="leafletMap"></div>
Javascript:
import * as Leaflet from 'leaflet';
class exampleMap
//create the map element we want to work with:
leafletMap: Leaflet.Map = Leaflet.map('leafletMap', {});
//store our urls for readability:
let pathToYourJPG = "your/URL/to/Image/test.png";
let pathToYourJGW = "your/URL/to/WorldFile/test.jgw";
// call the function which does the "magic"
leafletCreatorFunction(pathToYourJPG, pathToYourJGW);
getMeta = async (url) => {
const img = new Image();
img.src = url;
await img.decode();
return img
};
/** Function which loads a Georefered Image in to leaflet by it's urls only.
* Works js async and can of corse be used in a loop.
* pathToYourJPG: an url of image file (e.g. png/jpg...)
* pathToYourJGW: an url of the corresponding worldfile (The Georeferences)
*/
leafletCreatorFunction(pathToYourJPG , pathToYourJGW) {
//Fetching Image and TextData
Promise.all([
fetch(pathToYourJGW).then(r => r.text()),
this.getMeta(pathToYourJPG)
]).then(([jgwText, img]) => {
//Calculate the Bounding Box
let splitted = jgwText.split("\n")
let widthOf1PixelInCRSUnits = Number(splitted[0])
let heightOf1PixelInCRSUnits = Number(splitted[3])
let centerXCoordinateOfUpperLeftPixel = Number(splitted[4])
let centerYCoordinateOfUpperLeftPixel = Number(splitted[5])
let westBound = centerXCoordinateOfUpperLeftPixel - (widthOf1PixelInCRSUnits / 2)
let northBound = centerYCoordinateOfUpperLeftPixel - (heightOf1PixelInCRSUnits / 2)
let eastBound = westBound + ((img.naturalWidth) * widthOf1PixelInCRSUnits)
let southBound = northBound + ((img.naturalHeight) * heightOf1PixelInCRSUnits)
let westSouthBoundCoordinatesInWSG84= Leaflet.CRS.EPSG3857.unproject(Leaflet.point(westBound, southBound)) //important: use the correct CRS here!
let eastNorthBoundCoordinatesInWSG84= Leaflet.CRS.EPSG3857.unproject(Leaflet.point(eastBound, northBound))
//add now the imageOverlay to your map:
let myJpgJgwOverlay = Leaflet.imageOverlay(pathToYourJPG,
Leaflet.latLngBounds(westSouthBoundCoordinatesInWSG84, eastNorthBoundCoordinatesInWSG84), {
opacity: 1,
alt: "TestImage",
zIndex: 10,
interactive: false
}).addTo(this.leafletMap);
console.log("i'm happy to answer you question")
});
}
}
Q&A's which was used to create this minimal example or give a way deeper explonation: