From 220ffb6ee1dc74030d2263fb7eb85570bb1923be Mon Sep 17 00:00:00 2001 From: Modif93 <57270858+Modif93@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:08:15 +0900 Subject: [PATCH 1/2] added tms support --- src/tile/base.ts | 10 +++++++--- src/tile/terrainrgb.ts | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/tile/base.ts b/src/tile/base.ts index 9975ea4..24a3730 100644 --- a/src/tile/base.ts +++ b/src/tile/base.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import { WebpMachine, loadBinaryData } from 'webp-hero'; -import { lngLatToGoogle } from 'global-mercator'; +import { lngLatToGoogle,lngLatToTile } from 'global-mercator'; import PNG from '../png'; /** @@ -11,6 +11,8 @@ abstract class BaseTile { protected tileSize: number; + protected tms: boolean; + protected minzoom: number; protected maxzoom: number; @@ -19,12 +21,14 @@ abstract class BaseTile { * Constructor * @param url URL for terrain RGB raster tilesets * @param tileSize size of tile. 256 or 512 + * @param tms whether it is Tile Map Service * @param minzoom minzoom for terrain RGB raster tilesets * @param maxzoom maxzoom for terrain RGB raster tilesets */ - constructor(url: string, tileSize: number, minzoom: number, maxzoom: number) { + constructor(url: string, tileSize: number, tms: boolean, minzoom: number, maxzoom: number) { this.url = url; this.tileSize = tileSize; + this.tms = tms; this.minzoom = minzoom; this.maxzoom = maxzoom; } @@ -46,7 +50,7 @@ abstract class BaseTile { } else if (z < this.minzoom) { zoom = this.minzoom; } - const tile = lngLatToGoogle([lng, lat], zoom); + const tile = this.tms?lngLatToTile([lng, lat], zoom):lngLatToGoogle([lng, lat], zoom); const url: string = this.url .replace(/{x}/g, tile[0].toString()) .replace(/{y}/g, tile[1].toString()) diff --git a/src/tile/terrainrgb.ts b/src/tile/terrainrgb.ts index 42b4eac..2f77343 100644 --- a/src/tile/terrainrgb.ts +++ b/src/tile/terrainrgb.ts @@ -8,11 +8,12 @@ class TerrainRGB extends BaseTile { * Constructor * @param url URL for terrain RGB raster tilesets * @param tileSize size of tile. 256 or 512 + * @param tms whether it is Tile Map Service * @param minzoom minzoom for terrain RGB raster tilesets. default is 5 * @param maxzoom maxzoom for terrain RGB raster tilesets. default is 15 */ - constructor(url: string, tileSize: number, minzoom = 5, maxzoom = 15) { - super(url, tileSize, minzoom, maxzoom); + constructor(url: string, tileSize: number, tms:boolean = false, minzoom = 5, maxzoom = 15) { + super(url, tileSize, tms, minzoom, maxzoom); } /** From ab94a66f905525f4a25bcf64074a6e3adc4e7e5f Mon Sep 17 00:00:00 2001 From: Modif93 <57270858+Modif93@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:26:33 +0900 Subject: [PATCH 2/2] chg tms arg loc & fixed lint --- src/tile/base.ts | 14 +++++++------- src/tile/terrainrgb.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tile/base.ts b/src/tile/base.ts index 24a3730..c5de973 100644 --- a/src/tile/base.ts +++ b/src/tile/base.ts @@ -1,6 +1,6 @@ import axios from 'axios'; import { WebpMachine, loadBinaryData } from 'webp-hero'; -import { lngLatToGoogle,lngLatToTile } from 'global-mercator'; +import { lngLatToGoogle, lngLatToTile } from 'global-mercator'; import PNG from '../png'; /** @@ -11,26 +11,26 @@ abstract class BaseTile { protected tileSize: number; - protected tms: boolean; - protected minzoom: number; protected maxzoom: number; + protected tms: boolean; + /** * Constructor * @param url URL for terrain RGB raster tilesets * @param tileSize size of tile. 256 or 512 - * @param tms whether it is Tile Map Service * @param minzoom minzoom for terrain RGB raster tilesets * @param maxzoom maxzoom for terrain RGB raster tilesets + * @param tms whether it is Tile Map Service */ - constructor(url: string, tileSize: number, tms: boolean, minzoom: number, maxzoom: number) { + constructor(url: string, tileSize: number, minzoom: number, maxzoom: number, tms: boolean) { this.url = url; this.tileSize = tileSize; - this.tms = tms; this.minzoom = minzoom; this.maxzoom = maxzoom; + this.tms = tms; } /** @@ -50,7 +50,7 @@ abstract class BaseTile { } else if (z < this.minzoom) { zoom = this.minzoom; } - const tile = this.tms?lngLatToTile([lng, lat], zoom):lngLatToGoogle([lng, lat], zoom); + const tile = this.tms ? lngLatToTile([lng, lat], zoom) : lngLatToGoogle([lng, lat], zoom); const url: string = this.url .replace(/{x}/g, tile[0].toString()) .replace(/{y}/g, tile[1].toString()) diff --git a/src/tile/terrainrgb.ts b/src/tile/terrainrgb.ts index 2f77343..a97b744 100644 --- a/src/tile/terrainrgb.ts +++ b/src/tile/terrainrgb.ts @@ -12,8 +12,8 @@ class TerrainRGB extends BaseTile { * @param minzoom minzoom for terrain RGB raster tilesets. default is 5 * @param maxzoom maxzoom for terrain RGB raster tilesets. default is 15 */ - constructor(url: string, tileSize: number, tms:boolean = false, minzoom = 5, maxzoom = 15) { - super(url, tileSize, tms, minzoom, maxzoom); + constructor(url: string, tileSize: number, minzoom = 5, maxzoom = 15, tms = false) { + super(url, tileSize, minzoom, maxzoom, tms); } /**