Skip to content

v3.0.0

Choose a tag to compare

@github-actions github-actions released this 30 Oct 15:14
· 6 commits to master since this release

A rewrite around one use case: capturing one precise point in a form. The default map is now OpenStreetMap through Leaflet, with no API key; Google Maps and MapLibre are opt-in providers. The upgrade guide with every v1 and v2 API is docs/migration.md.

The MIT License applies to this release and to all prior versions of location-picker.

Added

  • <location-picker>, a form-associated custom element: it submits through FormData (name, lat-name, lng-name, address-name), validates with required, resets with the form and restores on back/forward navigation (#4). import 'location-picker' and the script build define it; location-picker/core stays side-effect free.
  • Keyless default: Leaflet 1.9.4 (loaded on demand from jsDelivr with Subresource Integrity, only when window.L is absent) and OpenStreetMap tiles, with the attribution always visible.
  • Providers as adapters: leafletProvider(), googleProvider() (importLibrary, a CSS-overlay pin, optional AdvancedMarkerElement) and maplibreProvider() (bring your own maplibre-gl, OpenFreeMap style by default). Custom engines plug in through the public ProviderAdapter contract.
  • Address search (search, #10) and reverse geocoding (reverse-geocode, addresschange), paired with the provider: Photon for Leaflet and MapLibre, PlaceAutocompleteElement and the Google Geocoder for Google. Custom geocoders are supported.
  • Field mode for phones (presentation="field", or "auto" for coarse-pointer viewports up to 640 px wide): a compact form control with the address or coordinates and a "Choose on map" button opens the map in a full-screen modal <dialog> sheet. Pans, search picks and locates there are a draft until Confirm (input + change with their source); Cancel, Escape (and the system back gesture where the browser sends it to dialogs) and close() leave the value untouched. The engine loads on first open. New: showPicker(), close(), the toggle event, the field, field-value, field-button, sheet, sheet-header and cancel-button parts, :state(open), and the chooseOnMap, fieldPlaceholder and cancel messages.
  • A locate button (locate="button", #1) that prompts only on click; locate() with a timeout and a watchdog, so it never hangs.
  • Bound inputs (lat-input, lng-input, value-input, address-input) that receive native input/change events, for jQuery, Livewire, Alpine and server-rendered forms with progressive enhancement.
  • input and change events with detail.source (user, api, geolocation, search); ready and error events; onInput, onChange, onAddressChange, onReady and onError class callbacks.
  • LocationPickerError with stable code, one-line fix and level; messages read [location-picker] … Fix: ….
  • location-picker/utils: parseLatLng (decimal, DMS, geo: URIs, Google, OpenStreetMap and Apple Maps URLs), formatLatLng, normalizeLatLng, isLatLng.
  • Script build dist/location-picker.global.js (the unpkg and jsdelivr fields; https://cdn.jsdelivr.net/npm/location-picker@3), which sets window.LocationPicker and defines the element.
  • Theming through CSS custom properties, ::part(), slots and :state(); marker="none" hides the pin (#9); dark mode and right-to-left layouts; keyboard support and a polite live region.
  • Experimental, opt-in WebMCP tools (webmcp attribute, registerWebMcpTools()).
  • JSX typings for React 19, Preact, Solid, Vue and Svelte (location-picker/jsx/*), custom-elements.json, llms.txt, an Agent Skill (skills/location-picker/SKILL.md, shipped in the package) and AGENTS.md.
  • center sets where the map starts while no value is chosen, instead of a built-in default location (#7).
  • On the website: a no-code snippet generator for WordPress, Webflow, Squarespace, Shopify and form services (/embed/, with the guide docs/embed.md), and a hosted pick link (/pick/) that asks a person for a location with nothing to install and returns it by copy, redirect or postMessage.

Known issues

  • Writing value while the user is moving the map (for example from an input listener that writes the live value back) stops the move without a commit. Update framework state from change; Vue's v-model is not affected.
  • The class option webmcp: true does not register WebMCP tools yet; call registerWebMcpTools(picker). The element's webmcp attribute works. Planned for 3.1.
  • Field mode (presentation="field"): a value set while the sheet is closed, and an address that resolves after Confirm, update the field's text but are not announced to screen readers. The sheet itself and the field's label and value are accessible.

Breaking

  • .map (sync google.maps.Map, v1/v2) is now undefined until ready. It is still set synchronously with provider: googleProvider() on a page where Google Maps is already loaded with a classic script tag (a one-line fix).
  • Implicit Google provider (v2): Google is selected only by apiKey, mapId, useAdvancedMarker or a 3rd constructor argument (or an explicit provider: 'google'). Otherwise the picker uses OpenStreetMap and logs a hint when google.maps is loaded.

Default changed

  • Option setCurrentPosition (default true): true now maps to locate: 'auto', and the default is locate: 'off'. Nothing prompts for location on load unless you ask for it.

Changed

  • onLocationChange(pos) is called like onChange (de-duplicated; the detail is a superset of LatLng). Like v2's first idle, it is also called once after ready with the current value (source api), but only when a value is set: an unset picker has no position to report.
  • .centerMarker / PNG pin: the pin is an SVG themed with CSS custom properties. Class mode keeps .lp-pin.centerMarker (the alias class), and the element exposes ::part(pin).
  • "type": "module", engines.node >= 18: the package is now "type": "commonjs" with .mjs/.cjs files and has no engines field. The deep .mjs/.cjs paths are kept.
  • setLocation(lat, lng) now commits: it fires input then change with source api. It also accepts any LatLngInput ('48.8584, 2.2945', { lat, lng }). An out-of-range latitude is clamped with a warning.
  • setCurrentPosition() is an alias of locate() that keeps the current zoom. It resolves with a LocationDetail and rejects with a LocationPickerError that has a .code.

Removed

  • The Tripoli fallback. With no value and no center, the map shows a world view (20, 0) at zoom 2 and the picker stays unset (#7). The frozen v1 file keeps the old behaviour.

Fixed

  • getMarkerPosition() returns a normalised position (longitude wrapped into [-180, 180), latitude clamped; #12) and never a fake { 0, 0 }. While the picker is unset it returns the view centre and warns once.
  • destroy() removes the created map, every listener and every node.
  • Type declarations: @types/google.maps is an optional peer referenced only by location-picker/google, specifiers carry explicit extensions, and no declaration file imports CSS (#2).
  • 0 is a valid latitude and longitude everywhere (#11).