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 🙏

© 2025 – Pkg Stats / Ryan Hefner

leaflet-city-autocomplete-usa

v1.2.2

Published

A Leaflet plugin that adds an autocomplete control for all U.S. cities, states, and ZIP codes using U.S. Census Gazetteer data.

Readme

🗺️ Leaflet City Autocomplete USA

npm version License: MIT Leaflet Demo

A lightweight Leaflet plugin that adds an autocomplete search control for all U.S. cities, states, and ZIP codes using official U.S. Census Gazetteer data.

This plugin allows you to search any U.S. city, state, or ZIP code, automatically fly the map to its coordinates, and optionally show a marker and popup with location information.


🚀 Features

  • 🔍 Autocomplete for 32,000+ U.S. cities, states, and ZIP codes
  • 📍 Displays marker + popup on selection
  • 🧭 Smooth fly-to animation
  • 🌎 Built-in timezone info for each city
  • 🧹 Clear button (❌) to reset search and map view
  • 🪶 Lightweight and dependency-free (only Leaflet)

📦 Installation

Option 1 — via npm

npm install leaflet-city-autocomplete-usa

Then import it in your project:

import "leaflet/dist/leaflet.css";
import "leaflet-city-autocomplete-usa/dist/leaflet.cityAutocompleteUSA.css";
import "leaflet-city-autocomplete-usa/dist/leaflet.cityAutocompleteUSA.js";

Option 2 — via direct download (manual include)

<link rel="stylesheet" href="dist/leaflet.cityAutocompleteUSA.css" />
<script src="dist/leaflet.cityAutocompleteUSA.js"></script>

🗺️ Usage Example

Here’s a complete example you can use directly in your project:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Leaflet City Autocomplete USA Example</title>

  <!-- Leaflet core -->
  <link
    rel="stylesheet"
    href="https://unpkg.com/[email protected]/dist/leaflet.css"
  />
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>

  <!-- Plugin -->
  <link
    rel="stylesheet"
    href="node_modules/leaflet-city-autocomplete-usa/dist/leaflet.cityAutocompleteUSA.css"
  />
  <script src="node_modules/leaflet-city-autocomplete-usa/dist/leaflet.cityAutocompleteUSA.js"></script>

  <style>
    #map { width: 100%; height: 600px; }
  </style>
</head>

<body>
  <div id="map"></div>

  <script>
    const map = L.map("map").setView([39.8283, -98.5795], 5);

    L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
      attribution: "© OpenStreetMap contributors"
    }).addTo(map);

    // Load location data and initialize the autocomplete control
    fetch("node_modules/leaflet-city-autocomplete-usa/data/us_states_with_cities.json")
      .then(res => res.json())
      .then(data => {
        const control = L.control.cityAutocompleteUSA({
          citiesData: data,
          flyTo: true,
          showMarker: true,
          showPopup: true
        });
        control.addTo(map);
      })
      .catch(err => console.error("❌ Error loading data:", err));
  </script>
</body>
</html>

⚙️ Options

| Option | Type | Default | Description | |--------|------|----------|-------------| | position | string | "topright" | Control position on the map | | placeholder | string | "Search city, state, or ZIP..." | Input placeholder text | | minLength | number | 2 | Minimum characters before search starts | | maxSuggestions | number | 25 | Max number of suggestions displayed | | flyTo | boolean | true | Animate map to location position | | showMarker | boolean | true | Show a marker on selection | | showPopup | boolean | true | Show popup with city + state + ZIP + timezone | | zoomLevel | number | 10 | Zoom level after selecting a location |


❌ Clear Button

When typing, a red “✖” button appears inside the input field. Clicking it:

  • Clears the search input
  • Removes all markers/popups
  • Returns the map to its initial U.S. view

🧪 Demo

You can view a live example at:

🔗 GitHub Pages Demo

Or run it locally:

npm start

Then open → http://localhost:3000/demo


📄 Data Source

Official dataset:
U.S. Census Gazetteer (2024)
https://www2.census.gov/geo/docs/maps-data/data/gazetteer/


🧑‍💻 Author

Developed by Sergio Barrios
License: MIT


⭐ Contribute

Contributions and pull requests are welcome!
If you find bugs or want to improve the search, open an issue on GitHub.