2023-06-24 20:44:16 +07:00
|
|
|
export let groups = [
|
2023-07-10 21:16:02 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Canada","Halifax"],[44.65166135030067, -63.59289968306866]],
|
2023-07-10 21:16:02 +07:00
|
|
|
members: 2,
|
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
|
|
|
},
|
2023-06-28 18:00:41 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Denmark","Copenhagen"],[55.6840661150132, 12.557133959514688]],
|
2023-07-06 05:25:38 +07:00
|
|
|
members: 1,
|
2023-07-09 19:25:09 +07:00
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
2023-06-28 18:00:41 +07:00
|
|
|
},
|
2023-07-06 05:25:38 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Denmark","Kolding"], [55.49261908652738, 9.470268969851743]],
|
2023-07-06 05:25:38 +07:00
|
|
|
members: 1,
|
2023-07-13 18:32:49 +07:00
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
2023-07-06 05:25:38 +07:00
|
|
|
},
|
2023-06-24 20:44:16 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Estonia","KohtlaJarve"], [59.40629447076191, 27.280605339416322]],
|
2023-06-24 20:44:16 +07:00
|
|
|
members: 3,
|
2023-07-13 18:32:49 +07:00
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
2023-06-26 03:20:08 +07:00
|
|
|
},
|
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Greece","Athens"], [37.94877252621736, 23.677622972996158]],
|
2023-06-26 03:20:08 +07:00
|
|
|
members: 1,
|
2023-07-13 18:32:49 +07:00
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
2023-06-26 03:20:08 +07:00
|
|
|
},
|
2023-07-12 05:42:33 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Ireland",""], [53.280192832733576, -7.688103518964818]],
|
2023-07-12 05:42:33 +07:00
|
|
|
members: 6,
|
|
|
|
contact: ["https://discord.gg/4BUau4AZre","DiscordInviteLink"]
|
|
|
|
},
|
2023-06-26 03:20:08 +07:00
|
|
|
{
|
2023-07-13 18:32:49 +07:00
|
|
|
location: [["Latvia","Riga"], [56.94748425529816, 24.003027136431925]],
|
2023-06-26 03:20:08 +07:00
|
|
|
members: 2,
|
2023-07-13 18:32:49 +07:00
|
|
|
contact: ["https://discord.gg/xAPZmyr8B6","DiscordInviteLink"]
|
2023-06-28 03:24:18 +07:00
|
|
|
},
|
2023-06-24 20:44:16 +07:00
|
|
|
]
|
|
|
|
|
2023-07-13 18:32:49 +07:00
|
|
|
export let groupsByCountry = {}
|
|
|
|
for (let g of groups) {
|
|
|
|
let country = g.location[0][0]
|
|
|
|
if (country in groupsByCountry) {
|
|
|
|
groupsByCountry[country].push(g)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
groupsByCountry[country] = [g]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-15 02:27:11 +07:00
|
|
|
export let groupsMarkersLayer = L.layerGroup()
|
2023-07-13 18:32:49 +07:00
|
|
|
let groupsMarkersLayerOut = L.layerGroup()
|
|
|
|
let groupsMarkersLayerIn = L.layerGroup()
|
|
|
|
|
|
|
|
let contactGeneral =["https://discord.gg/4BUau4AZre","DiscordInviteLink"]
|
|
|
|
|
2023-07-15 02:27:11 +07:00
|
|
|
function addMarkersToLayer(g,layer,content) {
|
2023-07-13 18:32:49 +07:00
|
|
|
let coordinates
|
2023-07-15 02:27:11 +07:00
|
|
|
let text = "<b>Group</b><br>"
|
2023-07-13 18:32:49 +07:00
|
|
|
for (let field in g) {
|
|
|
|
let fieldText = content[field] + ": "
|
|
|
|
if (field=="contact") {
|
|
|
|
text += fieldText + "<a href='" + g.contact[0] + "' target='_blank' rel=noreferrer>" + content[g.contact[1]] + "</a>"
|
|
|
|
}
|
|
|
|
else if (field=="location") {
|
|
|
|
let location = g[field][0]
|
|
|
|
let town = location[1]=="" ? "" : ", " + content[location[1]]
|
|
|
|
text += fieldText + content[location[0]] + town + "<br>"
|
|
|
|
coordinates = g[field][1]
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
text += fieldText + g[field] + "<br>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var markerIcon = new L.Icon({
|
|
|
|
iconUrl: 'https://www.libsoc.org/img/common/markers/marker-green.png',
|
|
|
|
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
|
|
|
|
iconSize: [25, 41],
|
|
|
|
iconAnchor: [12, 41],
|
|
|
|
popupAnchor: [1, -34],
|
|
|
|
shadowSize: [41, 41]
|
|
|
|
})
|
|
|
|
let marker = L.marker(coordinates, {icon: markerIcon})
|
|
|
|
marker.addTo(layer).bindPopup(text)
|
|
|
|
}
|
|
|
|
|
2023-07-09 19:25:09 +07:00
|
|
|
export function addMarkersGroups(map,content) {
|
2023-06-24 20:44:16 +07:00
|
|
|
for (let g of groups) {
|
2023-07-15 02:27:11 +07:00
|
|
|
addMarkersToLayer(g,groupsMarkersLayerIn,content)
|
2023-07-13 18:32:49 +07:00
|
|
|
}
|
|
|
|
for (let gs of Object.values(groupsByCountry)) {
|
|
|
|
if (gs.length==1) {
|
|
|
|
let g = {...gs[0]}
|
|
|
|
g.location[0][1] = ""
|
2023-07-15 02:27:11 +07:00
|
|
|
addMarkersToLayer(g,groupsMarkersLayerOut,content)
|
2023-07-13 18:32:49 +07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let locationName = [gs[0].location[0][0],""]
|
|
|
|
let locationCoordinates = [0,0]
|
|
|
|
let members = 0
|
|
|
|
let contact = gs[0].contact
|
|
|
|
for (let g of gs) {
|
|
|
|
locationCoordinates[0] += g.location[1][0]
|
|
|
|
locationCoordinates[1] += g.location[1][1]
|
|
|
|
members += g.members
|
|
|
|
if (g.contact[0]!=gs[0].contact[0]) {
|
|
|
|
contact = contactGeneral
|
|
|
|
}
|
2023-06-24 20:44:16 +07:00
|
|
|
}
|
2023-07-13 18:32:49 +07:00
|
|
|
locationCoordinates[0] = locationCoordinates[0]/gs.length
|
|
|
|
locationCoordinates[1] = locationCoordinates[1]/gs.length
|
|
|
|
let gNew = {
|
|
|
|
location: [locationName,locationCoordinates],
|
|
|
|
members: members,
|
|
|
|
contact: contact
|
2023-06-24 20:44:16 +07:00
|
|
|
}
|
2023-07-13 18:32:49 +07:00
|
|
|
|
2023-07-15 02:27:11 +07:00
|
|
|
addMarkersToLayer(gNew,groupsMarkersLayerOut,content)
|
2023-06-24 20:44:16 +07:00
|
|
|
}
|
2023-07-13 18:32:49 +07:00
|
|
|
}
|
2023-07-15 02:27:11 +07:00
|
|
|
groupsMarkersLayerOut.addTo(groupsMarkersLayer)
|
|
|
|
groupsMarkersLayer.addTo(map)
|
2023-07-13 18:32:49 +07:00
|
|
|
map.on("zoomend", () => onZoomEnd(map))
|
|
|
|
}
|
|
|
|
|
|
|
|
function onZoomEnd(map) {
|
|
|
|
let zoomLevel = map.getZoom()
|
|
|
|
if (zoomLevel==3) {
|
2023-07-15 02:27:11 +07:00
|
|
|
groupsMarkersLayer.removeLayer(groupsMarkersLayerIn)
|
|
|
|
groupsMarkersLayerOut.addTo(groupsMarkersLayer)
|
2023-07-13 18:32:49 +07:00
|
|
|
}
|
|
|
|
else if (zoomLevel==4) {
|
2023-07-15 02:27:11 +07:00
|
|
|
groupsMarkersLayer.removeLayer(groupsMarkersLayerOut)
|
|
|
|
groupsMarkersLayerIn.addTo(groupsMarkersLayer)
|
2023-06-24 20:44:16 +07:00
|
|
|
}
|
|
|
|
}
|