Creating a Map Tile Provider
Grid allows users to set their own backend server and map tile provider through the "Custom Provider" interface. You can opt to use Grid provided maps as well even if self-hosting. This guide will walk you through setting up Protomaps as your map tile provider.
About Protomaps
Protomaps is a free and open source map of the world. Grid is currently configured to use PMTiles from Protomaps.
What are PMTiles?
PMTiles is a single-file archive format for tiled map data. It enables:
- Hosting on commodity storage platforms like S3
- Low-cost, zero-maintenance map applications
- "Serverless" architecture - no custom tile backend needed
- Freedom from third-party provider dependencies
Implementation Steps
1. Download Protomaps Build
First, download the latest Protomaps build:
- File size: approximately 106GB
- Download link: Latest Protomaps Build
2. Extract Regional Data (Optional)
If you only need maps for specific regions:
- Install the PMTiles CLI
- Use it to extract your desired region
- Follow the PMTiles extraction documentation for detailed instructions
3. Upload to Cloudflare R2
We recommend using Cloudflare R2 for hosting PMTiles for several reasons:
- Strong privacy practices (Privacy Policy)
- Cost-effective hosting and data serving
- Wide adoption among self-hosters
- Simplified implementation compared to traditional tile servers
- Seamless integration with Cloudflare's ecosystem
Upload Process
- Set up
rclone
on your local machine - Configure it with your API key
- Run the upload command:
rclone copyto my-filename my-configuration:my-bucket/my-folder/my-filename.pmtiles --progress --s3-chunk-size=256M
After upload, verify that your R2 bucket contains a "protomaps.pmtiles" file (approximately 100-130GB).
Alternative Hosting Options
While not yet extensively tested, alternatives like MinIO are available for self-hosting.
4. Create Cloudflare Worker
Using Cloudflare R2
- Navigate to Cloudflare dashboard
- Create a new Worker
- Configure your
wrangler.toml
for R2 Bucket access - Use wrangler to build and deploy to Cloudflare
For detailed worker configuration, refer to the Protomaps Cloudflare documentation.
Self-Hosted Option
To create a self-hosted worker:
- Use Node.js to create an HTTP server
- Implement the code from
/serverless/src/index.ts
- Configure your server for production use
5. Configure DNS
Choose one of these options:
- Point a subdomain (e.g.,
maps.yourdomain.com
) to your Cloudflare Worker - Use your static IP if self-hosting
6. Configure Grid App
- Open Grid
- Press "Custom Provider" on the landing page
- Enter your Maps URL:
https://your.domain.com/v1/protomaps.pmtiles
Troubleshooting
Common issues and solutions:
-
Upload Failures
- Verify internet connection stability
- Check R2 bucket permissions
- Ensure sufficient storage space
-
Worker Issues
- Verify worker routes are correctly configured
- Check R2 bucket binding
- Monitor worker logs for errors
-
Map Loading Problems
- Verify URL format in Grid app
- Check CORS configuration
- Ensure pmtiles file is correctly uploaded
Performance Optimization
To optimize your map tile service:
- Enable Cloudflare caching
- Configure appropriate cache headers
- Monitor bandwidth usage
- Consider regional deployments for better performance
Cost Considerations
Typical monthly costs:
- R2 Storage: ~$0.015 per GB
- R2 Operations: First 1 million requests free
- Cloudflare Workers: 100,000 requests free per day
License Information
- PMTiles reference implementations: BSD 3-Clause License
- PMTiles specification: Public domain (CC0 where applicable)
- Protomaps data: Various open licenses