const MONTHS = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"]; const MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"]; var map; var mapview; var cur_active_layer; var layer_pdie; var layer_hth_das_info; var layer_hth_das_view; var source_pdie; var source_hth_das_info; var source_hth_das_view; var maptitle_hth; var maptitle_pdie; var legend_pdie = [ ["", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=pdie,0", "Tidak ada peringatan"], ["", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=pdie,1", "Waspada"], ["", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=pdie,2", "Siaga"], ["", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=pdie,3", "Awas"] ]; var legend_hth_das_view = [ ["1 - 5", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das1,0", "Sangat Pendek (Very Short)"], ["6 - 10", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das2,0", "Pendek (Short)"], ["11 - 20", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das3,0", "Menengah (Moderate)"], ["21 - 30", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das4,0", "Panjang (Long)"], ["31 - 60", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das5,0", "Sangat Panjang (Very Long)"], ["> 60", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das6,0", "Extrem Panjang (Extremely Long)"], ["", "https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg&mode=legendicon&icon=hth_das0,0", "Masih ada hujan s/d updating (No Drought)"] ]; var infodetails; $(function(){ infodetails = new ol.Overlay({ element: document.getElementById('infodetails'), autoPan: true, autoPanAnimation: { duration: 250, }, }); mapview = new ol.View({ center: ol.proj.fromLonLat([118.1661992, -2.2070457]), zoom: 5, constrainResolution: true }); //init ol map = new ol.Map({ target: 'mapcontainer', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], view: mapview, overlays: [infodetails], interactions: ol.interaction.defaults({mouseWheelZoom:false}) }); source_pdie = new ol.source.ImageWMS({url: 'https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg'}); layer_pdie = new ol.layer.Image({source:source_pdie, visible:false}); map.addLayer(layer_pdie); source_hth_das_info = new ol.source.ImageWMS({url: 'https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg'}); layer_hth_das_info = new ol.layer.Image({source:source_hth_das_info, visible:false}); map.addLayer(layer_hth_das_info); source_hth_das_view = new ol.source.ImageWMS({url: 'https://cews.bmkg.go.id/cgi-bin/mapserv?map=bmkg'}); layer_hth_das_view = new ol.layer.Image({source:source_hth_das_view, visible:false}); map.addLayer(layer_hth_das_view); //init layer switcher $(".layerswitcher .toggle").click(function(){ if($(this).parent().attr("state")=="opened"){ $(this).siblings(".content").hide(); $(this).children("button").children("i").removeClass("fa-times"); $(this).children("button").children("i").addClass("fa-layer-group"); $(this).parent().attr("state","closed"); }else{ $(this).siblings(".content").show(); $(this).children("button").children("i").removeClass("fa-layer-group"); $(this).children("button").children("i").addClass("fa-times"); $(this).parent().attr("state","opened"); } }); $(".layerswitcher .content input[name^='optlayer']").change(function(){ var date1 = $(this).siblings("select").children("option:selected").attr("date1") || $(this).attr("date1") || ""; var date2 = $(this).siblings("select").children("option:selected").attr("date2") || $(this).attr("date2") || ""; var num1 = $(this).siblings("select").children("option:selected").attr("num1") || $(this).attr("num1") || ""; var num2 = $(this).siblings("select").children("option:selected").attr("num2") || $(this).attr("num2") || ""; switchLayer({ layername:$(this).val(), date1:date1, date2:date2, num1:num1, num2:num2 }); }); $(".layerswitcher .content select").change(function(){ if($(this).siblings("input").is(":checked")){//hanya jika layer aktif var date1 = $(this).children("option:selected").attr("date1"); var date2 = $(this).children("option:selected").attr("date2"); var num1 = $(this).children("option:selected").attr("num1"); var num2 = $(this).children("option:selected").attr("num2"); switchLayer({ layername:$(this).siblings("input").val(), date1:date1, date2:date2, num1:num1, num2:num2 }); } }); //init default layer $(".layerswitcher .content input[value='pdie']").prop('checked', true); switchLayer({ layername:"pdie", date1:"2024-09-01", num1:"1" }); //init info details map.on('singleclick', function (e) { var viewResolution = mapview.getResolution(); var alllayers = [ { layercode: "pdie", url: source_pdie.getFeatureInfoUrl(e.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}), layertitle: "Peringatan Dini Kekeringan Meteorologis (PDKM)" }, { layercode: "hth", url: source_hth_das_info.getFeatureInfoUrl(e.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}), layertitle: "Hari Tanpa Hujan" } ]; $("#infodetails-content").html(""); var hasinfo = false; var processedlayer = 0; var totallayertoprocess = $("input[name^='optlayer']:checked").length; for(var i=0;i < alllayers.length;i++){ if($("input[value='"+alllayers[i].layercode+"']").is(":checked")){ var url = alllayers[i].url; fetch(url).then(async function (response) { if (!response.ok) { throw Error(response.statusText); } return { html: await response.text(), title: this.title }; }.bind({ title: alllayers[i].layertitle })).then(function (obj) { processedlayer++; var htmltrim = obj.html.trim(); if(htmltrim){ if(htmltrim.substring(0, 5) == "
"+obj.title+"
"+obj.html+""); hasinfo = true; } } if(processedlayer == totallayertoprocess){ if(hasinfo){ infodetails.setPosition(e.coordinate); }else{ infodetails.setPosition(undefined); } } }).catch(function(e){ processedlayer++; if(processedlayer == totallayertoprocess){ if(hasinfo){ infodetails.setPosition(e.coordinate); }else{ infodetails.setPosition(undefined); } } }); } } }); //print out $("#mapprint-pdie").click(function(){ var zoom = map.getView().getZoom(); var center = ol.proj.transform(map.getView().getCenter(), 'EPSG:3857', 'EPSG:4326'); var date = $(".layerswitcher .content select").children("option:selected").attr("date1"); var num = $(".layerswitcher .content select").children("option:selected").attr("num1"); window.open("peringatankekeringan_print.php?zoom=" + zoom + "¢er0=" + center[0] + "¢er1=" + center[1] + "&date=" + date + "&num=" + num); }); $("#mapprint-hth").click(function(){ $("#mdlprintout").modal("show"); }); // opacity control $(".slctransparant").val(1); $(".slctransparant").change(function(){ switch($(this).attr("layercode")){ case "pdie": layer_pdie.setOpacity(Number($(this).val())); break; case "hth": layer_hth_das_info.setOpacity(Number($(this).val())); layer_hth_das_view.setOpacity(Number($(this).val())); break; } }); }); function switchLayer(obj){ var layername = obj.layername || ""; var date1 = obj.date1 || ""; var date2 = obj.date2 || ""; var num1 = obj.num1 || ""; var num2 = obj.num2 || ""; cur_active_layer = layername; var omonth1_m2 = MONTHS[(parseInt(date1.substring(5,7))-3) < 0?(parseInt(date1.substring(5,7))-3+12):(parseInt(date1.substring(5,7))-3)]; var omonth1_m1 = MONTHS[(parseInt(date1.substring(5,7))-2) < 0?(parseInt(date1.substring(5,7))-2+12):(parseInt(date1.substring(5,7))-2)]; var omonth1 = MONTHS[parseInt(date1.substring(5,7))-1]; var omonth1_p1 = MONTHS[(parseInt(date1.substring(5,7))) > 11?(parseInt(date1.substring(5,7))-12):(parseInt(date1.substring(5,7)))]; var omonth1_p2 = MONTHS[(parseInt(date1.substring(5,7))+1) > 11?(parseInt(date1.substring(5,7))+1-12):(parseInt(date1.substring(5,7))+1)]; var omonth1_short = MONTHS_SHORT[parseInt(date1.substring(5,7))-1]; var oyear1 = date1.substring(0,4); var omonth2_m2 = MONTHS[(parseInt(date2.substring(5,7))-3) < 0?(parseInt(date2.substring(5,7))-3+12):(parseInt(date2.substring(5,7))-3)]; var omonth2_m1 = MONTHS[(parseInt(date2.substring(5,7))-2) < 0?(parseInt(date2.substring(5,7))-2+12):(parseInt(date2.substring(5,7))-2)]; var omonth2 = MONTHS[parseInt(date2.substring(5,7))-1]; var omonth2_p1 = MONTHS[(parseInt(date2.substring(5,7))) > 11?(parseInt(date2.substring(5,7))-12):(parseInt(date2.substring(5,7)))]; var omonth2_p2 = MONTHS[(parseInt(date2.substring(5,7))+1) > 11?(parseInt(date2.substring(5,7))+1-12):(parseInt(date2.substring(5,7))+1)]; var oyear2 = date2.substring(0,4); layer_pdie.setVisible($("input[value='pdie']").is(":checked")); layer_hth_das_info.setVisible($("input[value='hth']").is(":checked")); layer_hth_das_view.setVisible($("input[value='hth']").is(":checked")); setLegend(layername, date1, date2, num1); var maptitle = []; if($("input[value='pdie']").is(":checked")){ if(layername == "pdie"){ maptitle_pdie = "PERINGATAN DINI KEKERINGAN METEOROLOGIS
BERLAKU DASARIAN "+romawi(num1)+" "+omonth1.toUpperCase()+" "+oyear1; layer_pdie.getSource().updateParams({ 'LAYERS': 'pdie,prov,kabkot', 'date': date1, 'num': num1 }); } maptitle.push(maptitle_pdie); $("#mapprint-pdie").show(); $("#maplegend_pdie").show(); }else{ $("#maplegend_pdie").hide(); $("#mapprint-pdie").hide(); } if($("input[value='hth']").is(":checked")){ if(layername == "hth"){ maptitle_hth = "MONITORING HARI TANPA HUJAN BERTURUT-TURUT
PEMUTAKHIRAN DASARIAN "+romawi(num1)+" "+omonth1.toUpperCase()+" "+oyear1; layer_hth_das_info.getSource().updateParams({ 'LAYERS': 'kabkot,prov,hth_das_info', 'date': date1 }); layer_hth_das_view.getSource().updateParams({ 'LAYERS': 'kabkot,prov,hth_das0,hth_das1,hth_das2,hth_das3,hth_das4,hth_das5,hth_das6', 'date': date1 }); $("#mdlprintout a.indonesia").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-Indonesia.jpg"); $("#mdlprintout a.balinusa").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-BaliNustra.jpg"); $("#mdlprintout a.jawa").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-Jawa.jpg"); $("#mdlprintout a.kalimantan").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-Kalimantan.jpg"); $("#mdlprintout a.malukupapua").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-MalukuPapua.jpg"); $("#mdlprintout a.sulawesi").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-Sulawesi.jpg"); $("#mdlprintout a.sumatera").attr("href", "ftp/HTH_jpg/Das "+num1+" "+omonth1_short+" "+oyear1+"/PetaMonitoringHariTanpaHujan-Sumatera.jpg"); } maptitle.push(maptitle_hth); $("#mapprint-hth").show(); $("#maplegend_hth").show(); }else{ $("#maplegend_hth").hide(); $("#mapprint-hth").hide(); } if(maptitle.length > 0){ $("#maptitle").show(); $("#maptitle").html(maptitle.join(", ")); $("#legendcontainer").show(); }else{ $("#maptitle").hide(); $("#legendcontainer").hide(); } infodetails.setPosition(undefined); } function setLegend(layername, date1, date2, num1){ var legendsetting; switch(layername){ case "pdie": legendsetting = legend_pdie; $("#mapannotation").hide(); legendtext = "Peringatan Dini Iklim"; break; case "hth": legendsetting = legend_hth_das_view; $("#mapannotation").hide(); legendtext = "Hari Tanpa Hujan"; break; } var html=""; html+=""; for(var i=0;i"; } html+="
"+legendtext+"
"+legendsetting[i][2]+"
"; $("#areacoverage").hide(); $("#maplegend tr").unbind(); $("#maplegend_"+layername).html(html); if(layername!="titikstationmatahari"){ $("#maplegend_"+layername+" tr.trlegend").click(function(){ setAreaCoverage($(this).attr("layername"), $(this).attr("legendindex"), date1, date2, num1); }); } } function setAreaCoverage(layername, legendindex, date1, date2, num1){ $("#mapannotation").hide(); $("#areacoverage").show(); $("#areacoverage-content").html("Loading..."); $.post("areacoverage.php?req=getareacoverage", { layername:layername, legendindex:legendindex, date1:date1, date2:date2, num1:num1 },function(data){ if(jQuery.isEmptyObject(data)){ $("#areacoverage-content").html("Wilayah tidak ditemukan"); }else{ var html=""; for(var i=0;i"; html+="
"; for(var j=0;j"; } html+="
"; html+=""; } $("#areacoverage-content").html(html); } }); } function romawi(num){ switch(Number(num)){ case 1: return "I"; case 2: return "II"; case 3: return "III"; case 4: return "IV"; case 5: return "V"; } }