Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/GEOLYTIX/xyz
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Jan 29, 2024
2 parents 94f57c7 + 1fe0ec9 commit 7726e38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
22 changes: 22 additions & 0 deletions mod/workspace/_workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ async function locale(req, res) {
JSON.stringify(locale).replace(/\$\{(.*?)\}/g,
matched => process.env[`SRC_${matched.replace(/(^\${)|(}$)/g, '')}`])
)

// Return layer object instead of array of layer keys
if (req.params.layers) {

const layers = []

for (const key of Object.keys(locale.layers)) {

const layer = await getLayer({
locale: req.params.locale,
layer: key
})

if (!Roles.check(layer, roles)) continue;

layers.push(layer)
}

locale.layers = layers

return res.json(locale)
}

// Check layer access.
locale.layers = locale.layers && Object.entries(locale.layers)
Expand Down
22 changes: 4 additions & 18 deletions public/views/_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ window.onload = async () => {

// Get locale with list of layers from Workspace API.
const locale = await mapp.utils.xhr(
`${mapp.host}/api/workspace/locale?locale=${mapp.hooks.current.locale || locales[0].key}`);
`${mapp.host}/api/workspace/locale?locale=${mapp.hooks.current.locale || locales[0].key}&layers=true`);

if (locale instanceof Error) {

Expand Down Expand Up @@ -308,6 +308,9 @@ window.onload = async () => {
loadPlugins: true
});

// Add layers to mapview.
await mapview.addLayer(locale.layers);

// Add zoomIn button.
const btnZoomIn = btnColumn.appendChild(mapp.utils.html.node`
<button
Expand Down Expand Up @@ -341,23 +344,6 @@ window.onload = async () => {
btnZoomOut.disabled = z <= mapview.locale.minZoom;
});

// Load JSON layers from Workspace API.
const layers = locale.layers.length ? await mapp.utils.promiseAll(locale.layers.map(
layer => mapp.utils.xhr(`${mapp.host}/api/workspace/layer?`
+ `locale=${locale.key}&layer=${layer}`)))
: [{
key: 'OSM',
display: true,
format: 'tiles',
URI: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png',
style: {
hidden: true
}
}]

// Add layers to mapview.
await mapview.addLayer(layers);

if (mapview.locale.gazetteer) {

mapp.ui.Gazetteer(Object.assign(mapview.locale.gazetteer, {
Expand Down

0 comments on commit 7726e38

Please sign in to comment.