Skip to content

Commit

Permalink
for reverseGeocode, pass through apikey and token
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinr committed Apr 6, 2022
1 parent fa26967 commit 6815c5a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/Tasks/ReverseGeocodeSpec.js
Expand Up @@ -105,5 +105,25 @@ describe('L.esri.ReverseGeocode', function () {

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleFrenchResponse);
});

it('should pass through a token', function (done) {
var request = L.esri.Geocoding.reverseGeocode({ token: 'testToken' }).latlng([48.8583, 2.2945]).run(function (error, result, response) {
done();
});

expect(request.url).to.contain('token=testToken');

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleResponse);
});

it('should pass through an apikey', function (done) {
var request = L.esri.Geocoding.reverseGeocode({ apikey: 'testApiKey' }).latlng([48.8583, 2.2945]).run(function (error, result, response) {
done();
});

expect(request.url).to.contain('token=testApiKey');

request.respond(200, { 'Content-Type': 'text/plain; charset=utf-8' }, sampleResponse);
});
});
/* eslint-disable handle-callback-err */
9 changes: 8 additions & 1 deletion src/Tasks/ReverseGeocode.js
Expand Up @@ -13,7 +13,8 @@ export var ReverseGeocode = Task.extend({
setters: {
distance: 'distance',
language: 'langCode',
intersection: 'returnIntersection'
intersection: 'returnIntersection',
apikey: 'apikey'
},

initialize: function (options) {
Expand All @@ -29,6 +30,12 @@ export var ReverseGeocode = Task.extend({
},

run: function (callback, context) {
if (this.options.token) {
this.params.token = this.options.token;
}
if (this.options.apikey) {
this.params.token = this.options.apikey;
}
return this.request(function (error, response) {
var result;

Expand Down

0 comments on commit 6815c5a

Please sign in to comment.