function lacIndexLookup(lat, lng) { // Step 1: local index (bbox) — always takes priority over major polygons const idx = window._lacsIndex; if (idx && idx.length) { const hits = []; for (let i = 0; i < idx.length; i++) { const e = idx[i]; if (lng >= e[1] && lng <= e[3] && lat >= e[2] && lat <= e[4]) hits.push(e); } if (hits.length > 0) { let best = hits[0]; if (hits.length > 1) { let bd = Infinity; for (const e of hits) { const cx = (e[1] + e[3]) / 2, cy = (e[2] + e[4]) / 2; const d = (lng - cx) * (lng - cx) + (lat - cy) * (lat - cy); if (d < bd) { bd = d; best = e; } } const bcx = (best[1] + best[3]) / 2, bcy = (best[2] + best[4]) / 2; const sameLake = hits.filter(e => { const cx = (e[1] + e[3]) / 2, cy = (e[2] + e[4]) / 2; return Math.abs(cx - bcx) < 0.003 && Math.abs(cy - bcy) < 0.003; }); if (sameLake.length > 1) { const score = nm => { let s = 0; if (/^(lac|rivière|riviere|étang|etang|réservoir|reservoir|fleuve)\b/i.test(nm)) s += 2; if (/[àâäéèêëïîôöùûüç]/i.test(nm)) s += 1; s += nm.length / 100; return s; }; best = sameLake.reduce((a, b) => score(b[0]) > score(a[0]) ? b : a); } } return { name: best[0], waterType: 'lake' }; } } return null; }
Your Quebec sport fishing app. This quick tour shows you the key features.