From f371112c8d0acb7c7095f1d56ac3ff3cc7751026 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Mon, 14 Nov 2022 09:23:05 +0100 Subject: [PATCH] Consider tilesize when calculating the grid This never worked before. The calculation for sizes other than 1 did use the right center point for the static image. The patch fixes that and also adjusts the test for it. --- changelog.md | 4 ++++ index.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- test/test.js | 24 +++++++++++++++--------- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 7abf97a..60ea0af 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # CHANGELOG +# v3.1.1 + +Fixes a bug when calculating the center for sizes > 1 + # v3.1.0 * Update mocha to 6.x diff --git a/index.js b/index.js index 3b6fc14..c067f52 100644 --- a/index.js +++ b/index.js @@ -78,8 +78,8 @@ abaculus.tileList = function(z, s, center, tileSize) { var ts = Math.floor(size * s); var centerCoordinate = { - column: x / size, - row: y / size, + column: x / ts, + row: y / ts, zoom: z }; diff --git a/package-lock.json b/package-lock.json index ca95325..725ac57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mapbox/abaculus", - "version": "3.1.0", + "version": "3.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4051b93..b2d9e5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapbox/abaculus", - "version": "3.1.0", + "version": "3.1.1", "description": "stitches map tiles together for high-res exporting from tm2", "main": "index.js", "contributors": [ diff --git a/test/test.js b/test/test.js index d660694..c0193bc 100644 --- a/test/test.js +++ b/test/test.js @@ -88,19 +88,25 @@ describe('create list of tile coordinates', function() { it('should return a tiles object with correct coords', function() { var zoom = 5, scale = 4, - width = 1824, - height = 1832, - center = { x: 4096, y: 4096, w: width, h: height }; + width = 250, + height = 250, + center = printer.coordsFromCenter( + zoom, + scale, + { x: -47.368, y: -24.405, w: width, h: height }, + limit, + 256 + ); var expectedCoords = { tiles: [ - { z: zoom, x: 15, y: 15, px: -112, py: -108 }, - { z: zoom, x: 15, y: 16, px: -112, py: 916 }, - { z: zoom, x: 16, y: 15, px: 912, py: -108 }, - { z: zoom, x: 16, y: 16, px: 912, py: 916 } + { z: zoom, x: 11, y: 17, px: -308, py: -768 }, + { z: zoom, x: 11, y: 18, px: -308, py: 256 }, + { z: zoom, x: 12, y: 17, px: 716, py: -768 }, + { z: zoom, x: 12, y: 18, px: 716, py: 256 } ], - dimensions: { x: width, y: height }, - center: { row: 16, column: 16, zoom: zoom }, + dimensions: { x: width * scale, y: height * scale }, + center: { row: 18, column: 11, zoom: zoom }, scale: scale }; var coords = printer.tileList(zoom, scale, center);