Skip to content

Commit

Permalink
Merge pull request #47 from SDFIdk/v2.0
Browse files Browse the repository at this point in the history
V2.0
  • Loading branch information
Gebuz authored Jan 17, 2024
2 parents afa0c43 + cbddfb3 commit 6716ebe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GSearch-UI is configured using html data attributes.
|`data-placeholder`|The placeholder text to show in the input field.|no|yes|`søg...`|
|`data-api`|Use a custom URL for GSearch API (ie. if you want to use a test API)|no|yes|`https://api.dataforsyningen.dk/rest/gsearch/v1.0/`|
|`data-filter`|Use a custom filter in the search query. [Learn about filters in the GSearch docs.](https://github.com/SDFIdk/gsearch/tree/main/doc#filter)|no|no|`none`|
|`data-srid`|The coordinate system of the returned geometries. The following values are allowed: 2196, 2197, 2198, 3857, 4093, 4094, 4095, 4096, 4326, 25832, 25833. |no|yes|`25832`|

### On click event

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dataforsyningen/gsearch-ui",
"version": "1.5.1",
"version": "2.0.0",
"description": "UI component for GSearch.",
"main": "public/search.js",
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ <h4>Limit</h4>
</section>
<section class="demo">
<g-search id="gsearch" class="g-search"
data-token="fd44f26ab5701c01ca9f570e507fe9ab">
data-token="fd44f26ab5701c01ca9f570e507fe9ab"
data-srid="25832">
</g-search>
<article class="right-column">
<div id="map" class="map"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class GSearchUI extends HTMLElement {
return [
'data-placeholder',
'data-api',
'data-srid',
'data-filter',
'data-resources',
'data-resource-filter-enabled'
Expand Down Expand Up @@ -232,7 +233,7 @@ class GSearchUI extends HTMLElement {
return r.resource
}).toString()
if (!resourceString) resourceString = this.dataset.resources
search(searchString, this.dataset.token, resourceString, this.dataset.limit, this.dataset.filter).then((response) => {
search(searchString, this.dataset.token, resourceString, this.dataset.limit, this.dataset.filter, this.dataset.srid).then((response) => {
this.results_element.results = response.flat()
})
}
Expand Down
10 changes: 7 additions & 3 deletions src/modules/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let apiUrl = 'https://api.dataforsyningen.dk/rest/gsearch/v1.0/' // Default API URL'
let apiUrl = 'https://api.dataforsyningen.dk/rest/gsearch/v2.0/' // Default API URL'
const defaultResources = 'navngivenvej,husnummer,adresse,stednavn,kommune,region,retskreds,postnummer,opstillingskreds,sogn,politikreds,matrikel,matrikel_udgaaet'
const defaultLimit = 10
const defaultSrid = 25832

let error_msg

Expand Down Expand Up @@ -64,19 +65,22 @@ function HttpResponseHandler(response, is_json) {
}
}

function search(searchString, token, resources, limit, filter) {
function search(searchString, token, resources, limit, filter, srid) {
// if missing values use defaults
if (!resources) {
resources = defaultResources
}
if (!limit) {
limit = defaultLimit
}
if (!srid) {
srid = defaultSrid
}
const promises = []
const splitString = resources.split(',')
const filterstr = filter ? encodeURIComponent(filter) : false
splitString.forEach(string => {
const url = `${ apiUrl }${ string }?token=${ token }&q=${ searchString }&limit=${ limit }${ filterstr ? `&filter=${ filterstr }` : '' }`
const url = `${ apiUrl }${ string }?token=${ token }&q=${ searchString }&limit=${ limit }&srid=${ srid }${ filterstr ? `&filter=${ filterstr }` : '' }`
promises.push(get(url).then(response => {
if (response.length > 0) {
response.map(el => {
Expand Down

0 comments on commit 6716ebe

Please sign in to comment.