Make MapboxVector layer work in more access key scenarios

This commit is contained in:
Andreas Hocevar
2021-11-02 20:45:30 +01:00
parent d1930d4a3f
commit cbac16e21f
2 changed files with 64 additions and 9 deletions

View File

@@ -80,14 +80,20 @@ describe('ol/layer/MapboxVector', () => {
},
{
url: 'https://example.com/source/{z}/{x}/{y}.pbf',
expected: 'https://example.com/source/{z}/{x}/{y}.pbf',
expected: 'https://example.com/source/{z}/{x}/{y}.pbf?token=test-token',
},
{
url: 'https://example.com/source/{z}/{x}/{y}.pbf?foo=bar',
expected:
'https://example.com/source/{z}/{x}/{y}.pbf?foo=bar&token=test-token',
},
];
const token = 'test-token';
const tokenParam = 'token';
for (const c of cases) {
it(`works for ${c.url}`, () => {
expect(normalizeSourceUrl(c.url, token)).to.be(c.expected);
expect(normalizeSourceUrl(c.url, token, tokenParam)).to.be(c.expected);
});
}
});
@@ -116,4 +122,22 @@ describe('ol/layer/MapboxVector', () => {
});
});
});
describe('Access token', function () {
it('applies correct access token from access_token', function () {
const layer = new MapboxVectorLayer({
styleUrl: 'mapbox://styles/mapbox/streets-v7',
accessToken: '123',
});
expect(layer.accessToken).to.be('123');
expect(layer.accessTokenParam_).to.be(undefined);
});
it('applies correct access token from url', function () {
const layer = new MapboxVectorLayer({
styleUrl: '?key=123',
});
expect(layer.accessToken).to.be('123');
expect(layer.accessTokenParam_).to.be('key');
});
});
});