viewof SelectedCompanyMap = {
const container = html`<div style="height: 800px;"></div>`;
yield container;
const selectedCompanyData = SelectCompanyDataPoints;
const selectedCollegeData = SelectCollegeDataPoints;
var map = new maplibregl.Map({
container: container,
style: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
center: [selectedCompanyData[0].comp_longitude, selectedCompanyData[0].comp_latitude],
zoom: 6,
});
map.on('style.load', () => {
selectedCompanyData.forEach((company) => {
map.addLayer({
id: `company-circle-${company.company_id}`,
type: 'circle',
source: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [company.comp_longitude, company.comp_latitude],
},
properties: {
stream: company.stream,
},
},
],
},
},
// QUESTION: what do we want for company colors?
paint: {
'circle-radius': 5, // Adjust the radius of the circle
'circle-color': getColorForStream(company.stream), // Dynamically set circle color based on stream
'circle-opacity': 0.7,
},
});
});
// add points for colleges
Array.from(egSelectedColleges.values()).forEach(college => {
console.log(college);
// Add a label for the college's name
map.addLayer({
id: `college-label-${college.Colleges}`, // QUESTION: do we need layers for each point? seem to be getting just one...
type: 'symbol',
source: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [college.Longitude, college.Latitude],
},
},
],
},
},
layout: {
'text-field': college.Colleges,
'text-font': ['Open Sans Bold', 'Arial Unicode MS Bold'],
'text-size': 8,
'text-offset': [0, 1], // Adjust the offset if needed
'text-anchor': 'top',
},
paint: {
'text-color': getColorForStream(college.stream), // Use the same color as the circle
},
});
// Add a tooltip (popup) to each circle marker
const popup = new maplibregl.Popup({ closeOnClick: false })
.setLngLat([college.Longitude, college.Latitude])
.setHTML(`<b>${college.Colleges}</b><br>Stream: ${college.stream}`)
.addTo(map);
// Show the tooltip by default
popup.addTo(map);
});
});
// Resolve the promise when the map is loaded and data is plotted
map.on("load", () => {});
// Function to get a color based on the stream
function getColorForStream(stream) {
// Add logic to return different colors based on the stream
// For example, you can use a switch statement or a color scale
// Here, a simple switch statement is used for illustration
switch (stream) {
case 'Biology':
return 'blue';
case 'Physics':
return 'green';
// Add more cases as needed
default:
return 'red';
}
}
};