@rezw4n/maplibre-google-streetview
Version:
A MapLibre plugin that adds Google Street View functionality with pegman control
109 lines (75 loc) β’ 3.04 kB
Markdown
A MapLibre GL JS plugin that adds Google Street View functionality with a draggable pegman control, similar to Google Maps.

- πΆββοΈ Draggable pegman control that shows Street View coverage
- π Street View opens in an overlay with close button
- π Clicking on the pegman button toggles Street View coverage layer
- π± Fully responsive design
- π οΈ Customizable options
```bash
npm install @rezw4n/maplibre-google-streetview
```
```html
<link href="https://cdn.jsdelivr.net/npm/@rezw4n/maplibre-google-streetview@latest/dist/maplibre-google-streetview.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/@rezw4n/maplibre-google-streetview@latest/dist/maplibre-google-streetview.js"></script>
```
- MapLibre GL JS (v2.0.0 or higher)
- A Google Maps API key with the following APIs enabled:
- Street View Static API
- Maps Embed API
## Usage
### Basic Usage
```javascript
import MapLibreGL from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import MaplibreGoogleStreetView from 'maplibre-google-streetview';
import 'maplibre-google-streetview/dist/maplibre-google-streetview.css';
// Initialize MapLibre map
const map = new MapLibreGL.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json', // or your own style
center: [-74.0066, 40.7135], // New York City
zoom: 15
});
// Add navigation control
map.addControl(new MapLibreGL.NavigationControl());
// Initialize Street View plugin
const streetViewPlugin = new MaplibreGoogleStreetView({
map: map,
apiKey: 'YOUR_GOOGLE_MAPS_API_KEY'
});
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `map` | Object | (required) | MapLibre GL JS map instance |
| `apiKey` | String | (required) | Google Maps API key |
| `showPegmanButton` | Boolean | `true` | Whether to show the pegman button |
Removes the Street View plugin from the map and cleans up all event listeners and DOM elements.
```javascript
streetViewPlugin.remove();
```
1. Click the pegman button or start dragging it to show Street View coverage (blue lines).
2. Drag the pegman to a location with Street View coverage.
3. Drop the pegman to open Street View at that location.
4. Click the X button to close Street View and return to the map.
## Browser Support
This plugin works with all modern browsers that support MapLibre GL JS.
## Local Development
1. Clone the repository
2. Install dependencies: `npm install`
3. Start development server: `npm run dev`
4. Build: `npm run build`
## License
MIT
## Credits
- Street View coverage tiles are provided by Google Maps
- Street View functionality uses Google Maps Embed API