01 / Search
Search, then refine
Start with a plain field, then add a map when the interaction needs a physical point.
View markup
<wc-location-field
label="From"
placeholder="Try Paddington Station"
></wc-location-field>
Click the map or drag the pin to resolve a point.
View markup
<wc-location-field
label="Meeting point"
show-map
center-lat="51.505"
center-lng="-0.09"
></wc-location-field>
02 / Boundaries
Give the map a sense of place
Bias the search, draw a GeoJSON outline, or tune a radius without changing the component.
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>
Polygon overlay is assigned through the JS property.
View JavaScript
const field = document.querySelector('#demo-geojson');
field.geojson = {
type: 'Polygon',
coordinates: [ /* boundary */ ]
};
View markup
<wc-location-field
show-map
center-lat="52.2053"
center-lng="0.1218"
radius-km="2.5"
></wc-location-field>
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.
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);
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;
});