The component ElemrootAddressPicker is one script file without dependencies (with a map it
loads MapLibre GL JS itself). It works with Estonian, Latvian and Lithuanian addresses and returns an
output on every selection that you can store directly in your system. You can assemble the settings in
the configurator, which also gives you the ready code.
Installation
Add the script, an empty element and the create call. The element gets the class
eap; several components on one page are allowed.
<script src="https://examples.elemroot.com/widget/aadressivalija/v1/aadressivalija.js"></script>
<div id="aadress"></div>
<script>
var picker = ElemrootAddressPicker.create('#aadress', {
key: 'YOUR_API_KEY',
countries: ['ee'],
map: 'raster',
onChange: function (a) {
// a = null (cleared) or the output (see below)
}
});
</script>
Options
| Option | Default | Meaning |
|---|---|---|
key | – | API key (required). |
countries | ['ee'] | Allowed countries: ee, lv, lt. With several countries a country selector appears (or one combined search, see combined). |
country | first in the list | Initial country. |
lang | et | Component language: et, en, lv or lt (buttons, hints, level labels). |
search | true | Search field with autocomplete. |
short | true | Search suggestions come from the short version of the address search, with shorter name forms (Anne 1, Tartu linn, Tartu linn, Tartumaa). false takes the suggestions from the full service (Anne tänav 1, Tartu linn, Tartu linn, Tartu maakond). The same service also serves the id lookup for the L-EST97 coordinates. The output of the selected address is the same in both cases, in the official form. |
combined | false | One search across all countries without a country selector: the suggestions come from one request, the country is shown at the end of a suggestion and read from the selected address (the selection levels switch to that country). |
levels | true | Address selection by levels (dropdowns). The output is the same without them. |
map | false | 'raster' (the Elemroot raster map, Estonia only; Latvian and Lithuanian addresses get the vector map) or 'vector'. |
layout | 'stack' | Map position: 'stack' below, 'side' right, 'side-left' left. On narrow screens always below. |
drag | true | A click on the map places the marker there and the marker can be dragged; the address is taken from the point. false switches it off. |
logo | true | A small Elemroot logo below the component on the right. false leaves it out. |
labels | – | Override of level labels per country and level, e.g. { ee: { 1: 'County' } }. |
placeholder | 'Enter an address…' | Placeholder text of the search field (in language et 'Sisesta aadress…'). |
postcodeInAddress | false | The postal code is placed inside the output address string. In Estonia after the first part, before the second level (Anne tn 1-1, 50604 Tartu linn, Tartu linn, Tartu maakond, Vahtra, 61607 Illi küla, Nõo vald, Tartu maakond); in Latvia at the end (Elizabetes iela 2, Rīga, LV-1010); in Lithuania before the settlement in a municipality centre (Gedimino pr. 9, LT-01103 Vilnius, Vilniaus miesto sav.) and before the municipality elsewhere (Plento g. 17, Ariogala, Ariogalos miesto sen., LT-60249 Raseinių rajono sav.). Suited for a web shop delivery address, for example. |
requireHouse | false | The value is given only for an address exact to the building (level building/plot or apartment). Selecting a street or a settlement gives null and the component shows the hint “Pick the building too”. Suited for a delivery address. |
fields | – | Filling form fields without your own JavaScript, for example in a web shop order form: { address: '#f-address', postcode: '#f-postcode' }, with several countries also country: '#f-country'. The key is an output field (a dot reaches a sub-field, e.g. 'coordinates.lat'), the value a CSS selector or an element; on clearing the fields become empty. |
endpoints | Elemroot public | geocode, geocodeShort, gazetteer, revgeocode, xyz: override when the services run behind your proxy. |
style | Elemroot vector style | Style URL of the vector map (the key is appended automatically). |
onChange | – | Called on every selection and on clearing, with the output or null. |
onError | – | Called on a service error. |
The same setting can be given to all components at once: ElemrootAddressPicker.defaults = { endpoints: { … } }.
Map
When map is set, the map is visible at once. With an empty value it shows the area of the
configured countries (one country: that country; several: all of them; after a country switch that
country), with a selected address the marker at zoom 15. The map can be panned and zoomed with the
buttons and the mouse wheel. The raster map covers Estonia; for Latvian and Lithuanian addresses the
component shows the vector map even when 'raster' is set.
With drag on, a click on the map places the marker at the click point and the marker can be
dragged. Reverse geocoding finds the nearest address to the point, it is looked up in the address search
and selected like a normal match, so the output has the same shape as with a search. A point in another
allowed country switches the country. If there is no address within 500 m, the marker stays at the
previous address and the component says so.
The map size comes from CSS variables: --eap-map-h (height, default
180px, applies with the map below) and --eap-map-w (width beside the
form, default 300px).
Output
onChange delivers and getValue() returns an object; the same object comes with
the event elemroot-address (event.detail) from the component element.
| Field | Content |
|---|---|
address | The address in its full official form, most specific part first, all levels included (e.g. Anne tn 1-1, Tartu linn, Tartu linn, Tartu maakond: the settlement and the municipality are separate levels even when the name repeats); with postcodeInAddress the postal code is inside the string. |
addressId, gazId | AADRESS_ID and the address selection node id (the same in Estonia; in Latvia and Lithuania the register code with a prefix). |
country, level, levelLabel, final | Country, deepest filled level, its label and whether the address is final (no deeper levels). |
postcode | Postal code; in Latvia and Lithuania with the country prefix (LV-1010, LT-01103). |
coordinates | { lon, lat } WGS84 (EPSG:4326). |
nationalCoordinates | Estonia only: { epsg: 'EPSG:3301', x, y, north, east }, where x = north (N) and y = east (E) in the official L-EST97 order; north and east are the same values under unambiguous names. In Latvia and Lithuania null. |
components | Named breakdown: country, county, municipality, settlement, smallPlace, street, name, house, apartment. |
ehak | Estonian EHAK codes { county, municipality, settlement }; elsewhere null. |
adsType | Deepest filled address component (A1–A8). |
levels, skipped | The selected chain per level { 1: { id, name }, … } and the skipped levels. |
raw | The raw service response. |
{
"country": "ee",
"address": "Anne tn 1-1, Tartu linn, Tartu linn, Tartu maakond",
"addressId": 3124193,
"postcode": "50604",
"coordinates": { "lon": 26.742994, "lat": 58.381567 },
"nationalCoordinates": { "epsg": "EPSG:3301", "x": 6474513.33, "y": 660418.47, "north": 6474513.33, "east": 660418.47 },
"components": { "county": "Tartu maakond", "municipality": "Tartu linn", "settlement": "Tartu linn", "street": "Anne tänav", "house": "1", "apartment": "1" },
"adsType": "A8",
"final": true
}
Methods
| Method | Meaning |
|---|---|
getValue() | The current output or null. |
clear() | Clears the selection, calls onChange(null), the map returns to the default area. |
setCountry(c), getCountry() | Switch and read the country. |
openById(id) | Opens an address by AADRESS_ID on all levels (returns a promise). |
suggest(q), pick(match) | Programmatic search and selection of a match. |
pickPoint(lon, lat) | Address from a map point (what a click on the map does); returns a promise with the output or null. |
destroy() | Removes the component (map, timers, DOM). Needed when a framework re-creates the element. |
el, version | The component element and version. |
Styling
The component brings its own style. Override colours and sizes with CSS variables on the component
element: --eap-accent, --eap-border, --eap-bg, --eap-ink,
--eap-muted, --eap-field (background of the select boxes), --eap-radius, --eap-map-h, --eap-map-w.
All internal classes start with the prefix eap-.
#aadress { --eap-accent: #0a7d4f; --eap-map-h: 260px; --eap-map-w: 360px; }
Accessibility
For a screen reader the search field is a combo box (role="combobox") and the suggestions a list
(role="listbox", role="option"): the open state, the active row and the selection are in
the attributes aria-expanded, aria-activedescendant and aria-selected. Hints
are read out (aria-live="polite"). Arrow keys, Enter and Escape work in the list; the dropdowns and
buttons are ordinary labelled form elements.