diff --git a/public/js/annual_fisheries.js b/public/js/annual_fisheries.js index e7914c4..708947f 100644 --- a/public/js/annual_fisheries.js +++ b/public/js/annual_fisheries.js @@ -1,27 +1,30 @@ + function createPie(data, year) { - console.debug(data); var charts = L.featureGroup(); + let features = data.features.filter(f => { + return f.properties.YR == year; + }); - for (var i = 0; i < data.features.length; i++) { -   var d = data.features[i].properties; - var latlng = data.features[i].geometry.coordinates; -   if (d.YR == year) { -     var pieData = {values: [ -       d.TrawlPerc, -       d.PursesPerc, -       d.BoatsePerc, - d.otherPerc -     ], labels: ['trawl', 'purses', 'boatse', 'other']}; -     let chart = new PieChartMarker([latlng[1], latlng[0]], pieData, { - icon: L.divIcon({className: 'leaflet-pie-chart-marker'}), - width: 60, - height: 60, - colors: ['#ff0000', '#00ff00', '#0000ff', '#ff00ff'] - }); - charts.addLayer(chart); -   } - } - return charts; -} + let newData = {}; + features.forEach(f => { + let latlng = f.geometry.coordinates; + for (property in f.properties) { + const mapKey = fisheriesMap.get(property); + if (mapKey) { + newData[mapKey] = f.properties[property]; + } + } +    var pieData = {values: Object.values(newData), labels: Object.keys(newData)}; +    let chart = new PieChartMarker([latlng[1], latlng[0]], pieData, { + icon: L.divIcon({className: 'leaflet-pie-chart-marker'}), + width: 60, + height: 60, + colors: ['#ff0000', '#00ff00', '#0000ff', '#ff00ff'] + }); + charts.addLayer(chart); + }); + + return charts; +} diff --git a/public/js/constants.js b/public/js/constants.js index 8634e85..73bbadf 100644 --- a/public/js/constants.js +++ b/public/js/constants.js @@ -58,4 +58,14 @@ const hiddenRows = [ 'id', 'notes' ]; +const fisheriesMap = new Map([ + ['TrawlPerc', 'trawl'], + ['PursesPerc', 'purses'], + ['BoatsePerc', 'boatse'], + ['otherPerc', 'other'], + ['TAXON_B', 'taxon_b'], + ['TAXON_C', 'taxon_c'], + ['TAXON_F', 'taxon_f'], + ['TAXON_M', 'taxon_m'] +]); const EDITABLE = false; diff --git a/public/js/extras.js b/public/js/extras.js index 75378cd..4499e15 100644 --- a/public/js/extras.js +++ b/public/js/extras.js @@ -463,21 +463,20 @@ async function downloadShapefile(layerName, srs) { } -async function getFisheriesProduct() { +async function getFisheriesProduct(layerCode) { // Create timeline slider control const group = L.layerGroup(); // load contours in JSON const bgLayer = L.tileLayer.betterWms(BASE_URL + '/geoserver/wms', { layers: 'nssg_areas', transparent: true, format: "image/png"}); - const url = BASE_URL + "/interface/charts/afppy"; try { - const response = await fetch(url); - const data = await response.json(); + const data = await fetchGeoJson(layerCode); + console.debug("fisheries json: ", data); let pies; // Add the custom control to the map pies = createPie(data, 1990).addTo(group); - layerControls['AFPPY'] = L.control.slider(value => { + layerControls[layerCode] = L.control.slider(value => { pies.remove(); pies = createPie(data, value); group.addLayer(pies); diff --git a/public/js/layers.js b/public/js/layers.js index 1412444..4a229e8 100644 --- a/public/js/layers.js +++ b/public/js/layers.js @@ -341,8 +341,16 @@ var layersList = [ format: 'image', leafletid: null, },{ - name: 'Annual Fisheries Production per year', - code: 'AFPPY', + name: 'Annual Fisheries Production per Gear', + code: 'nssg-annual_prod_per_gear_1990-2019', + minSuffix: '1990', + maxSuffix: '2019', + active: false, + format: 'image', + leafletid: null + },{ + name: 'Annual Fisheries Production per Species', + code: 'nssg-annual_prod_per_species_1990-2019', active: false, format: 'image', leafletid: null @@ -360,6 +368,7 @@ async function layerTreeSwitch(node) { let leafletId = layer.leafletid; let l; + console.debug(intId); if (!layer.active && node.checkStatus) { if (intId === 'DPTH') { l = getBathymetry(); @@ -370,8 +379,8 @@ async function layerTreeSwitch(node) { l = getHabitat(layer.code); } else if (layer.isProduct) { l = getProduct(layer); - } else if (intId === 'AFPPY') { - l = await getFisheriesProduct(); + } else if (intId === 'nssg-annual_prod_per_gear_1990-2019' || intId === 'nssg-annual_prod_per_species_1990-2019') { + l = await getFisheriesProduct(intId); } else if (intId === 'PHPL') { l = getWMSSeries(node.checkStatus); } else if (intId.substr(0,3) === 'wfd') { diff --git a/public/js/treeview.js b/public/js/treeview.js index 31ccca5..1b044ad 100644 --- a/public/js/treeview.js +++ b/public/js/treeview.js @@ -303,7 +303,12 @@ const myData = [{ },{ n_id: 3111, n_title: 'Annual Fisheries Production per fishing gear per NSSG area (NSSG: National Statistical Service of Greece)', - code: 'AFPPY', + code: 'nssg-annual_prod_per_gear_1990-2019', + n_parentid: 311, + },{ + n_id: 3112, + n_title: 'Annual Fisheries Production per Species per NSSG area (NSSG: National Statistical Service of Greece)', + code: 'nssg-annual_prod_per_species_1990-2019', n_parentid: 311, },{ n_id: 321 , diff --git a/src/Controllers/InterfaceController.php b/src/Controllers/InterfaceController.php index 6943441..205fc66 100644 --- a/src/Controllers/InterfaceController.php +++ b/src/Controllers/InterfaceController.php @@ -33,7 +33,6 @@ class InterfaceController { public function geojson($data) { - $layer = $data['layer']; switch ($layer) { @@ -136,5 +135,3 @@ function convertToGeoJSON($json, $lon_alias, $lat_alias) { // encode the GeoJSON feature collection as a JSON string and return it return json_encode($geoJSON); } - - diff --git a/src/Controllers/StatsController.php b/src/Controllers/StatsController.php new file mode 100644 index 0000000..668b5c5 --- /dev/null +++ b/src/Controllers/StatsController.php @@ -0,0 +1,36 @@ +map('GET', '/actions/requests/[i:id]?', 'MSFD\Controllers\ActionControl - +// STATS +$router->map('GET', '/interface/stats/typecount', 'MSFD\Controllers\StatsController@countTypes', 'stat_types'); +$router->map('GET', '/interface/stats/totalrows', 'MSFD\Controllers\StatsController@countTotal', 'stat_total');