templates/analytic/explore.html.twig line 1

Open in your IDE?
  1. {% extends 'Layouts/layout.html.twig' %}
  2. {% block title %} Retabit Platform {% endblock %}
  3. {% block content %}
  4.     {% for message in app.flashes('notice') %}
  5.         <div class="flash-notice" id="flash_div">
  6.             <div class="text-end"><span class="material-symbols-outlined hover" onclick="removeDiv('flash_div')">close</span></div>
  7.             <div class="container">
  8.                 <p>{{ message | raw | trans}}</p>
  9.             </div>
  10.         </div>
  11.     {% endfor %}
  12.     <div class="modal fade" id="popUpIndicadores" tabindex="-1" >
  13.         <div class="modal-dialog modal-lg">
  14.             <div class="modal-content">
  15.                 <div class="modal-header">
  16.                     <h1 class="modal-title fs-5" id="exampleModalLabel">{% trans %}Selecciona los indicadores para descargar en un fichero Excel{% endtrans %}</h1>
  17.                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  18.                 </div>
  19.                 <div class="modal-body">
  20.                     <div class="row">
  21.                         <a id="selectAllBtn" class="px-5 mb-2" style="cursor: pointer; font-weight: 400; text-decoration:none;">{% trans %}Seleccionar Todos{% endtrans %}</a>
  22.                         <div class="col-12 px-5" id="project_actions_content">
  23.                             
  24.                         </div>
  25.                         <div class="text-center" id="popUpIndicadores_button">
  26.                             <button class="btn btn-primary" onclick="getExcel()">{% trans %}Descargar{% endtrans %} selección</button>
  27.                         </div>
  28.                     </div>
  29.                 </div>
  30.             </div>
  31.         </div>
  32.     </div>
  33.     <div class="container-fluid project_explore_container" id="container_in_content">
  34.         <div class="row justify-content-center">
  35.             <div id="infoview_content" class="col-12">
  36.                 {# {{dump(analytic_data)}} #}
  37.                 {% for item in analytic_data %}
  38.                 {% if item.slug == slug %}
  39.                     {#% dump(item) %#}
  40.                 <div class="row justify-content-center">
  41.                     <!-- Textai box -->
  42.                     <div class="col-12 p-3" id="header_content_info_top">
  43.                         
  44.                         <div class="d-flex justify-content-between align-items-center">
  45.                             <h2 class="d-inline-block" data-bs-toggle="collapse" href="#textai_box" role="button" aria-expanded="false" aria-controls="textai_box" onclick="expandIcon('analytics_title_arrow')" >
  46.                                 {% if app.request.locale == "ca" %}
  47.                                     {{item.name_ca}}
  48.                                 {% elseif app.request.locale == "en" %}
  49.                                     {{item.name_en}}
  50.                                 {% else %}
  51.                                     {{item.name}}
  52.                                 {% endif %}
  53.                                  
  54.                                 <span class="material-symbols-outlined hover" id="analytics_title_arrow">expand_more</span>
  55.                             </h2>
  56.                             <div class="d-flex">
  57.                                 <div class="d-flex align-items-center">                                    
  58.                                     <button class="btn btn-primary btn-sm" onclick="loadSelectorIndicators()">{% trans %}Descargar datos{% endtrans %}</button>
  59.                                 </div>
  60.                                 
  61.                             </div>
  62.                         </div>
  63.                         <div class="collapse" id="textai_box" style="max-width: 940px;">
  64.                             <p class="flex-fill mb-3" style="font-size: 14px;">{{item.textai}}</p>
  65.                         </div>
  66.                         
  67.                     </div>
  68.                     
  69.                     <div class="col-12 all_steps" id="analytic_step">
  70.                         <div class="row justify-content-center align-items-top">
  71.                             <div id="infoview" class="infoview_div col-12">
  72.                                 <div class="row align-items-center justify-content-center">
  73.                                     
  74.                                     <div class="col-12 collapse show" id="filter_div">
  75.                                         <div class="row align-items-center justify-content-center">
  76.                                             
  77.                                         </div>
  78.                                     </div>
  79.                                 </div>
  80.                                 <div class="row viewfindergroup" id="map_view" >
  81.                                     <div class="col-12">
  82.                                         
  83.                                         <div class="map__container" style="position:relative;">
  84.                                             <div id="map" class="map"></div>
  85.                                             <div class="legend"></div>
  86.                                             <div id="popup" class="popup d-none">
  87.                                                 <a href="#" id="popup-closer" class="popup__closer"></a>
  88.                                                 <div id="popup-content" class="popup__content"></div>
  89.                                             </div>
  90.                                             <button id="centerbutton" class="btn btn-light btn-sm pb-0" onclick="centerViewMap()">
  91.                                             <span class="material-symbols-outlined">fit_screen</span>
  92.                                             <span class="material-symbols-outlined d-none">collapse_content</span></button>
  93.                                             <button id="expand" class="btn btn-light btn-sm pb-0" onclick="infoviewToggle()">
  94.                                             <span class="material-symbols-outlined">expand_content</span></button>
  95.                                         </div>
  96.                                     </div>
  97.                                 </div>
  98.                                 <div class="row viewfindergroup" id="data_view">
  99.                                     <div class="col-12 pb-2" style="overflow-y: scroll; height: 80vh;">
  100.                                         <div id="wrapper"></div>
  101.                                     </div>
  102.                                 </div>
  103.                                 <div class="row viewfindergroup" id="card_view" >
  104.                                     <div class="col-12 pb-2" style="overflow-y: scroll; height: 80vh;">
  105.                                         <form class="row row-cols-lg-auto g-2 align-items-center mb-2 d-none">
  106.                                             <div class="col-12">
  107.                                                 <label class="visually-hidden" for="via">{% trans %}Tipo via{% endtrans %}</label>
  108.                                                 <select class="form-select" id="via">
  109.                                                     <option value="1">{% trans %}Calle{% endtrans %}</option>
  110.                                                     <option value="2">{% trans %}Avenida{% endtrans %}</option>
  111.                                                     <option value="3">{% trans %}Rambla{% endtrans %}</option>
  112.                                                 </select>
  113.                                             </div>
  114.                                             <div class="col-12">
  115.                                                 <label class="visually-hidden" for="street_name">{% trans %}Nombre calle{% endtrans %}</label>
  116.                                                 <div class="input-group">
  117.                                                     <input type="text" class="form-control" id="street" placeholder="Nombre de calle">
  118.                                                 </div>
  119.                                             </div>
  120.                                             <div class="col-12">
  121.                                                 <label class="visually-hidden" for="flat">{% trans %}Piso{% endtrans %}</label>
  122.                                                 <div class="input-group">
  123.                                                     <input type="text" class="form-control" id="flat" placeholder="Piso">
  124.                                                 </div>
  125.                                             </div>
  126.                                             <div class="col-12">
  127.                                                 <label class="visually-hidden" for="floor">{% trans %}Planta{% endtrans %}</label>
  128.                                                 <div class="input-group">
  129.                                                     <input type="text" class="form-control" id="floor" placeholder="Pta.">
  130.                                                 </div>
  131.                                             </div>
  132.                                             <div class="col-12">
  133.                                                 <button type="submit" class="btn btn-primary pb-0"><span class="material-symbols-outlined">search</span></button>
  134.                                             </div>
  135.                                         </form>
  136.                                         <div class="row" style=" padding: 20px; margin-bottom: 40px;    box-sizing: border-box;">
  137.                                             <div class="col-6 col-sm-3 overflow-hidden" id="img_fachada" style="background: #fbfbfb;  padding: 20px;"></div>
  138.                                             
  139.                                             <div class="col-6 col-sm-3 overflow-hidden me-4" id="img_catastro" style="background: #fbfbfb;  padding: 20px;"></div>
  140.                                             <div class="col-12 col-sm-5" id="txt_build"></div>
  141.                                             
  142.                                         </div>
  143.                                         
  144.                                         <div class="row g-3" id="build_indicators">
  145.                                         </div>
  146.                                     </div>
  147.                                 </div>
  148.                             </div>
  149.                             <div id="infoview2" class="infoview2_div collapse collapse-horizontal show">
  150.                                     
  151.                                 
  152.                                 <!-- Selected box -->
  153.                                 <div class="col-12 selected_box p-3 mb-3 sticky-top d-none">
  154.                                     <h4>{% trans %}Indicador seleccionado{% endtrans %}</h4>
  155.                                     <div id="selected_box_content" class="selected_box_item" title="Header" data-bs-toggle="popover_live_top" data-bs-trigger="hover focus" data-bs-title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?"></div>
  156.                                 </div>
  157.                                 <!-- Indicadores box -->
  158.                                 <div class="col-12 analytic_box box_blue_soft p-3 graphic_box stats_box mb-3">
  159.                                     <div class="d-flex justify-content-between">
  160.                                         <p class="fw-bold fs-5">{% trans %}Indicadores relacionados{% endtrans %}</p>
  161.                                         
  162.                                     </div>
  163.                                     <div class="" id="analytics_indicators">
  164.                                         {% set break = false %}
  165.                                         {% set array_used = [] %}
  166.                                         {% set category = '' %}
  167.                                         {#% dump("Item") %#}
  168.                                         {#% dump(item) %#}
  169.                                         {% for rel in item.relation %}
  170.                                             {% if break == false %}
  171.                                             {#% dump(rel) %#}
  172.                                             {% if app.request.locale == "ca" %}
  173.                                                 {% set title = rel.name_ca %}
  174.                                                 {% set description = rel.info_ca %}
  175.                                             {% elseif app.request.locale == "en" %}
  176.                                                 {% set title = rel.name_en %}
  177.                                                 {% set description = rel.info_en %}
  178.                                             {% else %}
  179.                                                 {% set title = rel.name %}
  180.                                                 {% set description = rel.info %}
  181.                                             {% endif %}
  182.                                             {% set array_used = array_used|merge([rel.kpi]) %}
  183.                                             
  184.                                             <div id="statline_id_{{rel.kpi}}" onclick="updateMapFromDiv({{rel.kpi}})" class="grayscale analytics_statsline_item" data-kpi="{{rel.kpi}}" data-slug="{{rel.slug}}" data-bs-toggle="popover_live_{{loop.index}}" data-bs-trigger="hover focus" data-bs-title="{{title|capitalize}}" data-bs-content="{{description}}" data-p="{{ rel.province }}" data-m="{{ rel.city }}" data-r="{{ rel.region }}" data-max="{{ rel.max_value }}" data-min="{{ rel.min_value }}">
  185.                                             
  186.                                                 <p class="mb-1 title" style="font-size: 14px; font-weight: 600;">{{title|capitalize}}</p>
  187.                                                 <div class="statsline mb-3" >
  188.                                                     {% set color = [] %}
  189.                                                     {% for rank in kpi_rank %}
  190.                                                         
  191.                                                         {% if rank.kpi_id == rel.kpi %}
  192.                                                             {% set color = color|merge([rank.bgcolor]) %}
  193.                                                         {% endif %}
  194.                                                     {% endfor %}
  195.                                                     {% set counter = color|length %}
  196.                                                     {% set partsize = 100/counter %}
  197.                                                     {% set stylestring = '' %}
  198.                                                     <div class="bk_line">
  199.                                                     {% for colorpart in color %}
  200.                                                         {% if loop.last %}
  201.                                                         {% set dato = 99.9-(partsize*(counter - 1)) %}
  202.                                                             <div class="analytic_color_bar" style="width:{{dato}}%; background-color: {{colorpart}};"></div>
  203.                                                         {% else %}
  204.                                                             <div class="analytic_color_bar" style="width:{{partsize|number_format(2, '.')}}%; background-color: {{colorpart}};"></div>        
  205.                                                         {% endif %}
  206.                                                         
  207.                                                     {% endfor %}
  208.                                                     
  209.                                                     </div>
  210.                                                     
  211.                                                     <span class="statsline_item statsline_{{loop.index}} item_tooltip" style="left: {{rel.theme_per}}%;margin-left: -6px;" data-text="{{rel.theme}}" data-kpi="{{rel.kpi}}" data-bs-custom-class="custom-tooltip" data-bs-placement="top"><i class="fa-solid triangle"></i></span>
  212.                                                     
  213.                                                 </div>
  214.                                                 <div class="statsline_range d-flex justify-content-between d-none">
  215.                                                     <span>{{rel.min_value}}</span>
  216.                                                     <span>{{rel.max_value}}</span>
  217.                                                 </div>
  218.                                                 {% if loop.index == 4 %}
  219.                                                 {% set break = true %}
  220.                                                 {% endif %}
  221.                                            
  222.                                             
  223.                                             </div>
  224.                                             <script>
  225.                                             $('[data-bs-toggle="popover_live_{{loop.index}}"]').mouseover(function(){
  226.                                                 $('[data-bs-toggle="popover_live_{{loop.index}}"]').popover();
  227.                                             })
  228.                                         </script>
  229.                                          {% endif %}
  230.                                         {% endfor %}
  231.                                         
  232.                                         </div>
  233.                                     </div>
  234.                                 <!-- Otros Indicadores box -->
  235.                                 <div class="col-12 analytic_box box_blue_soft p-3 graphic_box stats_box mb-3">
  236.                                     <div class="d-flex justify-content-between">
  237.                                         <p class="fw-bold fs-5" data-bs-toggle="collapse" data-bs-target="#analytics_indicators" aria-expanded="true" aria-controls="analytics_statsline" onclick="expandIcon('analytics_indicators_arrow')" role="button">{% trans %}Otros indicadores{% endtrans %}</p>
  238.                                         
  239.                                     </div>
  240.                                     <div class="" id="analytics_indicators_others">
  241.                                         {% set category = '' %}
  242.                                         
  243.                                         {#% dump("Analytic") %#}
  244.                                         
  245.                                         {% for rel in analytic_data_relation %}
  246.                                             {#% dump(rel) %#}
  247.                                             {% if rel.kpi not in array_used %}
  248.                                             {% if category != rel.category %}
  249.                                                 <p class="mt-2 fw-bold" style="font-size: 12px; font-weight: 700;"> 
  250.                                                      
  251.                                                     {% if app.request.locale == "ca" %}
  252.                                                         {{rel.category_ca}} 
  253.                                                     {% elseif app.request.locale == "en" %}
  254.                                                         {{rel.category_en}} 
  255.                                                     {% else %}
  256.                                                         {{rel.category}} 
  257.                                                     {% endif %}
  258.                                                 </p>
  259.                                                 {% set category = rel.category %}
  260.                                             {% endif %}
  261.                                             {% if app.request.locale == "ca" %}
  262.                                                 {% set title = rel.name_ca %}
  263.                                                 {% set description = rel.info_ca %}
  264.                                             {% elseif app.request.locale == "en" %}
  265.                                                 {% set title = rel.name_en %}
  266.                                                 {% set description = rel.info_en %}
  267.                                             {% else %}
  268.                                                 {% set title = rel.name %}
  269.                                                 {% set description = rel.info %}
  270.                                             {% endif %}
  271.                                             
  272.                                             <div id="statline_id_{{rel.kpi}}" onclick="updateMapFromDiv({{rel.kpi}})" class="grayscale analytics_statsline_item" data-kpi="{{rel.kpi}}" data-slug="{{rel.slug}}" data-bs-toggle="popover_live_{{loop.index}}" data-bs-trigger="hover focus" data-bs-title="{{title|capitalize}}" data-bs-content="{{description}}" data-p="{{ rel.province }}" data-m="{{ rel.city }}" data-r="{{ rel.region }}" data-max="{{ rel.max_value }}" data-min="{{ rel.min_value }}">
  273.                                             <script>
  274.                                             $('[data-bs-toggle="popover_live_{{loop.index}}"]').mouseover(function(){
  275.                                                 $('[data-bs-toggle="popover_live_{{loop.index}}"]').popover();
  276.                                             })
  277.                                             </script>
  278.                                             
  279.                                                 <p class="mb-1 title" style="font-size: 14px; font-weight: 600;">{{title|capitalize}}</p>
  280.                                                 <div class="statsline mb-3" >
  281.                                                     {% set color = [] %}
  282.                                                     {% for rank in kpi_rank %}
  283.                                                         
  284.                                                         {% if rank.kpi_id == rel.kpi %}
  285.                                                             {% set color = color|merge([rank.bgcolor]) %}
  286.                                                         {% endif %}
  287.                                                     {% endfor %}
  288.                                                     {% set counter = color|length %}
  289.                                                     {% set partsize = 100/counter %}
  290.                                                     {% set stylestring = '' %}
  291.                                                     <div class="bk_line">
  292.                                                     {% for colorpart in color %}
  293.                                                         {% if loop.last %}
  294.                                                         {% set dato = 99.9-(partsize*(counter - 1)) %}
  295.                                                             <div class="analytic_color_bar" style="width:{{dato}}%; background-color: {{colorpart}};"></div>
  296.                                                         {% else %}
  297.                                                             <div class="analytic_color_bar" style="width:{{partsize|number_format(2, '.')}}%; background-color: {{colorpart}};"></div>        
  298.                                                         {% endif %}
  299.                                                         
  300.                                                     {% endfor %}
  301.                                                     
  302.                                                     </div>
  303.                                                     
  304.                                                     <span class="statsline_item statsline_{{loop.index}} item_tooltip" style="left: {{rel.theme_per}}%; margin-left: -6px;" data-text="{{rel.theme}}" data-kpi="{{rel.kpi}}" data-bs-custom-class="custom-tooltip" data-bs-placement="top"><i class="fa-solid triangle"></i></span>
  305.                                                     
  306.                                                 </div>
  307.                                                 <div class="statsline_range d-flex justify-content-between d-none">
  308.                                                     <span>{{rel.min_value}}</span>
  309.                                                     <span>{{rel.max_value}}</span>
  310.                                                 </div>
  311.                                             
  312.                                             </div>
  313.                                             
  314.                                             {% endif %}
  315.                                         {% endfor %} 
  316.                                         </div>
  317.                                     </div>
  318.                                     
  319.                                 </div>
  320.                                         {# <div class="" id="analytics_barplot_container">
  321.                                             <div id="analytics_barplot">
  322.                                                 
  323.                                                 <div class="hover_window">
  324.                                                     <h5>Uso del edificio</h5>
  325.                                                     <div class="mb-3" id="statUseBox" style="position: relative;" onclick="updateMapFromStat(105)"></div>
  326.                                                 </div>
  327.                                                 
  328.                                                 <div class="hover_window">
  329.                                                     <h5>Año de construcción</h5>
  330.                                                     <div class="mb-3" id="statYearBox" style="position: relative;" onclick="updateMapFromStat(100)"></div>
  331.                                                 </div>
  332.                                                 
  333.                                                 <div class="hover_window">
  334.                                                     <h5>Área</h5>
  335.                                                     <div class="mb-3" id="statAreaBox" style="position: relative;" onclick="updateMapFromStat(101)"></div>
  336.                                                 </div>
  337.                                                 
  338.                                                 <div class="hover_window">
  339.                                                     <h5>Porcentaje de ocupación</h5>
  340.                                                     <div class="mb-3" id="statOccupationBox" style="position: relative;" onclick="updateMapFromStat(104)"></div>
  341.                                                 </div>
  342.                                                 
  343.                                             </div>
  344.                                         </div> #}
  345.                                 
  346.                                 
  347.                             </div>
  348.                         </div>
  349.                     </div>
  350.                 {% endif %}
  351.                 {% endfor %}
  352.                 </div>
  353.                 
  354.             </div>
  355.             
  356.             
  357.         </div>
  358.     </div>
  359. <style>
  360. td.gridjs-td{
  361.     //padding: 2px 24px !important;
  362. }
  363. </style>
  364. {% endblock %}
  365. {% block javascripts %}
  366. <script src="{{ asset('build/js/calls.js') }}"></script>
  367. <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
  368. <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
  369. <script src="https://cdnjs.cloudflare.com/ajax/libs/gridjs/6.0.6/gridjs.production.min.js" integrity="sha512-wpiJjuL800CTEBA0QFs+RFw0tFtpXnQGea1p9S16WcYNXC1F3U0l1L7FQrDC3ihkYRtOj4Td7lKR3mYKxrwMMA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  370. <link rel="stylesheet" type="text/css" href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" />
  371. <script type="text/javascript">
  372.     const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
  373.     const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  374.     var Routes = Routing; // loaded from router.min.js
  375.     // because ES5 doesn't support require syntax,
  376.     // we use jquery getJSON function in order to set
  377.     // routing data to our Routing object
  378.     $.getJSON("{{ asset('build/js/fos_js_routes.json') }}", function (routes) {
  379.         Routes.setRoutingData(routes);
  380.     });
  381.     {# console.log(Routes); #}
  382. </script>
  383. <script type="text/javascript">
  384.     //let explore_baseUrl = '{{ base_url }}';
  385.     $(document).ready(function(){
  386.         $('.viewfindergroup').hide();
  387.         $('#map_view').show();        
  388.         $('.build_bar').css('width','100%');
  389.         $('.people_bar').css('width','100%');
  390.         /*setTimeout(()=>{
  391.             $('#info_div').collapse('hide');
  392.         },10000);*/
  393.         let arrayData = document.querySelectorAll('.analytics_statsline_item');
  394.         let arraySlugs = [];
  395.         for(let i=0; arrayData.length > i; i++){
  396.             arraySlugs.push(arrayData[i].getAttribute('data-slug'));
  397.         }
  398.         // console.log(arraySlugs);
  399.         buttonsToHeaderBar();
  400.         $('#left_bar_button_map').addClass('active');
  401.     });
  402.     document.getElementById("selectAllBtn").addEventListener("click", function() {
  403.         let checkboxes = document.querySelectorAll(".form-check-input");
  404.         let allChecked = Array.from(checkboxes).every(checkbox => checkbox.checked);
  405.         checkboxes.forEach(checkbox => {
  406.             checkbox.checked = !allChecked; // Alterna selección
  407.         });
  408.         this.textContent = allChecked ? "Seleccionar Todos" : "Deseleccionar Todos"; 
  409.     });
  410.     function buttonsToHeaderBar(){
  411.         // <span class="material-symbols-outlined">bar_chart_4_bars</span>
  412.         document.getElementById('new_header_map').innerHTML = '<div id="left_bar_button_map" class="left_bar_button text-center d-inline-block" onclick="viewFinder(\'map\')"><span class="material-symbols-outlined">map</span><br>{{"Mapa" |trans}}</div>';
  413.         document.getElementById('new_header_table').innerHTML = '<div id="left_bar_button_data" class="left_bar_button text-center d-inline-block" onclick="viewFinder(\'data\')"><span class="material-symbols-outlined">table</span><br>{{"Tabla" |trans}}</div>';
  414.         document.getElementById('new_header_card').innerHTML = '<div id="left_bar_button_card" class="left_bar_button text-center d-inline-block" onclick="viewFinder(\'card\')"><span class="material-symbols-outlined">grid_view</span><br>{{"Ficha" |trans}}</div>';
  415.         
  416.     }
  417.     $('.item_tooltip').on('mouseover',function (){
  418.         
  419.         let name = this.getAttribute('data-text');
  420.         let kpi = this.getAttribute('data-kpi');
  421.         // console.log(name,kpi);
  422.         $('.item_tooltip[data-kpi='+kpi+']').tooltip({title: name, delay: {show: 100, hide: 100}}); 
  423.     })
  424.     const { Grid, html } = gridjs;
  425.     var rPlatform = map;
  426.     var caller = call;
  427.     let layers = {{ layers |raw}};
  428.     let configLayers = {{ configLayers|raw }};
  429.     let explore_baseUrl = '{{ base_url }}';
  430.     caller.vars.explore_baseUrl = '{{ base_url }}';
  431.     
  432.     let explore_mun = '{{ mun }}';
  433.     let explore_kpi = 3;
  434.     let explore_slug = '';
  435.     let explore_colors = {{ kpi_colors|raw }};
  436.     let explore_insight = [];
  437.     let explore_extrakpi = [];
  438.     let explore_layer_data = [];
  439.     let explore_url = window.location.href;
  440.     let explore_filter_url = '';
  441.     let filtered_data_array = {{ filtered_data|raw }};
  442.     let kpi_list = {{ kpi_list|raw }};
  443.     let kpi_list_complete = document.querySelectorAll('#kpi_list_data li');
  444.     for(i=0; kpi_list_complete.length > i; i++){
  445.         let name = kpi_list_complete[i].innerText;
  446.         let kpi = kpi_list_complete[i].getAttribute('data-kpi');
  447.         let slug = kpi_list_complete[i].getAttribute('data-slug');
  448.         kpi_list.push({'name':name,'kpi':kpi,'slug':slug});
  449.     }
  450.     // use stats data and print graphic
  451.     let useStat = {{ useStatData|raw }};
  452.     let useStatData = analyticOrganizeData(useStat);
  453.     var useStatTotalData = analyticOrganizeTotalData(useStat);
  454.     {# barplotDoubleDouble100('statUseBox',useStatData[0],useStatTotalData[1],useStatData[2], 'analytics_barplot_container',useStatTotalData[0]); #}
  455.     
  456.     // year stats data and print graphic
  457.     let yearStat = {{ yearStatData|raw }};
  458.     let yearStatData = analyticOrganizeData(yearStat);
  459.     var yearStatTotalData = analyticOrganizeTotalData(yearStat);
  460.     {# barplotDoubleDouble100('statYearBox',yearStatData[0],yearStatTotalData[1],yearStatData[2], 'analytics_barplot_container',yearStatTotalData[0]); #}
  461.     // area stats data and print graphic
  462.     let areaStat = {{ areaStatData|raw }};
  463.     let areaStatData = analyticOrganizeData(areaStat);
  464.     var areaStatTotalData = analyticOrganizeTotalData(areaStat);
  465.     {# barplotDoubleDouble100('statAreaBox',areaStatData[0],areaStatTotalData[1],areaStatData[2], 'analytics_barplot_container',areaStatTotalData[0]); #}
  466.     // occupation stats data and print graphic
  467.     let occupationStat = {{ occupationStatData|raw }};
  468.     let occupationStatData = analyticOrganizeData(occupationStat);
  469.     var occupationStatTotalData = analyticOrganizeTotalData(occupationStat);
  470.     {# barplotDoubleDouble100('statOccupationBox',occupationStatData[0],occupationStatTotalData[1],occupationStatData[2], 'analytics_barplot_container',occupationStatTotalData[0]); #}
  471.     let explore_mun_name = '{{ municipioname.adminunitname|capitalize }}';
  472.     let allgeodataUrl = explore_baseUrl + "/get-allgeodata?mun=" + explore_mun ;
  473.     let munPolygon = '{{ municipioname.geom }}';
  474.     let initGeo = '{{ municipioname.envelope }}';
  475.     
  476.     let queryString = window.location.search;
  477.     let urlParams = new URLSearchParams(queryString);
  478.     let filterStart = urlParams.get('fs');
  479.     let filterEnd = urlParams.get('fe');
  480.     window.appLocale = '{{ app.request.locale|e('js') }}';
  481.     if(filterStart == null){
  482.         filterStart = 0;
  483.     }
  484.     if(filterEnd == null){
  485.         filterEnd = 0;
  486.     }
  487.     rPlatform.setInpireidList(filtered_data_array);
  488.     rPlatform.setMun(explore_mun);
  489.     rPlatform.setBaseUrl(explore_baseUrl);
  490.     rPlatform.setLayers(layers);
  491.     rPlatform.setColorsStyle(explore_colors);
  492.     rPlatform.setLayerData(explore_layer_data);
  493.    
  494.     // ----------------------- Map ------------------------ //
  495.     async function init() { // Cargar mapa de inicio
  496.         let queryString = window.location.search;
  497.         let urlParams = new URLSearchParams(queryString);
  498.         // Crear indArr con el primer kpi del listado
  499.         let alldivi = document.getElementsByClassName('grayscale');
  500.         let kpi_init = alldivi[0].getAttribute('data-kpi');
  501.         let slug_init = alldivi[0].getAttribute('data-slug');
  502.         explore_kpi = kpi_init;
  503.         explore_slug = slug_init;
  504.         alldivi[0].classList.add('kpi_selected');
  505.         alldivi[0].classList.add('disabled');
  506.         // Colocar primer alldivi como seleccionado
  507.         selectedIndicator(alldivi[0]);
  508.         // Recibir parametros ind desde url
  509.         let indArr = [parseInt(kpi_init)];
  510.         let frArr = [filterStart, filterEnd];
  511.         await rPlatform.setiActive(indArr);
  512.         await rPlatform.initMapExplore(layers, explore_baseUrl, initGeo, explore_mun, frArr, indArr);
  513.         await rPlatform.getSimpleStyleDistrict();
  514.         await rPlatform.getSimpleStyleSection();
  515.         rPlatform.updateMap();
  516.     }
  517.     init();
  518.     
  519.     
  520.     // ----------------------- Table Map ------------------------ //
  521.     function tableData(){        
  522.         let wrapper = document.getElementById("wrapper");
  523.         wrapper.innerHTML = '';
  524.         let tabla = null; // Variable global para almacenar la instancia de la tabla
  525.         function renderizarTabla(data) {
  526.             // Eliminar la tabla anterior si existe
  527.             if (tabla !== null) {
  528.                 tabla.destroy();
  529.             }
  530.             // Crear una nueva instancia de Grid.js con los nuevos datos y renderizarla
  531.             tabla = new gridjs.Grid({
  532.                 columns: [{
  533.                     id: 'year',
  534.                     name: "{{'Año' |trans }}"
  535.                 },
  536.                 {
  537.                     id: 'currentuse',
  538.                     name: "{{'Uso' |trans }}",
  539.                     formatter: (cell, row) => {
  540.                         if (cell == '1_residential' ){
  541.                             return gridjs.html(`<span style="color: blue; cursor:pointer;" onclick=" viewFinder(\'card\'); viewCard(\'${row.cells[22].data}\')">Residential</span>`)  
  542.                         }else if(cell == '2_agriculture'){
  543.                             return gridjs.html(`<span style="color: green; cursor:pointer;" onclick="viewFinder(\'card\');  viewCard(\'${row.cells[22].data}\')">Agriculture</span>`)
  544.                         }else if(cell == '3_industrial'){
  545.                             return gridjs.html(`<span style="color: gray; cursor:pointer;" onclick="viewFinder(\'card\');  viewCard(\'${row.cells[22].data}\')">Industrial</span>`)
  546.                         }else if(cell == '4_3_publicServices'){
  547.                             return gridjs.html(`<span style="color: orange; cursor:pointer;" onclick="viewFinder(\'card\');  viewCard(\'${row.cells[22].data}\')">Public services</span>`)
  548.                         }else{
  549.                             return gridjs.html(`<span style="color: black">${cell}</span>`)
  550.                         }
  551.                     }
  552.                 },
  553.                 {
  554.                     id: 'grossfloorarea',
  555.                     name: "{{'Grossfloorarea' |trans }}",
  556.                     formatter: (cell) => html(`${cell} m<sup>2</sup>`)
  557.                 },
  558.                 {
  559.                     id: 'habitantes',
  560.                     name: "{{'Habitantes' |trans }}",
  561.                     formatter: (cell) => {
  562.                         return gridjs.html(`<div class="mt-2"><i class="fa-solid fa-users"></i> ${cell}</div>`)
  563.                     }
  564.                 },
  565.                 {
  566.                     id: 'numberofdwellings',
  567.                     name: "{{'Viviendas' |trans }}",
  568.                     formatter: (cell) => html(`${cell}`)
  569.                 },
  570.                 {
  571.                     id: 'kpi_1_energy_renovated_residential_buildings',
  572.                     name: "{{'Energy renovated residential buildings' |trans }}",
  573.                     formatter: (cell) => html(`${cell}`)
  574.                 },
  575.                 {
  576.                     id: 'kpi_2_final_energy_consumption',
  577.                     name: "{{'Final energy consumption' |trans }}",
  578.                     formatter: (cell) => html(`${cell}`)
  579.                 },
  580.                 {
  581.                     id: 'kpi_3_renewable_energy_consumption',
  582.                     name: "{{'Renewable energy consumption' |trans }}",
  583.                     formatter: (cell) => html(`${cell}`)
  584.                 },
  585.                 {
  586.                     id: 'kpi_4_pv_potential_generation',
  587.                     name: "{{'Pv potential generation' |trans }}",
  588.                     formatter: (cell) => html(`${cell}`)
  589.                 },
  590.                 {
  591.                     id: 'kpi_7_heating_energy_consumption',
  592.                     name: "{{'Heating energy consumption' |trans }}",
  593.                     formatter: (cell) => html(`${cell}`)
  594.                 },
  595.                 {
  596.                     id: 'kpi_8_ghg_emissions',
  597.                     name: "{{'GhG emissions' |trans }}",
  598.                     formatter: (cell) => html(`${cell}`)
  599.                 },
  600.                 {
  601.                     id: 'kpi_19_population_income_below_60_average',
  602.                     name: "{{'Population income below 60 average' |trans }}",
  603.                     formatter: (cell) => html(`${cell}`)
  604.                 },
  605.                 {
  606.                     id: 'kpi_20_median_household_income',
  607.                     name: "{{'Median household income' |trans }}",
  608.                     formatter: (cell) => html(`${cell}`)
  609.                 },
  610.                 {
  611.                     id: 'kpi_21_average_price_renting_compared_family_income',
  612.                     name: "{{'Average price renting compared family income' |trans }}",
  613.                     formatter: (cell) => html(`${cell}`)
  614.                 },
  615.                 {
  616.                     id: 'kpi_22_house_price',
  617.                     name: "{{'House price' |trans }}",
  618.                     formatter: (cell) => html(`${cell}`)
  619.                 },
  620.                 {
  621.                     id: 'kpi_27_urban_equipment_at_15_min',
  622.                     name: "{{'Urban equipment at 15 min' |trans }}",
  623.                     formatter: (cell) => html(`${cell}`)
  624.                 },
  625.                 {
  626.                     id: 'kpi_28_accessibility_to_bike_lane',
  627.                     name: "{{'Accessibility to bike lane' |trans }}",
  628.                     formatter: (cell) => html(`${cell}`)
  629.                 },{
  630.                     id: 'kpi_30_green_area_surfaces',
  631.                     name: "{{'Green area surfaces' |trans }}",
  632.                     formatter: (cell) => html(`${cell}`)
  633.                 },
  634.                 {
  635.                     id: 'kpi_31_vulnerability_heatwaves_temperature_rise',
  636.                     name: "{{'Vulnerability heatwaves temperature rise' |trans }}",
  637.                     formatter: (cell) => html(`${cell}`)
  638.                 },
  639.                 {
  640.                     id: 'kpi_36_charging_outlets',
  641.                     name: "{{'Charging outlets' |trans }}",
  642.                     formatter: (cell) => html(`${cell}`)
  643.                 },
  644.                 {
  645.                     id: 'kpi_6_1_energy_efficient_and_energy_recovering_homes',
  646.                     name: "{{'Energy efficient and energy recovering_homes' |trans }}",
  647.                     formatter: (cell) => html(`${cell}`)
  648.                 },
  649.                 {
  650.                     id: 'kpi_6_2_energy_efficient_and_energy_recovering_homes',
  651.                     name: "{{'Energy efficient and energy recovering homes' |trans }}",
  652.                     formatter: (cell) => html(`${cell}`)
  653.                 },
  654.                 {
  655.                     id: 'inspireid',
  656.                     name: "{{'inspireid' |trans }}",
  657.                     formatter: (cell) => html(`${cell}`)
  658.                 }],
  659.                 data: data,
  660.                 pagination: {
  661.                     limit: 50,
  662.                     summary: true,
  663.                 },
  664.                 resizable: true,
  665.                 search: false,
  666.                 sort: true,
  667.                 fixedHeader: true,
  668.                 height: $("#infoview").height(),
  669.             }).render(wrapper);
  670.         }
  671.         // Llamar a la función obtenerDatos() para obtener los datos inicialmente y renderizar la tabla
  672.         caller.obtenerDatos(explore_kpi, explore_mun, explore_slug)
  673.             .then((data) => {
  674.                 console.log(data);
  675.                 renderizarTabla(data);
  676.             })
  677.             .then(()=>{
  678.                 setTimeout(()=>{
  679.                     updateTable(explore_slug);
  680.                 },2000)
  681.                 
  682.             });
  683.     }
  684.     //------------------------ Descargar Datos ------------------- //
  685.     function loadSelectorIndicators()
  686.     {
  687.         $("#project_actions_content").html('');
  688.         {% for item in analytic_data %}
  689.             {% if item.slug == slug %}
  690.                 {% set break = false %}
  691.                 {% set array_used = [] %}
  692.                 {% for rel in item.relation %}
  693.                     {% if break == false %}
  694.                         {% set array_used = array_used|merge([rel.kpi]) %}
  695.                         var check = "<div class='form-check'> <input class='form-check-input' type='checkbox' value='{{rel.slug}}' id='flexCheckDefault' data-name='{{rel.name}}'> <label class='form-check-label' for='flexCheckDefault'> {{rel.name}} </label></div>";
  696.                         $("#project_actions_content").append(check);
  697.                         
  698.                         console.log('{{rel.name}}');
  699.                     {% endif %}
  700.                 {% endfor %}
  701.                 {% for rel in analytic_data_relation %}
  702.                     {% if rel.kpi not in array_used %}
  703.                         var check = "<div class='form-check'> <input class='form-check-input' type='checkbox' value='{{rel.slug}}' id='flexCheckDefault' data-name='{{rel.name}}'> <label class='form-check-label' for='flexCheckDefault'> {{rel.name}} </label></div>";
  704.                         $("#project_actions_content").append(check);
  705.                         console.log('{{rel.name}}');
  706.                     {% endif %} 
  707.                 {% endfor %} 
  708.             {% endif %} 
  709.         {% endfor %} 
  710.         $("#popUpIndicadores").modal('show');
  711.     }
  712.     function getExcel() {
  713.         const selectedNames = {};
  714.         const checkboxes = document.querySelectorAll('.form-check-input:checked');
  715.         const selectedValues = Array.from(checkboxes).map(checkbox => checkbox.value);
  716.         /*const selectedNames = Array.from(checkboxes).map(checkbox => ({
  717.             [checkbox.value]: checkbox.dataset.name
  718.         }));*/
  719.         checkboxes.forEach((checkbox) => selectedNames[checkbox.value] = checkbox.dataset.name);
  720.         console.log(selectedValues);
  721.         console.log(selectedNames);        
  722.         caller.getExcel(explore_kpi, explore_mun, explore_slug, selectedValues, selectedNames)
  723.             .then((data) => {
  724.                 console.log(data); 
  725.                 var bURL = "{{app.request.getBasePath() }}";
  726.                 var href = bURL + "/documents/" + data;            
  727.                 location = href;                             
  728.             }).then(
  729.                 //si hay que eliminar el archivo generado ---> here
  730.             );
  731.             
  732.     }
  733.     
  734.     // --------------------- Card ------------------------------- //
  735.     async function viewCard(id){
  736.         $("#infoview2").hide();
  737.         $('.viewfindergroup').hide();
  738.         $('#card_view').show();
  739.         let fachada = document.getElementById('img_fachada');
  740.         let catastro = document.getElementById('img_catastro');
  741.         let txt_build = document.getElementById('txt_build');
  742.         let build_indicators = document.getElementById('build_indicators');
  743.         let size = fachada.offsetWidth;
  744.         fachada.style.height = size + 'px';
  745.         catastro.style.height = size + 'px';
  746.         var imagenAlternativa = explore_baseUrl + '/img/img_bk_building.jpg';
  747.         let img_fachada = '<img class="img-fluid" src="https://ovc.catastro.meh.es/OVCServWeb/OVCWcfLibres/OVCFotoFachada.svc/RecuperarFotoFachadaGet?ReferenciaCatastral=' + id + '" width="auto" height="'+size+'px" onerror="this.onerror=null; this.src=\''+ imagenAlternativa + '\';" />';
  748.         let img_catastro = '<img class="img-fluid" src="https://www1.sedecatastro.gob.es/Cartografia/GeneraGraficoParcela.aspx?del=8&mun=279&refcat=' + id + '&AnchoPixels=500&AltoPixels=500" width="auto" height="'+size+'px" onerror="this.onerror=null; this.src=\''+ imagenAlternativa + '\';" />';
  749.         document.getElementById('img_fachada').innerHTML = img_fachada;
  750.         document.getElementById('img_catastro').innerHTML = img_catastro;
  751.         let buildData = await caller.getBuildData(id);
  752.         // console.log(buildData);
  753.         let UseValue = '';
  754.         let valuesContent = '';
  755.         if (buildData.use_numeric == 0) {
  756.             UseValue = 'SFH';
  757.         } else {
  758.             UseValue = 'MFH';
  759.         }
  760.                 
  761.         valuesContent += '<p style="font-size: 14px; "><b>{{"Referencia catastral" |trans}}:</b> <span style="color:#222222; padding-left: 15px;">' + buildData.inspireid + '</span></p>';
  762.         valuesContent += '<p style="font-size: 14px; "><b>{{"Año de construcción" |trans}}:</b> <span style="color:#222222; padding-left: 15px;">' + buildData.year + '</span></p>';
  763.         valuesContent += '<p style="font-size: 14px; "><b>{{"Uso" |trans}}:</b> <span style="color:#222222; padding-left: 15px;">' + UseValue + '</span></p>';
  764.         valuesContent += '<p style="font-size: 14px; "><b>{{"Plantas" |trans}}:</b> <span style="color:#222222; padding-left: 15px;">' + buildData.num_floors + '</span></p>';
  765.         valuesContent += '<p style="font-size: 14px; "><b>{{"Superficie" |trans}}:</b> <span style="color:#222222; padding-left: 15px;">' + buildData.grossfloorarea + '</span></p>';
  766.         document.getElementById('txt_build').innerHTML = valuesContent;
  767.         // console.log(kpi_list);      
  768.         build_indicators.innerHTML = '';
  769.         for(let i=0; kpi_list.length > i; i++){
  770.             // console.log(kpi_list[i].slug);
  771.             let buildDataFiltered = Object.keys(buildData).filter((key) => key === kpi_list[i].slug).map((key) => buildData[key]);
  772.             //console.log(kpi_list[i]);
  773.             if(kpi_list[i].name != 'Todos'){
  774.                 var styleBox = "";
  775.                 var grafica = "";
  776.                 if (kpi_list[i].name == "año de construcción" || kpi_list[i].name == "área" || kpi_list[i].name == "uso") 
  777.                     styleBox = "bk_box--color";
  778.                 
  779.                
  780.                 if ( $("#statline_id_"+kpi_list[i].id) ){
  781.                      
  782.                     let contenido = $("#statline_id_"+kpi_list[i].id).html();  // Obtiene el HTML
  783.                     let tempDiv = $("<div>").html(contenido);   // Lo convierte en un objeto jQuery
  784.                     tempDiv.find("p").hide();
  785.                     tempDiv.find(".statsline_range").removeClass("d-none");
  786.                     tempDiv.find(".statsline_range").css({
  787.                         "position": "relative",
  788.                         "font-size": "12px",
  789.                         "color": "#7a7a7a",
  790.                         //"top": "-10px"
  791.                     });
  792.                     let maxValue = $("#statline_id_"+kpi_list[i].id).data("max");
  793.                     let minValue = $("#statline_id_"+kpi_list[i].id).data("min");
  794.                     let per = Math.ceil(((buildDataFiltered[0]) - minValue)/(maxValue - minValue) * 100);
  795.                     
  796.                     tempDiv.find(".statsline_item").css("left", per+"%");                    
  797.                     grafica = tempDiv.html();
  798.                 }  else grafica = "";
  799.                 let dataNumber = "";
  800.                 if (buildDataFiltered[0] == null){
  801.                     if (window.appLocale == 'ca')   dataNumber = "No hi han dades";
  802.                     else if (window.appLocale == 'en')  dataNumber = "No data";
  803.                     else dataNumber = "No hay datos"; 
  804.                 }   
  805.                 else if (kpi_list[i].name != "año de construcción"){
  806.                     numero = Number.parseFloat(buildDataFiltered[0]);
  807.                     dataNumber = numero.toLocaleString("es-ES");
  808.                 }else  dataNumber =  buildDataFiltered[0];                           
  809.                 if (kpi_list[i].name == "uso" && buildDataFiltered[0] == 0){
  810.                     if (window.appLocale == 'ca')   dataNumber = "Unifamiliar";
  811.                     else if (window.appLocale == 'en')  dataNumber = "Unifamiliar";
  812.                     else dataNumber = "Unifamiliar";
  813.                     
  814.                 }         
  815.                 else if (kpi_list[i].name == "uso" && buildDataFiltered[0] == 1){
  816.                     if (window.appLocale == 'ca')   dataNumber = "Plurifamiliar";
  817.                     else if (window.appLocale == 'en')  dataNumber = "Plurifamiliar";
  818.                     else dataNumber = "Plurifamiliar";
  819.                 }     
  820.                 if (window.appLocale == 'ca')
  821.                 {
  822.                     var kpiName = kpi_list[i].name_ca;
  823.                     var KpiInfo = kpi_list[i].info_ca;
  824.                 }else if (window.appLocale == 'en') {
  825.                     var kpiName = kpi_list[i].name_en;
  826.                     var KpiInfo = kpi_list[i].info_en;
  827.                 }else{ 
  828.                     var kpiName = kpi_list[i].name;
  829.                     var KpiInfo = kpi_list[i].info; 
  830.                 }
  831.                 build_indicators.innerHTML += '<div class="col-6 col-sm-3 d-flex"><div class="bk_box '+styleBox+' p-3 w-100 d-flex flex-column"><div class="mb-2 d-flex justify-content-between align-items-baseline" style="height: 58px;"><p class="fw-bold mb-2" style="font-size: 14px; line-height: 18px; max-width: 70%;">'+ capitalizeFirstLetter(kpiName) +'</p><p style="font-weight:600; "><span style="font-size:16px; color:#6E93F6;"> '+ dataNumber +'</span></p></div><div class="d-flex justify-content-between mb-2"><div style="width: 100%;">'+grafica+'</div></div><p class=" mb-2 boxed_limited" onclick="activeClass(this)" >'+ KpiInfo +'</p></div></div>';
  832.                 
  833.             }
  834.             
  835.         }
  836.     }
  837.     function formatearNumero(numero) {
  838.         //return numero;
  839.         
  840.         if(typeof numero === 'number'){
  841.             numero = numero.toString();
  842.             numero = Number.parseFloat(numero);
  843.             return numero.toLocaleString("es-ES");
  844.             // return numero.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
  845.         }else if(numero === null){
  846.             return numero;
  847.         }else{
  848.             // console.log(numero);
  849.             numero = Number.parseFloat(numero);
  850.             return numero.toLocaleString("es-ES");
  851.             
  852.         }
  853.     }
  854.     function hideCardOnData(){
  855.         document.getElementById('info_window').innerHTML = '';
  856.     }
  857.     // --------------------- Fn OK ------------------------------- //
  858.     function updateMapFromDiv(a){
  859.         let indArr = [{'kpi': parseInt(a)}];
  860.         let divi = document.getElementById('statline_id_' + a);
  861.         let alldivi = document.getElementsByClassName('grayscale');
  862.         for(let i=0; alldivi.length > i; i++){
  863.             alldivi[i].classList.remove('kpi_selected');
  864.             alldivi[i].classList.remove('disabled');
  865.         }
  866.         divi.classList.add('kpi_selected');
  867.         divi.classList.add('disabled');
  868.         explore_kpi = divi.getAttribute('data-kpi');
  869.         explore_slug = divi.getAttribute('data-slug');
  870.         
  871.         rPlatform.setiSelected(indArr);
  872.         rPlatform.setiActive();
  873.         rPlatform.updateMap();
  874.         // console.log(indArr);
  875.         this.selectedIndicator(divi);
  876.         this.updateTable(explore_slug);
  877.         //this.selectedDiv();
  878.     }
  879.     function updateMapFromStat(a){
  880.         let indArr = [{'kpi': parseInt(a)}];
  881.         let slug = '';
  882.         let name = '';
  883.         if(a == 100){
  884.             slug = 'statYearBox';
  885.             name = 'Año de construcción';
  886.         }else if(a == 101){
  887.             slug = 'statAreaBox';
  888.             name = 'Área';
  889.         }else if(a == 104){
  890.             slug = 'statOccupationBox';
  891.             name = 'Porcentaje de ocupación';
  892.         }else if(a == 105){
  893.             slug = 'statUseBox';
  894.             name = 'Uso del edificio';
  895.         }
  896.         let divi = document.getElementById(slug);
  897.         
  898.         var selectedBox = document.getElementById('selected_box_content');
  899.         // selectedBox.innerHTML = divi.outerHTML;
  900.         let html = '<h6>'+name+'</h6>';
  901.         // selectedBox.insertAdjacentHTML("afterbegin", html);
  902.         rPlatform.setiSelected(indArr);
  903.         rPlatform.setiActive();
  904.         rPlatform.updateMap();
  905.     }
  906.     function updateTable(slug){
  907.         let kpiArray = ['kpi_1_energy_renovated_residential_buildings', 'kpi_2_final_energy_consumption', 'kpi_3_renewable_energy_consumption', 'kpi_4_pv_potential_generation', 'kpi_7_heating_energy_consumption', 'kpi_8_ghg_emissions', 'kpi_19_population_income_below_60_average', 'kpi_20_median_household_income', 'kpi_21_average_price_renting_compared_family_income', 'kpi_22_house_price', 'kpi_27_urban_equipment_at_15_min', 'kpi_28_accessibility_to_bike_lane', 'kpi_30_green_area_surfaces', 'kpi_31_vulnerability_heatwaves_temperature_rise', 'kpi_36_charging_outlets', 'kpi_6_2_energy_efficient_and_energy_recovering_homes', 'kpi_6_1_energy_efficient_and_energy_recovering_homes', 'inspireid']
  908.         // Seleccionar todas las columnas con slug
  909.         for(let i=0; kpiArray.length > i;i++){
  910.             let celda = document.querySelectorAll('#wrapper .gridjs-table [data-column-id='+kpiArray[i]+']');
  911.             for(let j=0; celda.length > j;j++){
  912.                 celda[j].classList.add('d-none');
  913.             }
  914.         }
  915.         
  916.         // Seleccionar las celdas de nuestro slug
  917.         let celdaSlug = document.querySelectorAll('#wrapper .gridjs-table [data-column-id='+slug+']');
  918.         for(let j=0; celdaSlug.length > j;j++){
  919.             celdaSlug[j].classList.remove('d-none');
  920.             celdaSlug[j].classList.add('selected');
  921.         }
  922.         
  923.         // console.log('updateTable',slug);
  924.     }
  925.     function selectedIndicator(a){
  926.         var dataDiv = '';
  927.         var selectedBox = document.getElementById('selected_box_content');
  928.         var linestat = a.getElementsByClassName('statsline');
  929.         var titlestat = a.getElementsByClassName('title');
  930.         
  931.         var p = parseFloat(a.getAttribute('data-p')).toFixed(2);
  932.         var m = parseFloat(a.getAttribute('data-m')).toFixed(2);
  933.         var r = parseFloat(a.getAttribute('data-r')).toFixed(2);
  934.         var max = parseFloat(a.getAttribute('data-max'));
  935.         // Si hay datos completos pintamos los pins en el indicador seleccionado
  936.         if (p !== null && m !== null && r !== null){
  937.             var dato_p = detres(p,max);
  938.             var dato_m = detres(m,max);
  939.             var dato_r = detres(r,max);
  940.             var pinDiv = '<span class="statsline_item_extra" style="left: '+dato_p+'%;"><i class="fa-solid vert_bar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="Provincia '+p+'"></i><span class="pindata">P</span></span> <span class="statsline_item_extra" style="left: '+dato_m+'%;"><i class="fa-solid vert_bar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="Municipio '+m+'"></i><span class="pindata">M</span></span> <span class="statsline_item_extra" style="left: '+dato_r+'%;"><i class="fa-solid vert_bar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="Región '+r+'"></i><span class="pindata">R</span></span> ';
  941.             var elemento = linestat[0];
  942.             // elemento.insertAdjacentHTML('beforeend', pinDiv);
  943.             dataDiv = titlestat[0].outerHTML + elemento.outerHTML;
  944.             // selectedBox.innerHTML = dataDiv;   
  945.         }else{
  946.             dataDiv = titlestat[0].outerHTML + linestat[0].outerHTML;
  947.             // selectedBox.innerHTML = dataDiv;
  948.         }
  949.         
  950.         let titleAttribute = a.getAttribute('data-bs-title');
  951.         let descAttribute = a.getAttribute('data-bs-content');
  952.         // selectedBox.setAttribute("data-bs-title", titleAttribute);
  953.         // selectedBox.setAttribute("data-bs-content", descAttribute);
  954.         $('[data-bs-toggle="popover_live_top"]').mouseover(function(){
  955.             $('[data-bs-toggle="popover_live_top"]').popover();
  956.         });
  957.         const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover_live_top"]')
  958.         const popovertipList = [...popoverTriggerList].map(item => new bootstrap.Popover(item));
  959.         const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
  960.         const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  961.     }
  962.     function detres(value,max){
  963.         let dato = (value*100)/max;
  964.         return dato.toFixed(2);
  965.     }
  966.     
  967.     function updateMap(){
  968.         var selectElement = document.querySelector('#kpi_selector');
  969.         var kpi_id = selectElement.value;
  970.         let indArr = [{'kpi': parseInt(kpi_id)}];
  971.         rPlatform.setiSelected(indArr);
  972.         rPlatform.setiActive();
  973.         rPlatform.updateMap();
  974.         var iActive = rPlatform.getiActive();
  975.         updateSelector(iActive)
  976.     }
  977.     // --------------------- Simple Fn OK ------------------------------- //
  978.     function updateSelector(kpi){
  979.         var selector = document.getElementById('kpi_selector');
  980.         selector.value = kpi;
  981.     }
  982.     function loadUrlBack(){
  983.         let url = explore_baseUrl + "/" + explore_mun ;
  984.         window.location.href = url;
  985.     }
  986.     
  987.     function gotoproject(){
  988.         let url = '';
  989.         url = explore_baseUrl + "/" + explore_mun + "/plan";
  990.         window.location.href = url;
  991.     }
  992.     function capitalizeFirstLetter(string) {
  993.         return string.charAt(0).toUpperCase() + string.slice(1);
  994.     }
  995.     function viewFinder(a){
  996.         $('.viewfindergroup').hide();
  997.         $('#'+ a +'_view').show();
  998.         
  999.         if(a == 'map' || a == 'data')
  1000.         {
  1001.             $("#infoview2").show();
  1002.         }else{
  1003.             $("#infoview2").hide();
  1004.         }
  1005.         if(a == 'data'){
  1006.             tableData();
  1007.         }
  1008.         console.log(a);
  1009.         [...document.querySelectorAll('.left_bar_button')].map(x => x.classList.remove('active'));       
  1010.         document.getElementById('left_bar_button_'+a).classList.add('active');
  1011.     }
  1012.     
  1013.     function centerViewMap(){
  1014.         var zoom = rPlatform.getZoom();
  1015.         rPlatform.setCenterView(initGeo);
  1016.     }
  1017.     function expandIcon(e){
  1018.         var elemento = document.getElementById(e);
  1019.         var textoExtraido = elemento.innerText;
  1020.         if (textoExtraido == 'expand_more'){
  1021.             elemento.innerText = 'expand_less';
  1022.         }else{
  1023.             elemento.innerText = 'expand_more';
  1024.         }
  1025.     }
  1026.     function infoviewToggle(){
  1027.         if($('#infoview2').hasClass('show')){
  1028.             $('#infoview2').collapse('hide');
  1029.             $('#infoview').addClass('w-100');
  1030.             $('#expand .material-symbols-outlined').text('collapse_content');
  1031.         }else{
  1032.             $('#infoview2').collapse('show');
  1033.             $('#infoview').removeClass('w-100');
  1034.             $('#expand .material-symbols-outlined').text('expand_content');
  1035.         }
  1036.     }
  1037.     function activeClass(elem){
  1038.         var elemento = $(elem);
  1039.         elemento.toggleClass('active');
  1040.     }
  1041.     
  1042. </script>
  1043. <script>
  1044.     $(document).ready(function(){
  1045.         document.getElementById('big_container').classList.add('full');
  1046.         
  1047.         var headerInTop = document.getElementById('header_in_top').offsetHeight;
  1048.         var containerInContent = document.getElementById('container_in_content').offsetHeight;
  1049.         var headerContentInfoTop = document.getElementById('header_content_info_top').offsetHeight;
  1050.         var bigContainer = document.getElementById('big_container').offsetHeight;
  1051.         var containerInContentTotal = bigContainer - headerInTop;
  1052.         var containerSteps = bigContainer - headerInTop - headerContentInfoTop;
  1053.         
  1054.         document.getElementById('container_in_content').style.height = containerInContentTotal + 'px';
  1055.         document.getElementById('infoview_content').style.height = containerInContentTotal + 'px';
  1056.         document.getElementById('analytic_step').style.height = containerInContentTotal + 'px';
  1057.         
  1058.         var divs = document.querySelectorAll('.infoview_div');
  1059.         for(let i=0; divs.length > i; i++){
  1060.             divs[i].style.height = containerSteps + 'px';
  1061.         }
  1062.         var divs2 = document.querySelectorAll('.infoview2_div');
  1063.         for(let i=0; divs2.length > i; i++){
  1064.             divs2[i].style.height = containerSteps + 'px';
  1065.         }
  1066.         var divsIn = document.querySelectorAll('.viewfindergroup');
  1067.         for(let i=0; divsIn.length > i; i++){
  1068.             divsIn[i].style.height = containerSteps + 'px';
  1069.         }
  1070.         let flashDiv = document.querySelector('.flash-notice');
  1071.         if(flashDiv){
  1072.             setTimeout(()=>{
  1073.                 flashDiv.remove();
  1074.             },10000);
  1075.         }
  1076.     });
  1077.     function removeDiv(id){
  1078.         let divi = document.getElementById(id);
  1079.         divi.remove();
  1080.     }
  1081. </script>
  1082. {% endblock %}