class AddressDisplay extends HTMLElement { constructor() { super(); // Create a shadow DOM this.attachShadow({ mode: "open" }); // Initial render this.render(); // Element references this._locationDisplay = this.shadowRoot.querySelector(".location-display"); this._streetAddress = this.shadowRoot.querySelector(".street-address"); this._postCode = this.shadowRoot.querySelector(".post-code"); this._district = this.shadowRoot.querySelector(".district"); this._region = this.shadowRoot.querySelector(".region"); this._country = this.shadowRoot.querySelector(".country"); } // Initial render of component render() { this.shadowRoot.innerHTML = `
Location Details
Street Address
-
Post Code
-
District/Place
-
Region/State
-
Country
-
`; } // Public methods show(location) { console.log("Showing location", location); // Extract context data from properties const props = location.properties; const context = props.context || {}; // Populate structured fields // Street Address - combine address, street, housenumber if available let addressStr = ""; if (context.address) addressStr += context.address.address_number; if (context.street) { if (addressStr) addressStr += " "; addressStr += context.street.name; } if (addressStr === "") { addressStr = props.name || props.full_address || "-"; } this._streetAddress.textContent = addressStr; // Post Code this._postCode.textContent = context.postcode.name || "-"; // District (could be district, locality, or place) this._district.textContent = context.district.name || context.place.name || context.locality.name || "-"; // Region (state, province, etc.) this._region.textContent = context.region.name || "-"; // Country this._country.textContent = context.country.name || "-"; } } customElements.define("address-display", AddressDisplay);