app.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import VectorLayer from 'ol/layer/Vector';
  2. import View from 'ol/View';
  3. import {Fill, Stroke, Style} from 'ol/style';
  4. import {OSM} from 'ol/source';
  5. import {Tile} from 'ol/layer';
  6. import nuts from './nuts';
  7. function getHostname() {
  8. const url = window.location.href;
  9. const urlArr = url.split('/');
  10. const domain = urlArr[2];
  11. return urlArr[0] + '//' + domain;
  12. }
  13. const stroke = new Stroke({
  14. color: '#3399CC',
  15. width: 0.25,
  16. });
  17. function perc2color(perc) {
  18. perc = perc * 100;
  19. let r;
  20. let g;
  21. const b = 0;
  22. if (perc < 50) {
  23. r = 255;
  24. g = Math.round(5.1 * perc);
  25. } else {
  26. g = 255;
  27. r = Math.round(510 - 5.1 * perc);
  28. }
  29. // eslint-disable-next-line no-unused-vars
  30. const h = r * 0x10000 + g * 0x100 + b * 0x1;
  31. return `rgba(${r}, ${g}, ${b}, 0.7)`;
  32. }
  33. const styles = function (feature) {
  34. if (isNaN(feature.get('total'))) {
  35. return [
  36. new Style({
  37. fill: new Fill({
  38. color: '#FFF',
  39. }),
  40. stroke: stroke,
  41. }),
  42. ];
  43. } else {
  44. return [
  45. new Style({
  46. fill: new Fill({
  47. color: perc2color(feature.get('total')),
  48. }),
  49. stroke: stroke,
  50. }),
  51. ];
  52. }
  53. };
  54. const nuts2Layer = new VectorLayer({
  55. source: nuts.nuts2Source,
  56. visible: false,
  57. style: styles,
  58. title: 'NUTS2 regions',
  59. });
  60. const nuts3Layer = new VectorLayer({
  61. source: nuts.nuts3Source,
  62. visible: true,
  63. style: styles,
  64. title: 'NUTS3 regions',
  65. });
  66. nuts3Layer.set('hoveredKeys', [
  67. 'NUTS_NAME',
  68. 'totalForHumans',
  69. 'Social & Human',
  70. 'Anthropic',
  71. 'Institutional',
  72. 'Economical',
  73. 'Natural',
  74. 'Cultural',
  75. ]);
  76. nuts3Layer.set('hoveredKeysTranslations', {
  77. NUTS_NAME: 'Name',
  78. totalForHumans: 'Calculated score',
  79. });
  80. export const AppConfig = {
  81. proxyPrefix: '../8085/',
  82. default_layers: [
  83. new Tile({
  84. source: new OSM(),
  85. title: 'Open street map',
  86. base: true,
  87. editor: {editable: false},
  88. removable: false,
  89. }),
  90. nuts2Layer,
  91. nuts3Layer,
  92. ],
  93. project_name: 'erra/map',
  94. default_view: new View({
  95. center: [2433348.3022471312, 7744501.813885343],
  96. zoom: 3.6,
  97. units: 'm',
  98. }),
  99. advanced_form: true,
  100. datasources: [],
  101. hostname: {
  102. default: {
  103. title: 'Default',
  104. type: 'default',
  105. editable: false,
  106. url: getHostname(),
  107. },
  108. },
  109. panelWidths: {},
  110. panelsEnabled: {
  111. language: false,
  112. composition_browser: false,
  113. legend: false,
  114. ows: false,
  115. info: false,
  116. saveMap: false,
  117. draw: false,
  118. },
  119. searchProvider: (q) => {
  120. return `/app/jupyter-test/8085/search/?q=${q}`;
  121. },
  122. };