Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Fix max results message #9607

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/query/MapQuerent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2024 Camptocamp SA
// Copyright (c) 2017-2025 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -225,7 +225,7 @@ export class MapQuerent {
console.assert(dataSource);
const querentResultItem = response[id];
const features = querentResultItem.features;
const limit = querentResultItem.limit;
const featuresCount = querentResultItem.featuresCount;
const tooManyResults = querentResultItem.tooManyFeatures === true;
const totalFeatureCount = querentResultItem.totalFeatureCount;
const requestPartners = querentResultItem.requestPartners;
Expand Down Expand Up @@ -299,7 +299,7 @@ export class MapQuerent {
features: featuresByType,
id: id,
label: label,
limit: limit,
featuresCount: featuresCount,
pending: false,
tooManyResults: tooManyResults,
totalFeatureCount: totalFeatureCount,
Expand Down
24 changes: 12 additions & 12 deletions src/query/Querent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2017-2024 Camptocamp SA
// Copyright (c) 2017-2025 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -46,7 +46,7 @@ import olSourceImageWMS from 'ol/source/ImageWMS';
/**
* @typedef {Object} QuerentResultItem
* @property {import('ol/Feature').default<import('ol/geom/Geometry').default>[]} features
* @property {number} limit
* @property {number} featuresCount
* @property {boolean} [tooManyFeatures]
* @property {number} [totalFeatureCount]
* @property {string []} [requestPartners] All datasources requested in the same request
Expand Down Expand Up @@ -403,8 +403,9 @@ export class Querent {
'version': '1.0.0',
});
}
const limit = formatWFS.readFeatures(response.data).length;
const tooManyFeatures = totalFeatureCount > limit;
const featuresCount = formatWFS.readFeatures(response.data).length;
const tooManyFeatures =
totalFeatureCount > 0 ? totalFeatureCount > featuresCount : maxFeatures <= featuresCount;
/** @type {string[]} */
const datasourceNames = [];
for (const dataSource of dataSources) {
Expand All @@ -418,13 +419,13 @@ export class Querent {
this.setUniqueIds_(features, dataSource.id);
hash[dataSourceId] = {
features,
limit,
featuresCount: featuresCount,
tooManyFeatures,
totalFeatureCount,
};
}
Object.values(hash).forEach(function (value, index) {
value.limit = limit;
value.featuresCount = featuresCount;
value.tooManyFeatures = tooManyFeatures;
value.requestPartners = datasourceNames;
});
Expand Down Expand Up @@ -456,7 +457,7 @@ export class Querent {
this.setUniqueIds_(features, dataSource.id);
hash[dataSourceId] = {
features,
limit,
featuresCount: limit,
tooManyFeatures,
totalFeatureCount,
};
Expand All @@ -468,7 +469,7 @@ export class Querent {
this.setUniqueIds_(features, dataSource.id);
hash[dataSourceId] = {
features,
limit,
featuresCount: limit,
};
}
}
Expand Down Expand Up @@ -740,7 +741,6 @@ export class Querent {
// If we do not need to count features first, then proceed with
// an normal WFS GetFeature request.

options.queryCountFirst = false;
const canceler = this.registerCanceler_();
/** @type {angular.IPromise<QuerentResult>} */
const countPromise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -877,7 +877,7 @@ export class Querent {
const promises = [];

// The 'limit' option is mandatory in the querent service
const FEATURE_COUNT = options.limit;
const limit = options.limit;
const map = options.map;
const view = map.getView();
const resolution = view.getResolution();
Expand Down Expand Up @@ -987,7 +987,7 @@ export class Querent {
// (4) Build query url, then launch
const wmsGetFeatureInfoUrl = wmsSource.getFeatureInfoUrl(coordinate, resolution, projCode, {
// Without extern, quoting is necessary
'FEATURE_COUNT': FEATURE_COUNT,
'FEATURE_COUNT': limit,
'INFO_FORMAT': INFO_FORMAT,
});
if (!wmsGetFeatureInfoUrl) {
Expand All @@ -1001,7 +1001,7 @@ export class Querent {
})
.then(
/** @type {function(angular.IHttpResponse<Document|Element|string>|number): QuerentResult} */
this.handleQueryResult_.bind(this, dataSources, FEATURE_COUNT, false),
this.handleQueryResult_.bind(this, dataSources, limit, false),
),
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/query/gridComponent.html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2024 Camptocamp SA
// Copyright (c) 2024-2025 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -62,9 +62,12 @@ export default `<div class="gmf-displayquerygrid panel" ng-show="ctrl.active">
>
<div class="col-md-5 my-auto">
<span ng-if="ctrl.hasOneWithTooManyResults_()" class="gmf-query-grid-too-many text-warning"
>{{'Only' | translate}} {{ctrl.sumOfFeatures}} {{'of' | translate}} {{ctrl.sumOfAvailableResults}}
><span ng-if="ctrl.sumOfAvailableResults >= 0">{{'Only' | translate}} {{ctrl.sumOfFeatures}} {{'of' | translate}} {{ctrl.sumOfAvailableResults}}
{{'results displayed, as the maximum number is reached. Please refine your query.' | translate
}}</span
><span ng-if="ctrl.sumOfAvailableResults < 0">{{'One of the queries returns the maximum number of results, but probably not all the results are displayed. Please refine your query.' | translate}}
</span
></span
>
</div>
<div class="col-md-7" class="pull-right">
Expand Down
13 changes: 9 additions & 4 deletions src/query/gridComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ QueryGridController.$inject = [
];
// The MIT License (MIT)
//
// Copyright (c) 2016-2024 Camptocamp SA
// Copyright (c) 2016-2025 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -368,7 +368,12 @@ QueryGridController.prototype.updateData_ = function () {
this.sumOfFeatures += source.features.length;
}
if (!source.requestPartners || !source.requestPartners.some((label) => countedSources.includes(label))) {
this.sumOfAvailableResults += source.totalFeatureCount;
if (source.totalFeatureCount < 0 || this.sumOfAvailableResults < 0) {
// At least one query without any count => we can't display the total count
this.sumOfAvailableResults = -1;
} else {
this.sumOfAvailableResults += source.totalFeatureCount;
}
}
countedSources.push(source.label);
});
Expand Down Expand Up @@ -520,7 +525,7 @@ QueryGridController.prototype.getMergedSource_ = function (source, mergedSources
features: [],
id: mergeSourceId,
label: mergeSourceId,
limit: 0,
featuresCount: 0,
//the sum of the obtained results of the query is computed later
pending: false,
tooManyResults: false,
Expand All @@ -547,7 +552,7 @@ QueryGridController.prototype.getMergedSource_ = function (source, mergedSources
? mergeSource.totalFeatureCount + source.totalFeatureCount
: source.totalFeatureCount;
}
mergeSource.limit += source.limit;
mergeSource.featuresCount += source.featuresCount;
}
return mergeSource;
};
Expand Down
5 changes: 2 additions & 3 deletions src/statemanager/WfsPermalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WfsPermalinkService.$inject = [
];
// The MIT License (MIT)
//
// Copyright (c) 2016-2024 Camptocamp SA
// Copyright (c) 2016-2025 Camptocamp SA
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -42,8 +42,7 @@ import olFormatWFS from 'ol/format/WFS';
* @property {Feature<import('ol/geom/Geometry').default>[]} features The matching features for this source.
* @property {number|string} id Identifier (can be not unique).
* @property {string} label Label.
* @property {number} [limit] The maximum number of features that can be returned for a query with this
* source.
* @property {number} [featuresCount] The total number of features that corresponds to the query.
* @property {boolean} pending Is the request for this source still ongoing?
* @property {boolean} [tooManyResults] If the last query for this source would return more features than the
* configured limit.
Expand Down
Loading