Fast Layer
A fast WebAssembly-based layer for high-performance MapLibre/Mapbox rendering using WebGL2.
π§ Status: Work In Progress
This project is currently in development and is not ready for production use. Features are being actively developed and the API may change.
Overview
Fast Layer is a WebAssembly (WASM) library written in Rust that provides high-performance map rendering capabilities by leveraging WebGL2. It's designed to integrate seamlessly with MapLibre GL JS and Mapbox GL JS, offering improved performance for complex map visualizations.
Key Features
- β‘ High Performance: WebGL2-accelerated rendering for smooth map interactions
- π¦ Rust + WebAssembly: Memory-safe, blazing-fast WebAssembly compilation
- πΊοΈ MapLibre Compatible: Seamless integration with MapLibre GL JS
- π§ Custom Shaders: Vertex and fragment shader support for advanced rendering effects
- π± Cross-Platform: Works in all modern browsers supporting WebGL2
Technology Stack
- Rust: Primary language for WASM compilation
- WebAssembly (WASM): High-performance web deployment
- WebGL2: Advanced graphics rendering
- MapLibre GL JS: Map rendering library
- wasm-bindgen: Rust-WebAssembly interoperability
- web-sys: Web API bindings for Rust
Quick Start
Prerequisites
- Rust (latest stable version)
- wasm-pack (WebAssembly packaging tool)
- A modern web browser with WebGL2 support
Installation
- Clone the repository:
- Build the WebAssembly module:
The build script will:
- Install wasm-pack if not already installed
- Compile Rust to WebAssembly
- Generate JavaScript bindings
- Output files to
www/pkg/
Running the Demo
- Open
www/index.htmlin a web browser - The demo will load MapLibre with a basic FastLayer implementation
- You should see a map with a red point rendered by the WebGL2 layer
Project Structure
fast-layer/
βββ src/
β βββ lib.rs # Main WASM library implementation
β βββ main.rs # Test/development binary
βββ www/
β βββ index.html # Demo webpage
β βββ map.js # MapLibre integration
β βββ pkg/ # Generated WASM package (after build)
βββ build.sh # Build script
βββ Cargo.toml # Rust dependencies and configuration
βββ README.md # This file
API Reference
FastLayer Struct
Methods
new(canvas_id: &str) -> FastLayer: Creates a new FastLayer instancecompile(&mut self): Compiles the WebGL2 shaders and links the programdraw(&self, matrix: &[f64]): Renders the layer using the provided transformation matrix
Usage Example
import from "./pkg/fast_layer.js";
// Initialize the WASM module
await ;
// Create a new FastLayer instance
const fastLayer = ;
// Compile shaders
fastLayer.;
// Draw with transformation matrix
const matrix = ;
fastLayer.;
Development
Building from Source
# Install wasm-pack if not already installed
|
# Build the project
Running Tests
Development Server
For development, you can serve the www/ directory with any static file server:
# Using Python
# Using Node.js (if you have serve installed)
# Using PHP
Then open http://localhost:8000 in your browser.
Performance
Fast Layer is designed to provide superior performance compared to JavaScript-based map layers by:
- Running compute-intensive operations in optimized WebAssembly
- Utilizing low-level WebGL2 APIs for maximum GPU utilization
- Minimizing JavaScript-WebAssembly boundary crossings
- Leveraging Rust's zero-cost abstractions
Browser Compatibility
- Chrome 56+ (WebGL2 support)
- Firefox 51+ (WebGL2 support)
- Safari 15+ (WebGL2 support)
- Edge 79+ (WebGL2 support)
Contributing
This project is in early development. Contributions are welcome!
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Test thoroughly
- Submit a pull request
Development Guidelines
- Follow Rust naming conventions
- Add tests for new functionality
- Update documentation as needed
- Ensure WebGL2 compatibility
Roadmap
- Complete shader pipeline implementation
- Add support for complex geometries
- Implement efficient data streaming
- Add animation and transition support
- Optimize memory usage
- Add comprehensive test suite
- Performance benchmarking
- Documentation improvements
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Author
Sebastian Oscar Lopez - sebastianoscarlopez@gmail.com
Acknowledgments
- MapLibre GL JS - Open-source map rendering
- Rust WebAssembly Working Group - WASM tooling and resources
- WebGL2 Specification - Graphics rendering standard
Support
For questions, issues, or contributions, please visit the GitHub repository or contact the author directly.
Note: This is a work-in-progress project. APIs and functionality may change significantly before the first stable release.