"use strict"; var g_map; var g_sublayer; var g_polylines = []; var g_first_circle = null; var g_line_width = 1.7; var g_opacity = 0.7; var g_markers = []; var g_popup = null; var g_markerlist = []; var g_funder_ids = []; var g_status = 1; var g_vgs = []; // OSM var g_tilelayer00 = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors', noWrap: true }); // standard mapbox map var g_tilelayer0 = L.tileLayer('http://{s}.tiles.mapbox.com/v4/xmnr-net.map-atiolmb8/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoieG1uci1uZXQiLCJhIjoiX1YyVm43WSJ9.db6f-l9SLulOORMs12Ez_w', { attribution: '© Map data © Mapbox contributors, CC-BY-SA', noWrap: true }); // terrain var g_tilelayer1 = L.tileLayer('https://api.mapbox.com/styles/v1/xmnr-net/cipduagpx006tdima4fgyk8ou/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoieG1uci1uZXQiLCJhIjoiX1YyVm43WSJ9.db6f-l9SLulOORMs12Ez_w', { attribution: '© Map data © Mapbox contributors, CC-BY-SA', noWrap: true }); // satellite var g_tilelayer2 = L.tileLayer('https://api.mapbox.com/styles/v1/xmnr-net/cioiz82fs0031cqno8gxvg772/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoieG1uci1uZXQiLCJhIjoiX1YyVm43WSJ9.db6f-l9SLulOORMs12Ez_w', { attribution: '© Map data © Mapbox contributors, CC-BY-SA', noWrap: true }); var g_currentlayer = g_tilelayer1; var isLoading = true; $(document).ready(function() { set_map_height(); // run this as early as possible so that map has correct div size //var geo_bounds = ; //init_leaflet(geo_bounds); var geo_bounds = [[124.98046,67.067433],[-95.625,-22.26876]]; //long lat var geo_bounds = [[84.55,66.79],[-106.69,-22.75]]; //long lat init_leaflet(geo_bounds); //init_leaflet(); var emptyslidersettings = {}; $.accordeon('map-accordeon',emptyslidersettings,false,-1); // $.accordeon('map-accordeon',emptyslidersettings,false,1); $(window).resize(function() { set_map_height(); }); show_pins([],1); // VGGTs: level 2 click $('ul#vgs > li > ul > li').on('click',function() { if ('1' === $(this).data('selected')) { $(this).removeClass('selected').data('selected','0'); } else { $(this).addClass('selected').data('selected','1'); } get_selected_vgs(); }); // VGGTs: level 1 click : select/deselect all $('ul#vgs > li > div .cat1title').on('click',function() { var elt = $(this).parent().parent(); if ('1' === elt.data('selected')) { elt.removeClass('selected').data('selected','0'); } else { elt.addClass('selected').data('selected','1'); } var $lis = elt.find('li'); var found_selection = false; $lis.each(function() { if ('1' === $(this).data('selected')) { found_selection = true; } }); if (found_selection) { $lis.removeClass('selected').data('selected','0'); } else { $lis.addClass('selected').data('selected','1'); } get_selected_vgs(); }); $('.chosen-select').chosen({ allow_single_deselect: true, width: '100%' }); var hash = window.location.hash.substring(1); if (hash.indexOf('programme') != -1) { // Load program details show_programmes(); } }); var get_selected_vgs = function() { var n = 0; g_vgs = []; $('ul#vgs > li > ul > li').each(function() { var $li = $(this); if ('1' === $li.data('selected')) { n++; g_vgs.push($li.data('vgid')); } }); if (n) { $('#idcountervgs').html('(' + n + ' selected)'); } else { $('#idcountervgs').html(''); } update_pins(); }; var set_map_height = function () { var fh = $('#footerarea').height(); var wh = $(window).height(); var new_h = wh - fh - 1; $('#map').height(new_h); //$('#mapcontent').height(new_h); //$('#map-accordeon').css('min-height', new_h + 'px'); $('#mapcontent').css('max-height', new_h+'px'); // adjust left content column return; }; var init_leaflet = function(geo_bounds) { if (typeof geo_bounds !== 'undefined') { var southWest = L.latLng(geo_bounds[0][1], geo_bounds[0][0]), northEast = L.latLng(geo_bounds[1][1], geo_bounds[1][0]), bounds = L.latLngBounds(southWest, northEast); } var centerPoint = [19.31114, 16.875]; var tilelayer = g_tilelayer1; if (typeof bounds === 'undefined') { g_map = L.map('map', { zoomControl: false, attributionControl: false }) .addLayer(tilelayer) //.setView([50.9384, 6.9604], 15) .setView(centerPoint, 3) ; } else { g_map = L.map('map', { zoomControl: false, attributionControl: false }) .addLayer(tilelayer) .setView(centerPoint, 3) //.fitBounds(bounds) ; } //.setView([52.3610, -71.0587], 2); new L.Control.Attribution({position: 'bottomright'}).addTo(g_map); //new L.Control.Zoom({ position: 'bottomright' }).addTo(g_map); new L.Control.Zoom({ position: 'topleft' }).addTo(g_map); // var southWest = L.latLng(40.712, -74.227); // var northEast = L.latLng(40.774, -74.125); // var mapBounds = L.latLngBounds(southWest, northEast); // g_map.setMaxBounds(mapBounds); g_map.options.minZoom = 3; g_map.options.maxZoom = 14; //g_map.on('mousemove click', function(e) { //}); g_map.on('click', function (e) { divpcontent_hide(); }); if (typeof leaflet_ready === 'function') { leaflet_ready(); } }; // --------------------------------- // funder_ids: array (if empty array then show all) var show_pins = function(funder_ids, status) { g_status = status; if (undefined === funder_ids) funder_ids = []; remove_all_pins(); var url = 'ajax/map/get-funder-receiver-countries'; var cy_index = $('#countrieslist').val(); var cy = g_markerlist[cy_index]; var cy_id = null; if (cy_index != -1) { if (cy != null && cy.cy_id) { cy_id = cy.cy_id; } } else { cy_id = -1; } var data = { 'funder_ids': funder_ids, 'vgs': g_vgs, 'status': status, 'cy_id': cy_id }; aj_post(url,data,function(d) { //infopopup('Daten da'); var pc, previousCyId; // draw pins g_markerlist = d.list; for(var i = 0; i < d.list.length; i++) { if (d.list[i].cy_id) { draw_divicon(i); } } // set partner countries var html = ''; var firstletter = ''; var nextletter = ''; var info = ''; $('#countrieslist').empty(); $('#countrieslist').append(''); $('#countrieslist').append(''); for(var i = 0; i < d.list.length; i++) { var pc = d.list[i]; if (pc.cy_id != null) { info += pc.cy_id + ','; nextletter = pc.cy_name.substr(0,1); $('#countrieslist').append(''); } } if (cy_id != null) { $('#countrieslist').val(cy_index); } $('#countrieslist').trigger('chosen:updated'); $('#countrieslist').on('change', function (evt, params) { if ($(this).val() != '') { if ($(this).val() != -1) { country_click($(this).val()); } update_pins(); } else { popup_close(); if (previousCyId == -1) { update_pins(); } } previousCyId = $(this).val(); }); $('#idcountercountries').html(d.list.length); g_funder_ids = d.funder_ids; // n_prog status = parseInt(status); var html = ''; if (2 === status) { html = d.n_prog+' active programmes'; } else if (3 === status) { html = d.n_prog+' completed programmes'; } else { html = d.n_prog+' programmes'; } $('#id_n_prog').html(html); }); }; // --------------------------------- // size 1 small 2 middle 3 large var draw_divicon = function(idx_markerlist) { var size; var d = g_markerlist[idx_markerlist]; var lat = d.cy_lat; var lng = d.cy_lng; var name = d.cy_name; var n = d.n; n = parseInt(n); if (n < 7) { size = 1; } else if (n < 15) { size = 2; } else { size = 3; } var classextra = ''; switch(g_status) { case 3: classextra = ' program-div-icon_status_3'; break; case 2: classextra = ' program-div-icon_status_2'; break; case 1: classextra = ' program-div-icon_status_' + g_status + '-' + size; break; // case 1: classextra = ' program-div-icon_status_' + g_status + '-2'; // console.log(classextra); // break; } var classextra = ' program-div-icon_status_' + g_status + '-' + size; switch(size) { case 3: var className = 'program-div-icon3' + classextra; var iconSize = L.point(42,51); var iconAnchor = L.point(21,51); break; case 2: var className = 'program-div-icon2' + classextra; var iconSize = L.point(32,39); var iconAnchor = L.point(16,39); break; case 1: var className = 'program-div-icon1' + classextra; var iconSize = L.point(22,27); var iconAnchor = L.point(11,27); break; default: console.log('ERROR: divicon size'); } //var myIcon = L.divIcon({className: 'my-div-icon'}); //L.marker([50.505, 30.57], {icon: myIcon}).addTo(map); //var myIcon = L.divIcon(); var myIcon = L.divIcon( { className: className, iconSize: iconSize, iconAnchor: iconAnchor, html: n } ); // Tooltip: title: name //var marker = L.marker([parseInt(lat),parseInt(lng)], {icon: myIcon,title: name}).addTo(g_map); var marker = L.marker([parseFloat(lat),parseFloat(lng)], { icon: myIcon, //title: name, title: name, idx_markerlist:idx_markerlist } ).addTo(g_map); marker.addTo(g_map); g_markers.push(marker); marker.on('click',marker_click); }; // --------------------------------- var marker_click = function(e) { popup_show(e.target.options.idx_markerlist); //var latlong = e.target.getLatLng(); }; // --------------------------------- var popup_show = function(idx_markerlist) { var d = g_markerlist[idx_markerlist]; var lat = d.cy_lat; var lng = d.cy_lng; var url = 'ajax/map/get-country-popup-data'; var data = { 'funder_ids': g_funder_ids, 'status': g_status, 'cy_id': d.cy_id }; aj_post(url,data,function(d) { if (!g_popup) { var myIcon = L.divIcon( { className: 'countrypopup', iconSize: L.point(250,197), iconAnchor: L.point(125,207), html: get_marker_html(idx_markerlist,d.data) } ); var marker = L.marker([lat,lng], {icon: myIcon,title: ''}).addTo(g_map); marker.setZIndexOffset(1000); g_popup = marker; //marker.on('click',popup_click); //console.log('Popup');console.log(marker); } else { var myIcon = g_popup.options.icon; myIcon.options.html = get_marker_html(idx_markerlist,d.data); var newpos = [lat,lng]; g_popup.setLatLng(newpos); g_popup.setIcon(myIcon); } }); //marker.bringToFront(); //marker.setZIndex(10000); }; // --------------------------------- var popup_click = function(e) { //popup_close(); }; // --------------------------------- var popup_close = function() { if (!g_popup) return; g_map.removeLayer(g_popup); g_popup = null; }; // --------------------------------- var popup_close_with_delay = function() { setTimeout(function(){ popup_close(); }, 200); }; // --------------------------------- var my_fund_format = function(fund) { fund.toFixed(1); } // ************ // FROM: http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript var my_formatMoney = function(v,decPlaces, thouSeparator, decSeparator) { var n = v, decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces, decSeparator = decSeparator == undefined ? "." : decSeparator, thouSeparator = thouSeparator == undefined ? "," : thouSeparator, sign = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : ""); }; // --------------------------------- var get_marker_html = function(idx_markerlist,data) { var d = g_markerlist[idx_markerlist]; var lat = d.cy_lat; var lng = d.cy_lng; var name = d.cy_name; var n = parseInt(d.n); var n_prog = n + ' programmes'; if (1 === n) n_prog = '1 programme'; var s = '
| Programmes by your selection | '
+ ' Funds [USD] | ' + '||
|---|---|---|---|
| ' + data.n2 + ' | ' + 'Active | ' + '' + my_formatMoney(data.funds2,1,',','.') + ' | ' + 'mio | ' + '
| ' + data.n3 + ' | ' + 'Completed | ' + '' + my_formatMoney(data.funds3,1,',','.') + ' | ' + 'mio | ' + '
| ' + data.n1 + ' | ' + 'Total | ' + '' + my_formatMoney(data.funds1,1,',','.') + ' | ' + 'mio | ' + '