app.config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import proj4 from 'proj4';
  2. import {Fill, Stroke, Style} from 'ol/style';
  3. import {OSM, Vector as VectorSource} from 'ol/source';
  4. import {Tile, Vector as VectorLayer} from 'ol/layer';
  5. import {TopoJSON} from 'ol/format';
  6. import {View} from 'ol';
  7. import {get as getProjection, transform} from 'ol/proj';
  8. import {register} from 'ol/proj/proj4';
  9. import i18n from './translations.json';
  10. proj4.defs(
  11. 'EPSG:3045',
  12. '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
  13. );
  14. proj4.defs(
  15. 'EPSG:5514',
  16. '+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 +alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 +ellps=bessel +towgs84=542.5,89.2,456.9,5.517,2.275,5.516,6.96 +units=m +no_defs'
  17. );
  18. register(proj4);
  19. const sjtskProjection = getProjection('EPSG:5514');
  20. //const utm33nProjection = getProjection('EPSG:3045');
  21. function getHostname() {
  22. const url = window.location.href;
  23. const urlArr = url.split('/');
  24. const domain = urlArr[2];
  25. return urlArr[0] + '//' + domain;
  26. }
  27. export const osmLayer = new Tile({
  28. source: new OSM(),
  29. title: 'OpenStreetMap',
  30. base: true,
  31. editor: {editable: false},
  32. removable: false,
  33. });
  34. const stroke = new Stroke({
  35. color: '#3399CC',
  36. width: 0.25,
  37. });
  38. function perc2color(perc) {
  39. perc = perc * 100;
  40. let r;
  41. let g;
  42. const b = 0;
  43. if (perc < 50) {
  44. r = 255;
  45. g = Math.round(5.1 * perc);
  46. } else {
  47. g = 255;
  48. r = Math.round(510 - 5.1 * perc);
  49. }
  50. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  51. const h = r * 0x10000 + g * 0x100 + b * 0x1;
  52. return `rgba(${r}, ${g}, ${b}, 0.7)`;
  53. }
  54. const indexStyle = function (feature) {
  55. if (isNaN(feature.get('aggregate'))) {
  56. return [
  57. new Style({
  58. fill: new Fill({
  59. color: '#FFF',
  60. }),
  61. stroke: stroke,
  62. }),
  63. ];
  64. } else {
  65. return [
  66. new Style({
  67. fill: new Fill({
  68. color: perc2color(feature.get('aggregate')),
  69. }),
  70. stroke: stroke,
  71. }),
  72. ];
  73. }
  74. };
  75. export const obce = new VectorSource({
  76. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  77. url: require('./data/obce_cr_20210310_5p_5514.topojson').default,
  78. overlaps: false,
  79. });
  80. export const obceIndexLayer = new VectorLayer({
  81. source: obce,
  82. editor: {editable: false},
  83. visible: true,
  84. style: indexStyle,
  85. title: 'Obce ČR: Rural attractiveness index',
  86. attributions: ['CC-BY ČÚZK, 2021'],
  87. });
  88. obceIndexLayer.set('popUp', {
  89. attributes: [
  90. {attribute: 'text', label: 'Název'},
  91. {
  92. attribute: 'aggregate',
  93. label: 'index',
  94. displayFunction: (x) => {
  95. return `${(x * 100).toFixed(2)}&nbsp;%`;
  96. },
  97. },
  98. 'Social & Human', //TODO: factors?
  99. ],
  100. });
  101. obceIndexLayer.set('editable', false);
  102. obceIndexLayer.set('queryable', false);
  103. const okresyStyle = new Style({
  104. stroke: new Stroke({
  105. color: '#111111',
  106. width: 0.4,
  107. }),
  108. });
  109. export const okresyLayer = new VectorLayer({
  110. source: new VectorSource({
  111. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  112. url: require('./data/okresy_cr_20210310_5p_5514.topojson').default,
  113. overlaps: false,
  114. }),
  115. editor: {editable: false},
  116. visible: false,
  117. style: okresyStyle,
  118. title: 'Okresy ČR',
  119. attributions: ['CC-BY ČÚZK, 2021'],
  120. });
  121. const krajeStyle = new Style({
  122. stroke: new Stroke({
  123. color: '#000000',
  124. width: 0.6,
  125. }),
  126. });
  127. export const krajeLayer = new VectorLayer({
  128. source: new VectorSource({
  129. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  130. url: require('./data/kraje_cr_20210310_5p_5514.topojson').default,
  131. overlaps: false,
  132. }),
  133. editor: {editable: false},
  134. visible: true,
  135. style: krajeStyle,
  136. title: 'Kraje ČR',
  137. attributions: ['CC-BY ČÚZK, 2021'],
  138. });
  139. export const AppConfig = {
  140. //proxyPrefix: '../8085/',
  141. default_layers: [osmLayer],
  142. popUpDisplay: 'hover',
  143. project_name: 'erra/map',
  144. default_view: new View({
  145. projection: sjtskProjection,
  146. center: transform([15.628, 49.864249], 'EPSG:4326', 'EPSG:5514'),
  147. zoom: 7.6,
  148. units: 'm',
  149. }),
  150. advanced_form: true,
  151. datasources: [],
  152. hostname: {
  153. default: {
  154. title: 'Default',
  155. type: 'default',
  156. editable: false,
  157. url: getHostname(),
  158. },
  159. },
  160. panelWidths: {
  161. datasource_selector: 400,
  162. },
  163. panelsEnabled: {
  164. composition_browser: false,
  165. feature_crossfilter: false,
  166. info: false,
  167. saveMap: false,
  168. sensors: false,
  169. tracking: false,
  170. routing: false,
  171. permalink: false,
  172. legend: false,
  173. feature_table: false,
  174. draw: false,
  175. },
  176. sidebarPosition: 'right',
  177. sizeMode: 'fullscreen',
  178. translationOverrides: i18n,
  179. };
  180. export default AppConfig;