Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixups
  • Loading branch information
karimnaaji committed Jan 30, 2023
commit ec03a25fa33162276f248e6ea3dbf782c8fa5254
14 changes: 6 additions & 8 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1654,14 +1654,12 @@ class Transform {
return this.mercatorMatrix.slice();
}

globeToMercatorMatrix(): ?Array<number> {
if (this.projection.name === 'globe') {
const pixelsToMerc = 1 / this.worldSize;
const m = mat4.fromScaling([], [pixelsToMerc, pixelsToMerc, pixelsToMerc]);
mat4.multiply(m, m, this.globeMatrix);
return m;
}
return undefined;
globeToMercatorMatrix(): Array<number> {
assert(this.projection.name === 'globe');
const pixelsToMerc = 1 / this.worldSize;
const m = mat4.fromScaling([], [pixelsToMerc, pixelsToMerc, pixelsToMerc]);
mat4.multiply(m, m, this.globeMatrix);
return m;
}

recenterOnTerrain() {
Expand Down
12 changes: 3 additions & 9 deletions src/render/draw_custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MercatorCoordinate from '../geo/mercator_coordinate.js';
import assert from 'assert';

function createMercatorGlobeMatrix(projection, pixelsPerMeterRatio, centerInMerc) {
var mercToPixelMatrix = mat4.create();
const mercToPixelMatrix = mat4.create();
mat4.identity(mercToPixelMatrix);

mercToPixelMatrix[0] = pixelsPerMeterRatio;
Expand All @@ -27,7 +27,6 @@ function createMercatorGlobeMatrix(projection, pixelsPerMeterRatio, centerInMerc
return mat4.multiply([], projection, mercToPixelMatrix);
}


function drawCustom(painter: Painter, sourceCache: SourceCache, layer: CustomStyleLayer, coords: Array<OverscaledTileID>) {

const context = painter.context;
Expand All @@ -46,12 +45,7 @@ function drawCustom(painter: Painter, sourceCache: SourceCache, layer: CustomSty
painter.setCustomLayerDefaults();
context.setColorMode(painter.colorModeForRenderPass());

if (painter.transform.projection.name === "globe") {
const center = painter.transform.pointMerc;
prerender.call(implementation, context.gl, painter.transform.customLayerMatrix(), painter.transform.getProjection(), painter.transform.globeToMercatorMatrix(), globeToMercatorTransition(painter.transform.zoom), [center.x, center.y], painter.transform.pixelsPerMeterRatio);
} else {
prerender.call(implementation, context.gl, painter.transform.customLayerMatrix());
}
prerender.call(implementation, context.gl, painter.transform.customLayerMatrix());

context.setDirty();
painter.setBaseState();
Expand Down Expand Up @@ -106,7 +100,7 @@ function drawCustom(painter: Painter, sourceCache: SourceCache, layer: CustomSty
context.gl.uniformMatrix4fv(context.gl.getUniformLocation(shaderProgram, "u_projection"), false, painter.transform.customLayerMatrix());
}
}

implementation.render(context.gl, painter.transform.customLayerMatrix());

context.setDirty();
Expand Down