Browse Source

improve pie markers system, add extra layer of this type

master
o.moresis 2 years ago
parent
commit
75deba74ac
  1. 35
      public/js/annual_fisheries.js
  2. 10
      public/js/constants.js
  3. 9
      public/js/extras.js
  4. 17
      public/js/layers.js
  5. 7
      public/js/treeview.js
  6. 3
      src/Controllers/InterfaceController.php
  7. 36
      src/Controllers/StatsController.php
  8. 4
      src/Routing/controls.php

35
public/js/annual_fisheries.js

@ -1,27 +1,30 @@
function createPie(data, year) { function createPie(data, year) {
console.debug(data);
var charts = L.featureGroup(); var charts = L.featureGroup();
let features = data.features.filter(f => {
return f.properties.YR == year;
});
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];
}
}
for (var i = 0; i < data.features.length; i++) {     var pieData = {values: Object.values(newData), labels: Object.keys(newData)};
  var d = data.features[i].properties;     let chart = new PieChartMarker([latlng[1], latlng[0]], pieData, {
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'}), icon: L.divIcon({className: 'leaflet-pie-chart-marker'}),
width: 60, width: 60,
height: 60, height: 60,
colors: ['#ff0000', '#00ff00', '#0000ff', '#ff00ff'] colors: ['#ff0000', '#00ff00', '#0000ff', '#ff00ff']
}); });
charts.addLayer(chart); charts.addLayer(chart);
  } });
}
return charts; return charts;
} }

10
public/js/constants.js

@ -58,4 +58,14 @@ const hiddenRows = [
'id', 'notes' '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; const EDITABLE = false;

9
public/js/extras.js

@ -463,21 +463,20 @@ async function downloadShapefile(layerName, srs) {
} }
async function getFisheriesProduct() { async function getFisheriesProduct(layerCode) {
// Create timeline slider control // Create timeline slider control
const group = L.layerGroup(); const group = L.layerGroup();
// load contours in JSON // load contours in JSON
const bgLayer = L.tileLayer.betterWms(BASE_URL + '/geoserver/wms', { layers: 'nssg_areas', transparent: true, format: "image/png"}); 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 { try {
const response = await fetch(url); const data = await fetchGeoJson(layerCode);
const data = await response.json(); console.debug("fisheries json: ", data);
let pies; let pies;
// Add the custom control to the map // Add the custom control to the map
pies = createPie(data, 1990).addTo(group); pies = createPie(data, 1990).addTo(group);
layerControls['AFPPY'] = L.control.slider(value => { layerControls[layerCode] = L.control.slider(value => {
pies.remove(); pies.remove();
pies = createPie(data, value); pies = createPie(data, value);
group.addLayer(pies); group.addLayer(pies);

17
public/js/layers.js

@ -341,8 +341,16 @@ var layersList = [
format: 'image', format: 'image',
leafletid: null, leafletid: null,
},{ },{
name: 'Annual Fisheries Production per year', name: 'Annual Fisheries Production per Gear',
code: 'AFPPY', 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, active: false,
format: 'image', format: 'image',
leafletid: null leafletid: null
@ -360,6 +368,7 @@ async function layerTreeSwitch(node) {
let leafletId = layer.leafletid; let leafletId = layer.leafletid;
let l; let l;
console.debug(intId);
if (!layer.active && node.checkStatus) { if (!layer.active && node.checkStatus) {
if (intId === 'DPTH') { if (intId === 'DPTH') {
l = getBathymetry(); l = getBathymetry();
@ -370,8 +379,8 @@ async function layerTreeSwitch(node) {
l = getHabitat(layer.code); l = getHabitat(layer.code);
} else if (layer.isProduct) { } else if (layer.isProduct) {
l = getProduct(layer); l = getProduct(layer);
} else if (intId === 'AFPPY') { } else if (intId === 'nssg-annual_prod_per_gear_1990-2019' || intId === 'nssg-annual_prod_per_species_1990-2019') {
l = await getFisheriesProduct(); l = await getFisheriesProduct(intId);
} else if (intId === 'PHPL') { } else if (intId === 'PHPL') {
l = getWMSSeries(node.checkStatus); l = getWMSSeries(node.checkStatus);
} else if (intId.substr(0,3) === 'wfd') { } else if (intId.substr(0,3) === 'wfd') {

7
public/js/treeview.js

@ -303,7 +303,12 @@ const myData = [{
},{ },{
n_id: 3111, n_id: 3111,
n_title: 'Annual Fisheries Production per fishing gear per NSSG area (NSSG: National Statistical Service of Greece)', 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_parentid: 311,
},{ },{
n_id: 321 , n_id: 321 ,

3
src/Controllers/InterfaceController.php

@ -33,7 +33,6 @@ class InterfaceController {
public function geojson($data) { public function geojson($data) {
$layer = $data['layer']; $layer = $data['layer'];
switch ($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 // encode the GeoJSON feature collection as a JSON string and return it
return json_encode($geoJSON); return json_encode($geoJSON);
} }

36
src/Controllers/StatsController.php

@ -0,0 +1,36 @@
<?php
namespace MSFD\Controllers;
use MSFD\Services\PgSql;
class StatsController {
public function fetchStats() {
if (!in_array(5, $_SESSION['user_groups'])) {
header('HTTP/1.1 403 Forbidden');
die();
}
require __DIR__.'/../Data/users.php';
}
public function countTypes() {
$sql = "SELECT * FROM webapp.stats_count_per_type";
$result = PgSql::getJson($sql);
echo $result;
}
public function countTotal() {
$sql = "SELECT * FROM webapp.stats_total_inserts";
$result = PgSql::getJson($sql);
echo $result;
}
public function countFiles() {
$sql = "SELECT * FROM webapp.stats_total_files";
$result = PgSql::getJson($sql);
echo $result;
}
}

4
src/Routing/controls.php

@ -11,4 +11,6 @@ $router->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');

Loading…
Cancel
Save