1var BFMap = (function () { 2 'use strict'; 3 4 var SVG_URL = '/static/static/map/kongeriget.svg'; 5 var NS = 'http://www.w3.org/2000/svg'; 6 7 function mercY(lat) { 8 return Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)); 9 } 10 11 var REGIONS = [ 12 { id: 'BH', navn: 'Bornholm', 13 lat: [54.90, 55.45], lng: [14.55, 15.35], 14 fit: { x0: -11190.302, sx: 882.5397, y0: 62689.872, sy: -53063.7527 } }, 15 16 { id: 'DK', navn: 'Danmark', 17 lat: [54.40, 57.95], lng: [7.80, 13.00], 18 fit: { x0: -2426.350, sx: 299.7463, y0: 21280.773, sy: -17141.9034 } }, 19 20 { id: 'FO', navn: 'Færøerne', 21 lat: [61.20, 62.55], lng: [-7.90, -6.05], 22 fit: { x0: 4053.822, sx: 384.9184, y0: 30877.717, sy: -21999.2018 } }, 23 24 { id: 'GL', navn: 'Grønland', 25 lat: [59.30, 83.90], lng: [-74.00, -10.50], 26 test: function (lat, lng) { 27 if (lat >= 63.0 && lat <= 67.0) { return lng <= -30.0; } 28 return true; 29 }, 30 fit: { x0: 2344.000, sx: 8.3562, y0: 1422.200, sy: -478.7734 } } 31 ]; 32 33 var CLIP = { 34 FO: [1090.62, 2.50, 1671.25, 825.85], 35 GL: [1714.45, 8.36, 2267.92, 824.33], 36 BH: [1715.63, 874.91, 2269.10, 1497.57] 37 }; 38 var VIEW = [0, 0, 2271.6, 1727.45]; 39 40 function regionFor(lat, lng) { 41 for (var i = 0; i < REGIONS.length; i++) { 42 var r = REGIONS[i]; 43 if (lat >= r.lat[0] && lat <= r.lat[1] && lng >= r.lng[0] && lng <= r.lng[1]) { 44 if (r.test && !r.test(lat, lng)) { continue; } 45 return r; 46 } 47 } 48 return null; 49 } 50 51 function inBox(x, y, b) { 52 return x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3]; 53 } 54 55 function project(lat, lng) { 56 var r = regionFor(lat, lng); 57 if (!r) { return null; } 58 59 var f = r.fit; 60 var x = f.x0 + lng * f.sx; 61 var y = f.y0 + mercY(lat) * f.sy; 62 63 if (CLIP[r.id]) { 64 if (!inBox(x, y, CLIP[r.id])) { return null; } 65 } else { 66 if (x < VIEW[0] || x > VIEW[2] || y < VIEW[1] || y > VIEW[3]) { return null; } 67 for (var k in CLIP) { 68 if (Object.prototype.hasOwnProperty.call(CLIP, k) && inBox(x, y, CLIP[k])) { 69 return null; 70 } 71 } 72 } 73 74 return { x: x, y: y, region: r.id, navn: r.navn }; 75 } 76 77 function el(name, attrs) { 78 var n = document.createElementNS(NS, name); 79 for (var k in attrs) { 80 if (Object.prototype.hasOwnProperty.call(attrs, k)) { 81 n.setAttribute(k, attrs[k]); 82 } 83 } 84 return n; 85 } 86 87 88 function render(host, points, opts) { 89 opts = opts || {}; 90 var url = opts.svg || SVG_URL; 91 92 return fetch(url).then(function (r) { 93 if (!r.ok) { throw new Error('kort kunne ikke hentes: ' + r.status); } 94 return r.text(); 95 }).then(function (txt) { 96 host.innerHTML = txt; 97 var svg = host.querySelector('svg'); 98 if (!svg) { throw new Error('ingen <svg> i kortfilen'); } 99 100 svg.removeAttribute('width'); 101 svg.removeAttribute('height'); 102 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet'); 103 svg.style.width = '100%'; 104 svg.style.height = 'auto'; 105 svg.style.display = 'block'; 106 107 if (opts.onlyRegion && CLIP[opts.onlyRegion]) { 108 var b = CLIP[opts.onlyRegion]; 109 svg.setAttribute('viewBox', 110 (b[0] - 10) + ' ' + (b[1] - 10) + ' ' + 111 (b[2] - b[0] + 20) + ' ' + (b[3] - b[1] + 20)); 112 } 113 114 var udenfor = []; 115 var plottet = 0; 116 117 var vb = (svg.getAttribute('viewBox') || VIEW.join(' ')).split(/[\s,]+/).map(Number); 118 var skala = (vb[2] || VIEW[2]) / VIEW[2]; 119 120 if (opts.dotScale) { skala *= opts.dotScale; } 121 122 (points || []).forEach(function (p) { 123 var lat = Number(p.lat), lng = Number(p.lng); 124 if (!isFinite(lat) || !isFinite(lng)) { return; } 125 126 var pos = project(lat, lng); 127 if (!pos) { udenfor.push(p); return; } 128 129 var g = el('g', { 'class': 'bfmap-point' + (p.current ? ' is-current' : '') }); 130 131 if (p.current) { 132 g.appendChild(el('circle', { 133 cx: pos.x, cy: pos.y, r: 30 * skala, 134 fill: 'var(--yellow-dark, #f3e256)', 'fill-opacity': '0.55' 135 })); 136 } 137 138 g.appendChild(el('circle', { 139 cx: pos.x, cy: pos.y, r: (p.current ? 15 : 10) * skala, 140 fill: p.current ? 'var(--red, #c00)' : 'var(--steel, #979da9)', 141 stroke: '#fff', 'stroke-width': (p.current ? 4.5 : 3) * skala 142 })); 143 144 if (p.label) { 145 var t = el('title', {}); 146 t.textContent = p.label; 147 g.appendChild(t); 148 } 149 150 svg.appendChild(g); 151 plottet++; 152 }); 153 154 return { plottet: plottet, udenfor: udenfor }; 155 }); 156 } 157 158 function renderPoint(host, punkt, opts) { 159 opts = opts || {}; 160 var url = opts.svg || SVG_URL; 161 162 return fetch(url).then(function (r) { 163 if (!r.ok) { throw new Error('kort kunne ikke hentes: ' + r.status); } 164 return r.text(); 165 }).then(function (txt) { 166 host.innerHTML = txt; 167 var svg = host.querySelector('svg'); 168 if (!svg) { throw new Error('ingen <svg> i kortfilen'); } 169 170 svg.removeAttribute('width'); 171 svg.removeAttribute('height'); 172 svg.setAttribute('preserveAspectRatio', 'xMidYMid meet'); 173 svg.style.width = '100%'; 174 svg.style.height = 'auto'; 175 svg.style.display = 'block'; 176 177 if (opts.onlyRegion && CLIP[opts.onlyRegion]) { 178 var b = CLIP[opts.onlyRegion]; 179 svg.setAttribute('viewBox', 180 (b[0] - 10) + ' ' + (b[1] - 10) + ' ' + 181 (b[2] - b[0] + 20) + ' ' + (b[3] - b[1] + 20)); 182 } 183 184 var vb = (svg.getAttribute('viewBox') || VIEW.join(' ')).split(/[\s,]+/).map(Number); 185 var skala = (vb[2] || VIEW[2]) / VIEW[2]; 186 if (opts.dotScale) { skala *= opts.dotScale; } 187 188 var g = el('g', { 'class': 'bfmap-point is-current' }); 189 g.appendChild(el('circle', { 190 cx: punkt.x, cy: punkt.y, r: 30 * skala, 191 fill: 'var(--yellow-dark, #f3e256)', 'fill-opacity': '0.55' 192 })); 193 g.appendChild(el('circle', { 194 cx: punkt.x, cy: punkt.y, r: 15 * skala, 195 fill: 'var(--red, #c00)', stroke: '#fff', 'stroke-width': 4.5 * skala 196 })); 197 svg.appendChild(g); 198 199 return { plottet: 1 }; 200 }); 201 } 202 203 return { 204 render: render, 205 renderPoint: renderPoint, 206 project: project, 207 regionFor: regionFor, 208 REGIONS: REGIONS 209 }; 210})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.