Skip to content

Commit

Permalink
Is there a way to get keyboard return event to pick top choice in dro…
Browse files Browse the repository at this point in the history
…pdown? #206

Set limit: 1, // Don't display the list but directly fies to the first found
[demo](http://dominique92.github.io/ol-geocoder/examples/index.html)
  • Loading branch information
Dominique92 committed Sep 13, 2023
1 parent eff2edd commit b8c6493
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ geocoder.on('addresschosen', (evt) => {
* `targetType` : `'glass-button'`; Can also be `'text-input'`;
* `featureStyle` : `ol.style.Style`; Feature style;
* `lang` : `'en-US'`; Preferable language;
* `limit` : `5`; Limit of results;
* `limit` : `5`; Limit of results; If limit = 1 : don't display the list but directly fies to the first found;
* `countrycodes` : `''`; Only valid for `osm` and `mapquest`; Limit search results to a specific country (or a list of country codes separated with commas `FR,US`). This is an [ISO 3166-1alpha2 code] (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), e.g. `gb` for the United Kingdom, `br` for Brazil, etc;
* `viewbox` : `''`; The preferred area to find search results. Any two corner points of the box are accepted as long as they span a real box. (string) '<x1>,<y1>,<x2>,<y2>' x is longitude, y is latitude (EPSG:4326);
* `keepOpen` : `false`; Whether the results keep openned;
Expand Down
32 changes: 17 additions & 15 deletions dist/ol-geocoder-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ol-geocoder-debug.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ol-geocoder.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ol-geocoder - v4.3.1-dev
* A geocoder extension compatible with OpenLayers v7+ & v8+
* https://github.com/Dominique92/ol-geocoder
* Built: Wed Sep 13 2023 11:09:17 GMT+0200 (heure d’été d’Europe centrale)
* Built: Wed Sep 13 2023 20:36:11 GMT+0200 (heure d’été d’Europe centrale)
*/

.ol-touch .ol-control.gcd-gl-control button {
Expand Down
4 changes: 2 additions & 2 deletions dist/ol-geocoder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ol-geocoder.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ol-geocoder.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/nodejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<a href="control-nominatim.html">control-nominatim</a> &nbsp;
<a href="control-glass.html">control-glass</a> &nbsp;
<a href="custom-provider.html">custom-provider</a> &nbsp;
<a href="index.html">Miscellaneous features</a>
</p>

<div id="map">
Expand Down
23 changes: 12 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions src/nominatim.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,28 @@ export class Nominatim {
switch (this.options.provider) {
case PROVIDERS.OSM:
addressHtml = `<span class="${klasses.road}">${row.address.name}</span>`;

break;

default:
addressHtml = this.addressTemplate(row.address);
}

const html = `<a href="#">${addressHtml}</a>`;
const li = createElement('li', html);

li.addEventListener(
'click',
(evt) => {
evt.preventDefault();
this.chosen(row, addressHtml, row.address, row.original);
},
false
);

ul.append(li);
if (response.length == 1) {
this.chosen(row, addressHtml, row.address, row.original);
} else {
const li = createElement('li', `<a href="#">${addressHtml}</a>`);

li.addEventListener(
'click',
(evt) => {
evt.preventDefault();
this.chosen(row, addressHtml, row.address, row.original);
},
false
);

ul.append(li);
}
});
}

Expand Down

0 comments on commit b8c6493

Please sign in to comment.