npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-google-maps

v0.0.5

Published

Plugin Vite: Provider automático + mini devtools para @vis.gl/react-google-maps

Downloads

211

Readme

Leer en Español

A Vite plugin that simplifies Google Maps integration in React applications using @vis.gl/react-google-maps.

Features

  • 🚀 Auto-configuration: Automatically wraps your app with APIProvider
  • 🎯 Default Map Options: Configure map defaults once, use everywhere
  • 🛠️ Developer Tools: Built-in debug panel for development
  • 📦 Zero Boilerplate: No need to manually set up providers

Installation

pnpm install vite-plugin-google-maps

Quick Start

1. Configure the plugin

Add the plugin to your vite.config.ts:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { GoogleMapsPlugin } from 'vite-plugin-google-maps';

export default defineConfig({
  plugins: [
    react(),
    GoogleMapsPlugin({
      apiKey: 'YOUR_GOOGLE_MAPS_API_KEY',
      libraries: ['places', 'marker'],
      debug: true, // Enable dev tools
      mapDefaults: {
        mapId: 'YOUR_MAP_ID',
        gestureHandling: 'greedy',
        defaultCenter: { lat: 40.7128, lng: -74.0060 },
        defaultZoom: 12,
        fullscreenControl: true,
        disableDefaultUI: false,
      }
    }),
  ],
});

2. Use the Map component

Import and use the pre-configured Map component:

import { Map } from '@google-maps/map';
import { AdvancedMarker } from '@vis.gl/react-google-maps';

function App() {
  return (
    <div style={{ height: '100vh', width: '100%' }}>
      <Map>
        <AdvancedMarker position={{ lat: 40.7128, lng: -74.0060 }} />
      </Map>
    </div>
  );
}

export default App;

TypeScript Setup

[!WARNING] To use the Map component with TypeScript, you need to declare the module type. Create a types.d.ts (or any *.d.ts) file in your project:

// types.d.ts or vite-env.d.ts
declare module "@google-maps/map" {
 import React from "react";
 import { Map as GoogleMapBase } from "@vis.gl/react-google-maps";
 
 export const Map: React.FC<React.ComponentProps<typeof GoogleMapBase>>;
}

This provides full type safety and autocomplete for the Map component props.

Configuration Options

GoogleMapsPluginOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | required | Your Google Maps API key | | libraries | string[] | ['places'] | Google Maps libraries to load | | debug | boolean | false | Enable developer tools panel | | mapDefaults | MapDefaultOptions | {} | Default options for Map component |

MapDefaultOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | mapId | string | - | Map ID for custom styling | | gestureHandling | 'cooperative' \| 'greedy' \| 'none' \| 'auto' | 'auto' | How map responds to gestures | | defaultCenter | { lat: number; lng: number } | - | Initial map center position | | defaultZoom | number | 8 | Initial zoom level (0-22) | | fullscreenControl | boolean | false | Show fullscreen button | | disableDefaultUI | boolean | false | Disable all default UI controls | | zoomControl | boolean | true | Show zoom controls (+/-) | | mapTypeControl | boolean | false | Show map/satellite toggle | | scaleControl | boolean | false | Show scale indicator | | streetViewControl | boolean | true | Show Street View pegman | | rotateControl | boolean | false | Show rotation control |

Usage Examples

Basic Map

import { Map } from '@google-maps/map';

function BasicMap() {
  return <Map />;
}

Override Default Options

import { Map } from '@google-maps/map';

function CustomMap() {
  return (
    <Map
      defaultZoom={15}
      defaultCenter={{ lat: 51.5074, lng: -0.1278 }}
      gestureHandling="cooperative"
    />
  );
}

With Markers

import { Map } from '@google-maps/map';
import { AdvancedMarker, InfoWindow } from '@vis.gl/react-google-maps';
import { useState } from 'react';

function MapWithMarkers() {
  const [open, setOpen] = useState(false);

  return (
    <Map>
      <AdvancedMarker
        position={{ lat: 40.7128, lng: -74.0060 }}
        onClick={() => setOpen(true)}
      />
      {open && (
        <InfoWindow
          position={{ lat: 40.7128, lng: -74.0060 }}
          onCloseClick={() => setOpen(false)}
        >
          <div>New York City</div>
        </InfoWindow>
      )}
    </Map>
  );
}

Multiple Maps with Different Settings

import { Map } from '@google-maps/map';

function MultipleMaps() {
  return (
    <div>
      {/* Uses plugin defaults */}
      <Map style={{ height: '50vh' }} />
      
      {/* Custom settings */}
      <Map
        style={{ height: '50vh' }}
        defaultCenter={{ lat: 48.8566, lng: 2.3522 }}
        defaultZoom={10}
      />
    </div>
  );
}

Developer Tools

When debug: true is enabled, a developer tools panel appears in the bottom-right corner showing:

  • API Key: First 5 characters of your API key
  • Libraries: Loaded Google Maps libraries
  • Map Status: Whether the map has loaded
  • Zoom Level: Current zoom level
  • Center: Current map center coordinates
  • Mouse Position: Real-time cursor coordinates
  • Click Position: Last clicked coordinates with geocoded address
  • Copy Button: Copy clicked coordinates to clipboard
  • Map Type: Current mapTypeId (roadmap, satellite, hybrid, terrain)
  • Map ID: Active mapId in use
  • Gesture Handling: Current interaction mode (auto, greedy, none, etc.)
  • Tilt: Current tilt angle of the map
  • Heading: Current rotation angle
  • Bounds: Current visible map boundaries (north, south, east, west)
  • Copy Config Button: Copies the full map configuration (center, zoom, tilt, heading, mapId, typeId, bounds)
  • My Location Button: Centers the map using browser geolocation
  • Reset Button: Restores the initial map configuration

How It Works

  1. Auto-wrapping: The plugin automatically wraps your React app with APIProvider in main.tsx
  2. Virtual Module: Creates a virtual module @google-maps/map that exports a pre-configured Map component
  3. Default Props: Merges plugin defaults with component props (component props take precedence)

Getting a Google Maps API Key

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Maps JavaScript API
  4. Go to Credentials and create an API key
  5. (Optional) Restrict your API key for security

Learn more

Troubleshooting

Map not loading

  • Verify your API key is correct
  • Check that the Maps JavaScript API is enabled in Google Cloud Console
  • Open browser console for error messages

TypeScript errors

  • Ensure @vis.gl/react-google-maps is installed
  • Check that your tsconfig.json includes the plugin directory

Devtools not showing

  • Verify debug: true in plugin options
  • Check that the Map component from @google-maps/map is being used

License

MIT

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Related