Skip to content

Commit

Permalink
Combine multiple lat/longs onto same map (#13)
Browse files Browse the repository at this point in the history
* Combine multiple lat/longs onto same map

---------

Co-authored-by: Patricia Schott <[email protected]>
  • Loading branch information
pschott and Patricia Schott authored Oct 23, 2023
1 parent 0a34191 commit 8685c44
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 1,931 deletions.
2 changes: 1 addition & 1 deletion dist/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,4 @@ button:hover {
.formatted-address label {
width: 100%;
} */
}
}
Binary file removed dist/images/hero-image.png
Binary file not shown.
Binary file added dist/images/marker-icon-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/w3w.loc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dist/images/w3w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed dist/images/w3w_Symbol_RGB_WhiteRed.png
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/js/experian-address-validation.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/lib/address-search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default class AddressValidation {
private inputs;
private lastSearchTerm;
private currentSearchTerm;
private shouldTriggerWhat3WordsEnrichment;
private currentCountryCode;
private currentDataSet;
private hasSearchInputBeenReset;
Expand Down
1,243 changes: 0 additions & 1,243 deletions dist/lib/address-search.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/address-search.js.map

This file was deleted.

44 changes: 0 additions & 44 deletions dist/lib/class-types.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/class-types.js.map

This file was deleted.

462 changes: 0 additions & 462 deletions dist/lib/datasets-codes.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/datasets-codes.js.map

This file was deleted.

42 changes: 0 additions & 42 deletions dist/lib/event-factory.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/event-factory.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/lib/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/index.js.map

This file was deleted.

50 changes: 0 additions & 50 deletions dist/lib/request.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/request.js.map

This file was deleted.

27 changes: 0 additions & 27 deletions dist/lib/search-options.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/search-options.js.map

This file was deleted.

18 changes: 0 additions & 18 deletions dist/lib/translations.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/lib/translations.js.map

This file was deleted.

81 changes: 58 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +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>
<span id="what3words-key" class="hidden"><img src="./dist/images/w3w.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 @@ -375,7 +375,7 @@ <h2>Validated address information</h2>

// Initialise address validation
var address = new AddressValidation(options);
var addressValidationMap, addressValidationMarker;
var addressValidationMap, addressValidationW3wMarker, addressValidationGeoMarker;

// Accept a new token from the token prompt and set this in the AddressValidation class
function addToken() {
Expand Down Expand Up @@ -469,39 +469,72 @@ <h2>Validated address information</h2>
address.events.on("post-enrichment", function(data) {
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.latitude && data.result.what3words.longitude && data.result.what3words.name) {
document.querySelector("#map").classList.remove("hidden");
document.querySelector(".metadata #what3words-key").classList.add("hidden");
document.querySelector(".metadata #what3words-value").classList.add("hidden");

let w3wLat, w3wLong, w3wLatLong;
if (data.result.what3words && data.result.what3words.latitude) {
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;
}
w3wLat = data.result.what3words.latitude;
w3wLong = data.result.what3words.longitude;
w3wLatLong = [w3wLat, w3wLong];
}

let geoLat, geoLong, geoLatLong;
if (data.result.geocodes && data.result.geocodes.latitude) {
geoLat = data.result.geocodes.latitude;
geoLong = data.result.geocodes.longitude;
geoLatLong = [geoLat, geoLong];
}

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

// Define a custom icon for what3words
var w3wIcon = L.icon({
iconUrl: './dist/images/w3w.loc.png',
iconSize: [30, 37], // size of the icon
iconAnchor: [15, 36], // point of the icon which will correspond to marker's location
popupAnchor: [0, -20] // point from which the popup should open relative to the iconAnchor
});

// Intantiate a new map
// Instantiate a new map
if (!addressValidationMap) {
addressValidationMap = L.map('map').setView(latlong, zoom);
// The hardcoded coordinated are needed to initialize the map. Will be overwritten with the what3words and geocode markers.
addressValidationMap = L.map('map').setView([51.500264, 0.633506],zoom);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution}).addTo(addressValidationMap);
addressValidationMarker = L.marker(latlong).addTo(addressValidationMap);
} else {
// Update the previous map instance
addressValidationMap.panTo(latlong, {duration: 1});
addressValidationMarker.setLatLng(latlong);
// Update the previous map instance by removing any existing markers
if (addressValidationW3wMarker) {
addressValidationW3wMarker.remove();
}

if (addressValidationGeoMarker) {
addressValidationGeoMarker.remove();
}
}

// Add new markers for location insight datasets
var markerArray = [];
if (w3wLatLong) {
addressValidationMap.panTo(w3wLatLong, {duration: 1});
addressValidationW3wMarker = L.marker(w3wLatLong, {icon: w3wIcon}).addTo(addressValidationMap);
markerArray.push(addressValidationW3wMarker);
}

if (geoLatLong) {
addressValidationMap.panTo(geoLatLong, {duration: 1});
addressValidationGeoMarker = L.marker(geoLatLong).addTo(addressValidationMap);
markerArray.push(addressValidationGeoMarker);
}

// Ensure all markers fit onto the map
var group = L.featureGroup(markerArray);
addressValidationMap.fitBounds(group.getBounds().pad(0.25));
}
});

Expand Down Expand Up @@ -536,7 +569,7 @@ <h2>Validated address information</h2>
}
}

document.querySelector(".metadata #delivery-address-key").innerText = data.result.address ? '📍' : '';
document.querySelector(".metadata #delivery-address-key").innerHTML = data.result.address ? '<img src="./dist/images/marker-icon-s.png"/>' : '';
document.querySelector(".metadata #delivery-address-value").innerHTML = data.result.address ? Object.values(data.result.address).filter(line => line !== "").join("<br>") : '';

document.querySelector(".metadata").classList.remove("invisible");
Expand All @@ -548,6 +581,8 @@ <h2>Validated address information</h2>
document.querySelector(".metadata #confidence-value").innerText = '';
document.querySelector(".metadata #delivery-type-key").innerText = '';
document.querySelector(".metadata #delivery-type-value").innerText = '';
document.querySelector(".metadata #what3words-key").classList.add("hidden");
document.querySelector(".metadata #what3words-value").classList.add("hidden");

document.querySelector(".metadata").classList.add("invisible");
document.querySelector("#map").classList.add("hidden");
Expand Down
Binary file added src/images/marker-icon-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/w3w.loc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/w3w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/images/w3w_Symbol_RGB_WhiteRed.png
Binary file not shown.
Loading

0 comments on commit 8685c44

Please sign in to comment.