Location Field Interaction lab Live surface

CSSScript.com Demo Page

Location Field Web Component Demos

Download Back To CSSScript.Com

Search for places, shape a map boundary, seed a fixed pin, and inspect the component state as it changes.

02 / Boundaries

Give the map a sense of place

Bias the search, draw a GeoJSON outline, or tune a radius without changing the component.

03

Search bias

Near Cambridge

Nominatim
Search bias 52.2053, 0.1218
View markup
<wc-location-field
  label="Destination"
  show-map
  center-lat="52.2053"
  center-lng="0.1218"
></wc-location-field>
04

GeoJSON property

Polygon boundary

Overlay
Polygon overlay is assigned through the JS property.
View JavaScript
const field = document.querySelector('#demo-geojson');
field.geojson = {
  type: 'Polygon',
  coordinates: [ /* boundary */ ]
};
05

Radius overlay

Adjust the range

Live control
2.5 km
View markup
<wc-location-field
  show-map
  center-lat="52.2053"
  center-lng="0.1218"
  radius-km="2.5"
></wc-location-field>
06

Readonly mode

Display-only pin

Prefilled
Fixed location 51.50140, -0.14190
View JavaScript
const map = document.querySelector('#demo-readonly');
map.prefill({
  address: 'Buckingham Palace',
  lat: 51.5014,
  lng: -0.1419
});

03 / API and events

Inspect the live state

Use the public methods and watch the bubbling location-change event write its payload below.

07

Public methods

Prefill, clear, read

State
Current getters
address: waiting for a value
lat: null
lng: null
View JavaScript
const field = document.querySelector('#demo-api');
field.prefill({ address, lat, lng });
field.clear();
console.log(field.value, field.lat, field.lng);
08

CustomEvent

location-change stream

Bubbles
Event payload 0 received
Interact with the field above to receive an event.
View JavaScript
field.addEventListener('location-change', event => {
  const { lat, lng, address, w3w } = event.detail;
});