Skip to content

Commit

Permalink
Converted HoverController CancelToken to AbortController
Browse files Browse the repository at this point in the history
  • Loading branch information
sronveaux committed Sep 20, 2024
1 parent bcf6a5e commit 73a2a0d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/components/ol/HoverController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class HoverController {
conf = null;
timerHandle = null;
activeOverlayId = null;
pendingRequestsCancelSrc = null;
pendingRequestsAbortCtrl = null;

/**
* Initializes the map hover functionality:
Expand Down Expand Up @@ -71,9 +71,9 @@ export default class HoverController {
me.timerHandle = null;
}

if (me.pendingRequestsCancelSrc) {
me.pendingRequestsCancelSrc.cancel();
me.pendingRequestsCancelSrc = null;
if (me.pendingRequestsAbortCtrl) {
me.pendingRequestsAbortCtrl.abort();
me.pendingRequestsAbortCtrl = null;
}

if (me.activeOverlayId) {
Expand All @@ -95,16 +95,16 @@ export default class HoverController {
const map = me.map;
const pixel = event.pixel;
const coordinate = event.coordinate;
const cancelToken = axios.CancelToken;
const abortController = new AbortController();
const featureInfos = [];
let resetTooltip = true;

// Cancel pending requests and create a new cancel token source which corresponds
// to all async requests sent in this iteration.
if (me.pendingRequestsCancelSrc) {
me.pendingRequestsCancelSrc.cancel();
if (me.pendingRequestsAbortCtrl) {
me.pendingRequestsAbortCtrl.abort();
}
me.pendingRequestsCancelSrc = cancelToken.source();
me.pendingRequestsAbortCtrl = abortController;

// Acquire features for all layers.
map.getLayers().forEach((layer) => {
Expand All @@ -114,7 +114,7 @@ export default class HoverController {
const source = layer.getSource();
if (source instanceof TileWmsSource || source instanceof ImageWMSSource) {
resetTooltip = false;
me.getWMSFeaturesAsync(map, layer, coordinate, me.pendingRequestsCancelSrc)
me.getWMSFeaturesAsync(map, layer, coordinate, me.pendingRequestsAbortCtrl)
.then(function (features) {
featureInfos.push(...features.map((feat) => {
return { layer, feature: feat };
Expand Down Expand Up @@ -162,10 +162,10 @@ export default class HoverController {
* @param {ol.Map} map OpenLayers map.
* @param {ol.layer.Tile | ol.layer.Image} layer The layer to acquire the features for.
* @param {ol.Coordinate} coordinate The coordinate in map projection.
* @param {axios.CancelTokenSource} cancelTokenSrc An optional cancel token to abort the request.
* @param {AbortController} abortCtrl An optional abort controller to abort the request.
* @returns {Promise<Array<ol.Feature>>}
*/
getWMSFeaturesAsync (map, layer, coordinate, cancelTokenSrc) {
getWMSFeaturesAsync (map, layer, coordinate, abortCtrl) {
const view = map.getView();
return new Promise((resolve, reject) => {
const url = layer.getSource().getFeatureInfoUrl(
Expand All @@ -183,7 +183,7 @@ export default class HoverController {
const request = {
method: 'GET',
url,
cancelToken: cancelTokenSrc?.token
signal: abortCtrl?.signal
};
axios(request)
.then(response => {
Expand Down

0 comments on commit 73a2a0d

Please sign in to comment.