app.service.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import {Injectable} from '@angular/core';
  2. import proj4 from 'proj4';
  3. import {GeoJSON} from 'ol/format';
  4. import {OSM, TileWMS, Vector as VectorSource} from 'ol/source';
  5. import {Tile, Vector as VectorLayer} from 'ol/layer';
  6. import {View} from 'ol';
  7. import {bbox as bboxStrategy} from 'ol/loadingstrategy';
  8. import {get as getProjection, transform} from 'ol/proj';
  9. import {register} from 'ol/proj/proj4';
  10. import {
  11. HsConfig,
  12. HsEventBusService,
  13. HsLanguageService,
  14. HsLayerManagerService,
  15. HsLayoutService,
  16. HsPanelContainerService,
  17. HsSidebarService,
  18. } from 'hslayers-ng';
  19. import i18n from './translations.json';
  20. import {CalculatorService} from './calculator/calculator.service';
  21. import {imageWmsTLayer} from './calculator/image-wms-t-layer';
  22. proj4.defs(
  23. 'EPSG:3045',
  24. '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'
  25. );
  26. proj4.defs(
  27. 'EPSG:5514',
  28. '+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'
  29. );
  30. register(proj4);
  31. @Injectable({providedIn: 'root'})
  32. export class AppService {
  33. sjtskProjection = getProjection('EPSG:5514');
  34. constructor(
  35. public calcService: CalculatorService,
  36. public hsConfig: HsConfig,
  37. public hsEventBus: HsEventBusService,
  38. public hsLanguageService: HsLanguageService,
  39. public hsLayerManagerService: HsLayerManagerService,
  40. public hsLayoutService: HsLayoutService,
  41. public hsPanelContainerService: HsPanelContainerService,
  42. public hsSidebarService: HsSidebarService
  43. ) {
  44. /* Define the polygon's style using SLD */
  45. const fieldSld = `<?xml version="1.0" encoding="ISO-8859-1"?>
  46. <StyledLayerDescriptor version="1.0.0"
  47. xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
  48. xmlns="http://www.opengis.net/sld"
  49. xmlns:ogc="http://www.opengis.net/ogc"
  50. xmlns:xlink="http://www.w3.org/1999/xlink"
  51. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  52. <NamedLayer>
  53. <Name>Simple point with stroke</Name>
  54. <UserStyle>
  55. <Title>Default</Title>
  56. <FeatureTypeStyle>
  57. <Rule>
  58. <PolygonSymbolizer>
  59. <Fill>
  60. <CssParameter name="fill">#ffffff</CssParameter>
  61. <CssParameter name="fill-opacity">0.7</CssParameter>
  62. </Fill>
  63. <Stroke>
  64. <CssParameter name="stroke">#33cccc</CssParameter>
  65. <CssParameter name="stroke-opacity">1</CssParameter>
  66. <CssParameter name="stroke-width">2.0</CssParameter>
  67. </Stroke>
  68. </PolygonSymbolizer>
  69. </Rule>
  70. </FeatureTypeStyle>
  71. </UserStyle>
  72. </NamedLayer>
  73. </StyledLayerDescriptor>
  74. `;
  75. const lpisSource = new VectorSource({
  76. format: new GeoJSON({
  77. dataProjection: 'EPSG:5514',
  78. }),
  79. url: (extent) => {
  80. const kulturaKod = 1; // Doesn't seem to work
  81. const proxyPath = window.location.hostname.includes('localhost')
  82. ? 'http://localhost:8085/'
  83. : '/proxy/';
  84. return (
  85. proxyPath +
  86. 'https://gis.lesprojekt.cz/cgi-bin/mapserv?map=/home/dima/maps/foodie/lpis.map' +
  87. '&service=WFS' +
  88. '&VERSION=1.1.0' +
  89. '&REQUEST=GetFeature' +
  90. '&TYPENAME=lpis_borders' +
  91. '&COUNT=100' +
  92. '&outputformat=geojson' +
  93. '&SRSNAME=EPSG:5514' +
  94. `&BBOX=${extent ? extent.join(',') : ''}`
  95. // + `FILTER=&<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:PropertyIsEqualTo><ogc:PropertyName>kultura</ogc:PropertyName><ogc:Literal>${kulturaKod}</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>`
  96. );
  97. //%3Cgml:Box%3E%3Cgml:coordinates%3E${
  98. //extent.join(',')
  99. //}%3C/gml:coordinates%3E%3C/gml:Box%3E%3C/ogc:Filter%3E`;
  100. },
  101. strategy: bboxStrategy,
  102. });
  103. lpisSource.on(
  104. 'featuresloadstart',
  105. () => (this.calcService.lpisLoading = true)
  106. );
  107. lpisSource.on(
  108. 'featuresloadend',
  109. () => (this.calcService.lpisLoading = false)
  110. );
  111. lpisSource.on('featuresloaderror', (evt) => {
  112. this.calcService.lpisLoading = false;
  113. console.warn('error when loading LPIS layer');
  114. console.log(evt);
  115. });
  116. /* Define and update the HsConfig configuration object */
  117. this.hsConfig.update(
  118. {
  119. datasources: [
  120. /* You need to set up Layman in order to use it. See https://github.com/LayerManager/layman */
  121. /*{
  122. title: 'Layman',
  123. url: 'http://localhost:8087',
  124. user: 'anonymous',
  125. type: 'layman',
  126. liferayProtocol: 'https',
  127. },*/
  128. {
  129. title: 'Micka',
  130. url: 'https://www.agrihub.cz/micka/csw',
  131. language: 'eng',
  132. type: 'micka',
  133. },
  134. ],
  135. default_view: new View({
  136. projection: this.sjtskProjection,
  137. center: transform([16.964, 49.248], 'EPSG:4326', 'EPSG:5514'),
  138. zoom: 14,
  139. }),
  140. /* Use hslayers-server if you need to proxify your requests to other services. See https://www.npmjs.com/package/hslayers-server */
  141. proxyPrefix: window.location.hostname.includes('localhost')
  142. ? `${window.location.protocol}//${window.location.hostname}:8085/`
  143. : '/proxy/',
  144. useProxy: true,
  145. panelsEnabled: {
  146. composition_browser: true,
  147. info: false,
  148. saveMap: false,
  149. legend: false,
  150. tripPlanner: false,
  151. },
  152. componentsEnabled: {
  153. basemapGallery: true,
  154. },
  155. assetsPath: 'assets',
  156. symbolizerIcons: [
  157. {name: 'beach', url: '/assets/icons/beach17.svg'},
  158. {name: 'bicycles', url: '/assets/icons/bicycles.svg'},
  159. {name: 'coffee-shop', url: '/assets/icons/coffee-shop1.svg'},
  160. {name: 'mountain', url: '/assets/icons/mountain42.svg'},
  161. {name: 'warning', url: '/assets/icons/warning.svg'},
  162. ],
  163. popUpDisplay: 'hover',
  164. default_layers: [
  165. /* Baselayers */
  166. new Tile({
  167. source: new OSM(),
  168. visible: true,
  169. properties: {
  170. title: 'OpenStreetMap',
  171. base: true,
  172. removable: false,
  173. },
  174. }),
  175. new Tile({
  176. properties: {
  177. title: 'Ortofoto ČÚZK',
  178. base: true,
  179. removable: false,
  180. thumbnail: 'https://www.agrihub.sk/hsl-ng/img/orto.jpg',
  181. },
  182. source: new TileWMS({
  183. url: 'https://geoportal.cuzk.cz/WMS_ORTOFOTO_PUB/WMService.aspx',
  184. params: {
  185. LAYERS: 'GR_ORTFOTORGB',
  186. },
  187. attributions: [
  188. '© <a href="geoportal.cuzk.cz" target="_blank">ČÚZK</a>',
  189. ],
  190. }),
  191. visible: false,
  192. }),
  193. /* Thematic layers */
  194. imageWmsTLayer,
  195. new VectorLayer({
  196. properties: {
  197. title: 'LPIS (WFS)',
  198. synchronize: false,
  199. cluster: false,
  200. inlineLegend: true,
  201. editor: {
  202. editable: false,
  203. },
  204. sld: fieldSld,
  205. popUp: {
  206. attributes: [
  207. 'id_dpb',
  208. 'id_uz',
  209. 'nkod_dpb',
  210. 'kultura',
  211. 'svazitost',
  212. 'vymeram',
  213. ],
  214. },
  215. //path: 'User generated',
  216. },
  217. minZoom: this.calcService.MIN_LPIS_VISIBLE_ZOOM,
  218. opacity: 0.7,
  219. source: lpisSource,
  220. }),
  221. new Tile({
  222. properties: {
  223. title: 'LPIS (WMS)',
  224. queryCapabilities: false,
  225. },
  226. maxZoom: this.calcService.MIN_LPIS_VISIBLE_ZOOM,
  227. source: new TileWMS({
  228. url: 'https://gis.lesprojekt.cz/cgi-bin/mapserv?map=/home/dima/maps/foodie/lpis.map',
  229. params: {
  230. LAYERS: 'lpis_borders', //'lpis_cultures'
  231. INFO_FORMAT: undefined,
  232. FORMAT: 'image/png; mode=8bit',
  233. },
  234. crossOrigin: 'anonymous',
  235. }),
  236. }),
  237. ],
  238. translationOverrides: i18n,
  239. },
  240. 'default'
  241. );
  242. }
  243. }