diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index be950799..ed920caf 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -442,6 +442,11 @@ class Awards extends CI_Controller { } public function was() { + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/wasmap.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/wasmap.js")) + ]; + $this->load->model('was'); $this->load->model('modes'); $this->load->model('bands'); @@ -491,7 +496,7 @@ class Awards extends CI_Controller { $data['page_title'] = "Awards - WAS (Worked All States)"; $this->load->view('interface_assets/header', $data); $this->load->view('awards/was/index'); - $this->load->view('interface_assets/footer'); + $this->load->view('interface_assets/footer', $footerData); } public function iota () { @@ -874,28 +879,53 @@ class Awards extends CI_Controller { This displays the WAS map and requires the $band_type and $mode_type */ - public function was_map($band_type, $mode_type) { + public function was_map() { + $stateString = 'AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY'; + $wasArray = explode(',', $stateString); $this->load->model('was'); - $data['mode'] = $mode_type; + $bands[] = $this->security->xss_clean($this->input->post('band')); - $bands[] = $band_type; + $postdata['qsl'] = $this->input->post('qsl') == 0 ? NULL: 1; + $postdata['lotw'] = $this->input->post('lotw') == 0 ? NULL: 1; + $postdata['eqsl'] = $this->input->post('eqsl') == 0 ? NULL: 1; + $postdata['worked'] = $this->input->post('worked') == 0 ? NULL: 1; + $postdata['confirmed'] = $this->input->post('confirmed') == 0 ? NULL: 1; + $postdata['notworked'] = $this->input->post('notworked') == 0 ? NULL: 1; + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); - $postdata['qsl'] = 1; - $postdata['lotw'] = 1; - $postdata['eqsl'] = 0; - $postdata['worked'] = 1; - $postdata['confirmed'] = 1; - $postdata['notworked'] = 1; - $postdata['band'] = $band_type; - $postdata['mode'] = $mode_type; + $was_array = $this->was->get_was_array($bands, $postdata); - $data['was_array'] = $this->was->get_was_array($bands, $postdata); + $states = array(); - $data['page_title'] = ""; + foreach ($wasArray as $state) { // Generating array for use in the table + $states[$state] = '-'; // Inits each state's count + } - $this->load->view('awards/was/map', $data); + + foreach ($was_array as $was => $value) { + foreach ($value as $key) { + if($key != "") { + if (strpos($key, '>W<') !== false) { + $states[$was] = 'W'; + break; + } + if (strpos($key, '>C<') !== false) { + $states[$was] = 'C'; + break; + } + if (strpos($key, '-') !== false) { + $states[$was] = '-'; + break; + } + } + } + } + + header('Content-Type: application/json'); + echo json_encode($states); } /* diff --git a/application/views/awards/was/index.php b/application/views/awards/was/index.php index 943bbcdd..268e86e4 100644 --- a/application/views/awards/was/index.php +++ b/application/views/awards/was/index.php @@ -1,3 +1,55 @@ + + +
@@ -103,6 +155,27 @@ + +
+ +
+
+
+ +
+ +
+ +
+ + Nothing found!
'; } + ?> +
+
+ diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 5a1cd98e..6b255491 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -55,18 +55,6 @@ $('[data-bs-toggle="tooltip"]').tooltip(); }); -uri->segment(1) == "awards" && ($this->uri->segment(2) == "was") ) { ?> - - - - + '); + } + + map = new L.Map('wasmap', { + fullscreenControl: true, + fullscreenControlOptions: { + position: 'topleft' + }, + }); + + L.tileLayer( + osmUrl, + { + attribution: '© OpenStreetMap contributors, CC-BY-SA', + maxZoom: 18 + } + ).addTo(map); + + var notworked = mapcoordinates.features.length; + var confirmed = 0; + var workednotconfirmed = 0; + + for(var k in data) { + var mapColor = 'red'; + + if (data[k] == 'C') { + mapColor = 'green'; + confirmed++; + notworked--; + } + if (data[k] == 'W') { + mapColor = 'orange'; + workednotconfirmed++; + notworked--; + } + } + + /*Legend specific*/ + var legend = L.control({ position: "topright" }); + + legend.onAdd = function(map) { + var div = L.DomUtil.create("div", "legend"); + div.innerHTML += "

" + lang_general_word_colors + "

"; + div.innerHTML += "" + lang_general_word_confirmed + " (" + confirmed + ")
"; + div.innerHTML += "" + lang_general_word_worked_not_confirmed + " (" + workednotconfirmed + ")
"; + div.innerHTML += "" + lang_general_word_not_worked + " (" + notworked + ")
"; + return div; + }; + + legend.addTo(map); + + info = L.control(); + +info.onAdd = function (map) { + this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info" + this.update(); + return this._div; +}; + +// method that we will use to update the control based on feature properties passed +info.update = function (props) { + this._div.innerHTML = '

State

' + (props ? + '' + props.id.substring(3,5) + ' - ' + props.name + '
' : 'Hover over a state'); +}; + +info.addTo(map); + + geojson = L.geoJson(mapcoordinates, {style: style, onEachFeature: onEachFeature}).addTo(map); + + map.setView([52, -100], 3); +} + +function getColor(d) { + var res = d.substring(3, 5); + return was[res] == 'C' ? 'green' : + was[res] == 'W' ? 'orange' : + 'red'; +} + +function highlightFeature(e) { + var layer = e.target; + + layer.setStyle({ + weight: 3, + color: 'white', + dashArray: '', + fillOpacity: 0.8 + }); + + layer.bringToFront(); + info.update(layer.feature.properties); +} + +function onEachFeature(feature, layer) { + layer.on({ + mouseover: highlightFeature, + mouseout: resetHighlight, + click: onClick + }); +} + +function zoomToFeature(e) { + map.fitBounds(e.target.getBounds()); +} + +function resetHighlight(e) { + geojson.resetStyle(e.target); + info.update(); +} + +function style(feature) { + return { + fillColor: getColor(feature.id), + weight: 1, + opacity: 1, + color: 'white', + // dashArray: '3', + fillOpacity: 0.6 + }; +} + +function onClick(e) { + zoomToFeature(e); + var marker = e.target; + var res = marker.feature.id.substring(3, 5); + displayContactsOnMap($("#wasmap"),res, $('#band2').val(), $('#mode').val(), 'WAS'); +}