ol-ishare/info

Functions for working with WMS and WFS

ESM example:

import * as info from 'ol-ishare/info'

// All functions in the info module are accessible as properties of an `info` Object
let url = info.getWfsUrl(owsUrl);

Global example:

// All functions in the info module are accessible as properties of `oli.info`
var url = oli.info.getWfsUrl(owsUrl);

Methods

(inner) infoResultsToHtml(errs, infoLayers, featureCollections) → {String}

Create a HTML String by applying a default info template for each layer from infoLayers and the corresponding features from featureCollections.

import { infoResultsToHtml } from 'ol-ishare/info';
Parameters:
Name Type Description
errs Array.<(Error|null)>

Array containing either null (no error) or Error instance for each infoLayer (in the same order as infoLayers)

infoLayers Array.<ol/layer/Base~BaseLayer>

Layers for which features have been queried

featureCollections Array.<Array.<ol/Feature~Feature>>

An Array containing an Array of features for each infoLayer

Returns:

HTML suitable for display

Type
String

(inner) infoResultToHtml(err, infoLayer, features) → {String}

Create a HTML String by applying a default info template for infoLayer and the corresponding features from features.

import { infoResultToHtml } from 'ol-ishare/info';
Parameters:
Name Type Description
err Error | null

Either null (no error) or Error instance for the infoLayer

infoLayer ol/layer/Base~BaseLayer

Layer for which features have been queried

features Array.<ol/Feature~Feature>

An Array of features for infoLayer

Returns:

HTML suitable for display

Type
String

(inner) wmsGetFeatureInfoReader(text) → {Array.<ol/Feature~Feature>}

Parse WMS GetFeatureInfo response into Array of features, suitable for use in a Promise chain

Parameters:
Name Type Description
text String

String to parse

Throws:

Error if features can't be parsed. Error instance has info property with value of the text that could not be parsed.

Returns:

Array of features parsed from text

Type
Array.<ol/Feature~Feature>

(inner) wfsGetFeatureReader(text) → {Array.<ol/Feature~Feature>}

Parse WFS GetFeature response into Array of features, suitable for use in a Promise chain

Parameters:
Name Type Description
text String

String to parse

Throws:

Error if features can't be parsed. Error instance has info property with value of the text that could not be parsed.

Returns:

Array of features parsed from text

Type
Array.<ol/Feature~Feature>

(inner) getInfoTolerance(defaultTolerance, infoTolerance) → {String}

Gets the info tolerance settings suitable for use as a query string parameter value. If infoTolerance is passed (generally accessed from layerConfig.infoTolerance) then its values will be used, otherwise the defaultTolerance values will be used. If the infoTolerance Object has no properties then the returned value will be undefined and the mapfile values are used.

Parameters:
Name Type Description
defaultTolerance Object

Object with default tolerance and toleranceUnit properties

infoTolerance Object

Object with tolerance and toleranceUnit properties

Returns:

URL parameter value to be associated with the layer

Type
String

(inner) getInfoAtPoint(map, infoLayers, coordinate) → {Promise}

Queries for features at coordinate from each ol/layer/Layer~Layer.

import { getInfoAtPoint } from 'ol-ishare/info';

The info tolerance can be specified for each layer by setting a infoTolerance property of the layer config to an Object with tolerance and toleranceUnit values. For example:

// Only features that are exactly at the point clicked will be returned
layerConfig.infoTolerance = {
  tolerance: 0,
  toleranceUnits: 'PIXELS'
}
Parameters:
Name Type Description
map ol/Map

OpenLayers Map instance

infoLayers Array.<ol/layer/Layer~Layer>

Layers to be queried

coordinate Array.<Number>

Coordinate that will be queried

Returns:

resolves to Promise with {module:ol-ishare/info~InfoResult} argument

Type
Promise

(inner) getInfoLayers(layerGroup) → {Array.<ol/layer/Layer~Layer>}

Get a list of all ol/layer/Layer~Layer instances that should be queried for info based on the layer's config in the profile

import { getInfoLayers } from 'ol-ishare/info';
Parameters:
Name Type Description
layerGroup ol/layer/Group~LayerGroup

Generally the root ol/Map~Map layer group obtained via map.getLayerGroup()

Returns:

List of layers for which info should be fetched

Type
Array.<ol/layer/Layer~Layer>

(inner) getWfsUrl(owsUrl) → {String}

Get a WFS URL based on a base OWS URL

import { getWfsUrl } from 'ol-ishare/info';
Parameters:
Name Type Description
owsUrl String

Base URL for WMS/ WFS services

Returns:

Base WFS URL

Type
String

(inner) getWfsGetFeatureUrl(owsUrl, layerName, outputFormat, filter, params) → {String}

Get a complete WFS GetFeature URL based on a base OWS URL, layerName and optional output format and OGC Filter.

import { getWfsGetFeatureUrl } from 'ol-ishare/info';
Parameters:
Name Type Description
owsUrl String

Base URL for WMS/ WFS services

layerName String

The name of the layer to query

outputFormat String

Optional WFS output format, defaults to GML2

filter Element | String

Optional OpenLayers OGC filter as an XML Element or String

params Object

Optional Object with key/ value pair of params to include in the query string, commonly used for vender parameters such as iShare VIEWPARAMS.

Returns:

Complete WFS GetFeature URL

Type
String

(inner) getFeatureResponse(owsUrl, layerName, filter, params, outputFormatopt) → {Promise}

Make a WFS GetFeature request for features from a given OWS server, layer name, optionally applying a filter.

import { getFeatureText } from 'ol-ishare/info';
Parameters:
Name Type Attributes Default Description
owsUrl String

Base URL for WMS/ WFS services

layerName String

The name of the layer to query

filter Element | String

Optional OpenLayers OGC filter as an XML Element or String

params Object

Optional Object with key/ value pair of params to include in the query string, commonly used for vender parameters such as iShare VIEWPARAMS.

outputFormat String <optional>
'GML2'

OGC standard, or vendor-specific, format in which to return the data

Returns:

resolves to response

Type
Promise

(inner) getFeature(owsUrl, layerName, filter, params) → {Promise}

Make a WFS GetFeature request for features from a given OWS server, layer name, optionally applying a filter.

import { getFeature } from 'ol-ishare/info';
Parameters:
Name Type Description
owsUrl String

Base URL for WMS/ WFS services

layerName String

The name of the layer to query

filter Element | String

Optional OpenLayers OGC filter as an XML Element or String

params Object

Optional Object with key/ value pair of params to include in the query string, commonly used for vender parameters such as iShare VIEWPARAMS.

Returns:

resolves to OpenLayers ol/Feature~Feature objects for data in response

Type
Promise

(inner) getFeatureByValue(owsUrl, layerName, column, value) → {Promise}

Make a WFS GetFeature request for features which match the equalTo filter.

import { getFeatureByValue } from 'ol-ishare/info';
Parameters:
Name Type Description
owsUrl String

Base URL for WMS/ WFS services

layerName String

The name of the layer to query

column String

Name of the column to query

value String

Value to query column for

Returns:

resolve gets {Array<ol/Feature~Feature>} features and reject gets {Error} error

Type
Promise

(package, inner) createFeatureReader(formatClass, testStr) → {function}

Creates a function to read a string of features in a given format

Parameters:
Name Type Description
formatClass function

Class constructor used to create a reader

testStr String

String that must be in the text that is parsed for the text to be considered a valid feature collection (commonly 'FeatureCollection' or ':gml')

Returns:

Function that accepts a single text argument to read features from, throws an exception if features can't be parsed. Suitable for use in a Promise chain

Type
function

(inner) getInfo(layer, filteropt, paramsopt) → {Promise}

Requests features (that match a WFS filter) for the specified ol/layer/Layer~Layer. You probably want getInfoForExtent (when working with a map) or getFeatureResponse (when not). Also be aware that requests for e.g. boundary layers for an entire country are likely to be slow and memory-intensive for the WFS service.

import { getInfo } from 'ol-ishare/info';
Parameters:
Name Type Attributes Default Description
layer ol/layer/Layer~Layer

Layer to be queried - expected to be WFS- or WMS-based

filter ol/format/filter <optional>
None

OpenLayers Filter object to apply to the layer. (Geometry names will be set automatically.)

params Object <optional>

Additional key-values to pass to WFS requests

Returns:

Returns a Promise for each infoLayer resolving to response from WFS service

Type
Promise

(inner) getInfoForExtent(layer, extent, filteropt, paramsopt) → {Promise}

Requests features within specified extent for the specified ol/layer/Layer~Layer. Typically used with current visible extent of map, or the extent of the entire iShare layer/profile. Without specifying an OUTPUTFORMAT parameter, get response text and run through info.wfsGetFeatureReader to get OpenLayers Features.

import { getInfoForExtent } from 'ol-ishare/info';
Parameters:
Name Type Attributes Default Description
layer ol/layer/Layer~Layer

Layer to be queried - expected to be WFS- or WMS-based

extent ol/extent

Array of extent coordinates

filter ol/format/filter <optional>
None

OpenLayers Filter object to apply to the layer, this will be applied as well as a filter for the extent

params Object <optional>

Additional key-values to pass to WFS requests

Returns:

Returns a Promise resolving to Fetch.Response from WFS service

Type
Promise

Type Definitions

InfoResult

Properties:
Name Type Description
errors Array.<(Error|null)>

Array containing either null (no error) or Error instance for each infoLayer (in the same order as infoLayers)

infoLayers Array.<ol/layer/Layer~Layer>

Info layers passed to getInfoAtPoint

collections Array.<FeatureCollection>

Result GeoJSON FeatureCollections