Comparing version 1.0.0 to 1.0.1
34
index.js
// @ts-ignore | ||
import * as L from 'https://unpkg.com/leaflet@1.4.0/dist/leaflet-src.esm.js'; | ||
async function getGBIFIDFromQuery (q) { | ||
const urlEncodedQuery = encodeURIComponent(q); | ||
const response = await fetch('http://api.gbif.org/v1/species/suggest?q=' + urlEncodedQuery); | ||
const json = await response.json(); | ||
const results = json | ||
.filter(item => item.rank === 'SPECIES') | ||
.filter(item => !item.synonym) | ||
.sort((a, b) => { | ||
if (a.status === 'ACCEPTED') { | ||
return 1; | ||
} | ||
if (b.status === 'ACCEPTED') { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
return results[0]; | ||
} | ||
class GBIFMap extends HTMLElement { | ||
@@ -46,3 +69,4 @@ async connectedCallback () { | ||
const gbifId = this.getAttribute('gbif-id'); | ||
let gbifId = this.getAttribute('gbif-id'); | ||
const gbifQuery = this.getAttribute('gbif-query'); | ||
const gbifStyle = this.getAttribute('gbif-style') || 'purpleHeat.point'; | ||
@@ -58,2 +82,10 @@ const latitude = parseFloat(this.getAttribute('center-latitude')); | ||
if (gbifQuery) { | ||
gbifId = await getGBIFIDFromQuery(gbifQuery); | ||
} | ||
if (!gbifId) { | ||
throw new Error('No GBIF id.'); | ||
} | ||
const map = L.map(mapWrapperElement).setView([latitude, longitude], zoom); | ||
@@ -60,0 +92,0 @@ |
{ | ||
"name": "gbif-map", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
6353
88
2