app.config.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. export const perc2color = (perc: number): string => {
  35. perc = perc * 100;
  36. let r;
  37. let g;
  38. const b = 0;
  39. if (perc < 50) {
  40. r = 255;
  41. g = Math.round(5.1 * perc);
  42. } else {
  43. g = 255;
  44. r = Math.round(510 - 5.1 * perc);
  45. }
  46. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  47. const h = r * 0x10000 + g * 0x100 + b * 0x1;
  48. return `rgba(${r}, ${g}, ${b}, 0.7)`;
  49. };
  50. const decimal2prettyPerc = (x) => {
  51. return `${(x * 100).toFixed(2)}&nbsp;%`;
  52. };
  53. const indexStyle = (feature) => {
  54. if (isNaN(feature.get('aggregate'))) {
  55. return [
  56. new Style({
  57. fill: new Fill({
  58. color: '#FFF',
  59. }),
  60. stroke: new Stroke({
  61. color: '#3399CC',
  62. width: 0.25,
  63. }),
  64. }),
  65. ];
  66. } else {
  67. return [
  68. new Style({
  69. fill: new Fill({
  70. color: perc2color(feature.get('aggregate')),
  71. }),
  72. stroke: new Stroke({
  73. color: '#FFFFFF',
  74. width: 0.15,
  75. }),
  76. }),
  77. ];
  78. }
  79. };
  80. export const obce = new VectorSource({
  81. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  82. url: require('./data/obce_cr_20210310_5p_5514.topojson').default,
  83. overlaps: false,
  84. });
  85. export const obceIndexLayer = new VectorLayer({
  86. source: obce,
  87. editor: {editable: false},
  88. visible: true,
  89. style: indexStyle,
  90. title: 'Obce ČR: Rural attractiveness index',
  91. attributions: ['CC-BY ČÚZK, 2021'],
  92. });
  93. obceIndexLayer.set('popUp', {
  94. attributes: [
  95. {
  96. attribute: 'aggregate',
  97. label: 'agregovaný index',
  98. displayFunction: decimal2prettyPerc,
  99. },
  100. {
  101. attribute: 'Konec chudoby',
  102. displayFunction: decimal2prettyPerc,
  103. },
  104. {
  105. attribute: 'Zdraví a kvalitní život',
  106. displayFunction: decimal2prettyPerc,
  107. },
  108. {
  109. attribute: 'Kvalitní vzdělání',
  110. displayFunction: decimal2prettyPerc,
  111. },
  112. {
  113. attribute: 'Důstojná práce a ekonomický růst',
  114. displayFunction: decimal2prettyPerc,
  115. },
  116. {
  117. attribute: 'Udržitelná města a obce',
  118. displayFunction: decimal2prettyPerc,
  119. },
  120. {
  121. attribute: 'Ostatní',
  122. displayFunction: decimal2prettyPerc,
  123. },
  124. ],
  125. });
  126. obceIndexLayer.set('editable', false);
  127. //obceIndexLayer.set('queryable', false);
  128. const okresyStyle = new Style({
  129. stroke: new Stroke({
  130. color: '#111111',
  131. width: 0.4,
  132. }),
  133. });
  134. export const okresyLayer = new VectorLayer({
  135. source: new VectorSource({
  136. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  137. url: require('./data/okresy_cr_20210310_5p_5514.topojson').default,
  138. overlaps: false,
  139. }),
  140. editor: {editable: false},
  141. visible: false,
  142. style: okresyStyle,
  143. title: 'Okresy ČR',
  144. attributions: ['CC-BY ČÚZK, 2021'],
  145. });
  146. const krajeStyle = new Style({
  147. stroke: new Stroke({
  148. color: '#000000',
  149. width: 0.6,
  150. }),
  151. });
  152. export const krajeLayer = new VectorLayer({
  153. source: new VectorSource({
  154. format: new TopoJSON({dataProjection: 'EPSG:5514'}),
  155. url: require('./data/kraje_cr_20210310_5p_5514.topojson').default,
  156. overlaps: false,
  157. }),
  158. editor: {editable: false},
  159. visible: true,
  160. style: krajeStyle,
  161. title: 'Kraje ČR',
  162. attributions: ['CC-BY ČÚZK, 2021'],
  163. });
  164. export const AppConfig = {
  165. //proxyPrefix: '../8085/',
  166. default_layers: [osmLayer],
  167. popUpDisplay: 'hover',
  168. project_name: 'erra/map',
  169. default_view: new View({
  170. projection: sjtskProjection,
  171. center: transform([15.628, 49.864249], 'EPSG:4326', 'EPSG:5514'),
  172. zoom: 7.6,
  173. units: 'm',
  174. }),
  175. advanced_form: true,
  176. datasources: [],
  177. hostname: {
  178. default: {
  179. title: 'Default',
  180. type: 'default',
  181. editable: false,
  182. url: getHostname(),
  183. },
  184. },
  185. panelWidths: {
  186. datasource_selector: 400,
  187. },
  188. panelsEnabled: {
  189. composition_browser: false,
  190. feature_crossfilter: false,
  191. info: true,
  192. saveMap: false,
  193. sensors: false,
  194. tracking: false,
  195. routing: false,
  196. permalink: false,
  197. legend: false,
  198. feature_table: false,
  199. draw: false,
  200. },
  201. status_manager_url: '/statusmanager/',
  202. sidebarPosition: 'right',
  203. sizeMode: 'fullscreen',
  204. translationOverrides: i18n,
  205. };
  206. export default AppConfig;