From 36c1749d6d3bd330d781e2aff9f380c0789592ea Mon Sep 17 00:00:00 2001 From: ozero dien <139508+ozero@users.noreply.github.com> Date: Tue, 5 Apr 2022 03:26:48 +0900 Subject: [PATCH] Allow duplicated coordinates in tile request URLs (#11441) --- src/source/tile_id.js | 6 +++--- test/unit/source/tile_id.test.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/source/tile_id.js b/src/source/tile_id.js index 478595470cf..be9f96a0b35 100644 --- a/src/source/tile_id.js +++ b/src/source/tile_id.js @@ -31,9 +31,9 @@ export class CanonicalTileID { return urls[(this.x + this.y) % urls.length] .replace('{prefix}', (this.x % 16).toString(16) + (this.y % 16).toString(16)) - .replace('{z}', String(this.z)) - .replace('{x}', String(this.x)) - .replace('{y}', String(scheme === 'tms' ? (Math.pow(2, this.z) - this.y - 1) : this.y)) + .replace(/{z}/g, String(this.z)) + .replace(/{x}/g, String(this.x)) + .replace(/{y}/g, String(scheme === 'tms' ? (Math.pow(2, this.z) - this.y - 1) : this.y)) .replace('{quadkey}', quadkey) .replace('{bbox-epsg-3857}', bbox); } diff --git a/test/unit/source/tile_id.test.js b/test/unit/source/tile_id.test.js index 05858a856ce..3d0f6aeecbe 100644 --- a/test/unit/source/tile_id.test.js +++ b/test/unit/source/tile_id.test.js @@ -39,6 +39,7 @@ test('CanonicalTileID', (t) => { t.test('.url', (t) => { t.test('replaces {z}/{x}/{y}', (t) => { t.equal(new CanonicalTileID(1, 0, 0).url(['{z}/{x}/{y}.json']), '1/0/0.json'); + t.equal(new CanonicalTileID(15, 9876, 4321).url(['{z}/{x}/{z}_{x}_{y}.json']), '15/9876/15_9876_4321.json'); t.end(); });