|
| 1 | +import F_ from '../Basics/Formulae_/Formulae_' |
| 2 | +import calls from '../../pre/calls' |
| 3 | + |
| 4 | +const Datasets = { |
| 5 | + populateFromDataset(layer, cb) { |
| 6 | + if ( |
| 7 | + layer.options.layerName && |
| 8 | + L_.layers.data[layer.options.layerName] && |
| 9 | + L_.layers.data[layer.options.layerName].variables && |
| 10 | + L_.layers.data[layer.options.layerName].variables.datasetLinks |
| 11 | + ) { |
| 12 | + const dl = |
| 13 | + L_.layers.data[layer.options.layerName].variables.datasetLinks |
| 14 | + let dlFilled = dl |
| 15 | + for (let i = 0; i < dlFilled.length; i++) { |
| 16 | + dlFilled[i].search = F_.getIn( |
| 17 | + layer.feature.properties, |
| 18 | + dlFilled[i].prop.split('.') |
| 19 | + ) |
| 20 | + } |
| 21 | + |
| 22 | + calls.api( |
| 23 | + 'datasets_get', |
| 24 | + { |
| 25 | + queries: JSON.stringify(dlFilled), |
| 26 | + }, |
| 27 | + function (data) { |
| 28 | + const d = data.body |
| 29 | + for (let i = 0; i < d.length; i++) { |
| 30 | + if (d[i].type == 'images') { |
| 31 | + layer.feature.properties.images = |
| 32 | + layer.feature.properties.images || [] |
| 33 | + for (let j = 0; j < d[i].results.length; j++) { |
| 34 | + layer.feature.properties.images.push( |
| 35 | + d[i].results[j] |
| 36 | + ) |
| 37 | + } |
| 38 | + //remove duplicates |
| 39 | + layer.feature.properties.images = |
| 40 | + F_.removeDuplicatesInArrayOfObjects( |
| 41 | + layer.feature.properties.images |
| 42 | + ) |
| 43 | + } else { |
| 44 | + layer.feature.properties._dataset = { |
| 45 | + prop: dlFilled[i].displayProp || d[i].prop, |
| 46 | + results: d[i].results, |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + if (cb != null && typeof cb === 'function') cb() |
| 51 | + }, |
| 52 | + function (data) { |
| 53 | + if (cb != null && typeof cb === 'function') cb() |
| 54 | + } |
| 55 | + ) |
| 56 | + } else { |
| 57 | + if (cb != null && typeof cb === 'function') cb() |
| 58 | + } |
| 59 | + }, |
| 60 | +} |
| 61 | + |
| 62 | +export default Datasets |
0 commit comments