Skip to content

Commit 310bfec

Browse files
authored
Merge branch 'master' into alasarr/authorization-headers
2 parents 3036f7e + 7e1c115 commit 310bfec

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

examples/get-started/scripting/carto/index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<html>
22
<head>
33
<!-- deck.gl standalone bundle -->
4-
<script src="https://unpkg.com/deck.gl@^8.3.0/dist.min.js"></script>
5-
<script src="https://unpkg.com/@deck.gl/carto@^8.3.0/dist.min.js"></script>
6-
4+
<script src="https://unpkg.com/deck.gl@^8.5.0/dist.min.js"></script>
5+
<script src="https://unpkg.com/@deck.gl/carto@^8.5.0/dist.min.js"></script>
76
<!-- Mapbox dependencies -->
87
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.js"></script>
98
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.4.0/mapbox-gl.css" rel="stylesheet" />
@@ -90,9 +89,10 @@ <h3>Layer selector</h3>
9089
// Function to render the layers. Will be invoked any time visibility changes.
9190
function render() {
9291
const layers = [
93-
new deck.carto.CartoSQLLayer({
92+
new deck.carto.CartoLayer({
9493
id: 'airports',
9594
data: 'SELECT * FROM ne_10m_airports',
95+
type: deck.carto.MAP_TYPES.QUERY,
9696
visible: visibleLayer === 'airports',
9797
filled: true,
9898
pointRadiusMinPixels: 2,
@@ -101,9 +101,10 @@ <h3>Layer selector</h3>
101101
getFillColor: [200, 0, 80, 180],
102102
autoHighlight: true
103103
}),
104-
new deck.carto.CartoBQTilerLayer({
104+
new deck.carto.CartoLayer({
105105
id: 'osm_buildings',
106106
data: 'cartobq.maps.osm_buildings',
107+
type: deck.carto.MAP_TYPES.TILESET,
107108
visible: visibleLayer === 'building',
108109
getFillColor: object => {
109110
// Apply color based on an attribute

modules/geo-layers/src/tile-layer/tileset-2d.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ export default class Tileset2D {
174174

175175
// Add custom metadata to tiles
176176
getTileMetadata({x, y, z}) {
177-
return {bbox: tileToBoundingBox(this._viewport, x, y, z)};
177+
const {tileSize} = this.opts;
178+
return {bbox: tileToBoundingBox(this._viewport, x, y, z, tileSize)};
178179
}
179180

180181
// Returns {x, y, z} of the parent tile

modules/geo-layers/src/tile-layer/utils.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,38 +117,37 @@ function getIndexingCoords(bbox, scale, modelMatrixInverse) {
117117
return bbox.map(i => (i * scale) / TILE_SIZE);
118118
}
119119

120-
function getScale(z) {
121-
return Math.pow(2, z);
120+
function getScale(z, tileSize) {
121+
return (Math.pow(2, z) * TILE_SIZE) / tileSize;
122122
}
123123

124124
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2
125125
export function osmTile2lngLat(x, y, z) {
126-
const scale = getScale(z);
126+
const scale = getScale(z, TILE_SIZE);
127127
const lng = (x / scale) * 360 - 180;
128128
const n = Math.PI - (2 * Math.PI * y) / scale;
129129
const lat = (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
130130
return [lng, lat];
131131
}
132132

133-
function tile2XY(x, y, z) {
134-
const scale = getScale(z);
133+
function tile2XY(x, y, z, tileSize) {
134+
const scale = getScale(z, tileSize);
135135
return [(x / scale) * TILE_SIZE, (y / scale) * TILE_SIZE];
136136
}
137-
138-
export function tileToBoundingBox(viewport, x, y, z) {
137+
export function tileToBoundingBox(viewport, x, y, z, tileSize = TILE_SIZE) {
139138
if (viewport.isGeospatial) {
140139
const [west, north] = osmTile2lngLat(x, y, z);
141140
const [east, south] = osmTile2lngLat(x + 1, y + 1, z);
142141
return {west, north, east, south};
143142
}
144-
const [left, top] = tile2XY(x, y, z);
145-
const [right, bottom] = tile2XY(x + 1, y + 1, z);
143+
const [left, top] = tile2XY(x, y, z, tileSize);
144+
const [right, bottom] = tile2XY(x + 1, y + 1, z, tileSize);
146145
return {left, top, right, bottom};
147146
}
148147

149-
function getIdentityTileIndices(viewport, z, extent, modelMatrixInverse) {
148+
function getIdentityTileIndices(viewport, z, tileSize, extent, modelMatrixInverse) {
150149
const bbox = getBoundingBox(viewport, null, extent);
151-
const scale = getScale(z);
150+
const scale = getScale(z, tileSize);
152151
const [minX, minY, maxX, maxY] = getIndexingCoords(bbox, scale, modelMatrixInverse);
153152
const indices = [];
154153

@@ -180,7 +179,9 @@ export function getTileIndices({
180179
modelMatrix,
181180
modelMatrixInverse
182181
}) {
183-
let z = Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize));
182+
let z = viewport.isGeospatial
183+
? Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize))
184+
: Math.ceil(viewport.zoom);
184185
if (Number.isFinite(minZoom) && z < minZoom) {
185186
if (!extent) {
186187
return [];
@@ -196,7 +197,13 @@ export function getTileIndices({
196197
}
197198
return viewport.isGeospatial
198199
? getOSMTileIndices(viewport, z, zRange, extent || DEFAULT_EXTENT)
199-
: getIdentityTileIndices(viewport, z, transformedExtent || DEFAULT_EXTENT, modelMatrixInverse);
200+
: getIdentityTileIndices(
201+
viewport,
202+
z,
203+
tileSize,
204+
transformedExtent || DEFAULT_EXTENT,
205+
modelMatrixInverse
206+
);
200207
}
201208

202209
/**

test/modules/geo-layers/tile-layer/utils.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const TEST_CASES = [
142142
}
143143
}),
144144
tileSize: 256,
145-
output: ['1,2,4', '1,3,4', '2,2,4', '2,3,4', '3,2,4', '3,3,4', '4,2,4', '4,3,4']
145+
output: ['1,2,3', '1,3,3', '2,2,3', '2,3,3', '3,2,3', '3,3,3', '4,2,3', '4,3,3']
146146
},
147147
{
148148
title: 'non-geospatial modelMatrix identity',
@@ -396,6 +396,12 @@ test('tileToBoundingBox#Infovis', t => {
396396
'0,0,1 Should match the results.'
397397
);
398398

399+
t.deepEqual(
400+
tileToBoundingBox(viewport, 0, 0, 0, 256),
401+
{left: 0, top: 0, right: 256, bottom: 256},
402+
'0,0,0 with custom tileSize Should match the results.'
403+
);
404+
399405
t.deepEqual(
400406
tileToBoundingBox(viewport, 4, -1, 2),
401407
{left: 512, top: -128, right: 640, bottom: 0},
@@ -408,6 +414,12 @@ test('tileToBoundingBox#Infovis', t => {
408414
'4,-1,3 Should match the results.'
409415
);
410416

417+
t.deepEqual(
418+
tileToBoundingBox(viewport, 4, -1, 2, 256),
419+
{left: 256, top: -64, right: 320, bottom: 0},
420+
'4,-1,2 with custom tileSize Should match the results.'
421+
);
422+
411423
t.end();
412424
});
413425

0 commit comments

Comments
 (0)