@@ -47,13 +49,13 @@
- import { WfsEndpoint } from '@camptocamp/ogc-client';
+import { WfsEndpoint } from '@camptocamp/ogc-client';
- new WfsEndpoint("https://my.server.org/ows")
- .isReady()
- .then(
- (endpoint) => console.log(endpoint.getFeatureTypes())
- )
+new WfsEndpoint("https://my.server.org/ows")
+ .isReady()
+ .then(
+ (endpoint) => console.log(endpoint.getFeatureTypes())
+ )
@@ -126,23 +128,12 @@
-
- No WMTS parsing:
- alternatives already exist, such as the OpenLayers
- WMTS Capabilities
- class (example)
-
- -
- No GML geometry parsing: again,
+ No GML geometry parsing: the
alternatives do existOpenLayers GML parser
+ offers extensive support of the GML format
@@ -153,13 +144,13 @@
- import { WmsEndpoint } from '@camptocamp/ogc-client';
+import { WmsEndpoint } from '@camptocamp/ogc-client';
- async function readExtent() {
- const endpoint = await new WmsEndpoint('https://my.server.org/ows').isReady();
- const layer = endpoint.getLayerByName();
- const extent = layer.boundingBoxes['EPSG:4326'];
- }
@@ -169,15 +160,15 @@
- import { WfsEndpoint } from '@camptocamp/ogc-client';
-
- async function getFeatureUrl() {
- const endpoint = await new WfsEndpoint('https://my.server.org/ows').isReady();
- const url = endpoint.getFeatureUrl('my:featureType', {
- asJson: true,
- maxFeature: 1000
- });
- }
@@ -187,13 +178,57 @@
- import { OgcApiEndpoint } from '@camptocamp/ogc-client';
+import { OgcApiEndpoint } from '@camptocamp/ogc-client';
+
+async function getFirstTenRecords() {
+ const endpoint = await new OgcApiEndpoint('https://my.server.org/main')
+ const firstCollection = (await endpoint.recordCollections)[0];
+ return endpoint.getCollectionItems(firstCollection, 10, 0);
+}
+
+
+
+
+ Add a WMTS layer to an
+ OpenLayers map
+
- async function getFirstTenRecords() {
- const endpoint = await new OgcApiEndpoint('https://my.server.org/main')
- const firstCollection = (await endpoint.recordCollections)[0];
- return endpoint.getCollectionItems(firstCollection, 10, 0);
- }
+
+
+import TileLayer from 'ol/layer/Tile';
+import WMTS from 'ol/source/WMTS';
+import { WmtsEndpoint } from '@camptocamp/ogc-client';
+
+// create the OpenLayers map
+// ...
+
+async function addWmtsLayer() {
+ const endpoint = await new WmtsEndpoint('https://my.server.org/wmts').isReady();
+ const layer = endpoint.getLayers()[0];
+ const matrixSet = layer.matrixSets[0];
+ const tileGrid = await endpoint.getOpenLayersTileGrid(
+ layer.name,
+ matrixSet.identifier
+ );
+ const resourceUrl = layer.resourceUrls[0];
+ const dimensions = endpoint.getDefaultDimensions(layer.name);
+ const layer = new TileLayer({
+ source: new WMTS({
+ layer: layer.name,
+ style: layer.defaultStyle,
+ matrixSet: matrixSet.identifier,
+ format: resourceUrl.format,
+ url: resourceUrl.url,
+ requestEncoding: resourceUrl.encoding,
+ tileGrid,
+ projection: matrixSet.crs,
+ dimensions,
+ }),
+ });
+ openLayersMap.addLayer(layer);
+}
diff --git a/app/src/api-utils.js b/app/src/api-utils.js
index 157a8f7..93df5b1 100644
--- a/app/src/api-utils.js
+++ b/app/src/api-utils.js
@@ -27,6 +27,8 @@ export function formatTypeToString(typeObj) {
switch (typeObj.type || typeObj) {
case 'Array':
return `${subType}[]`;
+ case 'Record':
+ return `Record`;
case 'Response':
return `[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)`;
case 'Promise':
diff --git a/app/src/components/wmts/WmtsLayerInfo.vue b/app/src/components/wmts/WmtsLayerInfo.vue
index c93ed67..1241745 100644
--- a/app/src/components/wmts/WmtsLayerInfo.vue
+++ b/app/src/components/wmts/WmtsLayerInfo.vue
@@ -44,10 +44,39 @@ import TileLayer from 'ol/layer/Tile';
import WMTS from 'ol/source/WMTS';
import proj4 from 'proj4';
import { register } from 'ol/proj/proj4';
+import WmtsEndpoint from '../../../../src/wmts/endpoint';
// this is necessary for tile reprojection to work
register(proj4);
+async function addWmtsLayer(olMap) {
+ const endpoint = await new WmtsEndpoint(
+ 'https://basemap.at/wmts/1.0.0/WMTSCapabilities.xml'
+ ).isReady();
+ const layer = endpoint.getLayers()[0];
+ const matrixSetLink = layer.matrixSets[0];
+ const tileGrid = await endpoint.getOpenLayersTileGrid(
+ layer.name,
+ matrixSetLink.identifier
+ );
+ const resourceUrl = layer.resourceUrls[0];
+ const dimensions = endpoint.getDefaultDimensions(layer.name);
+ const olLayer = new TileLayer({
+ source: new WMTS({
+ layer: layer.name,
+ style: layer.defaultStyle,
+ matrixSet: matrixSetLink.identifier,
+ format: resourceUrl.format,
+ url: resourceUrl.url,
+ requestEncoding: resourceUrl.encoding,
+ tileGrid,
+ projection: matrixSetLink.crs,
+ dimensions,
+ }),
+ });
+ olMap.addLayer(olLayer);
+}
+
export default {
name: 'WmtsLayerInfo',
components: { InfoList },
@@ -95,22 +124,23 @@ export default {
} else {
this.olMap.getLayers().pop();
}
- const resourceUrl = this.layer.resourceUrls[0];
- const dimensions = this.endpoint.getDefaultDimensions(this.layer.name);
- const layer = new TileLayer({
- source: new WMTS({
- layer: this.layer.name,
- style: this.selectedStyle,
- matrixSet: matrixSetLink.identifier,
- format: resourceUrl.format,
- url: resourceUrl.url,
- requestEncoding: resourceUrl.encoding,
- tileGrid,
- projection: matrixSetLink.crs,
- dimensions,
- }),
- });
- this.olMap.addLayer(layer);
+ // const resourceUrl = this.layer.resourceUrls[0];
+ // const dimensions = this.endpoint.getDefaultDimensions(this.layer.name);
+ // const layer = new TileLayer({
+ // source: new WMTS({
+ // layer: this.layer.name,
+ // style: this.selectedStyle,
+ // matrixSet: matrixSetLink.identifier,
+ // format: resourceUrl.format,
+ // url: resourceUrl.url,
+ // requestEncoding: resourceUrl.encoding,
+ // tileGrid,
+ // projection: matrixSetLink.crs,
+ // dimensions,
+ // }),
+ // });
+ // this.olMap.addLayer(layer);
+ addWmtsLayer(this.olMap);
},
},
},
diff --git a/app/src/data/api.js b/app/src/data/api.js
index d92605f..53b8a57 100644
--- a/app/src/data/api.js
+++ b/app/src/data/api.js
@@ -243,6 +243,93 @@ available layers, bounding boxes etc. Layer name is case sensitive.`,
},
],
},
+ {
+ name: 'WmtsEndpoint',
+ type: 'Class',
+ constructor: {
+ params: [{ name: 'url', type: 'string' }],
+ description: `Creates a new WMTS endpoint; wait for the \`isReady()\` promise before using the endpoint methods.`,
+ },
+ methods: [
+ {
+ name: 'isReady',
+ description: `Resolves when the endpoint is ready to use. Returns the same endpoint object for convenience.`,
+ params: [],
+ return: { type: 'Promise', subType: 'WmtsEndpoint' },
+ },
+ {
+ name: 'getServiceInfo',
+ description: `Returns the service info.`,
+ params: [],
+ return: { type: 'WmtsEndpointInfo' },
+ },
+ {
+ name: 'getLayers',
+ description: `Returns the layers advertised in the endpoint.`,
+ params: [],
+ return: { type: 'Array', subType: 'WmtsLayer' },
+ },
+ {
+ name: 'getMatrixSets',
+ description: `Returns the matrix sets available for that endpoint. Each matrix set contains a list of tile matrices
+as well as a supported CRS.`,
+ params: [],
+ return: { type: 'Array', subType: 'WmtsMatrixSet' },
+ },
+ {
+ name: 'getLayerByName',
+ description: `Returns a layer object based on its name.`,
+ params: [{ name: 'name', type: 'string' }],
+ return: { type: 'WmtsLayer' },
+ },
+ {
+ name: 'getMatrixSetByIdentifier',
+ description: `Returns a matrix set object based on its identifier.`,
+ params: [{ name: 'identifier', type: 'string' }],
+ return: { type: 'WmtsMatrixSet' },
+ },
+ {
+ name: 'getLayerResourceUrl',
+ description: `Returns a layer resource info. If no type hint is specified, the first resource will be returned. A resource
+info contains a URL as well as an image format and a request encoding (KVP or REST).`,
+ params: [
+ { name: 'layerName', type: 'string' },
+ { name: 'formatHint', type: 'MimeType', optional: true },
+ ],
+ return: { type: 'LayerResourceUrl' },
+ },
+ {
+ name: 'getTileUrl',
+ description: `Generates a tile URL for a layer and a set of parameters.`,
+ params: [
+ { name: 'layerName', type: 'string' },
+ { name: 'styleName', type: 'string' },
+ { name: 'matrixSetName', type: 'string' },
+ { name: 'tileMatrix', type: 'string' },
+ { name: 'tileRow', type: 'number' },
+ { name: 'tileCol', type: 'number' },
+ { name: 'outputFormat', type: 'MimeType' },
+ ],
+ return: { type: 'string' },
+ },
+ {
+ name: 'getDefaultDimensions',
+ description: `Return an object with all defined dimensions for the layer, as well as their default values.`,
+ params: [{ name: 'layerName', type: 'string' }],
+ return: { type: 'Record', subType: 'LayerDimensionValue' },
+ },
+ {
+ name: 'getOpenLayersTileGrid',
+ description: `Creates a \`WMTSTileGrid\` instance from the [\`ol\` package](https://www.npmjs.com/package/ol), for a given layer. Optionally, a matrix set
+ can be provided. Will return \`null\` if the \`ol\` package is not present (as it is considered an optional peer dependency).`,
+ params: [
+ { name: 'layerName', type: 'string' },
+ { name: 'matrixSetIdentifier', type: 'string', optional: true },
+ ],
+ return: { type: 'WMTSTileGrid' },
+ },
+ ],
+ },
{
name: 'useCache',
type: 'Function',
diff --git a/app/src/data/examples.js b/app/src/data/examples.js
deleted file mode 100644
index 20fafb1..0000000
--- a/app/src/data/examples.js
+++ /dev/null
@@ -1,38 +0,0 @@
-const EXAMPLES = [
- {
- description: 'Read a WMS layer extent',
- code: `import { WmsEndpoint } from '@camptocamp/ogc-client';
-
-async function readExtent() {
- const endpoint = await new WmsEndpoint('https://my.server.org/ows').isReady()
- const layer = endpoint.getLayerByName();
- const extent = layer.boundingBoxes['EPSG:4326'];
- return extent;
-}`,
- },
- {
- description: 'Compute a WFS GetFeature url',
- code: `import { WfsEndpoint } from '@camptocamp/ogc-client';
-
-async function getFeatureUrl() {
- const endpoint = await new WfsEndpoint('https://my.server.org/ows').isReady()
- const url = endpoint.getFeatureUrl('my:featureType', {
- asJson: true,
- maxFeature: 1000
- });
- return url;
-}`,
- },
- {
- description: 'Query the first 10 items of an OGC API Records collection',
- code: `import { OgcApiEndpoint } from '@camptocamp/ogc-client';
-
-async function getFirstTenRecords() {
- const endpoint = await new OgcApiEndpoint('https://my.server.org/main')
- const firstCollection = (await endpoint.recordCollections)[0];
- return endpoint.getCollectionItems(firstCollection, 10, 0);
-}`,
- },
-];
-
-export default EXAMPLES;
diff --git a/src/wmts/endpoint.ts b/src/wmts/endpoint.ts
index 1e92f1d..bf7ca3e 100644
--- a/src/wmts/endpoint.ts
+++ b/src/wmts/endpoint.ts
@@ -185,17 +185,4 @@ export default class WmtsEndpoint {
buildOpenLayersTileGrid(matrixSet, matrixSetLink.limits)
);
}
-
- /**
- * Needed for an OL layer
- * - urls: string[]
- * - matrix set: string
- * - format: string
- * - projection: string
- * - request encoding: string
- * - tile grid: extent, minimum zoom, origins (one [x,y] per zoom level), resolutions
- * - style: string
- * - dimensions: object with dimension names -> values
- * - global: boolean, true if the matrix set covers the whole world
- */
}