UNPKG

globi-data

Version:

Find out who eats who in the world: what do rats (Rattus rattus) eat?, or what do hardhead catfish (Ariopsis felis) eat?. Data provided via Global Biotic Interactions (GloBI, https://globalbioticinteractions.org) .

50 lines (45 loc) 2.21 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="../globi-data-dist.js" charset="utf-8"> </script> <script type="text/javascript" charset="utf-8"> window.onload = function() { var consoleDiv = document.getElementById('console'); // lookup some species by some string 'sea otter' var closeMatchCallback = function(closeMatches) { closeMatches.forEach(function(closeMatch){ // log scientific names of matches console.log(closeMatch.scientificName); var p = document.createElement('p'); p.innerHTML = 'close match for sea otter [' + closeMatch.scientificName + ']'; consoleDiv.appendChild(p); }); }; globiData.findCloseTaxonMatches('sea otter', closeMatchCallback); // find out what a sea otter (Enhydra lutris) eats. . . var search = {sourceTaxonScientificName: 'Enhydra lutris', interactionType: 'preysOn'}; var callback = function(interactions) { interactions.forEach(function(interaction) { var p = document.createElement('p'); p.innerHTML = '[' + interaction.source.name + '] preys on [' + interaction.target.name + ']'; consoleDiv.appendChild(p); }); }; globiData.findSpeciesInteractions(search, callback); // lookup some more info (including image urls) about the sea otter var infoCallback = function(taxonInfo) { var name = taxonInfo.commonName + ' (<i>' + taxonInfo.scientificName + '</i>)'; var infoDiv = document.createElement('div'); infoDiv.innerHTML = '<table class="image"><caption align="bottom">' + name + '</caption>' + '<tr><td><img src="' + taxonInfo.thumbnailURL + '"/></td></tr></table>'; consoleDiv.appendChild(infoDiv); }; globiData.findTaxonInfo('Enhydra lutris', infoCallback); }; </script> </head> <body> <div id='console'></div> </body>