Skip to content

Commit

Permalink
Typescript: minor fixes to formatting (#241)
Browse files Browse the repository at this point in the history
* minor fixes

* fix formatting of object key value types
  • Loading branch information
chippieTV authored Aug 9, 2021
1 parent 140ad58 commit c730494
Show file tree
Hide file tree
Showing 57 changed files with 225 additions and 542 deletions.
8 changes: 2 additions & 6 deletions src/data/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export interface Bucket {
update(
states: FeatureStates,
vtLayer: VectorTileLayer,
imagePositions: {
[_: string]: ImagePosition
}
imagePositions: {[_: string]: ImagePosition}
): void;
isEmpty(): boolean;
upload(context: Context): void;
Expand All @@ -105,9 +103,7 @@ export interface Bucket {
destroy(): void;
}

export function deserialize(input: Array<Bucket>, style: Style): {
[_: string]: Bucket
} {
export function deserialize(input: Array<Bucket>, style: Style): {[_: string]: Bucket} {
const output = {};

// Guard against the case where the map's style has been set to null while
Expand Down
14 changes: 4 additions & 10 deletions src/data/bucket/circle_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement

populate(features: Array<IndexedFeature>, options: PopulateParameters, canonical: CanonicalTileID) {
const styleLayer = this.layers[0];
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];
let circleSortKey = null;
let sortFeaturesByKey = false;

// Heatmap layers are handled in this bucket and have no evaluated properties, so we check our access
if (styleLayer.type === 'circle') {
circleSortKey = (styleLayer as any as CircleStyleLayer).layout.get('circle-sort-key');
circleSortKey = (styleLayer as CircleStyleLayer).layout.get('circle-sort-key');
sortFeaturesByKey = !circleSortKey.isConstant();
}

Expand All @@ -94,7 +94,6 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;

const sortKey = sortFeaturesByKey ?
// $FlowFixMe
circleSortKey.evaluate(evaluationFeature, {}, canonical) :
undefined;

Expand All @@ -114,10 +113,7 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement
}

if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
});
bucketFeatures.sort((a, b) => a.sortKey - b.sortKey);
}

for (const bucketFeature of bucketFeatures) {
Expand All @@ -129,9 +125,7 @@ class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implement
}
}

update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {
[_: string]: ImagePosition
}) {
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
if (!this.stateDependentLayers.length) return;
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
}
Expand Down
5 changes: 2 additions & 3 deletions src/data/bucket/fill_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class FillBucket implements Bucket {
this.hasPattern = hasPattern('fill', this.layers, options);
const fillSortKey = this.layers[0].layout.get('fill-sort-key');
const sortFeaturesByKey = !fillSortKey.isConstant();
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
const needGeometry = this.layers[0]._featureFilter.needGeometry;
Expand Down Expand Up @@ -105,8 +105,7 @@ class FillBucket implements Bucket {

if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey) - (b.sortKey);
});
}

Expand Down
12 changes: 3 additions & 9 deletions src/data/bucket/fill_extrusion_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,14 @@ class FillExtrusionBucket implements Bucket {
}
}

addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {
[_: string]: ImagePosition
}) {
addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const feature of this.features) {
const {geometry} = feature;
this.addFeature(feature, geometry, feature.index, canonical, imagePositions);
}
}

update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {
[_: string]: ImagePosition
}) {
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
if (!this.stateDependentLayers.length) return;
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
}
Expand Down Expand Up @@ -158,9 +154,7 @@ class FillExtrusionBucket implements Bucket {
this.segments.destroy();
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {
[_: string]: ImagePosition
}) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const polygon of classifyRings(geometry, EARCUT_MAX_RINGS)) {
let numVertices = 0;
for (const ring of polygon) {
Expand Down
27 changes: 9 additions & 18 deletions src/data/bucket/line_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type LineClips = {

type GradientTexture = {
texture: Texture,
gradient: RGBAImage | undefined | null,
gradient?: RGBAImage,
version: number
};

Expand All @@ -88,7 +88,7 @@ class LineBucket implements Bucket {
totalDistance: number;
maxLineLength: number;
scaledDistance: number;
lineClips: LineClips | undefined | null;
lineClips?: LineClips;

e1: number;
e2: number;
Expand All @@ -98,9 +98,7 @@ class LineBucket implements Bucket {
overscaling: number;
layers: Array<LineStyleLayer>;
layerIds: Array<string>;
gradients: {
[x: string]: GradientTexture
};
gradients: {[x: string]: GradientTexture};
stateDependentLayers: Array<any>;
stateDependentLayerIds: Array<string>;
patternFeatures: Array<BucketFeature>;
Expand Down Expand Up @@ -147,7 +145,7 @@ class LineBucket implements Bucket {
this.hasPattern = hasPattern('line', this.layers, options);
const lineSortKey = this.layers[0].layout.get('line-sort-key');
const sortFeaturesByKey = !lineSortKey.isConstant();
const bucketFeatures = [];
const bucketFeatures: BucketFeature[] = [];

for (const {feature, id, index, sourceLayerIndex} of features) {
const needGeometry = this.layers[0]._featureFilter.needGeometry;
Expand Down Expand Up @@ -175,8 +173,7 @@ class LineBucket implements Bucket {

if (sortFeaturesByKey) {
bucketFeatures.sort((a, b) => {
// a.sortKey is always a number when in use
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey) - (b.sortKey);
});
}

Expand All @@ -197,16 +194,12 @@ class LineBucket implements Bucket {
}
}

update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {
[_: string]: ImagePosition
}) {
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
if (!this.stateDependentLayers.length) return;
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
}

addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {
[_: string]: ImagePosition
}) {
addFeatures(options: PopulateParameters, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
for (const feature of this.patternFeatures) {
this.addFeature(feature, feature.geometry, feature.index, canonical, imagePositions);
}
Expand Down Expand Up @@ -240,17 +233,15 @@ class LineBucket implements Bucket {
this.segments.destroy();
}

lineFeatureClips(feature: BucketFeature): LineClips | undefined | null {
lineFeatureClips(feature: BucketFeature): LineClips | undefined {
if (!!feature.properties && Object.prototype.hasOwnProperty.call(feature.properties, 'mapbox_clip_start') && Object.prototype.hasOwnProperty.call(feature.properties, 'mapbox_clip_end')) {
const start = +feature.properties['mapbox_clip_start'];
const end = +feature.properties['mapbox_clip_end'];
return {start, end};
}
}

addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {
[_: string]: ImagePosition
}) {
addFeature(feature: BucketFeature, geometry: Array<Array<Point>>, index: number, canonical: CanonicalTileID, imagePositions: {[_: string]: ImagePosition}) {
const layout = this.layers[0].layout;
const join = layout.get('line-join').evaluate(feature, {});
const cap = layout.get('line-cap');
Expand Down
20 changes: 8 additions & 12 deletions src/data/bucket/symbol_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ class SymbolBucket implements Bucket {
sortKeyRanges: Array<SortKeyRange>;
pixelRatio: number;
tilePixelRatio: number;
compareText: {
[_: string]: Array<Point>
};
compareText: {[_: string]: Array<Point>};
fadeStartTime: number;
sortFeaturesByKey: boolean;
sortFeaturesByY: boolean;
Expand Down Expand Up @@ -539,14 +537,12 @@ class SymbolBucket implements Bucket {
if (this.sortFeaturesByKey) {
this.features.sort((a, b) => {
// a.sortKey is always a number when sortFeaturesByKey is true
return (a.sortKey as any as number) - (b.sortKey as any as number);
return (a.sortKey as number) - (b.sortKey as number);
});
}
}

update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {
[_: string]: ImagePosition
}) {
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
if (!this.stateDependentLayers.length) return;
this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
Expand Down Expand Up @@ -720,7 +716,7 @@ class SymbolBucket implements Bucket {

addDebugCollisionBoxes(startIndex: number, endIndex: number, symbolInstance: SymbolInstance, isText: boolean) {
for (let b = startIndex; b < endIndex; b++) {
const box: CollisionBox = (this.collisionBoxArray.get(b) as any);
const box: CollisionBox = this.collisionBoxArray.get(b);
const x1 = box.x1;
const y1 = box.y1;
const x2 = box.x2;
Expand Down Expand Up @@ -765,27 +761,27 @@ class SymbolBucket implements Bucket {

const collisionArrays = {} as CollisionArrays;
for (let k = textStartIndex; k < textEndIndex; k++) {
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.textBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.textFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = verticalTextStartIndex; k < verticalTextEndIndex; k++) {
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.verticalTextBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.verticalTextFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = iconStartIndex; k < iconEndIndex; k++) {
// An icon can only have one box now, so this indexing is a bit vestigial...
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.iconBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.iconFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
}
for (let k = verticalIconStartIndex; k < verticalIconEndIndex; k++) {
// An icon can only have one box now, so this indexing is a bit vestigial...
const box: CollisionBox = (collisionBoxArray.get(k) as any);
const box: CollisionBox = collisionBoxArray.get(k);
collisionArrays.verticalIconBox = {x1: box.x1, y1: box.y1, x2: box.x2, y2: box.y2, anchorPointX: box.anchorPointX, anchorPointY: box.anchorPointY};
collisionArrays.verticalIconFeatureIndex = box.featureIndex;
break; // Only one box allowed per instance
Expand Down
4 changes: 1 addition & 3 deletions src/data/evaluation_feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import type Point from '../symbol/point';
type EvaluationFeature = {
readonly type: 1 | 2 | 3 | "Unknown" | "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon",
readonly id?: any,
readonly properties: {
[_: string]: any
},
readonly properties: {[_: string]: any},
readonly patterns?: {
[_: string]: {
"min": string,
Expand Down
39 changes: 9 additions & 30 deletions src/data/feature_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class FeatureIndex {
rawTileData: ArrayBuffer;
bucketLayerIDs: Array<Array<string>>;

vtLayers: {
[_: string]: VectorTileLayer
};
vtLayers: {[_: string]: VectorTileLayer};
sourceLayerCoder: DictionaryCoder;

constructor(tileID: OverscaledTileID, promoteId?: PromoteIdSpecification | null) {
Expand Down Expand Up @@ -96,9 +94,7 @@ class FeatureIndex {
}
}

loadVTLayers(): {
[_: string]: VectorTileLayer
} {
loadVTLayers(): {[_: string]: VectorTileLayer} {
if (!this.vtLayers) {
this.vtLayers = new vt.VectorTile(new Protobuf(this.rawTileData)).layers;
this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
Expand All @@ -109,19 +105,10 @@ class FeatureIndex {
// Finds non-symbol features in this tile at a particular position.
query(
args: QueryParameters,
styleLayers: {
[_: string]: StyleLayer
},
serializedLayers: {
[_: string]: any
},
styleLayers: {[_: string]: StyleLayer},
serializedLayers: {[_: string]: any},
sourceFeatureState: SourceFeatureState
): {
[_: string]: Array<{
featureIndex: number,
feature: GeoJSONFeature
}>
} {
): {[_: string]: Array<{featureIndex: number, feature: GeoJSONFeature}>} {
this.loadVTLayers();

const params = args.params || {} as { filter: any, layers: string[], availableImages: string[] },
Expand Down Expand Up @@ -196,12 +183,8 @@ class FeatureIndex {
filter: FeatureFilter,
filterLayerIDs: Array<string>,
availableImages: Array<string>,
styleLayers: {
[_: string]: StyleLayer
},
serializedLayers: {
[_: string]: any
},
styleLayers: {[_: string]: StyleLayer},
serializedLayers: {[_: string]: any},
sourceFeatureState?: SourceFeatureState,
intersectionTest?: (
feature: VectorTileFeature,
Expand Down Expand Up @@ -270,17 +253,13 @@ class FeatureIndex {
// Given a set of symbol indexes that have already been looked up,
// return a matching set of GeoJSONFeatures
lookupSymbolFeatures(symbolFeatureIndexes: Array<number>,
serializedLayers: {
[x: string]: StyleLayer
},
serializedLayers: {[_: string]: StyleLayer},
bucketIndex: number,
sourceLayerIndex: number,
filterSpec: FilterSpecification,
filterLayerIDs: Array<string>,
availableImages: Array<string>,
styleLayers: {
[_: string]: StyleLayer
}) {
styleLayers: {[_: string]: StyleLayer}) {
const result = {};
this.loadVTLayers();

Expand Down
Loading

0 comments on commit c730494

Please sign in to comment.