Skip to content

Commit

Permalink
Merge pull request #278 from geoblocks/additionalSource_order
Browse files Browse the repository at this point in the history
Add additionalSource to types to set the display order
  • Loading branch information
fredj authored Jul 12, 2023
2 parents ad5000a + 953b678 commit dac388f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The component has to have an `input` and `ul` as children element. The query tex
| `limit` | `number` | `15` | The number of result per type.
| `debounceTime` | `number` | `200` | Time in milliseconds that the component should wait after last keystroke before calling search function.
| `lang` | `string` | | Language code (`de`, `fr`, `it` , `rm`, or `en`). Default is the value of the `lang` attribute of the HTML document.
| `types` | `string` | `'location'` | A comma separated list of types of search to use. Can be a combination of `'location'`, `'layer'` and `'feature'`. The order of this list is used as the display order.
| `types` | `string` | `'location'` | A comma separated list of types of search to use. Can be a combination of `'location'`, `'layer'`, `'feature'` and `'additionalSource'`. The order of this list is used as the display order.
| `sr` | `string` | `'4326'` | The spatial reference code for output geometries. Can be `21781`, `2056`, `3857` or `4326`
| `locationOrigins` | `string` | `'zipcode,gg25'` | A comma separated list of location origins. Possible origins are: `zipcode`, `gg25`, `district`, `kantone`, `gazetteer`, `address` and `parcel`.
| `featureLayers` | `string` | | A comma separated list of technical layer names to be used by the `feature` search.
Expand Down
2 changes: 1 addition & 1 deletion demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ul class="autocomplete-result-list"></ul>
</ga-search>

<ga-search id="custom-sources" types="location">
<ga-search id="custom-sources" types="additionalSource,location">
<input type="search" class="autocomplete-input" placeholder="Search location and custom source">
<ul class="autocomplete-result-list"></ul>
</ga-search>
Expand Down
11 changes: 7 additions & 4 deletions ga-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class GeoadminSearch extends LitElement {
search: input => {
return new Promise(resolve => {
const urls = [];
const types = this.types.split(',');
if (input.length < this.minlength && this.historyEnabled) {
const history = this.storage.getHistory();
if (input.length === 0) {
Expand All @@ -64,7 +65,7 @@ class GeoadminSearch extends LitElement {
}
}
if (input.length >= this.minlength) {
this.types.split(',').forEach(type => {
types.forEach(type => {
if (type === 'location') {
const locationUrl = locationSearchUrl.replace('{origins}', this.locationOrigins);
urls.push(locationUrl);
Expand All @@ -88,14 +89,16 @@ class GeoadminSearch extends LitElement {
.then(featureCollection => featureCollection.features);
});
if (this.additionalSource) {
promises.push(this.additionalSource.search(input)
const promise = this.additionalSource.search(input)
.then(results => results.map(result => {
return {
type: 'additionalSource',
result: result
};
}))
);
}));
// insert additionalSource at the right place to respect the order of the types
const index = types.indexOf('additionalSource');
promises.splice(index === -1 ? 0 : index, 0, promise);
}

Promise.all(promises)
Expand Down

0 comments on commit dac388f

Please sign in to comment.