scribo-maps
Version:
Embeddable map widget for store locators
417 lines (323 loc) β’ 10.7 kB
Markdown
# πΊοΈ Scribo Maps
An embeddable, responsive map widget for store locators and location-based applications. Built with Google Maps API and designed for easy integration into any website.
[](https://www.npmjs.com/package/scribo-maps)
[](https://www.npmjs.com/package/scribo-maps)
[](https://opensource.org/licenses/MIT)
## β¨ Features
- π **Interactive Google Maps** with marker clustering
- π **Smart search** with Google Places autocomplete
- π **Geolocation support** for finding nearby locations
- πͺ **Sidebar with location details** and "Get Directions" links
- π **Multi-language support** (English, Portuguese)
- π± **Fully responsive** design
- π¨ **Beautiful, modern UI** with smooth animations
- β‘ **Lightweight** (~17KB total, ~11KB minified)
- π **Easy integration** - just a few lines of code
## π Quick Start
```html
<!DOCTYPE html>
<html>
<head>
<!-- Scribo Maps CSS -->
<link rel="stylesheet" href="https://unpkg.com/scribo-maps@1.0.0/dist/scribo-maps.min.css">
</head>
<body>
<div id="map-container" style="height: 500px;"></div>
<!-- Dependencies -->
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_KEY&libraries=places"></script>
<script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script>
<!-- Scribo Maps JS -->
<script src="https://unpkg.com/scribo-maps@1.0.0/dist/scribo-maps.min.js"></script>
<!-- Initialize -->
<script>
new ScriboMap('map-container', {
locale: 'en-US', // or 'pt-BR'
locations: [
{
name: "Store Location",
address: "123 Main St, City",
lat: 40.7128,
lng: -74.0060,
image: "https://example.com/store-image.jpg"
}
]
});
</script>
</body>
</html>
```
## π API Reference
### Constructor
```javascript
new ScriboMap(elementId, config)
```
#### Parameters
- **elementId** `string` - ID of the HTML element to render the map
- **config** `object` - Configuration object
#### Configuration Object
```javascript
{
locale: 'en-US', // 'en-US' or 'pt-BR'
locations: [ // Array of location objects
{
name: 'Store Name', // Required: Display name
address: 'Full Address', // Optional: Full address string
lat: 40.7128, // Required: Latitude
lng: -74.0060, // Required: Longitude
image: 'image-url.jpg' // Optional: Store image URL
}
]
}
```
### Methods
```javascript
const map = new ScriboMap('container', config);
// Change language dynamically
map.setLocale('pt-BR');
// Get currently displayed locations
const visibleLocations = map.getCurrentlyDisplayedLocations();
```
## π Internationalization
Scribo Maps supports multiple languages:
### English (en-US)
```javascript
new ScriboMap('map', {
locale: 'en-US',
locations: [...]
});
```
### Portuguese (pt-BR)
```javascript
new ScriboMap('map', {
locale: 'pt-BR',
locations: [...]
});
```
## π¨ Customization
### Custom Styling
Override CSS variables to match your brand:
```css
:root {
--scribo-primary-color: #your-brand-color;
--scribo-border-radius: 12px;
--scribo-sidebar-width: 380px;
}
```
### Responsive Design
The widget automatically adapts to different screen sizes:
- **Desktop**: Full sidebar + map view
- **Mobile**: Optimized sidebar width and spacing
## π¦ File Structure
When you install or use via CDN, you get:
```
scribo-maps/
βββ dist/
β βββ scribo-maps.js # Source (16KB)
β βββ scribo-maps.min.js # Minified (11KB)
β βββ scribo-maps.css # Source styles (8KB)
β βββ scribo-maps.min.css # Minified styles (6KB)
β βββ scribo-maps.min.js.map # Source map
```
## π§ Dependencies
### Required
- **Google Maps JavaScript API** with Places library
- **MarkerClusterer** for marker clustering
### Peer Dependencies
- `@googlemaps/markerclusterer: ^2.0.0`
## π‘ Usage Examples
### Basic Store Locator
```javascript
new ScriboMap('store-locator', {
locale: 'en-US',
locations: [
{
name: "Downtown Store",
address: "123 Main St, Downtown",
lat: 40.7128,
lng: -74.0060,
image: "https://example.com/store1.jpg"
},
{
name: "Mall Location",
address: "456 Shopping Center Dr",
lat: 40.7589,
lng: -73.9851,
image: "https://example.com/store2.jpg"
}
]
});
```
### Restaurant Locator
```javascript
new ScriboMap('restaurant-finder', {
locale: 'pt-BR',
locations: [
{
name: "Restaurante Central",
address: "Rua Principal, 100 - Centro",
lat: -23.5505,
lng: -46.6333,
image: "https://example.com/restaurant.jpg"
}
]
});
```
### Service Locations
```javascript
new ScriboMap('service-locations', {
locale: 'en-US',
locations: [
{
name: "Service Center North",
address: "789 Service Ave, North District",
lat: 41.8781,
lng: -87.6298,
image: "" // Will use placeholder icon
}
]
});
```
## π CDN Options
- **unpkg**: `https://unpkg.com/scribo-maps@1.0.0/dist/`
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/scribo-maps@1.0.0/dist/`
## π¦ How to Deploy Your Own Version
If you want to create your own version or contribute to Scribo Maps, here's how to set up and deploy:
### Prerequisites
- Node.js 16+ and npm
- NPM account (create at [npmjs.com](https://npmjs.com))
- Google Maps API key for testing
### Development Setup
1. **Clone and setup:**
```bash
git clone https://github.com/scribo-dev/scribo-maps.git
cd scribo-maps
npm install
```
2. **Build the project:**
```bash
npm run build
```
This creates minified files in the `dist/` folder:
- `scribo-maps.min.js` (11KB)
- `scribo-maps.min.css` (6KB)
- Source maps for debugging
3. **Test locally:**
```bash
# Open index.html in your browser
# Or serve with a local server
npx serve .
```
### Publishing to NPM
1. **Login to NPM:**
```bash
npm login
```
2. **Update version (if needed):**
```bash
npm version patch # 1.0.0 β 1.0.1
npm version minor # 1.0.0 β 1.1.0
npm version major # 1.0.0 β 2.0.0
```
3. **Publish:**
```bash
npm publish
```
The `prepublishOnly` script automatically builds fresh minified files before publishing.
### What Gets Published
Your NPM package will include:
- `dist/scribo-maps.js` - Source JavaScript (16KB)
- `dist/scribo-maps.min.js` - Minified JavaScript (11KB)
- `dist/scribo-maps.css` - Source CSS (8KB)
- `dist/scribo-maps.min.css` - Minified CSS (6KB)
- `dist/scribo-maps.min.js.map` - Source map for debugging
- `package.json` - Package metadata
### CDN Availability
Once published, your package is automatically available on:
- **unpkg**: `https://unpkg.com/your-package@version/dist/`
- **jsDelivr**: `https://cdn.jsdelivr.net/npm/your-package@version/dist/`
Files are available within minutes of publishing!
### Build Scripts
```bash
npm run clean # Remove dist/ folder
npm run build:js # Minify JavaScript with source maps
npm run build:css # Minify CSS
npm run build # Complete build process
```
### Package Structure
```
scribo-maps/
βββ π Source files (committed to git)
β βββ scribo-maps.js β Main JavaScript
β βββ scribo-maps.css β Main stylesheet
β βββ index.html β Demo page
β βββ package.json β NPM configuration
β
βββ π dist/ (ignored by git, published to NPM)
β βββ scribo-maps.js β Source copy
β βββ scribo-maps.css β Source copy
β βββ scribo-maps.min.js β Minified JS
β βββ scribo-maps.min.css β Minified CSS
β βββ *.js.map β Source maps
β
βββ π node_modules/ (ignored)
```
### Best Practices
- β
**Test before publishing** with `npm run build`
- β
**Use semantic versioning** for updates
- β
**Update README** for major changes
- β
**Keep source files clean** (dist/ is auto-generated)
- β
**Test on multiple CDNs** after publishing
## π Browser Support
- β
Chrome 60+
- β
Firefox 55+
- β
Safari 12+
- β
Edge 79+
- β
Mobile browsers (iOS Safari, Chrome Mobile)
## π± Mobile Features
- Touch-friendly interface
- Responsive sidebar
- Optimized marker clustering
- Smooth pan and zoom
- Native "Get Directions" integration
## π Security
- No API keys hardcoded
- Client provides their own Google Maps API key
- Content Security Policy friendly
- XSS protection built-in
## β‘ Performance
- **Lazy loading** of map tiles
- **Marker clustering** for large datasets
- **Debounced search** to reduce API calls
- **Minified assets** for fast loading
- **CDN delivery** for global performance
## π Troubleshooting
### Common Issues
**Map not showing:**
- Check that your Google Maps API key is valid
- Ensure the Places library is included: `&libraries=places`
- Verify the container element exists
**Locations not appearing:**
- Check that lat/lng coordinates are valid numbers
- Ensure locations array is properly formatted
- Verify API key has proper permissions
**Styling issues:**
- Make sure CSS file is loaded before JS
- Check for CSS conflicts with your site's styles
- Verify container has a defined height
## π License
MIT License - see [LICENSE](LICENSE) file for details.
## π€ Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## π Support
- π **Issues**: [GitHub Issues](https://github.com/scribo-dev/scribo-maps/issues)
- π **Documentation**: [GitHub Wiki](https://github.com/scribo-dev/scribo-maps/wiki)
- π¬ **Discussions**: [GitHub Discussions](https://github.com/scribo-dev/scribo-maps/discussions)
## π Showcase
*Using Scribo Maps in your project? Let us know and we'll feature it here!*
---
**Made with β€οΈ by the Scribo team**
*Scribo Maps - Making location-based applications simple and beautiful.*