From ee736182531c71b0e12395651940a1d8f926b106 Mon Sep 17 00:00:00 2001 From: Vlad Medved Date: Mon, 23 Jan 2023 18:29:56 +0300 Subject: [PATCH] remove unsupported keys --- lib/index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 8fbc22c..b95c918 100644 --- a/lib/index.js +++ b/lib/index.js @@ -633,7 +633,7 @@ MapboxGeocoder.prototype = { 'countries', 'types', 'language', - 'mode', // permanent so for actual for both v5 and v6 + 'mode', 'autocomplete', 'worldview' ]; @@ -686,13 +686,6 @@ MapboxGeocoder.prototype = { this.options.version === 'v6' ? { longitude: coords[0], latitude: coords[1]} : { query: coords }, {limit: 1 } ); - - // Remove config options not supported by the reverseGeocoder - ['proximity', 'autocomplete', 'fuzzyMatch', 'bbox'].forEach(function(key) { - if (key in config) { - delete config[key] - } - }); } break; case GEOCODE_REQUEST_TYPE.FORWARD: { // Ensure that any reverse geocoding looking request is cleaned up @@ -710,6 +703,18 @@ MapboxGeocoder.prototype = { } break; } + // Remove config options not supported by the reverseGeocoder and v5 keys if v6 mode chosen + const unsupportedKeys = [ + ...(requestType === GEOCODE_REQUEST_TYPE.REVERSE ? ['proximity', 'autocomplete', 'fuzzyMatch', 'bbox'] : []), + ...(this.options.version === 'v6' ? v5Keys : []) + ]; + + unsupportedKeys.forEach(function(key) { + if (key in config) { + delete config[key] + } + }); + return config; },