Skip to content

Commit

Permalink
Merge pull request #44 from camptocamp/wfs_check_startIndex
Browse files Browse the repository at this point in the history
[WFS] Add startIndex Support in URL generation and supportsStartIndex Method
  • Loading branch information
ronitjadhav authored May 14, 2024
2 parents a0aadb6 + aea1b16 commit ddbb5b0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/wfs/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,11 @@ describe('WfsEndpoint', () => {
);
});
});

describe('#supportsStartIndex', () => {
it('returns true if the WFS version is 2.0.0 or higher', async () => {
await endpoint.isReady();
expect(endpoint.supportsStartIndex()).toBeTruthy();
});
});
});
24 changes: 21 additions & 3 deletions src/wfs/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ export default class WfsEndpoint {
return !!this._getJsonCompatibleOutputFormat(featureType);
}

/**
* Returns true if the WFS service supports the startIndex parameter.
*/
supportsStartIndex(): boolean {
if (!this._version) return false;
return this._version >= '2.0.0';
}

/**
* Returns a URL that can be used to query features from this feature type.
* @param featureType
Expand All @@ -245,6 +253,7 @@ export default class WfsEndpoint {
* @property [options.outputCrs] if unspecified, this will be the data native projection
* @property [options.extent] an extent to restrict returned objects
* @property [options.extentCrs] if unspecified, `extent` should be in the data native projection
* @property [options.startIndex] if the service supports it, this will be the index of the first feature to return
* @returns Returns null if endpoint is not ready
*/
getFeatureUrl(
Expand All @@ -256,13 +265,21 @@ export default class WfsEndpoint {
outputCrs?: CrsCode;
extent?: BoundingBox;
extentCrs?: CrsCode;
startIndex?: number;
}
) {
if (!this._featureTypes) {
return null;
}
const { maxFeatures, asJson, outputFormat, outputCrs, extent, extentCrs } =
options || {};
const {
maxFeatures,
asJson,
outputFormat,
outputCrs,
extent,
extentCrs,
startIndex,
} = options || {};
const internalFeatureType = this._getFeatureTypeByName(featureType);
if (!internalFeatureType) {
throw new Error(
Expand Down Expand Up @@ -296,7 +313,8 @@ export default class WfsEndpoint {
undefined,
outputCrs,
extent,
extentCrs
extentCrs,
startIndex
);
}
}
19 changes: 19 additions & 0 deletions src/wfs/url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@ describe('WFS url helpers', () => {
'http://example.com/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my%3Atype&SRSNAME=EPSG%3A2154&BBOX=10%2C20%2C100%2C200%2CEPSG%3A3857'
);
});
it('generates a correct URL (v2.0.0, startIndex set)', () => {
expect(
generateGetFeatureUrl(
'http://example.com/wfs',
'2.0.0',
'my:type',
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
10
)
).toBe(
'http://example.com/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=my%3Atype&STARTINDEX=10'
);
});
});

describe('generateDescribeFeatureTypeUrl', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/wfs/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WfsVersion } from './model.js';
* @param [outputCrs] if unspecified, this will be the data native projection
* @param [extent] an extent to restrict returned objects
* @param [extentCrs] if unspecified, `extent` should be in the data native projection
* @param [startIndex] if the service supports it, this will be the index of the first feature to return
*/
export function generateGetFeatureUrl(
serviceUrl: string,
Expand All @@ -26,7 +27,8 @@ export function generateGetFeatureUrl(
hitsOnly?: boolean,
outputCrs?: CrsCode,
extent?: BoundingBox,
extentCrs?: CrsCode
extentCrs?: CrsCode,
startIndex?: number
) {
const typeParam = version === '2.0.0' ? 'TYPENAMES' : 'TYPENAME';
const countParam = version === '2.0.0' ? 'COUNT' : 'MAXFEATURES';
Expand All @@ -51,6 +53,9 @@ export function generateGetFeatureUrl(
const extentJoined = extent.join(',');
newParams.BBOX = extentCrs ? `${extentJoined},${extentCrs}` : extentJoined;
}
if (startIndex) {
newParams.STARTINDEX = startIndex.toString(10);
}

return setQueryParams(serviceUrl, newParams);
}
Expand Down

0 comments on commit ddbb5b0

Please sign in to comment.