import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { FeatureCollection } from 'geojson' ; import Feature from 'ol/Feature' ; import GeoJSON from 'ol/format/GeoJSON' ; import LineString from 'ol/geom/LineString' ; import Point from 'ol/geom/Point' ; import Polygon from 'ol/geom/Polygon' ; import Map from 'ol/Map' ; import TileWMS from 'ol/source/TileWMS' ; import { Observable , throwError } from 'rxjs' ; import { catchError , map , take } from 'rxjs/operators' ; import { MangolLayer } from '../../classes/Layer' ; import * as fromMangol from '../../store/mangol.reducers' ; @ Injectable ( { providedIn : 'root' } ) export class FeatureinfoService { geojsonFormat = new GeoJSON ( ) ; constructor ( private store , private http ) { } param layer param m param coordinates getFeatureinfoUrl$ ( layer , m , coordinates ) { return this . store . select ( ( state ) => state . featureinfo . maxFeatures ) . pipe ( take ( 1 ) , map ( ( maxFeatures ) => { const source = < TileWMS > layer . layer . getSource ( ) ; let url = source . getFeatureInfoUrl ( coordinates , m . getView ( ) . getResolution ( ) , m . getView ( ) . getProjection ( ) . getCode ( ) , { INFO_FORMAT : 'application/json' , FEATURE_COUNT : maxFeatures } ) ; if ( url ) { url = url . replace ( '&I=' , '&X=' ) . replace ( '&J=' , '&Y=' ) ; } else { url = null ; } return url ; } ) ) ; } param url param dataProjection param featureProjection getFeatureinfo ( url , dataProjection , featureProjection ) { return this . http . get ( url , { observe : 'body' , responseType : 'json' } ) . pipe ( map ( ( response ) => { const featureCollection = < FeatureCollection < any , any > > response ; let format = new GeoJSON ( ) ; if ( dataProjection !== featureProjection ) { const pseudoGeoJSONFormat = < any > GeoJSON ; format = new pseudoGeoJSONFormat ( { dataProjection : dataProjection , featureProjection : featureProjection } ) ; } return format . readFeatures ( featureCollection ) ; } ) , catchError ( ( error ) => { return throwError ( error ) ; } ) ) ; } }