|
3 | 3 | <head> |
4 | 4 | <meta charset="utf-8" /> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
6 | | - <title>[archlinuxcn] mirror locations</title> |
7 | | - <script src=" https://unpkg.com/[email protected]/dist/leaflet.js" ></script> |
| 6 | + <link |
| 7 | + rel="icon" |
| 8 | + href="https://build.archlinuxcn.org/favicon.ico" |
| 9 | + type="image/ico" |
| 10 | + /> |
| 11 | + <title>ArchLinuxCN Mirrors Map</title> |
| 12 | + <meta |
| 13 | + name="description" |
| 14 | + content="Here is a list of public mirrors of Arch Linux CN Community Repository" |
| 15 | + /> |
| 16 | + <script src=" https://unpkg.com/[email protected]/dist/leaflet.js" ></script> |
8 | 17 | <link |
9 | 18 | rel="stylesheet" |
10 | | - href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" |
| 19 | + href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" |
11 | 20 | /> |
12 | | - <script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script> |
| 21 | + <script src="https://unpkg.com/leaflet.markercluster@1.5.3/dist/leaflet.markercluster.js"></script> |
13 | 22 | <link |
14 | 23 | rel="stylesheet" |
15 | | - href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.css" |
| 24 | + href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.css" |
16 | 25 | /> |
17 | 26 | <link |
18 | 27 | rel="stylesheet" |
19 | | - href="https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css" |
| 28 | + href="https://unpkg.com/leaflet.markercluster@1.5.3/dist/MarkerCluster.Default.css" |
20 | 29 | /> |
21 | 30 | <style> |
22 | 31 | html, |
23 | 32 | body { |
| 33 | + width: 100%; |
24 | 34 | height: 100%; |
25 | | - padding: 0; |
26 | 35 | margin: 0; |
27 | 36 | } |
| 37 | + |
28 | 38 | #map { |
29 | 39 | /* configure the size of the map */ |
30 | 40 | width: 100%; |
31 | 41 | height: 100%; |
32 | 42 | } |
33 | 43 |
|
34 | 44 | .circle { |
| 45 | + display: inline-block; |
35 | 46 | width: 1em; |
36 | 47 | height: 1em; |
37 | | - display: inline-block; |
38 | 48 | border-radius: 1em; |
39 | 49 | } |
| 50 | + |
40 | 51 | .legend { |
41 | | - background-color: rgba(238, 238, 238, 0.5); |
| 52 | + padding: 5px; |
| 53 | + background-color: hsl(0deg 0% 100% / 70%); |
| 54 | + border-radius: 5px; |
| 55 | + } |
| 56 | + |
| 57 | + .leaflet-popup-content-wrapper { |
| 58 | + background-color: hsl(0deg 0% 100% / 90%); |
| 59 | + border-radius: 5px; |
| 60 | + box-shadow: none; |
42 | 61 | } |
43 | 62 | </style> |
44 | 63 | </head> |
| 64 | + |
45 | 65 | <body> |
46 | 66 | <div id="map"></div> |
47 | 67 | <script> |
|
50 | 70 |
|
51 | 71 | // add the OpenStreetMap tiles |
52 | 72 | L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { |
53 | | - maxZoom: 19, |
| 73 | + minZoom: 2, |
| 74 | + maxZoom: 12, |
54 | 75 | attribution: |
55 | 76 | '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>', |
56 | 77 | }).addTo(map); |
57 | 78 |
|
58 | | - // show the scale bar on the lower left corner |
59 | | - L.control.scale({ imperial: true, metric: true }).addTo(map); |
60 | | - |
61 | | - const load_data = async function () { |
| 79 | + const loadData = async function () { |
62 | 80 | const res = await fetch( |
63 | | - "https://raw.githubusercontent.com/archlinuxcn/mirrorlist-repo/master/geolocs.json" |
| 81 | + "https://raw.githubusercontent.com/archlinuxcn/mirrorlist-repo/master/mirrors.geojson" |
64 | 82 | ); |
65 | 83 | const data = await res.json(); |
66 | | - // sort by mirror |
67 | | - data.features.sort((a, b) => { |
68 | | - const ma = a.properties.mirror; |
69 | | - const mb = b.properties.mirror; |
70 | | - if (ma < mb) { |
71 | | - return -1; |
72 | | - } else if (ma === mb) { |
73 | | - return 0; |
74 | | - } else { |
75 | | - return 1; |
76 | | - } |
77 | | - }); |
78 | | - const state = [0, data.features[0].properties.mirror]; |
| 84 | + const state = [0, data.features[0].properties.provider]; |
79 | 85 | const colors = new Map(); |
80 | 86 | for (const d of data.features) { |
81 | | - if (state[1] !== d.properties.mirror) { |
| 87 | + if (state[1] !== d.properties.provider) { |
82 | 88 | state[0] += 1; |
83 | | - state[1] = d.properties.mirror; |
| 89 | + state[1] = d.properties.provider; |
84 | 90 | } |
85 | | - const color = `hsl(${137.508 * state[0]}, 90%, 50%)`; |
| 91 | + const color = `oklch(61.8033% 61.8033% ${state[0] * 360 * 0.618033})`; |
86 | 92 | d.properties.color = color; |
87 | | - colors.set(color, d.properties.mirror); |
| 93 | + colors.set(color, d.properties.provider); |
88 | 94 | } |
89 | 95 |
|
90 | 96 | const legend = L.control({ position: "topright" }); |
91 | 97 | legend.onAdd = function (map) { |
92 | 98 | const div = L.DomUtil.create("div", "info legend"); |
93 | 99 | const labels = []; |
94 | | - for (const [color, mirror] of colors) { |
| 100 | + for (const [color, provider] of colors) { |
95 | 101 | labels.push( |
96 | | - `<i class="circle" style="background: ${color}"></i> ${mirror}` |
| 102 | + `<i class="circle" style="background: ${color}"></i> ${provider}` |
97 | 103 | ); |
98 | 104 | } |
99 | 105 | div.innerHTML = labels.join("<br>"); |
|
102 | 108 | legend.addTo(map); |
103 | 109 |
|
104 | 110 | const markers = L.markerClusterGroup({ |
| 111 | + showCoverageOnHover: false, |
105 | 112 | zoomToBoundsOnClick: false, |
106 | 113 | maxClusterRadius: 30, |
107 | 114 | }); |
108 | 115 | L.geoJSON(data, { |
109 | 116 | onEachFeature: function (feature, layer) { |
110 | 117 | const p = feature.properties; |
111 | | - // console.log(feature.geometry.coordinates, feature.properties.name) |
112 | 118 | layer.bindPopup( |
113 | | - `<p>${p.name}<br/><small><a href="${p.url}">${p.mirror}</a></small></p>` |
| 119 | + `<a href="${p.url}" style="text-decoration: none">${p.provider}</a> (${p.location})`, |
| 120 | + { maxWidth: 500 } |
114 | 121 | ); |
115 | 122 | }, |
116 | 123 | pointToLayer: function (feature, latlng) { |
117 | 124 | return L.circleMarker(latlng, { |
118 | 125 | radius: 7, |
119 | | - fillColor: feature.properties.color, |
120 | 126 | color: feature.properties.color, |
121 | 127 | weight: 1, |
122 | | - opacity: 0.9, |
| 128 | + fillColor: feature.properties.color, |
123 | 129 | fillOpacity: 0.5, |
124 | 130 | }); |
125 | 131 | }, |
126 | 132 | }).addTo(markers); |
127 | 133 | map.addLayer(markers); |
128 | 134 | }; |
129 | | - load_data(); |
| 135 | + loadData(); |
130 | 136 | </script> |
131 | 137 | </body> |
132 | 138 | </html> |
0 commit comments