-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
187 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
{ | ||
"start": { | ||
"title": "Dod o hyd i leoedd i ailgylchu." | ||
}, | ||
"about": { | ||
"title": "About this service", | ||
"intro": "Powered by RecycleNow.com, this tool can be used to search and find recycling locations throughout the United Kingdom.", | ||
"becomeAPartner": { | ||
"title": "Add this tool to your website", | ||
"description": "It’s been created as an embeddable widget that can be added to any website to help visitors discover more recycling options. For example, a beverage manufacturer could use the tool to show places to recycle drinks cans.", | ||
"cta": "Become a partner", | ||
"url": "https://wrap.org.uk/taking-action/citizen-behaviour-change/recycle-now/recycling-locator-tool" | ||
"title": "Dod o hyd i leoedd i ailgylchu.", | ||
"location": { | ||
"title": "What do you need to recycle?" | ||
}, | ||
"feedback": { | ||
"title": "Improving this service", | ||
"description": "We’re always looking to improve this tool and would be interested to hear about your experience whilst using it, good or bad.", | ||
"cta": "Feedback on this tool", | ||
"url": "https://wrapcymru.org.uk/contact-wrap-cymru" | ||
"about": { | ||
"title": "About this service", | ||
"intro": "Powered by RecycleNow.com, this tool can be used to search and find recycling locations throughout the United Kingdom.", | ||
"becomeAPartner": { | ||
"title": "Add this tool to your website", | ||
"description": "It’s been created as an embeddable widget that can be added to any website to help visitors discover more recycling options. For example, a beverage manufacturer could use the tool to show places to recycle drinks cans.", | ||
"cta": "Become a partner", | ||
"url": "https://wrap.org.uk/taking-action/citizen-behaviour-change/recycle-now/recycling-locator-tool" | ||
}, | ||
"feedback": { | ||
"title": "Improving this service", | ||
"description": "We’re always looking to improve this tool and would be interested to hear about your experience whilst using it, good or bad.", | ||
"cta": "Feedback on this tool", | ||
"url": "https://wrapcymru.org.uk/contact-wrap-cymru" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
{ | ||
"start": { | ||
"title": "Find places to recycle." | ||
}, | ||
"about": { | ||
"title": "About this service", | ||
"intro": "Powered by RecycleNow.com, this tool can be used to search and find recycling locations throughout the United Kingdom.", | ||
"becomeAPartner": { | ||
"title": "Add this tool to your website", | ||
"description": "It’s been created as an embeddable widget that can be added to any website to help visitors discover more recycling options. For example, a beverage manufacturer could use the tool to show places to recycle drinks cans.", | ||
"cta": "Become a partner", | ||
"url": "https://wrap.org.uk/taking-action/citizen-behaviour-change/recycle-now/recycling-locator-tool" | ||
"title": "Find places to recycle.", | ||
"location": { | ||
"title": "What do you need to recycle?" | ||
}, | ||
"feedback": { | ||
"title": "Improving this service", | ||
"description": "We’re always looking to improve this tool and would be interested to hear about your experience whilst using it, good or bad.", | ||
"cta": "Feedback on this tool", | ||
"url": "https://wrap.org.uk/contact-us" | ||
"about": { | ||
"title": "About this service", | ||
"intro": "Powered by RecycleNow.com, this tool can be used to search and find recycling locations throughout the United Kingdom.", | ||
"becomeAPartner": { | ||
"title": "Add this tool to your website", | ||
"description": "It’s been created as an embeddable widget that can be added to any website to help visitors discover more recycling options. For example, a beverage manufacturer could use the tool to show places to recycle drinks cans.", | ||
"cta": "Become a partner", | ||
"url": "https://wrap.org.uk/taking-action/citizen-behaviour-change/recycle-now/recycling-locator-tool" | ||
}, | ||
"feedback": { | ||
"title": "Improving this service", | ||
"description": "We’re always looking to improve this tool and would be interested to hear about your experience whilst using it, good or bad.", | ||
"cta": "Feedback on this tool", | ||
"url": "https://wrap.org.uk/contact-us" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { service } from '@here/maps-api-for-javascript'; | ||
|
||
import config from '../config'; | ||
|
||
interface HereMapsGeocodeResponse { | ||
items: { | ||
position: { | ||
lat: number; | ||
lng: number; | ||
}; | ||
}[]; | ||
} | ||
|
||
export default class PostCodeResolver { | ||
private static ERROR_POSTCODE_NOT_FOUND = 'Postcode not found'; | ||
private static ERROR_SEARCH_FAILED = 'Search failed'; | ||
|
||
private static async getLatLng( | ||
location: string, | ||
): Promise<{ lat: number; lng: number }> { | ||
const { default: H } = await import( | ||
// @ts-expect-error TS can't find the maps types | ||
'@here/maps-api-for-javascript/bin/mapsjs.bundle' | ||
); | ||
const apikey = config.mapsPlacesKey; | ||
const platform = new H.service.Platform({ apikey }); | ||
const service = platform.getSearchService() as service.GeocodingService; | ||
const result: HereMapsGeocodeResponse = await new Promise( | ||
(resolve, reject) => { | ||
service.geocode({ q: location }, resolve, reject); | ||
}, | ||
); | ||
|
||
if (result?.items?.length === 0) { | ||
throw new Error(PostCodeResolver.ERROR_SEARCH_FAILED); | ||
} | ||
|
||
return result.items[0].position; | ||
} | ||
|
||
private static extractPostcodeFromString( | ||
locationOrPostcode: string, | ||
): string | null { | ||
const matches = locationOrPostcode.match( | ||
/(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})/i, | ||
); | ||
|
||
if (!matches) { | ||
return null; | ||
} | ||
|
||
return matches[0].toUpperCase().replace(/ /g, ''); | ||
} | ||
|
||
static async fromLatLng(lat: number, lng: number): Promise<string> { | ||
// var url = config.widgetRoutePrefix + '/postcode/' + | ||
// encodeURIComponent(latitude) + ',' + | ||
// encodeURIComponent(longitude) + | ||
// (window.location.hostname === 'localhost' ? '' : '?callback=?'); | ||
// $.getJSON({ | ||
// url: url | ||
// }).done(function(data) { | ||
// if (data.error && data.error == 'Not Found') { | ||
// deferred.reject(resolver.ERROR_POSTCODE_NOT_FOUND); | ||
// } else if (data.error) { | ||
// deferred.reject(resolver.ERROR_SEARCH_FAILED); | ||
// } else { | ||
// deferred.resolve(data.postcode); | ||
// } | ||
// }).fail(function() { | ||
// deferred.reject(resolver.ERROR_SEARCH_FAILED); | ||
// }); | ||
return `${lat} ${lng}`; | ||
} | ||
|
||
static async fromString(locationOrPostcode: string): Promise<string> { | ||
const postcode = | ||
PostCodeResolver.extractPostcodeFromString(locationOrPostcode); | ||
|
||
if (postcode) { | ||
return postcode; | ||
} | ||
|
||
const { lat, lng } = await PostCodeResolver.getLatLng(locationOrPostcode); | ||
return PostCodeResolver.fromLatLng(lat, lng); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function StartLocationPage() { | ||
const { t } = useTranslation(); | ||
|
||
return <h2>{t('start.location.title')}</h2>; | ||
} |
Oops, something went wrong.