Skip to content

Commit

Permalink
Merge branch 'GEOLYTIX:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cityremade authored Apr 29, 2024
2 parents 54fa21d + e4c222c commit 11c0e6d
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/layer/format/mvt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function tileUrlFunction(layer) {

// Create a set of feature properties for styling.
layer.params.fields = [...new Set([
layer.params.default_fields,
Array.isArray(layer.style.theme?.fields) ?
layer.style.theme.fields : layer.style.theme?.field,
layer.style.theme?.field,
Expand Down Expand Up @@ -265,10 +266,11 @@ function changeEndLoad(layer) {

// Create a set of feature properties for styling.
layer.params.fields = [...new Set([
layer.params.default_fields,
Array.isArray(layer.style.theme?.fields) ?
layer.style.theme.fields : layer.style.theme?.field,
layer.style.theme?.field,
layer.style.label?.field
layer.style.label?.field,
].flat().filter(field => !!field))]

const bounds = layer.mapview.getBounds()
Expand Down
3 changes: 2 additions & 1 deletion lib/layer/format/vector.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ export default layer => {

// Create a set of feature properties for styling.
layer.params.fields = [...new Set([
layer.params.default_fields,
Array.isArray(layer.style.theme?.fields) ?
layer.style.theme.fields : layer.style.theme?.field,
layer.style.theme?.field,
layer.style.label?.field,
layer.cluster?.label
layer.cluster?.label,
].flat().filter(field => !!field))]


Expand Down
2 changes: 1 addition & 1 deletion lib/location/decorate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async function syncFields(fields) {

// Return if response is falsy or error.
if (!response || response instanceof Error) {
console.warn('No data returned from location_get request.')
console.warn('No data returned from location_get request using ID:', this.id)
return
}
// Check if the response is an array.
Expand Down
2 changes: 1 addition & 1 deletion lib/location/get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function getInfoj(location) {

// Check if the response is empty.
if (!response || response instanceof Error) {
console.warn('No data returned from location_get request.')
console.warn('No data returned from location_get request using ID:', location.id)
return
}
// Check if the response is an array.
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/elements/slider.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ export default params => {
const group = e.target.closest('.input-range')

if (val > params.max) {
val = params.max;
group.style.setProperty(`--max`, val)
group.querySelectorAll('input').forEach(el => el.max = val)
}

e.target.value = val;

group.style.setProperty(`--${e.target.dataset.id}`, val)

group.querySelectorAll('input')
Expand Down
11 changes: 9 additions & 2 deletions lib/ui/locations/infoj.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ export default (location, infoj) => {
.xhr(`${entry.host || entry.location?.layer?.mapview?.host || mapp.host}/api/query?${paramString}`)
.then(response => {

// Assign query response as entry value.
entry.value = entry.field? response[entry.field] :response;
if (response) {

// Assign query response as entry value.
entry.value = entry.field ? response[entry.field] : response;

} else {

entry.value = entry.nullValue
}

// Check whether entry should be skipped.
if (skipEntry(entry)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/queryParams.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default _this => {
// ID will be taken if a location object is provided with the params.
id: _this.queryparams.id ? _this.location?.id : undefined,

// qID will be taken if a location object is provided with the params.
qID: _this.queryparams.qID ? _this.location?.layer?.qID : undefined,

// Email will be taken if a location object is provided with the params.
email: _this.queryparams.email ? mapp.user.email : undefined,

Expand Down
9 changes: 9 additions & 0 deletions mod/workspace/templates/_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ module.exports = {
layer_extent: {
template: require('./layer_extent'),
},
st_intersects_ab: {
template: require('./st_intersects_ab'),
},
st_distance_ab: {
template: require('./st_distance_ab'),
},
st_distance_ab_multiple: {
template: require('./st_distance_ab_multiple'),
},
location_get: {
render: require('./location_get'),
},
Expand Down
15 changes: 15 additions & 0 deletions mod/workspace/templates/st_distance_ab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = `
SELECT
ST_DISTANCE(st_transform(a.\${geom},4326)::geography, closest.geom ) AS dist
FROM
\${table} a
LEFT JOIN LATERAL (
SELECT
st_transform(b.\${geom_b},4326)::geography as geom
FROM \${table_b} b
ORDER BY st_transform(b.\${geom_b},4326)::geography <-> st_transform(a.\${geom},4326)::geography
LIMIT 1
) closest
on true
WHERE a.\${qID} = %{id}
`
17 changes: 17 additions & 0 deletions mod/workspace/templates/st_distance_ab_multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = `
SELECT
closest.field_b AS \${as},
ST_DISTANCE(st_transform(a.\${geom},4326)::geography, closest.geom ) AS dist
FROM
\${table} a
LEFT JOIN LATERAL (
SELECT
b.\${field_b} as field_b,
st_transform(b.\${geom_b},4326)::geography as geom
FROM \${table_b} b
ORDER BY st_transform(b.\${geom_b},4326)::geography <-> st_transform(a.\${geom},4326)::geography
LIMIT \${limit}
) closest
on true
WHERE a.\${qID} = %{id}
`
10 changes: 10 additions & 0 deletions mod/workspace/templates/st_intersects_ab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = `
SELECT
b.\${field_b} AS \${as}
FROM
\${table} a
LEFT JOIN
\${table_b} b
ON ST_INTERSECTS(a.\${geom}, b.\${geom_b})
WHERE a.\${qID} = %{id}
`

0 comments on commit 11c0e6d

Please sign in to comment.