A Leaflet plugin that provides enhanced image overlay capabilities, allowing you to transform (rotate, scale, and move) images on Leaflet maps with interactive controls.
- Rotated Image Overlays: Display images at any angle on your map
- Transform Controls: Interactive handles for rotating and scaling images
- Draggable: Move images by dragging
- Scale Control: Adjust image size using meters per pixel
- Center-based Positioning: Position images using center point and transformation parameters
- TypeScript Support: Includes TypeScript type definitions
You can install the package via npm:
npm install leaflet-imageoverlay-transform
Or include it directly in your HTML:
<link rel="stylesheet" href="path/to/leaflet-imageoverlay-transform.css" />
<script src="path/to/leaflet-imageoverlay-rotated.js"></script>
<script src="path/to/leaflet-imageoverlay-transform.js"></script>
// Create a map
var map = L.map('map').setView([51.505, -0.09], 13);
// Add your tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
// Define transform parameters
var transform = {
center: L.latLng(51.505, -0.09),
scale: 0.5, // meters per pixel
rotation: 45 // degrees
};
// Create and add the transform overlay
var overlay = L.imageOverlay.transform("path/to/image.jpg", transform, {
opacity: 0.8,
interactive: true
}).addTo(map);
L.imageOverlay.transform(<String|HTMLImageElement|HTMLCanvasElement> image,
<Transform> transform,
<ImageOverlayOptions> options?)
interface Transform {
center: L.LatLng; // Center position of the image
scale: number; // Scale in meters per pixel
rotation: number; // Rotation in degrees
}
setTransform(transform: Transform)
: Update the image transformationgetTransform()
: Get current transform parameterssetInteractive(interactive: boolean)
: Enable/disable transform controlssetOpacity(opacity: number)
: Set the overlay opacity
Extends standard Leaflet's ImageOverlay
options with:
interactive: boolean
- Enable transform controls (default: false)- All standard L.ImageOverlay options are supported
When interactive: true
is set, the overlay provides three ways to transform the image:
- Drag: Click and drag the image to move it
- Rotate: Use the handle above the image to rotate
- Scale: Use the handle at the top-right corner to scale the image
The overlay extends Leaflet's ImageOverlay events and includes:
- Standard Leaflet events (
click
,dblclick
, etc.) - Mouse events for interaction with transform handles
- Supports all modern browsers
- Requires Leaflet 1.0.0 or newer
# Install dependencies
npm install
# Run development server
npm start
# Build for production
npm run build
Check out the demo files included in the project:
demo.html
: Basic rotated image overlay demodemo-transform.html
: Interactive transform controls demo
This project is licensed under the Beerware License. See the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This plugin builds upon the work of:
- Original Leaflet.ImageOverlay.Rotated by Iván Sánchez Ortega
- Contributions from Julius Buset Asplin and other community members
For questions and support:
- Open an issue in the GitHub repository
- Check existing issues for similar problems
- Read the documentation carefully