Hello DEV Community! 👋
I'm excited to share an open-source project I'm working on: leaflet-polyline-history.
If you've worked with Leaflet maps, especially when drawing or editing polylines and polygons, you may have encountered a common challenge:
How do you implement reliable Undo and Redo functionality for map editing?
Leaflet provides excellent mapping and drawing capabilities, but managing editing history and restoring previous geometry states can require additional implementation.
I wanted to make this easier for developers, so I started building a reusable TypeScript npm library.
💡 What is leaflet-polyline-history?
leaflet-polyline-history aims to provide a simple history management solution for Leaflet geometry editing.
The planned features include:
↩️ Undo drawing and editing operations.
↪️ Redo previously undone changes.
🗺️ Track polyline and polygon modifications.
🗑️ Restore deleted shapes.
📚 Maintain configurable editing history.
💾 Export and restore history.
⚛️ React Leaflet integration.
📘 TypeScript support.
🛠️ Technology Stack
The project is built around:
TypeScript
Leaflet
Vite
Vitest
React Leaflet integration
The core engine is designed to remain framework-independent, making it easier to integrate into different Leaflet applications.
📦 Installation
npm install leaflet-polyline-history
👩💻 Example Usage
The proposed API looks like this:
import L from "leaflet";
import { createPolylineHistory } from "leaflet-polyline-history";
const history = createPolylineHistory(map, {
maxHistory: 50,
trackPolylines: true,
trackPolygons: true
});
history.undo();
history.redo();
history.canUndo();
history.canRedo();
API and integration details may evolve as development progresses.
🎯 Why did I build this?
While working with map-based applications, I realized that managing geometry changes and restoring previous states can become complicated, particularly when multiple shapes are involved.
Instead of solving the same problem separately in every application, I wanted to explore building a reusable solution that other developers could benefit from.
🤝 Looking for feedback and contributors!
This is an open-source project, and I would love to connect with developers who work with:
Leaflet
React Leaflet
Leaflet.Draw
Leaflet-Geoman
GIS applications
TypeScript
I'd appreciate your feedback, suggestions, feature requests and contributions.
If you have encountered similar challenges while working with Leaflet, I'd love to hear how you solved them!
📦 npm: https://www.npmjs.com/package/leaflet-polyline-history?activeTab=readme
💻 GitHub: https://github.com/sweety-124/leaflet-polyline-history
If you find the idea useful, consider giving the GitHub repository a ⭐.
Thanks for reading! Happy coding! 💚
