Add satellite layer to map (draft)
This commit is contained in:
@@ -1,12 +1,48 @@
|
||||
import {
|
||||
fetchResourceList,
|
||||
createLinks,
|
||||
BASE_URL
|
||||
} from "../ds.js";
|
||||
'use strict';
|
||||
|
||||
document.addEventListener('readystatechange', async () => {
|
||||
const resList = await fetchResourceList();
|
||||
const BASE_URL = 'http://dataspace.ispc.cnr.it';
|
||||
/**
|
||||
* Create links list
|
||||
* @param {string[]} links The fetched resource links
|
||||
* @param {string} id The ID of the UL element
|
||||
* @param {string} replace The string that should replace loalhost...
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function createLinks(links, id, replace)
|
||||
{
|
||||
for (const link of links) {
|
||||
const item = document.createElement('li');
|
||||
|
||||
item.innerHTML =
|
||||
`<a href="${link.replace('http://localhost:8000/resources/', replace)}">
|
||||
${link.substring(link.lastIndexOf('/') + 1)}
|
||||
</a>`;
|
||||
document.querySelector(`#${id}`).appendChild(item);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @todo Query report links to determine resource type?
|
||||
* @param {int} max Max number of resources to list
|
||||
* (randomly selected)
|
||||
*
|
||||
* @returns {Array} An array with selected resource links
|
||||
*/
|
||||
async function fetchResourceList(max = 20)
|
||||
{
|
||||
// TODO Errors!!
|
||||
const list = await fetch(`${BASE_URL}${RES_ENDPOINT}`)
|
||||
.then(res => res.json())
|
||||
.catch();
|
||||
|
||||
// Arbitrary slice...
|
||||
return list['ldp:contains'].slice(100, max + 100);
|
||||
}
|
||||
|
||||
document.addEventListener('readystatechange', () => {
|
||||
const resList = fetchResourceList();
|
||||
|
||||
createLinks(resList, 'links', `${BASE_URL}/report/`);
|
||||
createLinks( resList, 'rep-links', `/report?id=`);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user