This directory contains example projects demonstrating how to use ol-contextmenu in different scenarios.
Best for: Quick start, no build tools required
This example shows how to use ol-contextmenu with CDN-hosted libraries. It demonstrates:
- Basic menu item setup with callbacks
- Menu items with icons
- Submenus (nested menu items)
- Separators
- Dynamic menu updates based on context
- Feature detection at click location
- Custom data propagation to callbacks
How to run:
- Open
contextmenu.htmlin a web browser - Right-click anywhere on the map to see the context menu
- Right-click on a marker to see a different menu
Key concepts demonstrated:
- Creating a context menu with custom items
- Using the
openevent to dynamically change menu items - Detecting features at the click location
- Passing custom data to callback functions
Best for: Projects using Webpack as a bundler
This example demonstrates how to integrate ol-contextmenu in a Webpack-based project with ES6 modules. It shows:
- ES6 module imports
- Multi-level nested submenus
- Using
defaultItemsoption beforeopenevent handling- CSS imports with Webpack
See the Webpack example README for detailed setup instructions.
Best for: Modern projects using Vite with TypeScript
This example shows how to use ol-contextmenu in a Vite + TypeScript project. It demonstrates:
- TypeScript type imports
- Type-safe callback functions
- Module bundling with Vite
- CSS imports with Vite
See the Vite example README for detailed setup instructions.
- Check out the main README for complete API documentation
- Explore the source code to see how different features are implemented
- Try modifying the examples to add your own menu items and callbacks