Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 'Update HERE API autocomplete' to v0.27 #11908

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions decidim-core/app/packs/src/decidim/geocoding/provider/here.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 34,28 @@ $(() => {
if (`${query}`.trim().length < queryMinLength) {
return;
}

// Changes to the autocomplete api call based on:
// https://developer.here.com/documentation/geocoding-search-api/migration_guide/migration-geocoder/topics-api/autocomplete.html
currentSuggestionQuery = setTimeout(() => {
$.ajax({
method: "GET",
url: "https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json",
url: "https://autocomplete.search.hereapi.com/v1/autocomplete",
data: {
apiKey: config.apiKey,
query: query,
language: language
// eslint-disable-next-line
q: query,
lang: language
},
dataType: "json"
}).done((resp) => {
if (resp.suggestions) {
return callback(resp.suggestions.map((item) => {
if (resp.items) {
return callback(resp.items.map((item) => {
const label = generateAddressLabel(item.address, addressFormat);

return {
key: label,
value: label,
locationId: item.locationId
locationId: item.id
}
}));
}
Expand All @@ -65,30 67,24 @@ $(() => {
$input.on("geocoder-suggest-select.decidim", (_ev, selectedItem) => {
$.ajax({
method: "GET",
url: "https://geocoder.ls.hereapi.com/6.2/geocode.json",
url: "https://lookup.search.hereapi.com/v1/lookup",
data: {
apiKey: config.apiKey,
gen: 9,
jsonattributes: 1,
locationid: selectedItem.locationId
id: selectedItem.locationId
},
dataType: "json"
}).done((resp) => {
if (!resp.response || !Array.isArray(resp.response.view) ||
resp.response.view.length < 1
if (!resp || Object.keys(resp).length < 1
) {
return;
}

const view = resp.response.view[0];
if (!Array.isArray(view.result) || view.result.length < 1) {
return;
const position = resp.position;
if (!position || !position.lat || !position.lng) {
return
}

const result = view.result[0];
const coordinates = [
result.location.displayPosition.latitude,
result.location.displayPosition.longitude
position.lat,
position.lng
];

$input.trigger(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 23,37 @@ module Autocomplete
$("#ajax_request").text(JSON.stringify(request));

var response = {};
if (request.url === "https://geocoder.ls.hereapi.com/6.2/geocode.json") {
if (request.url === "https://lookup.search.hereapi.com/v1/lookup") {
response = {
response: {
view: [
{
result: [
{
location:{
displayPosition: {
latitude: 1.123,
longitude: 2.234
}
}
}
]
}
]
position: {
lat: 1.123,
lng: 2.234
}
};
} else {
response = {
suggestions: [
items: [
{
label: "first item",
title: "first item",
address: { street: "first item" },
locationId: "location1"
id: "location1"
},
{
label: "second item",
title: "second item",
address: { street: "second item" },
locationId: "location2"
id: "location2"
},
{
label: "third item",
title: "third item",
address: { street: "third item" },
locationId: "location3"
id: "location3"
}
]
};
}

// This is a normal suggest call to:
// https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json
// https://autocomplete.search.hereapi.com/v1/autocomplete
var deferred = $.Deferred().resolve(response);
return deferred.promise();
};
Expand Down Expand Up @@ -94,11 82,11 @@ module Autocomplete
"#ajax_request",
text: {
method: "GET",
url: "https://autocomplete.geocoder.ls.hereapi.com/6.2/suggest.json",
url: "https://autocomplete.search.hereapi.com/v1/autocomplete",
data: {
apiKey: "key1234",
query: "item",
language: "en"
q: "item",
lang: "en"
},
dataType: "json"
}.to_json
Expand All @@ -109,12 97,10 @@ module Autocomplete
"#ajax_request",
text: {
method: "GET",
url: "https://geocoder.ls.hereapi.com/6.2/geocode.json",
url: "https://lookup.search.hereapi.com/v1/lookup",
data: {
apiKey: "key1234",
gen: 9,
jsonattributes: 1,
locationid: "location1"
id: "location1"
},
dataType: "json"
}.to_json
Expand Down
Loading