Skip to content

Commit

Permalink
Add w3w enrichment call and add w3w name and icon (#11)
Browse files Browse the repository at this point in the history
* Add w3w enrichment call and add w3w name and icon

* remove empty line and unused method

---------

Co-authored-by: Georgi Dobrilov <[email protected]>
  • Loading branch information
gdobrilov and GeorgiDobrilov authored Oct 11, 2023
1 parent ee37952 commit 881bdf6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 5 deletions.
9 changes: 9 additions & 0 deletions dist/css/experian-address-validation.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ input.showing-suggestions {
font-style: italic;
padding-top: 0px;
font-size: 12px;
}

#what3words-key {
padding-top: 10px;
padding-right: 5px;
}

#what3words-value {
padding-top: 10px;
}
Binary file added dist/images/w3w_Symbol_RGB_WhiteRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions dist/js/experian-address-validation.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/lib/address-search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class AddressValidation {
private inputs;
private lastSearchTerm;
private currentSearchTerm;
private shouldTriggerWhat3WordsEnrichment;
private currentCountryCode;
private currentDataSet;
private hasSearchInputBeenReset;
Expand Down
23 changes: 21 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ <h2>Validated address information</h2>
<span id="confidence-key"></span><span id="confidence-value"></span>
<span id="delivery-type-key"></span><span id="delivery-type-value"></span>
<span id="delivery-address-key"></span><span id="delivery-address-value"></span>
<span id="what3words-key" class="hidden"><img src="./dist/images/w3w_Symbol_RGB_WhiteRed.png"/></span><span id="what3words-value" class="hidden"></span>
</div>
<div class="map hidden" id="map"></div>
<a href="https://github.com/experianplc/Experian-Address-Validation" target="_blank" class="download-button">Download sample code</a>
Expand Down Expand Up @@ -466,13 +467,31 @@ <h2>Validated address information</h2>

// Display a map with the lat/long details after a data enrichment lookup
address.events.on("post-enrichment", function(data) {
if (data.result.geocodes && data.result.geocodes.latitude) {
if ((data.result.geocodes && data.result.geocodes.latitude) ||
(data.result.what3words && data.result.what3words.latitude)) {
document.querySelector("#map").classList.remove("hidden");

let lat, long;
if (data.result.what3words) {
document.querySelector(".metadata #what3words-key").classList.remove("hidden");
document.querySelector(".metadata #what3words-value").classList.remove("hidden");
document.querySelector(".metadata #what3words-value").innerHTML = '///' + data.result.what3words.name;

lat = data.result.what3words.latitude;
long = data.result.what3words.longitude;
} else {
document.querySelector(".metadata #what3words-key").classList.add("hidden");
document.querySelector(".metadata #what3words-value").classList.add("hidden");

lat = data.result.geocodes.latitude;
long = data.result.geocodes.longitude;
}

var latlong = [data.result.geocodes.latitude, data.result.geocodes.longitude];
var latlong = [lat, long];
var zoom = 16;
var attribution = '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';


// Intantiate a new map
if (!addressValidationMap) {
addressValidationMap = L.map('map').setView(latlong, zoom);
Expand Down
9 changes: 9 additions & 0 deletions src/css/experian-address-validation.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ input.showing-suggestions {
font-style: italic;
padding-top: 0px;
font-size: 12px;
}

#what3words-key {
padding-top: 10px;
padding-right: 5px;
}

#what3words-value {
padding-top: 10px;
}
Binary file added src/images/w3w_Symbol_RGB_WhiteRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/ts/address-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class AddressValidation {
private inputs: HTMLInputElement[];
private lastSearchTerm: string;
private currentSearchTerm: string;
private shouldTriggerWhat3WordsEnrichment: boolean;
private currentCountryCode: string;
private currentDataSet: string | string[];
private hasSearchInputBeenReset: boolean;
Expand Down Expand Up @@ -64,9 +65,12 @@ export default class AddressValidation {
global_address_key: globalAddressKey
},
attributes: {
geocodes: ['latitude', 'longitude', 'match_level']
geocodes: ['latitude', 'longitude', 'match_level'],
what3words: this.shouldTriggerWhat3WordsEnrichment ?
['latitude', 'longitude', 'name', 'description'] : null
}
};

this.events.trigger('pre-enrichment');
this.request.send(this.baseUrl + this.enrichmentEndpoint, 'POST', this.handleEnrichmentResult.bind(this), JSON.stringify(data));
}
Expand Down Expand Up @@ -392,6 +396,7 @@ export default class AddressValidation {
}
else {
this.isWhat3Words = false;
this.shouldTriggerWhat3WordsEnrichment = false;
}

// Fire an event before a search takes place
Expand Down Expand Up @@ -1065,6 +1070,9 @@ export default class AddressValidation {
const headers = [{ key: 'Add-Addresses', value: true }];
const callback = this.picklist.showLookup;

//Set the shouldTriggerWhat3WordsEnrichment so that we can trigger it after the user chooses an address.
this.shouldTriggerWhat3WordsEnrichment = true;

// Initiate new Search request
this.request.send(url, 'POST', callback, lookupV2Request, headers);
}
Expand Down

0 comments on commit 881bdf6

Please sign in to comment.