From 37c987de0a5e51e96a836aeae81c72002181aea5 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 20 Nov 2018 13:31:54 -0700 Subject: [PATCH] Move quadKey function to the one place it is used --- src/ol/source/BingMaps.js | 28 +++++++++++++++++++++++++++- src/ol/tilecoord.js | 25 ------------------------- test/spec/ol/source/bingmaps.test.js | 11 +++++++++-- test/spec/ol/tilecoord.test.js | 9 --------- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/ol/source/BingMaps.js b/src/ol/source/BingMaps.js index 0d6689b358..9d488b68e4 100644 --- a/src/ol/source/BingMaps.js +++ b/src/ol/source/BingMaps.js @@ -8,10 +8,35 @@ import {jsonp as requestJSONP} from '../net.js'; import {get as getProjection, getTransformFromProjections} from '../proj.js'; import SourceState from './State.js'; import TileImage from './TileImage.js'; -import {createOrUpdate, quadKey} from '../tilecoord.js'; +import {createOrUpdate} from '../tilecoord.js'; import {createXYZ, extentFromProjection} from '../tilegrid.js'; +/** + * @param {import('../tilecoord.js').TileCoord} tileCoord Tile coord. + * @return {string} Quad key. + */ +export function quadKey(tileCoord) { + const z = tileCoord[0]; + const digits = new Array(z); + let mask = 1 << (z - 1); + let i, charCode; + for (i = 0; i < z; ++i) { + // 48 is charCode for 0 - '0'.charCodeAt(0) + charCode = 48; + if (tileCoord[1] & mask) { + charCode += 1; + } + if (tileCoord[2] & mask) { + charCode += 2; + } + digits[i] = String.fromCharCode(charCode); + mask >>= 1; + } + return digits.join(''); +} + + /** * The attribution containing a link to the Microsoft® Bing™ Maps Platform APIs’ * Terms Of Use. @@ -209,6 +234,7 @@ class BingMaps extends TileImage { const hidpi = this.hidpi_; this.tileUrlFunction = createFromTileUrlFunctions( resource.imageUrlSubdomains.map(function(subdomain) { + /** @type {import('../tilecoord.js').TileCoord} */ const quadKeyTileCoord = [0, 0, 0]; const imageUrl = resource.imageUrl .replace('{subdomain}', subdomain) diff --git a/src/ol/tilecoord.js b/src/ol/tilecoord.js index eca96866d0..b43c3a60eb 100644 --- a/src/ol/tilecoord.js +++ b/src/ol/tilecoord.js @@ -70,31 +70,6 @@ export function hash(tileCoord) { } -/** - * @param {TileCoord} tileCoord Tile coord. - * @return {string} Quad key. - */ -export function quadKey(tileCoord) { - const z = tileCoord[0]; - const digits = new Array(z); - let mask = 1 << (z - 1); - let i, charCode; - for (i = 0; i < z; ++i) { - // 48 is charCode for 0 - '0'.charCodeAt(0) - charCode = 48; - if (tileCoord[1] & mask) { - charCode += 1; - } - if (tileCoord[2] & mask) { - charCode += 2; - } - digits[i] = String.fromCharCode(charCode); - mask >>= 1; - } - return digits.join(''); -} - - /** * @param {TileCoord} tileCoord Tile coordinate. * @param {!import("./tilegrid/TileGrid.js").default} tileGrid Tile grid. diff --git a/test/spec/ol/source/bingmaps.test.js b/test/spec/ol/source/bingmaps.test.js index 1823b89e67..9fa3a9a92c 100644 --- a/test/spec/ol/source/bingmaps.test.js +++ b/test/spec/ol/source/bingmaps.test.js @@ -1,10 +1,17 @@ -import BingMaps from '../../../../src/ol/source/BingMaps.js'; -import {quadKey} from '../../../../src/ol/tilecoord.js'; +import BingMaps, {quadKey} from '../../../../src/ol/source/BingMaps.js'; import {unByKey} from '../../../../src/ol/Observable.js'; describe('ol.source.BingMaps', function() { + describe('quadKey()', function() { + it('returns expected string', function() { + const tileCoord = [3, 3, 5]; + const s = quadKey(tileCoord); + expect(s).to.eql('213'); + }); + }); + describe('#tileUrlFunction()', function() { let source, tileGrid; diff --git a/test/spec/ol/tilecoord.test.js b/test/spec/ol/tilecoord.test.js index 669c65a73e..29ad8c5bce 100644 --- a/test/spec/ol/tilecoord.test.js +++ b/test/spec/ol/tilecoord.test.js @@ -1,5 +1,4 @@ import { - quadKey, getKey, fromKey, hash, @@ -19,14 +18,6 @@ describe('ol.TileCoord', function() { }); }); - describe('call quadKey', function() { - it('returns expected string', function() { - const tileCoord = [3, 3, 5]; - const s = quadKey(tileCoord); - expect(s).to.eql('213'); - }); - }); - describe('getKey()', function() { it('returns a key for a tile coord', function() { const key = getKey([1, 2, 3]);