From 06028992aa77237fb83b626be3cd5d7968e3f37e Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Tue, 22 Nov 2022 17:51:31 +0100 Subject: [PATCH] [DXCC Mao] Fixed so that worked/confirmed/not worked works with map --- application/controllers/Awards.php | 2 +- assets/js/sections/dxccmap.js | 114 +++++++++++++++++------------ 2 files changed, 69 insertions(+), 47 deletions(-) diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index eccea206..8f24a371 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -644,7 +644,7 @@ class Awards extends CI_Controller { } $newdxcc[$i]['lat'] = $dxcc->lat; $newdxcc[$i]['long'] = $dxcc->long; - $newdxcc[$i++]['status'] = $this->returnStatus($dxcc_array[$dxcc->adif]); + $newdxcc[$i++]['status'] = isset($dxcc_array[$dxcc->adif]) ? $this->returnStatus($dxcc_array[$dxcc->adif]) : 'x'; } header('Content-Type: application/json'); diff --git a/assets/js/sections/dxccmap.js b/assets/js/sections/dxccmap.js index 3620b134..2d5aa88a 100644 --- a/assets/js/sections/dxccmap.js +++ b/assets/js/sections/dxccmap.js @@ -23,7 +23,7 @@ function load_dxcc_map() { Antarctica: +$('#Antarctica').prop('checked'), }, success: function(data) { - load_dxcc_map2(data); + load_dxcc_map2(data, worked, confirmed, notworked); }, error: function() { @@ -31,7 +31,7 @@ function load_dxcc_map() { }); } -function load_dxcc_map2(data) { +function load_dxcc_map2(data, worked, confirmed, notworked) { // If map is already initialized var container = L.DomUtil.get('dxccmap'); @@ -51,61 +51,55 @@ function load_dxcc_map2(data) { } ).addTo(map); - var notworked = data.length; - var confirmed = 0; - var workednotconfirmed = 0; + var notworkedcount = data.length; + var confirmedcount = 0; + var workednotconfirmedcount = 0; for (var i = 0; i < data.length; i++) { - var D = data[i]; - var mapColor = 'red'; - - if (D['status'] == 'C') { - mapColor = 'green'; - confirmed++; - notworked--; - } - if (D['status'] == 'W') { - mapColor = 'orange'; - workednotconfirmed++; - notworked--; - } - - const markerHtmlStyles = ` - background-color: ${mapColor}; - width: 1rem; - height: 1rem; - display: block; - position: relative; - border-radius: 3rem 3rem 0; - transform: rotate(45deg); - border: 1px solid #FFFFFF` - - const icon = L.divIcon({ - className: "my-custom-pin", - iconAnchor: [0, 24], - labelAnchor: [-6, 0], - popupAnchor: [0, -36], - html: `` - }) - - L.marker( - [D['lat'], D['long']], { - icon: icon, - adif: D['adif'], - title: D['prefix'] + ' - ' + D['name'], + var D = data[i]; + if (D['status'] != 'x') { + var mapColor = 'red'; + + if (D['status'] == 'C') { + mapColor = 'green'; + if (confirmed != '0') { + addMarker(L, D, mapColor, map); + confirmedcount++; + notworkedcount--; + } } - ).addTo(map).on('click', onClick); + if (D['status'] == 'W') { + mapColor = 'orange'; + if (worked != '0') { + addMarker(L, D, mapColor, map); + workednotconfirmedcount++; + notworkedcount--; + } + } + + + // Make a check here and hide what I don't want to show + if (notworked != '0') { + if (mapColor == 'red') { + addMarker(L, D, mapColor, map); + } + } + } } /*Legend specific*/ var legend = L.control({ position: "topright" }); + if (notworked.checked == false) { + notworkedcount = 0; + } + legend.onAdd = function(map) { var div = L.DomUtil.create("div", "legend"); div.innerHTML += "

Colors

"; - div.innerHTML += 'Confirmed ('+confirmed+')
'; - div.innerHTML += 'Worked not confirmed ('+workednotconfirmed+')
'; - div.innerHTML += 'Not worked ('+notworked+')
'; + div.innerHTML += 'Confirmed ('+confirmedcount+')
'; + div.innerHTML += 'Worked not confirmed ('+workednotconfirmedcount+')
'; + div.innerHTML += 'Not worked ('+notworkedcount+')
'; return div; }; @@ -114,6 +108,34 @@ function load_dxcc_map2(data) { map.setView([20, 0], 2); } +function addMarker(L, D, mapColor, map) { + const markerHtmlStyles = ` + background-color: ${mapColor}; + width: 1rem; + height: 1rem; + display: block; + position: relative; + border-radius: 3rem 3rem 0; + transform: rotate(45deg); + border: 1px solid #FFFFFF` + + const icon = L.divIcon({ + className: "my-custom-pin", + iconAnchor: [0, 24], + labelAnchor: [-6, 0], + popupAnchor: [0, -36], + html: `` + }) + + L.marker( + [D['lat'], D['long']], { + icon: icon, + adif: D['adif'], + title: D['prefix'] + ' - ' + D['name'], + } + ).addTo(map).on('click', onClick); +} + function onClick(e) { var marker = e.target; displayContacts(marker.options.adif, $('#band2').val(), $('#mode').val(), 'DXCC2');