Example #1
0
 // Gets requested metric data
 getMetrics(metric?: String) : Observable <Metric[]>{
   var metricsURL = 'http://service.iris.edu/mustang/metrics/1/query?output=jsonp&nodata=200';
   if (metric)
     metricsURL += metric;
   return this.http.jsonp(metricsURL,"callback")
     .pipe(
       map(this.mapMetrics),
       catchError((error: Error) => {
         return observableThrowError(error);
       })
   );
 }
 search(query): Promise<SearchResult[]> {
   const params = new HttpParams() //
     .set('name', query) //
     .set('minScore', '0.7') //
     .set('itemsPerPage', '10') //
     .set('outputSRS', '4326') //
     .set('embed', '0') //
     .set('outputStyle', 'detail') //
     .set('outputFormat', 'jsonx') //
     .set('callback', 'JSONP_CALLBACK') //
     .toString();
   return this.http.jsonp(
     `https://apps.gov.bc.ca/pub/bcgnws/names/soundlike?${params}`,
     'jsonp12345'
   ).toPromise().then(data => {
     const matches: SearchResult[] = [];
     const found = false;
     const features = data['features'];
     if (features) {
       for (const feature of features) {
         const props = feature.properties;
         const name = props.name;
         let label = name;
         let featureType = props.featureType;
         if (featureType) {
           const parenStartIndex = featureType.indexOf('(');
           const parenEndIndex = featureType.indexOf(')');
           if (parenStartIndex !== -1 && parenEndIndex > parenStartIndex) {
             featureType = featureType.substring(0, parenStartIndex) + featureType.substring(parenEndIndex + 1);
           }
           label += ' (' + featureType + ')';
         }
         label += '  ' + props.feature.relativeLocation;
         matches.push(new SearchResult(
           props['uri'],
           label,
           props['featurePoint']
         ));
       }
     }
     return matches;
   });
 }
 jsonp<TResponseBody>(url: string, callbackParam: string): Observable<TResponseBody> {
     return this.httpClient.jsonp<TResponseBody>(url, callbackParam);
 }