Use Case · Maps & Visualization

Interactive Maps & Location Search

Open Serverless MapLibre Prototype
Replaces Mapbox Search JS, Google Maps Places Search Box

Putting a reliable search bar onto an interactive web map usually ties you to a metered platform: you pay per map load, pay again per autocomplete session, and pay again every time a user clicks the map to inspect an address.

With texspace/maplibre, you add a drop-in search control directly to any MapLibre GL JS map in three lines of code. Pair it with free vector tiles (like OpenFreeMap or your own static map tiles) and you can deploy a complete worldwide interactive map with 450M+ searchable addresses on GitHub Pages, Vercel, Netlify, or Cloudflare Pages for $0/mo.

What this solves#

  • 3-line MapLibre integration: Zero external CSS files to bundle, automatic light/dark theming, and keyboard navigation built in.
  • Viewport-aware search: Automatically biases suggestions toward the area currently visible on the map, so searching "Market St" shows San Francisco when you're viewing California and Philadelphia when you're viewing Pennsylvania.
  • Click-to-reverse geocoding: Enable reverseOnClick: true to turn any click on the map into an instant street address, rooftop, or landmark lookup.
  • Automatic framing & boundary polygons: Selecting a city, state, country, or postal code smoothly fits the map to its bounding box and can draw its boundary polygon right onto the map.

Quick Example (3 Lines)#

ts
import maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
import { TexspaceControl } from "texspace/maplibre";

const map = new maplibregl.Map({
  container: "map",
  style: "https://tiles.openfreemap.org/styles/liberty",
  center: [-122.4194, 37.7749],
  zoom: 12,
});

const geocoder = new TexspaceControl("https://shards.texspace.dev/txg/v2", {
  maplibre: maplibregl,
  placeholder: "Search any address, landmark, or coordinate...",
  proximity: true,
  reverseOnClick: true,
  theme: "auto",
  onSelect: (hit) => {
    console.log("Selected:", hit.label, hit.lat, hit.lon);
  },
  onReverse: (rev) => {
    console.log("Clicked address:", rev.results[0]?.label);
  },
});

map.addControl(geocoder, "top-left");
TIP

Try the live zero-server MapLibre + OpenFreeMap demo hosted directly on GitHub Pages at nside.github.io/texspace.

Control Options#

OptionDefaultDescription
placeholder"Search any address or place..."Placeholder shown in the search input.
limit5Maximum number of suggestions per search.
proximitytrueBiases results toward the current map center.
flyTotrueSmoothly flies or fits bounds to the selected location.
zoom16Target zoom level for rooftop and street hits.
markertrueDrops a MapLibre marker at the selected coordinate.
maplibrewindow.maplibreglPass your imported maplibregl module when using Vite, Webpack, or Next.js.
reverseOnClickfalseReverse-geocodes whenever the user clicks anywhere on the map.
theme"auto""auto", "light", or "dark".
prefetchtruePre-warms the local region on map load so the first search feels instant.
openOptions{}Extra options passed to Texspace.open() (e.g., private overlays).
onSelect / onReverse / onResults / onError—Event callbacks for integrating with your own sidebar or Inspector panel.

Drawing Boundary Polygons & Sharing One Client#

If you also want to highlight territory polygons (for example from geo.lookupLayer() or geo.enrich()) or share the same cache with custom map interactions, access the underlying client via geocoder.getClient():

ts
const client = await geocoder.getClient();

// Highlight the clicked state or custom territory polygon directly on the map
const state = await client.lookupLayer("layers/us_states.txg", 37.72047, -122.43765, {
  includeGeometry: true,
});
if (state.matches[0]?.geometry) {
  geocoder.setOverlay(state.matches[0].geometry);
}

Keeping Interactive Demos Instant with Background Warming#

For public maps with featured demo buttons or common cities, call client.warm() after mount. It quietly pre-fetches sample queries during idle time, pauses automatically whenever the user starts typing, and skips itself on slow or Save-Data mobile connections:

ts
const client = await geocoder.getClient();
client.warm(["10 Downing Street, London, SW1A 2AA", "4865 Mission St, San Francisco, CA 94112"]);

Go Deeper#