/*** Global object that contains the app ***/ var app = app || {}; // keep our map stuff in a part of the app object as to not pollute the global name space app.map = (function(w,d, $, _){ var el = { map:null,cdbURL:null,styles: null,params:null, styleCur:null,sql:null, mapboxTiles:null,satellite:null,taxLots:null, baseLayers:null,capaMANZ:null,capaCALLES:null,capasinCCC:null,polygon:null, bushwick:null,colony : null,linden : null,groveSt : null,featureGroup : null, template:null,menu:null, legend:null,menud:null, mostrar: null, taxLotActions:null,story:null }; //SE CARGAN VALORES REUTILIZABLES el.styles = app.mapStyles; //ESTILOS el.params = app.param; //PARAMETROS el.cdbURL = app.url; //URL MAPA BASE // compile the underscore legend template for rendering map legends for choropleth layers _.templateSettings.variable = "legend"; el.template = _.template($("script.template").html()); el.legendcontainer = $('#ui-leyenda-contenedor'); el.legend = $('#ui-legend'); el.menu = $('#accordion'); // Configuramos el mapa y sus capas! var initMap = function() { // Ocultamos datos, resumen y tooltip $('#box2').hide();$('#tool-tip').hide(); // Parametros del mapa de FONDO var params = {center:[lat,lng],minZoom:minzoom,maxZoom:maxzoom,zoom:zoom,maxBounds:L.latLngBounds(corner1,corner2),zoomControl:false,infoControl:false,attributionControl:true} el.map = new L.map('map', params); // tileLayer for mapbox basemap el.mapboxTiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: '© OpenStreetMap contributors' }); el.map.addLayer(el.mapboxTiles); //TODO: Capa Nokia layer.tileLayer('http://{s}.maps.nlp.nokia.com/maptile/2.1/maptile/newest/satellite.day/{z}/{x}/{y}/256/jpg?lg=eng&token=A7tBPacePg9Mj_zghvKt9Q&app_id=KuYppsdXZznpffJsKT24', { // subdomains:"1234", attribution: '© Nokia Maps contributors, © YVAGA'}).addTo(map); // add mapbox and osm attribution var attr = "© Mapbox © OpenStreetMap" el.map.attributionControl.addAttribution(attr); // add Bing satelitte imagery layer el.satellite = new L.BingLayer('AkuX5_O7AVBpUN7ujcWGCf4uovayfogcNVYhWKjbz2Foggzu8cYBxk6e7wfQyBQW'); // Capas bases para leaflet el.baseLayers = {geometrico: el.mapboxTiles,foto: el.satellite}; // inits UI element for toggling base tile layers L.control.layers(el.baseLayers, {}, {position: 'bottomleft'}).addTo(el.map); // makes sure base layers stay below the cartodb data el.map.on('baselayerchange', function(e){e.layer.bringToBack();}) // se agregan las capas $(document).ajaxStart(function() { Pace.restart(); }); getCDBData(); $('#box').show(); } // Carga capa Base y ADICIONALES var getCDBData = function() { cartodb.createLayer(el.map, el.cdbURL, {cartodb_logo: false,legends: false,https: true}, function(layer) { //TODO: VERIFICAR QUE ESTE 'LOADER' FUNKE var loader = new cdb.geo.ui.TilesLoader({ template: function(){ return '
' } }); function addLoader(layer) { layer.bind('loading', function() { loader.show() }); layer.bind('load', function() { loader.hide(); }); } // se almacenan las capas en las variables correspondientes layer.getSubLayer(0).setCartoCSS(el.styles.regular); layer.getSubLayer(0).setSQL(el.params.morosidadtodos); el.taxLots = layer.getSubLayer(0); //CAPAS ADICIONALES el.capaMANZ = layer.createSubLayer({sql : el.params.manzanas, cartocss : el.styles.manzanas}); el.capaCALLES = layer.createSubLayer({sql : el.params.calles, cartocss : el.styles.calles}); el.capasinCCC = layer.createSubLayer({sql : el.params.lotesincc,cartocss : el.styles.lotesincc}); // Mueve la posición del tool-tip respecto a la ubicación del mouse 5px, para no interferir en el proceso de "click" var event = function (e) {$('#tool-tip').css({left: e.pageX + 5,top: e.pageY + 5});}; // hide and set interactivity on the DOB permit layers var num_sublayers = layer.getSubLayerCount(); // Se esconden todas las capas cargadas for (var i = 1; i < num_sublayers; i++) {layer.getSubLayer(i).hide();} //console.log(num_sublayers); // Se activa la interactividad y se especifica los campos activados para dicho fin layer.getSubLayer(0).setInteraction(true); layer.getSubLayer(0).setInteractivity('cartodb_id, ultimo_pago, trb_total_deuda, ccc, cc_man, cc_lote, layer, obs, inm_ficha'); //Feature on Mouse CLICK layer.on('featureClick', function(e, pos, latlng, data) { if (typeof impuesto !== "undefined") { showFeature(data.cartodb_id, data.ccc); }else{showFeature(data.cartodb_id, data.ccc);} }); //Feature Mouse OVER layer.getSubLayer(0).on('featureOver', function(e, pos, latlng, data) { ultimo_pago = data.ultimo_pago; cuenta = data.ccc; if (data.ultimo_pago == null){ultimo_pago = "N/A";}else{ultimo_pago = data.ultimo_pago;} if (data.inm_ficha == null){ficha = "SIN FICHA";}else{ficha = data.inm_ficha;} if (data.obs == null){observaciones = "SIN OBSERVACIONES";}else{observaciones = data.obs;} $('#map').css('cursor', 'pointer'); $('#tool-tip').show().html( // Contenido del Tool-Tip 'FICHA: ' + ficha + '
' + 'Manzana: ' + data.cc_man + '
' + 'Numero de Lote: ' + data.cc_lote + '
' + 'OBS.: ' + observaciones + '
' ); $(document).bind('mousemove', event); document.getElementById("ultimo").innerHTML = ultimo_pago; document.getElementById("ccc").innerHTML = cuenta; }); //Feature Mouse OUT layer.getSubLayer(0).on('featureOut', function(e,pos,latlng,data){ $('#tool-tip').hide(); $(document).unbind('mousemove', event, false); }); el.map.addLayer(layer, false); // make sure the base layer stays below the cdb layer el.mapboxTiles.bringToBack(); }).on('done', function() { }); // end cartodb.createLayer! }; var showFeature = function (cartodb_id, ccc) { $('#box2').show(); $('#tool-tip').hide(); $.ajax({ url: "api/callREAD.php", type: "POST", data: {cartodb_id: cartodb_id, type: 'lote', entidad: entidad}, dataType: 'json', success: function (geojson) { if (el.polygon) {el.map.removeLayer(el.polygon);} el.polygon = L.geoJson(geojson, { style: { color: "#000", fillColor: "#edd711", weight: 6, opacity: 0.8, fillOpacity: 0.2 } }); el.map.fitBounds(el.polygon.getBounds(), {maxZoom: 17}); el.polygon.addTo(el.map); //console.log(polygon.getBounds()); //DEFINICION DEL POLIGONO if (typeof impuesto !== "undefined") { //console.log(entidad, impuesto, estado); $.ajax ({ url: 'login/get_liquidacion.php', //Se parsea el numero de ccc a fin de obtener los datos del lote type: 'POST', data: {ccc: ccc, entidad: entidad, impuesto: impuesto, estado: estado},//parseo de ccc dataType: "json", //text or html or json or script success:function(data) { var largo = data.length; //SE LIMPIA EL DIV DE RESULTADOS $("#toggle_resumen").html("").append('Mostrar Todos'); $("#box").css({'opacity':'0.8'}); //TODO: aca podria haber sido overlowY en el "scroll" para contemplar solo el scroll vertical, preferi dejar ambos para que se "note que hay algo" //console.log(largo); if (largo > 0){ // SE CREA EL INFORME POR LOTE $("#resumen").html("").css({display: 'block', height: '90%', overflow: 'scroll'} ).append('' + 'Informe Catastral
' + 'Lote: '+ccc+' Ficha: '+data[0].inm_ficha+'
'+ //SE CREA LA TABLA PARA EL RESUMEN '| Ejercicio Fiscal | '+ 'Tributo | '+ 'Estado | '+ 'Importe | '+ 'Fecha de pago | '+ '
|---|---|---|---|---|
| '+item.ejer_fisca+' | ' + ''+item.trb_tributo+' | ' + ''+item.liq_estado+' | ' + ''+$.number(item.liq_importe_apagar,0,',','.')+' | ' + ''+estadopago+' | ' + '
Total '+tiporesumen+': '+ $.number(sum,0,',','.')+' Gs.
'); $('#toggle_resumen').append('Ocultar Resumen'+ '' ); }else{ $("#box2").css({display: 'block', height: 'auto'}); $("#resumen").html("").css({display: 'block', height: 'auto', overflow: ''}).append('No se encontraron Datos
'); } }, error:function(data){ $('#resumen').html("").append('
No se encontraron datos
') } });; }else { //alert("FAVOR ELIJA TIPO DE IMPUESTO!"); } } }); }; // change the cartoCSS of a layer var changeCartoCSS = function(layer, css) {layer.setCartoCSS(css);}; // change SQL query of a layer var changeSQL = function(layer, sql) {layer.setSQL(sql);}; // corresponding cartoCSS & SQL changes to tax lot layer buttons // legends are displayed or hidden as needed el.taxLotActions = { regular : function() { changeCartoCSS(el.taxLots, el.styles.regular); changeSQL(el.taxLots, el.params.morosidadtodos); renderLegend(null); return true; }, totales : function() { //TODO: MEJORAR LOGICA!! switch (estado){ case 'REG': colormaximo = '#BD0026'; color80 = '#F03B20'; color60 = '#FFCC00'; color40 = '#95ad42'; color20 = '#2a722f'; colorminimo = '#8e8e8e'; titulo = 'ADEUDADO'; label_leyenda = 'NO REGISTRADOS/NO LIQUIDADOS'; break; case 'PAG': colormaximo = '#2a722f'; color80 = '#95ad42'; color60 = '#FFCC00'; color40 = '#F03B20'; color20 = '#BD0026'; colorminimo= '#8e8e8e'; titulo = 'PAGADO'; label_leyenda = 'NO REGISTRADOS/NO PAGADOS'; break; } if (porciento80 === minimo) { lotetotales = '#e'+entidad+'_lotes_conccc{polygon-fill: #FFFFB2;polygon-opacity: 0.8;line-color: #FFF;line-width: 0.5;line-opacity: 1;}'+ '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' > ' +porciento80+ ' ] {polygon-fill: '+colormaximo+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' = ' +porciento80+ '] {polygon-fill: '+color80+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' < ' +minimo+ '] {polygon-fill: '+colorminimo+';}'+ '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' = null] {polygon-fill: '+colorminimo+';}' ; } else { lotetotales = '' + '#e'+entidad+'_lotes_conccc{polygon-fill: #FFFFB2;polygon-opacity: 0.8;line-color: #FFF;line-width: 0.5;line-opacity: 1;}'+ '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' > ' +porciento80+ ' ] {polygon-fill: '+colormaximo+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' <= ' +porciento80+ '] {polygon-fill: '+color80+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' <= ' +porciento60+ '] {polygon-fill: '+color60+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' <= ' +porciento40+'] {polygon-fill: '+color40+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' <= ' +porciento20+ '] {polygon-fill: '+color20+';}' + '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' < ' +minimo+ '] {polygon-fill: '+colorminimo+';}'+ '#e'+entidad+'_lotes_conccc [ '+tipodeuda+' = null] {polygon-fill: '+colorminimo+';}' ; } changeCartoCSS(el.taxLots, lotetotales); //el.params.morosidadtodos+ " where (trb_tributo ilike '"+impuesto+"' and "+tipodeuda+" > 0) or trb_tributo is null"; sqltotales = el.params.morosidadtodos + " where (trb_tributo ilike '"+impuesto+"' or trb_tributo is null) "; if (sqlnuevo === "") { changeSQL(el.taxLots, sqltotales); }else{ filtro = parseInt(array.rows[idactual][filtroactual]); //console.log (typeof filtro); sqlnuevo = sqlnuevo + " and "+tipodeuda+" " + op + " " + eval(filtro); //console.log(sqlnuevo); changeSQL(el.taxLots, sqlnuevo); changeCartoCSS(el.taxLots, lotetotales); sqlnuevo = ""; filtro = ""; } //TODO: MEJORAR LOGICA DE RENDER LEGENDA! if (porciento80 === minimo){ renderLegend( {title : "Total "+ titulo, items : [ {color : colormaximo, label : "> " +$.number(porciento80,0,',','.')+" Gs", filtroid : "porciento80", op : " > " }, {color : color80, label : "= "+$.number(porciento80,0,',','.')+" Gs", filtroid : "porciento80", op : " = " }, {color : "hsl(48, 100%, 50%)", label : label_leyenda, filtroid : "minimo", op : " < " } ] } ); } else{ renderLegend( {title : "Total "+ titulo, items : [ {color : colormaximo, label : "> " +$.number(porciento80,0,',','.')+" Gs", filtroid : "porciento80", op : " > " }, {color : color80, label : "<= "+$.number(porciento80,0,',','.')+" Gs", filtroid : "porciento80", op: " <= " }, {color : color60, label : "<= "+$.number(porciento60,0,',','.')+" Gs", filtroid : "porciento60", op: " <= "}, {color : color40, label : "<= "+$.number(porciento40,0,',','.')+" Gs", filtroid : "porciento40", op: " <= " }, {color : color20, label : "<= "+$.number(porciento20,0,',','.')+" Gs", filtroid : "porciento20", op: " <= " }, {color : "#787878", label : label_leyenda, filtroid : "minimo", op: "<"} ] } ); } $('#tool-tip').show(); $('#box').show(); //TODO: seguir //getCDBData().getSubLayer(0).hide(); return true; }, ultimopagado : function(){ switch (estado){ case 'REG': //TODO: REVISAR LOGICA colormaximo = '#2a722f'; color80 = '#95ad42'; color60 = '#FFCC00'; color40 = '#F03B20'; color20 = '#BD0026'; colorminimo= '#8e8e8e'; titulo = 'ADEUDADO'; break; case 'PAG': colormaximo = '#2a722f'; color80 = '#95ad42'; color60 = '#FFCC00'; color40 = '#F03B20'; color20 = '#BD0026'; colorminimo= '#8e8e8e'; titulo = 'PAGADO'; break; } //TODO: Dinamico lotesultimopagado = '#e'+entidad+'_lotes_conccc{polygon-fill: #006D2C;polygon-opacity: 0.8;line-color: #FFF;line-width: 0.5;line-opacity: 1;}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago = '+periodo+'] {polygon-fill: '+colormaximo+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago <= '+periodo1+'] {polygon-fill: '+color80+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago <= '+periodo2+'] {polygon-fill: '+color60+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago <= '+periodo3+'] {polygon-fill: '+color40+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago <= '+periodo4+'] {polygon-fill: '+color20+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago <= '+periodo5+'] {polygon-fill: '+color20+';}'+ '#e'+entidad+'_lotes_conccc [ ultimo_pago = null] {polygon-fill: '+colorminimo+';}'; changeCartoCSS(el.taxLots, lotesultimopagado); sqlultimopagado = el.params.morosidadtodos+ " where (trb_tributo ilike '"+impuesto+"' and "+tipodeuda+" > 0) or trb_tributo is null"; //console.log(sqlultimopagado); if (sqlnuevo === ""){changeSQL(el.taxLots, sqlultimopagado);} else { sqlnuevo = sqlnuevo + "and ultimo_pago " +op+ " " + eval(filtroactual); //console.log(sqlnuevo); changeSQL(el.taxLots, sqlnuevo); changeCartoCSS(el.taxLots, lotesultimopagado); sqlnuevo = ""; filtro = ""; } //TODO: Debe ser dinamico renderLegend({ title : "Ultimo "+ titulo, items : [ {color : colormaximo, label : "= " + periodo, filtroid : periodo, op : " = " }, // igual a ultimo anho {color : color80, label : " <= " + periodo1, filtroid : periodo1, op : " <= " }, {color : color60, label : "<= "+ periodo2, filtroid : periodo2, op : " <= " }, {color : color40, label : "<= "+ periodo3, filtroid : periodo3, op : " <= " }, {color : color20, label : "<= "+ periodo4, filtroid : periodo4, op : " <= " }, {color : color20, label : "<= "+ periodo5, filtroid : periodo5, op : " <= " }, {color : colorminimo, label : "SIN DEUDA O DEUDAS PRESCRIPTAS", filtroid : periodo6, op : "=<" } ] }); return true; } }; // add tax lot layer button event listeners var initButtons = function() { $('.button').click(function(e) { //e.preventDefault(); $(document).ajaxStart(function() { Pace.restart(); }); limpiar(); $('.button').removeClass('active'); $(this).addClass('active'); idactual = $(this).attr('name'); impuesto = array.rows[idactual].trb_tributo; estado = array.rows[idactual].estado; switch (estado) { case 'REG':tipodeuda = "trb_total_deuda";break; case 'PAG':tipodeuda = "trb_total_pago";break; } maximo = parseInt(array.rows[idactual].maximo); minimo = parseInt(array.rows[idactual].minimo); porciento20 = parseInt(array.rows[idactual].porciento20); porciento40 = parseInt(array.rows[idactual].porciento40); porciento60 = parseInt(array.rows[idactual].porciento60); porciento80 = parseInt(array.rows[idactual].porciento80); tipofiltro = $(this).attr('id'); app.map.el.taxLotActions[tipofiltro](); var sqlnuevo = ""; //console.log(tipofiltro); //console.log(idactual, impuesto, estado, maximo, minimo, porciento20, porciento40, porciento60, porciento80); //console.log(tipodeuda); //app.map.el.taxLots.show(); }); } //SUBFILTRO ONCLICK EN LA LEYENDA var initsubfiltro = function(e) { $(".subfiltro").click(function() { //TODO: AL ELGIR UN FILTRO, PONER EN GRIS LOS DEMAS //limpiarfiltros(); $(this).addClass("selected"); filtroactual = $(this).attr(toString("filtroid")); op = $(this).attr("op"); //console.log(filtroactual, op); //TODO: HASTA LLEGUE POR HOY 11/12/2017 12:26 sqlnuevo = el.params.morosidadtodos + " where trb_tributo ilike '"+impuesto+"'"; app.map.el.taxLotActions[tipofiltro](); }); } // Muestra las capas adicionales a medida que son marcados los checkboxes var initCheckboxes = function() { var checkboxDOB = $('input.dob:checkbox'), $manz = $('#manz'), $calle = $('#calle'), $sinccc = $('#sinccc'); $manz.change(function() {if ($manz.is(':checked')) {el.capaMANZ.show()} else {el.capaMANZ.hide()}}); $calle.change(function() {if ($calle.is(':checked')) {el.capaCALLES.show()}else {el.capaCALLES.hide()}}); $sinccc.change(function(){if ($sinccc.is(':checked')){el.capasinCCC.show()}else {el.capasinCCC.hide()}}); } // function to render choropleth legends var renderLegend = function(data) { if (data === null) { //el.legend.addClass('hidden'); el.legend.removeClass('hidden'); return; } var legendData = {title : data.title,items : data.items,}; el.legend.html(el.template(legendData)); if (el.legend.hasClass('hidden')) el.legend.removeClass('hidden'); initsubfiltro(); } // Botones de Zoom Custom var initZoomButtons = function(){ $('#zoom-in').on('click', function(){el.map.zoomIn();}); $('#zoom-out').on('click', function(){el.map.zoomOut();}); } // get it all going! var init = function() { //searchAddress(); initZoomButtons(); $(document).ajaxStart(function() { Pace.restart(); }); //EFECTO "CARGANDO..." initCheckboxes(); initButtons(); $(document).ajaxStart(function() { Pace.restart(); }); //EFECTO "CARGANDO..." initMap(); } // only return init() and the stuff in the el object return { init : init, el : el } })(window, document, jQuery, _); // call app.map.init() once the DOM is loaded window.addEventListener('DOMContentLoaded', function(){ app.conf.init(); app.map.init(); });