Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 6 additions & 8 deletions build/generate-struct-arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,12 @@ function createStructArrayLayoutType({members, size, alignment}) {
const key = `${members.map(m => `${m.components}${typeAbbreviations[m.type]}`).join('')}${size}`;
const className = `StructArrayLayout${key}`;

if (!layoutCache[key]) {
layoutCache[key] = {
className,
members,
size,
usedTypes
};
}
layoutCache[key] ||= {
className,
members,
size,
usedTypes
};

return className;
}
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default [
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],

'logical-assignment-operators': ['error', 'always', {enforceForIfStatements: true}],
'prefer-object-spread': 'error',
'prefer-object-has-own': 'error',
'object-shorthand': 'error',
Expand Down
2 changes: 1 addition & 1 deletion src/data/bucket/circle_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
sortFeaturesByKey = !circleSortKey.isConstant();

// Circles that are "printed" onto the map surface should be tessellated to follow the globe's curvature.
subdivide = subdivide || circleStyle.paint.get('circle-pitch-alignment') === 'map';
subdivide ||= circleStyle.paint.get('circle-pitch-alignment') === 'map';
}

const granularity = subdivide ? options.subdivisionGranularity.circle : 1;
Expand Down
2 changes: 1 addition & 1 deletion src/data/bucket/line_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class LineBucket implements Bucket {

// If we still don't have a previous normal, this is the beginning of a
// non-closed line, so we're doing a straight "join".
prevNormal = prevNormal || nextNormal;
prevNormal ||= nextNormal;

// Determine the normal of the join extrusion. It is the angle bisector
// of the segments between the previous line and the next line.
Expand Down
12 changes: 6 additions & 6 deletions src/data/bucket/symbol_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ export class SymbolBucket implements Bucket {
const formattedText = Formatted.factory(resolvedTokens);

// on this instance: if hasRTLText is already true, all future calls to containsRTLText can be skipped.
const bucketHasRTLText = this.hasRTLText = (this.hasRTLText || containsRTLText(formattedText));
this.hasRTLText ||= containsRTLText(formattedText);
if (
!bucketHasRTLText || // non-rtl text so can proceed safely
!this.hasRTLText || // non-rtl text so can proceed safely
rtlWorkerPlugin.getRTLTextPluginStatus() === 'unavailable' || // We don't intend to lazy-load the rtl text plugin, so proceed with incorrect shaping
bucketHasRTLText && rtlWorkerPlugin.isParsed() // Use the rtlText plugin to shape text
this.hasRTLText && rtlWorkerPlugin.isParsed() // Use the rtlText plugin to shape text
) {
text = transformText(formattedText, layer, evaluationFeature);
}
Expand Down Expand Up @@ -533,8 +533,8 @@ export class SymbolBucket implements Bucket {
if (!section.image) {
const doesAllowVerticalWritingMode = allowsVerticalWritingMode(text.toString());
const sectionFont = section.fontStack || fontStack;
const sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
stacks[sectionFont] ||= {};
this.calculateGlyphDependencies(section.text, stacks[sectionFont], textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
} else {
// Add section image to the list of dependencies.
icons[section.image.name] = true;
Expand All @@ -544,7 +544,7 @@ export class SymbolBucket implements Bucket {
}

if (layout.get('symbol-placement') === 'line') {
// Merge adjacent lines with the same text to improve labelling.
// Merge adjacent lines with the same text to improve labeling.
// It's better to place labels on one long line than on many short segments.
this.features = mergeLines(this.features);
}
Expand Down
4 changes: 1 addition & 3 deletions src/data/feature_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ export class FeatureIndex {
serializedLayers,
sourceFeatureState,
(feature: VectorTileFeatureLike, styleLayer: StyleLayer, featureState: FeatureState) => {
if (!featureGeometry) {
featureGeometry = loadGeometry(feature);
}
featureGeometry ||= loadGeometry(feature);

return styleLayer.queryIntersectsFeature({
queryGeometry,
Expand Down
8 changes: 3 additions & 5 deletions src/geo/projection/vertical_perspective_projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ export class VerticalPerspectiveProjection implements Projection {
}

public updateGPUdependent(renderContext: ProjectionGPUContext): void {
if (!this._errorMeasurement) {
this._errorMeasurement = new ProjectionErrorMeasurement(renderContext);
}
this._errorMeasurement ||= new ProjectionErrorMeasurement(renderContext);
const mercatorY = mercatorYfromLat(this._errorQueryLatitudeDegrees);
const expectedResult = 2.0 * Math.atan(Math.exp(Math.PI - (mercatorY * Math.PI * 2.0))) - Math.PI * 0.5;
const newValue = this._errorMeasurement.updateErrorLoop(mercatorY, expectedResult);
Expand Down Expand Up @@ -155,9 +153,9 @@ export class VerticalPerspectiveProjection implements Projection {
const currentTime = now();
let dirty = false;
// Error correction transition
dirty = dirty || (currentTime - this._errorMeasurementLastChangeTime) / 1000.0 < (globeConstants.errorTransitionTimeSeconds + 0.2);
dirty ||= (currentTime - this._errorMeasurementLastChangeTime) / 1000.0 < (globeConstants.errorTransitionTimeSeconds + 0.2);
// Error correction query in flight
dirty = dirty || (this._errorMeasurement?.awaitingQuery);
dirty ||= (this._errorMeasurement?.awaitingQuery);
return dirty;
}

Expand Down
2 changes: 1 addition & 1 deletion src/render/draw_color_relief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function renderColorRelief(
context.activeTexture.set(gl.TEXTURE0);

context.pixelStoreUnpackPremultiplyAlpha.set(false);
tile.demTexture = tile.demTexture || painter.getTileTexture(textureStride);
tile.demTexture ||= painter.getTileTexture(textureStride);
if (tile.demTexture) {
const demTexture = tile.demTexture;
demTexture.update(pixelData, {premultiply: false});
Expand Down
4 changes: 1 addition & 3 deletions src/render/draw_heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ function createHeatmapFbo(context: Context, width: number, height: number): Fram
}

function getColorRampTexture(context: Context, layer: HeatmapStyleLayer): Texture {
if (!layer.colorRampTexture) {
layer.colorRampTexture = new Texture(context, layer.colorRamp, context.gl.RGBA);
}
layer.colorRampTexture ||= new Texture(context, layer.colorRamp, context.gl.RGBA);
return layer.colorRampTexture;
}
2 changes: 1 addition & 1 deletion src/render/draw_hillshade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function prepareHillshade(
context.activeTexture.set(gl.TEXTURE1);

context.pixelStoreUnpackPremultiplyAlpha.set(false);
tile.demTexture = tile.demTexture || painter.getTileTexture(textureStride);
tile.demTexture ||= painter.getTileTexture(textureStride);
if (tile.demTexture) {
const demTexture = tile.demTexture;
demTexture.update(pixelData, {premultiply: false});
Expand Down
26 changes: 6 additions & 20 deletions src/render/glyph_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export class GlyphManager {
const result: GetGlyphsResponse = {};

for (const {stack, id, glyph} of updatedGlyphs) {
if (!result[stack]) {
result[stack] = {};
}
result[stack] ||= {};
// Clone the glyph so that our own copy of its ArrayBuffer doesn't get transferred.
result[stack][id] = glyph && {
id: glyph.id,
Expand All @@ -94,14 +92,8 @@ export class GlyphManager {

async _getAndCacheGlyphsPromise(stack: string, id: number): Promise<{stack: string; id: number; glyph: StyleGlyph}> {
// Create an entry for this fontstack if it doesn’t already exist.
let entry = this.entries[stack];
if (!entry) {
entry = this.entries[stack] = {
glyphs: {},
requests: {},
ranges: {}
};
}
this.entries[stack] ??= {glyphs: {}, requests: {}, ranges: {}};
const entry = this.entries[stack];

// Try to get the glyph from the cache of client-side glyphs by codepoint.
let glyph = entry.glyphs[id];
Expand All @@ -127,9 +119,7 @@ export class GlyphManager {
}

// Start downloading this range unless we’re currently downloading it.
if (!entry.requests[range]) {
entry.requests[range] = GlyphManager.loadGlyphRange(stack, range, this.url, this.requestManager);
}
entry.requests[range] ||= GlyphManager.loadGlyphRange(stack, range, this.url, this.requestManager);

try {
// Get the response and cache the glyphs from it.
Expand Down Expand Up @@ -269,12 +259,8 @@ export class GlyphManager {
destroy() {
for (const stack in this.entries) {
const entry = this.entries[stack];
if (entry.tinySDF) {
entry.tinySDF = null;
}
if (entry.ideographTinySDF) {
entry.ideographTinySDF = null;
}
entry.tinySDF = null;
entry.ideographTinySDF = null;
entry.glyphs = {};
entry.requests = {};
entry.ranges = {};
Expand Down
4 changes: 1 addition & 3 deletions src/render/line_atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export class LineAtlas {
getDash(dasharray: number[], round: boolean) {
const key = dasharray.join(',') + String(round);

if (!this.dashEntry[key]) {
this.dashEntry[key] = this.addDash(dasharray, round);
}
this.dashEntry[key] ||= this.addDash(dasharray, round);
return this.dashEntry[key];
}

Expand Down
26 changes: 12 additions & 14 deletions src/render/painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ export class Painter {
* @returns
*/
useProgram(name: string, programConfiguration?: ProgramConfiguration | null, forceSimpleProjection: boolean = false, defines: string[] = []): Program<any> {
this.cache = this.cache || {};
this.cache ||= {};
const useTerrain = !!this.style.map.terrain;

const projection = this.style.projection;
Expand All @@ -742,19 +742,17 @@ export class Painter {

const key = name + configurationKey + projectionKey + overdrawKey + terrainKey + definesKey;

if (!this.cache[key]) {
this.cache[key] = new Program(
this.context,
shaders[name],
programConfiguration,
programUniforms[name],
this._showOverdrawInspector,
useTerrain,
projectionPrelude,
projectionDefine,
defines
);
}
this.cache[key] ||= new Program(
this.context,
shaders[name],
programConfiguration,
programUniforms[name],
this._showOverdrawInspector,
useTerrain,
projectionPrelude,
projectionDefine,
defines
);
return this.cache[key];
}

Expand Down
7 changes: 3 additions & 4 deletions src/render/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ export class Program<Us extends UniformBindings> {
}

for (const segment of segments.get()) {
const vaos = segment.vaos || (segment.vaos = {});
const vao: VertexArrayObject = vaos[layerID] || (vaos[layerID] = new VertexArrayObject());

vao.bind(
segment.vaos ||= {};
segment.vaos[layerID] ||= new VertexArrayObject();
segment.vaos[layerID].bind(
context,
this,
layoutVertexBuffer,
Expand Down
2 changes: 1 addition & 1 deletion src/render/render_to_texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class RenderToTexture {
for (const tileID of tileIDs) {
const keys = this.terrain.tileManager.getTerrainCoords(tileID, terrainTileRanges);
for (const key in keys) {
if (!this._coordsAscending[id][key]) this._coordsAscending[id][key] = [];
this._coordsAscending[id][key] ||= [];
this._coordsAscending[id][key].push(keys[key]);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/source/canvas_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ export class CanvasSource extends ImageSource {

async load() {
this._loaded = true;
if (!this.canvas) {
this.canvas = (this.options.canvas instanceof HTMLCanvasElement) ?
this.options.canvas :
document.getElementById(this.options.canvas) as HTMLCanvasElement;
// cast to HTMLCanvasElement in else of ternary
// should we do a safety check and throw if it's not actually HTMLCanvasElement?
}
this.canvas ||= (this.options.canvas instanceof HTMLCanvasElement) ?
this.options.canvas :
document.getElementById(this.options.canvas) as HTMLCanvasElement;
// cast to HTMLCanvasElement in else of ternary
// should we do a safety check and throw if it's not actually HTMLCanvasElement?
this.width = this.canvas.width;
this.height = this.canvas.height;

Expand Down
2 changes: 1 addition & 1 deletion src/source/geojson_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('GeoJSONSource.constructor', () => {

describe('GeoJSONSource.setData', () => {
function createSource(opts?) {
opts = opts || {};
opts ||= {};
opts = extend(opts, {data: {}});
return new GeoJSONSource('id', opts, wrapDispatcher({
sendAsync(_message) {
Expand Down
2 changes: 1 addition & 1 deletion src/source/geojson_worker_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe('resourceTiming', () => {
return null;
});
window.performance.measure = vi.fn().mockImplementation((name, start, end) => {
measures[name] = measures[name] || [];
measures[name] ||= [];
measures[name].push({
duration: marks[end] - marks[start],
entryType: 'measure',
Expand Down
22 changes: 11 additions & 11 deletions src/source/query_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export function queryRenderedSymbols(styleLayers: {[_: string]: StyleLayer},
styleLayers);

for (const layerID in bucketSymbols) {
const resultFeatures = result[layerID] = result[layerID] || [];
result[layerID] ||= [];
const layerSymbols = bucketSymbols[layerID];
layerSymbols.sort((a, b) => {
// Match topDownFeatureComparator from FeatureIndex, but using
Expand All @@ -195,7 +195,7 @@ export function queryRenderedSymbols(styleLayers: {[_: string]: StyleLayer},
if (featureSortOrder) {
// queryRenderedSymbols documentation says we'll return features in
// "top-to-bottom" rendering order (aka last-to-first).
// Actually there can be multiple symbol instances per feature, so
// Actually, there can be multiple symbol instances per feature, so
// we sort each feature based on the first matching symbol instance.
const sortedA = featureSortOrder.indexOf(a.featureIndex);
const sortedB = featureSortOrder.indexOf(b.featureIndex);
Expand All @@ -207,7 +207,7 @@ export function queryRenderedSymbols(styleLayers: {[_: string]: StyleLayer},
}
});
for (const symbolFeature of layerSymbols) {
resultFeatures.push(symbolFeature);
result[layerID].push(symbolFeature);
}
}
}
Expand Down Expand Up @@ -245,18 +245,18 @@ function mergeRenderedFeatureLayers(tiles: RenderedFeatureLayer[]): QueryResults
// wrapped ID, don't duplicate features between the two tiles
const result: QueryResults = {};
const wrappedIDLayerMap = {};
for (const tile of tiles) {
const queryResults = tile.queryResults;
const wrappedID = tile.wrappedTileID;
const wrappedIDLayers = wrappedIDLayerMap[wrappedID] = wrappedIDLayerMap[wrappedID] || {};
for (const {queryResults, wrappedTileID} of tiles) {
wrappedIDLayerMap[wrappedTileID] ||= {};
const wrappedIDLayers = wrappedIDLayerMap[wrappedTileID];
for (const layerID in queryResults) {
const tileFeatures = queryResults[layerID];
const wrappedIDFeatures = wrappedIDLayers[layerID] = wrappedIDLayers[layerID] || {};
const resultFeatures = result[layerID] = result[layerID] || [];
wrappedIDLayers[layerID] ||= {};
const wrappedIDFeatures = wrappedIDLayers[layerID];
result[layerID] ||= [];
for (const tileFeature of tileFeatures) {
if (!wrappedIDFeatures[tileFeature.featureIndex]) {
wrappedIDFeatures[tileFeature.featureIndex] = true;
resultFeatures.push(tileFeature);
result[layerID].push(tileFeature);
}
}
}
Expand All @@ -269,7 +269,7 @@ function convertFeaturesToMapFeatures(result: QueryResults, tileManager: TileMan
for (const layerID in result) {
for (const featureWrapper of result[layerID]) {
convertFeatureToMapFeature(featureWrapper, tileManager);
};
}
}
return result as QueryRenderedFeaturesResults;
}
Expand Down
2 changes: 1 addition & 1 deletion src/source/raster_dem_tile_worker_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class RasterDEMTileWorkerSource {
new RGBAImage({width, height}, await getImageData(rawImageData, -1, -1, width, height)) :
rawImageData;
const dem = new DEMData(uid, imagePixels, encoding, redFactor, greenFactor, blueFactor, baseShift);
this.loaded = this.loaded || {};
this.loaded ||= {};
this.loaded[uid] = dem;
return dem;
}
Expand Down
4 changes: 1 addition & 3 deletions src/source/rtl_text_plugin_main_thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class RTLMainThreadPlugin extends Evented {
let rtlMainThreadPlugin: RTLMainThreadPlugin = null;

export function rtlMainThreadPluginFactory(): RTLMainThreadPlugin {
if (!rtlMainThreadPlugin) {
rtlMainThreadPlugin = new RTLMainThreadPlugin();
}
rtlMainThreadPlugin ||= new RTLMainThreadPlugin();
return rtlMainThreadPlugin;
}
Loading
Loading