Skip to content

Commit 0b69379

Browse files
committed
Geodatasets support nested _source
1 parent 3ba4206 commit 0b69379

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

API/Backend/Geodatasets/routes/geodatasets.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ function get(reqtype, req, res, next) {
109109
properties = `jsonb_build_object(
110110
${_source
111111
.map((v, i) => {
112-
if (["feature_id", "group_id"].indexOf(v) === -1)
113-
return `:prop_${i}, properties->:prop_${i}`;
114-
else return "";
112+
if (["feature_id", "group_id"].indexOf(v) === -1) {
113+
let toReturn = `:prop_${i}, properties`;
114+
const vSplit = v.split(".");
115+
vSplit.forEach((vs, idx) => {
116+
toReturn += ` -> :prop_${i}_${idx}`;
117+
});
118+
return toReturn;
119+
} else return "";
115120
})
116121
.filter(Boolean)
117122
.join(",")}
@@ -222,6 +227,10 @@ function get(reqtype, req, res, next) {
222227

223228
if (Array.isArray(_source)) {
224229
_source.forEach((v, i) => {
230+
const vSplit = v.split(".");
231+
vSplit.forEach((vs, idx) => {
232+
replacements[`prop_${i}_${idx}`] = vs;
233+
});
225234
replacements[`prop_${i}`] = v;
226235
});
227236
}
@@ -300,6 +309,14 @@ function get(reqtype, req, res, next) {
300309
result.dataValues.feature_id_field != null
301310
? results[i].feature_id
302311
: results[i].id;
312+
313+
_source.forEach((s) => {
314+
if (s && s.split(".").length > 1) {
315+
const savedValue = feature.properties[s];
316+
delete feature.properties[s];
317+
Utils.setIn2(feature.properties, s, savedValue, true);
318+
}
319+
});
303320
}
304321
feature.geometry = JSON.parse(results[i].st_asgeojson);
305322
geojson.features.push(feature);

API/utils.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ const Utils = {
3737
}
3838
return index;
3939
},
40+
isNumeric: function (value) {
41+
return /^\d+$/.test(value);
42+
},
4043
setIn: function (obj, keyArray, value, splice, assumeLayerHierarchy) {
41-
if (keyArray == null || keyArray === []) return false;
44+
if (keyArray == null || keyArray.length === 0) return false;
4245
if (typeof keyArray === "string") keyArray = keyArray.split(".");
4346
let object = obj;
4447
for (let i = 0; i < keyArray.length - 1; i++) {
@@ -60,6 +63,34 @@ const Utils = {
6063
else object[keyArray[keyArray.length - 1]] = value;
6164
return true;
6265
},
66+
setIn2: function (obj, keyArray, value, force) {
67+
if (keyArray == null || keyArray.length === 0) return null;
68+
if (typeof keyArray === "string") keyArray = keyArray.split(".");
69+
let object = obj;
70+
for (let i = 0; i < keyArray.length - 1; i++) {
71+
if (force) {
72+
// If string but setting a number index at the end of keyArray, turn into array
73+
if (i === keyArray.length - 2) {
74+
if (
75+
Utils.isNumeric(keyArray[i + 1]) &&
76+
!Array.isArray(object[keyArray[i]])
77+
)
78+
object[keyArray[i]] = Array(object[keyArray[i]]);
79+
}
80+
if (!object.hasOwnProperty(keyArray[i])) {
81+
object[keyArray[i]] =
82+
i === keyArray.length - 2 && Utils.isNumeric(keyArray[i + 1])
83+
? []
84+
: {};
85+
}
86+
object = object[keyArray[i]];
87+
} else {
88+
if (object.hasOwnProperty(keyArray[i])) object = object[keyArray[i]];
89+
else return null;
90+
}
91+
}
92+
object[keyArray[keyArray.length - 1]] = value;
93+
},
6394
traverseLayers: function (layers, onLayer) {
6495
let removedUUIDs = [];
6596
depthTraversal(layers, 0, []);

src/essence/Basics/Layers_/Layers_.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,13 +2085,20 @@ const L_ = {
20852085
},
20862086
// Returns any array of all the "fromProp"-like configuration fields for a layer
20872087
getDynamicProps(layerData) {
2088-
const dynamicProps = []
2088+
let dynamicProps = []
20892089
if (layerData?.style) {
20902090
Object.keys(layerData.style).forEach((key) => {
20912091
if (key.endsWith('Prop'))
20922092
dynamicProps.push(layerData.style[key])
20932093
})
20942094
}
2095+
if (layerData?.variables?.useKeyAsName) {
2096+
dynamicProps = dynamicProps.concat(
2097+
typeof layerData.variables.useKeyAsName === 'string'
2098+
? [layerData.variables.useKeyAsName]
2099+
: layerData.variables.useKeyAsName
2100+
)
2101+
}
20952102
return dynamicProps
20962103
},
20972104
/**
@@ -3301,7 +3308,10 @@ const L_ = {
33013308
propertyNames = [propertyNames]
33023309
propertyValues = Array(propertyNames.length).fill(null)
33033310
propertyNames.forEach((propertyName, idx) => {
3304-
if (feature.properties.hasOwnProperty(propertyName)) {
3311+
if (
3312+
feature.properties.hasOwnProperty(propertyName) ||
3313+
l.getFeaturePropertiesOnClick === true
3314+
) {
33053315
propertyValues[idx] = F_.getIn(
33063316
feature.properties,
33073317
propertyName

0 commit comments

Comments
 (0)