๐ GIS โ Jamaica Agricultural Map
Farms ยท Markets ยท Cold Storage ยท Agro Parks ยท Labor Zones ยท Export Points
Farm
Agro Park
Market
Cold Storage
Labor Zone
Export Port
Research Station
Parish Capital
Avg: J$'+avg+'/kg
'+items.length+' commodities');_pm.addTo(mapInstance);});addMapLayer('farms');} function addMapLayer(type){if(!mapInstance)return;const pins=MAP_PINS[type]||[];const color=layerColors[type]||'#555';leafletPins[type]=pins.map(p=>{const m=L.circleMarker([p.lat,p.lng],{radius:10,fillColor:color,color:'white',weight:2,fillOpacity:.9});m.bindPopup(`${p.name}
${p.info}`);m.addTo(mapInstance);return m;});} function removeMapLayer(type){(leafletPins[type]||[]).forEach(m=>mapInstance.removeLayer(m));leafletPins[type]=[];} function toggleLayer(type){activeLayers[type]=!activeLayers[type];document.getElementById('layer-'+type).classList.toggle('active',activeLayers[type]);if(activeLayers[type])addMapLayer(type);else removeMapLayer(type);} // SHARING function shareEmail(){window.open(`mailto:?subject=HelloAG Jamaica Market Watch May 2026&body=Jamaica agricultural market prices and insights: ${window.location.href}`);} function shareWhatsApp(){window.open(`https://wa.me/?text=${encodeURIComponent('๐ฏ๐ฒ Jamaica Market Watch โ Week of May 3, 2026. HelloAG: '+window.location.href)}`);} function shareFacebook(){window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(window.location.href)}`);} function shareTwitter(){window.open(`https://twitter.com/intent/tweet?text=${encodeURIComponent('๐ฏ๐ฒ Jamaica Market Watch May 2026')}&url=${encodeURIComponent(window.location.href)}`);} function copyLink(){navigator.clipboard.writeText(window.location.href).then(()=>toast('๐ Link copied!')).catch(()=>{});} // MODALS function openModal(id){document.getElementById('modal-'+id)?.classList.add('open');} function closeModal(id){document.getElementById('modal-'+id)?.classList.remove('open');} document.querySelectorAll('.modal-overlay').forEach(o=>o.addEventListener('click',function(e){if(e.target===this)this.classList.remove('open');})); function submitForm(type){closeModal(type);const msgs={subscribe:'โ Welcome to HelloAG! Check your WhatsApp soon.',register:'โ Registered! You\'ll appear in the directory within 24 hours.',labor:'โ Listing posted!'};toast(msgs[type]||'โ Done!');} // CALCULATOR function switchCalc(n){[1,2,3].forEach(i=>{document.getElementById('ct'+i)?.classList.toggle('active',i===n);document.getElementById(i===1?'calc-unit':i===2?'calc-revenue':'calc-markup').style.display=i===n?'block':'none';});} function calcUnit(){const v=parseFloat(document.getElementById('inp-kg').value)||0;document.getElementById('inp-lb').value=(v*2.2046).toFixed(2);const r=document.getElementById('unit-result');if(v){r.style.display='block';r.textContent=`${v} kg = ${(v*2.2046).toFixed(2)} lbs`;}} function calcUnitRev(){const v=parseFloat(document.getElementById('inp-lb').value)||0;document.getElementById('inp-kg').value=(v/2.2046).toFixed(2);const r=document.getElementById('unit-result');if(v){r.style.display='block';r.textContent=`${v} lbs = ${(v/2.2046).toFixed(2)} kg`;}} function calcRevenue(){const p=parseFloat(document.getElementById('r-price').value)||0,q=parseFloat(document.getElementById('r-qty').value)||0,t=parseFloat(document.getElementById('r-transport').value)||0;const g=p*q,n=g-t,r=document.getElementById('rev-result');if(p&&q){r.style.display='block';r.innerHTML=`Gross: J$${g.toLocaleString()}
Net (after transport): J$${n.toLocaleString()}
Net per kg: J$${(n/q).toFixed(0)}`;}} function calcMarkup(){const f=parseFloat(document.getElementById('m-farm').value)||0,s=parseFloat(document.getElementById('m-sell').value)||0,d=s-f,pct=f?((d/f)*100).toFixed(1):0,r=document.getElementById('markup-result');if(f&&s){r.style.display='block';r.innerHTML=`Margin: J$${d.toFixed(0)}/kg
Markup: ${pct}%
${pct>100?'โ Good margin':'โ ๏ธ Review your costs'}`;}} // TOAST function toast(msg){const t=document.getElementById('toast');t.textContent=msg;t.classList.add('show');setTimeout(()=>t.classList.remove('show'),2800);} // TAB SWITCH const TAB_ORDER=['dashboard','prices','heatmap','alerts','export','agroparks','gismap','labor','govt','research','mechanization','education','directory','videos','news','whatsapp','faq','subscribe']; function switchTab(id){document.querySelectorAll('.tab').forEach(p=>p.classList.remove('active'));document.querySelectorAll('.nav-btn').forEach(b=>b.classList.remove('active'));document.getElementById('tab-'+id)?.classList.add('active');const nb=document.querySelectorAll('.nav-btn');const idx=TAB_ORDER.indexOf(id);if(idx>=0&&nb[idx])nb[idx].classList.add('active');if(id==='gismap')setTimeout(initMap,100);window.scrollTo({top:0,behavior:'smooth'});} // โโ SUBSCRIBE & SHARE FUNCTIONS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ function submitSubscribe() { var name = document.querySelector('#modal-subscribe .m-inp[type="text"]'); var phone = document.querySelector('#modal-subscribe .m-inp[type="tel"]'); var email = document.querySelector('#modal-subscribe .m-inp[type="email"]'); var tier = document.querySelector('#modal-subscribe select') ; var nameVal = name ? name.value.trim() : ''; var phoneVal = phone ? phone.value.trim() : ''; var emailVal = email ? email.value.trim() : ''; if (!nameVal || !phoneVal) { showToast('Please enter your name and WhatsApp number'); return; } // Build WhatsApp message to HelloAG registration number var msg = 'HelloAG Registration%0AName: ' + encodeURIComponent(nameVal) + '%0AWhatsApp: ' + encodeURIComponent(phoneVal) + (emailVal ? '%0AEmail: ' + encodeURIComponent(emailVal) : '') + '%0ATier: Free'; window.open('https://wa.me/18765551234?text=' + msg, '_blank'); showToast('Redirecting to WhatsApp registrationโฆ'); closeModal('subscribe'); } function copyCard(idx) { var cards = document.querySelectorAll('.wa-body'); if (cards[idx]) { var text = cards[idx].textContent || ''; if (navigator.clipboard) { navigator.clipboard.writeText(text).then(function() { showToast('Card copied to clipboard โ'); }); } else { var ta = document.createElement('textarea'); ta.value = text; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta); showToast('Card copied โ'); } } } function shareWA(text) { window.open('https://wa.me/?text=' + encodeURIComponent(text), '_blank'); } function shareFB() { window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.location.href), '_blank'); } function shareTW(text) { window.open('https://twitter.com/intent/tweet?text=' + encodeURIComponent(text || 'Check out HelloAG Jamaica market intelligence'), '_blank'); } function printPage() { window.print(); } // โโ INIT โโ // 1) Render immediately with fallback data โ visitors never see a blank page buildTicker(); buildKPIs(); buildBestVal(); buildTopScarce(); buildParishOv(); buildBarChart(); buildParishFilter(); renderTable(DATA); renderHeatmap(); buildAlerts(); buildExport(); buildAgroParkGrid(); renderGovt(); buildResearch(); buildTractors(); buildSchools(); filterDir(); buildLabor(); filterVideos(); buildWhatsApp(); buildFAQ(); applyWeekLabel(); setDataStatus('fallback', 'Loadingโฆ'); // 2) Fetch live data in background and refresh if successful loadFromGoogleSheets().then(function(liveData) { if (liveData && liveData.length > 0) { rebuildDashboard(liveData); applyWeekLabel(); } });