MapLibre GL JS: every NFL team's logo at its 2024 home stadium, a native symbol layer over a free OpenFreeMap basemap
With JavaScript on, MapLibre GL JS draws this figure here.
{
"logos": 32,
"images": 32,
"first": [
[
"22",
-112.2625948,
33.5277555,
34,
"https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/f8/f870b58b43585a5b7717d578dd433b0b1e0c462d64ef4bea2aeb8c03f4ae7854.png"
],
[
"1",
-84.4008484,
33.7555052,
34,
"https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/fe/fe566e9da6f7986b2bac321571bd751247ff93af15c51ae555486fb1bee90c91.png"
],
[
"33",
-76.6227221,
39.277958,
34,
"https://sdv.nyc3.cdn.digitaloceanspaces.com/assets/public/sha256/67/67796023c172c9aeab5bcdac9204823d3590097246ad1cb92971134b5f26dcc0.png"
]
]
}import { NFL_STADIUMS_2024 } from "@sportsdataverse/examples/data";
import { loadLeague } from "@sportsdataverse/sdvplot";
import { addLogoImages, basemap, drawnMarks, logoSymbols } from "@sportsdataverse/sdvplot/maplibre";
await loadLeague("nfl");
// Each team's 2024 home stadium, joined by nflverse stadium_id to nfelo's stadium table (via nfl-data). The Rams and
// the Chargers share SoFi Stadium, and the Giants and the Jets MetLife Stadium, so one logo of each pair sits on the
// other.
const logos = logoSymbols(NFL_STADIUMS_2024, { x: "lon", y: "lat", team: "team", league: "nfl", size: 34 });
const { style } = basemap("light");
// In the browser this page calls mount with maplibre-gl's module and the map's element.
export const browser = {
lib: "maplibre",
mount: async ({ maplibregl }: { maplibregl: typeof import("maplibre-gl") }, el: HTMLElement) => {
const map = new maplibregl.Map({
container: el,
style, // OpenFreeMap's credit shows in the map's attribution control, from the style's own source
bounds: [
[-124, 25],
[-70, 48],
],
fitBoundsOptions: { padding: 24 },
});
await map.once("load");
// the logos as map images first (each fetched once), then the layer that draws them
await addLogoImages(map, logos);
map.addSource(logos.id, logos.source);
map.addLayer(logos.layer);
return { map };
},
width: 720,
height: 440,
label: "Map of the United States with each NFL team's logo at its 2024 home stadium",
} as const;
// MapLibre draws only in a browser (and the basemap's tiles come from OpenFreeMap); without JavaScript the page shows
// what the layer holds: each logo, its stadium and coordinates.
{
logos: logos.source.data.features.length,
images: logos.images.length,
first: drawnMarks(logos).slice(0, 3),
};
Tags: maplibre · logoSymbols · addLogoImages · basemap · nfl · map. All sdvplot examples.