Interactive mesh subdivision tool for maps using Next.js and map-toolkit.
- Draw polygon boundaries using the map drawing tool
- Automatically subdivide polygons into a grid of quad faces (default 3x3)
- Adjust subdivision count with sliders (rows and columns independently)
- Select individual faces by clicking on the map
- Edit face properties:
- Color picker for fill color
- Opacity slider
- Optional text labels
- Active/inactive toggle (inactive faces render with gray overlay)
- Multiple mesh support with independent subdivisions
- Real-time visual feedback with hover and selection states
- Node.js 22+
- pnpm 10+
pnpm installpnpm devOpen http://localhost:3000 in your browser.
pnpm buildpnpm start-
Create a Mesh
- Click the "Create Mesh" button in the toolbar
- Click on the map to add polygon vertices
- Double-click to finish the polygon
- The mesh will be automatically subdivided into a 3x3 grid
-
Adjust Subdivisions
- Select a mesh from the list in the toolbar
- Use the "Rows" slider to change the number of horizontal divisions (2-10)
- Use the "Columns" slider to change the number of vertical divisions (2-10)
- The mesh updates in real-time
-
Edit Faces
- Click on any quad face to select it
- The property editor appears on the right
- Change the color using the color picker
- Adjust opacity with the slider
- Add an optional label
- Toggle active/inactive state
-
Manage Meshes
- View all meshes in the sidebar list
- Click to select a mesh
- Delete meshes using the delete button
- MeshDisplayLayer - Custom deck.gl layer for rendering mesh faces
- MeshToolbar - Sidebar UI for mesh creation and subdivision controls
- FacePropertyEditor - Property panel for editing selected faces
- mesh-store - State management using createMapStore pattern
- subdivision - Grid generation and face calculation algorithms
src/lib/mesh/types.ts- Type definitionssrc/lib/mesh/subdivision.ts- Grid subdivision algorithmsrc/lib/mesh/mesh-utils.ts- Mesh manipulation utilitiessrc/components/mesh-layer/mesh-display-layer.ts- Rendering layersrc/hooks/mesh-store.ts- State managementapp/page.tsx- Main application page
- Next.js 14 - React framework with App Router
- @accelint/map-toolkit - Map components and utilities
- deck.gl - WebGL-powered visualization
- MapLibre GL - Base map rendering
- Tailwind CSS - Styling
- TypeScript - Type safety
The mesh subdivision algorithm:
- Calculates a bounding box around the polygon
- Divides the box into rows × columns
- Generates grid points at intersections
- Creates quad faces from adjacent grid points
- Preserves face properties when subdivision changes
- Click events are handled by the MeshDisplayLayer
- Selection state is managed through the mesh store
- Face highlighting uses increased border width
- Property changes trigger immediate re-renders
Uses the map-toolkit's createMapStore pattern:
- Per-map instance isolation
- Event bus integration for cross-component communication
- Automatic cleanup on unmount
- Type-safe actions and state
Private demo application.