Skip to content

Commit

Permalink
Extract WorkerSource types to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jul 12, 2017
1 parent f3c55fb commit 52359d8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/source/geojson_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const VectorTileWorkerSource = require('./vector_tile_worker_source');
import type {
WorkerTileParameters,
WorkerTileCallback,
} from '../source/source';
} from '../source/worker_source';

import type {Actor} from '../util/actor';
import type StyleLayerIndex from '../style/style_layer_index';
Expand Down
92 changes: 0 additions & 92 deletions src/source/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,95 +109,3 @@ exports.setType = function (name: string, type: any) {
*/


import type TileCoord from './tile_coord';
import type {Actor} from '../util/actor';
import type StyleLayerIndex from '../style/style_layer_index';
import type {SerializedBucket} from '../data/bucket';
import type {SerializedFeatureIndex} from '../data/feature_index';
import type {SerializedCollisionTile} from '../symbol/collision_tile';
import type {SerializedStructArray} from '../util/struct_array';

export type TileParameters = {
source: string,
uid: string,
};

export type PlacementConfig = {
angle: number,
pitch: number,
cameraToCenterDistance: number,
cameraToTileDistance: number,
showCollisionBoxes: boolean,
};

export type WorkerTileParameters = TileParameters & {
coord: TileCoord,
url: string,
zoom: number,
maxZoom: number,
tileSize: number,
overscaling: number,
} & PlacementConfig;

export type WorkerTileResult = {
buckets: Array<SerializedBucket>,
featureIndex: SerializedFeatureIndex,
collisionTile: SerializedCollisionTile,
collisionBoxArray: SerializedStructArray,
rawTileData?: ArrayBuffer,
};

export type WorkerTileCallback = (error: ?Error, result: ?WorkerTileResult, transferables: ?Array<Transferable>) => void;

export type RedoPlacementParameters = TileParameters & PlacementConfig;

export type RedoPlacementResult = {
buckets: Array<SerializedBucket>,
collisionTile: SerializedCollisionTile
};

export type RedoPlacementCallback = (error: ?Error, result: ?RedoPlacementResult, transferables: ?Array<Transferable>) => void;

/**
* May be implemented by custom source types to provide code that can be run on
* the WebWorkers. In addition to providing a custom
* {@link WorkerSource#loadTile}, any other methods attached to a `WorkerSource`
* implementation may also be targeted by the {@link Source} via
* `dispatcher.send('source-type.methodname', params, callback)`.
*
* @see {@link Map#addSourceType}
* @private
*
* @class WorkerSource
* @param actor
* @param layerIndex
*/
export interface WorkerSource {
constructor(actor: Actor, layerIndex: StyleLayerIndex): WorkerSource;

/**
* Loads a tile from the given params and parse it into buckets ready to send
* back to the main thread for rendering. Should call the callback with:
* `{ buckets, featureIndex, collisionTile, rawTileData}`.
*/
loadTile(params: WorkerTileParameters, callback: WorkerTileCallback): void;

/**
* Re-parses a tile that has already been loaded. Yields the same data as
* {@link WorkerSource#loadTile}.
*/
reloadTile(params: WorkerTileParameters, callback: WorkerTileCallback): void;

/**
* Aborts loading a tile that is in progress.
*/
abortTile(params: TileParameters): void;

/**
* Removes this tile from any local caches.
*/
removeTile(params: TileParameters): void;

redoPlacement(params: RedoPlacementParameters, callback: RedoPlacementCallback): void;
removeSource?: (params: {source: string}) => void;
}
2 changes: 1 addition & 1 deletion src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Throttler = require('../util/throttler');
const CLOCK_SKEW_RETRY_TIMEOUT = 30000;

import type TileCoord from './tile_coord';
import type {WorkerTileResult} from './source';
import type {WorkerTileResult} from './worker_source';

/**
* A tile object is the combination of a Coordinate, which defines
Expand Down
2 changes: 1 addition & 1 deletion src/source/vector_tile_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
TileParameters,
RedoPlacementParameters,
RedoPlacementCallback,
} from '../source/source';
} from '../source/worker_source';

import type {Actor} from '../util/actor';
import type StyleLayerIndex from '../style/style_layer_index';
Expand Down
2 changes: 1 addition & 1 deletion src/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
TileParameters,
RedoPlacementParameters,
RedoPlacementCallback
} from '../source/source';
} from '../source/worker_source';

/**
* @private
Expand Down
94 changes: 94 additions & 0 deletions src/source/worker_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// @flow

import type TileCoord from './tile_coord';
import type {Actor} from '../util/actor';
import type StyleLayerIndex from '../style/style_layer_index';
import type {SerializedBucket} from '../data/bucket';
import type {SerializedFeatureIndex} from '../data/feature_index';
import type {SerializedCollisionTile} from '../symbol/collision_tile';
import type {SerializedStructArray} from '../util/struct_array';

export type TileParameters = {
source: string,
uid: string,
};

export type PlacementConfig = {
angle: number,
pitch: number,
cameraToCenterDistance: number,
cameraToTileDistance: number,
showCollisionBoxes: boolean,
};

export type WorkerTileParameters = TileParameters & {
coord: TileCoord,
url: string,
zoom: number,
maxZoom: number,
tileSize: number,
overscaling: number,
} & PlacementConfig;

export type WorkerTileResult = {
buckets: Array<SerializedBucket>,
featureIndex: SerializedFeatureIndex,
collisionTile: SerializedCollisionTile,
collisionBoxArray: SerializedStructArray,
rawTileData?: ArrayBuffer,
};

export type WorkerTileCallback = (error: ?Error, result: ?WorkerTileResult, transferables: ?Array<Transferable>) => void;

export type RedoPlacementParameters = TileParameters & PlacementConfig;

export type RedoPlacementResult = {
buckets: Array<SerializedBucket>,
collisionTile: SerializedCollisionTile
};

export type RedoPlacementCallback = (error: ?Error, result: ?RedoPlacementResult, transferables: ?Array<Transferable>) => void;

/**
* May be implemented by custom source types to provide code that can be run on
* the WebWorkers. In addition to providing a custom
* {@link WorkerSource#loadTile}, any other methods attached to a `WorkerSource`
* implementation may also be targeted by the {@link Source} via
* `dispatcher.send('source-type.methodname', params, callback)`.
*
* @see {@link Map#addSourceType}
* @private
*
* @class WorkerSource
* @param actor
* @param layerIndex
*/
export interface WorkerSource {
constructor(actor: Actor, layerIndex: StyleLayerIndex): WorkerSource;

/**
* Loads a tile from the given params and parse it into buckets ready to send
* back to the main thread for rendering. Should call the callback with:
* `{ buckets, featureIndex, collisionTile, rawTileData}`.
*/
loadTile(params: WorkerTileParameters, callback: WorkerTileCallback): void;

/**
* Re-parses a tile that has already been loaded. Yields the same data as
* {@link WorkerSource#loadTile}.
*/
reloadTile(params: WorkerTileParameters, callback: WorkerTileCallback): void;

/**
* Aborts loading a tile that is in progress.
*/
abortTile(params: TileParameters): void;

/**
* Removes this tile from any local caches.
*/
removeTile(params: TileParameters): void;

redoPlacement(params: RedoPlacementParameters, callback: RedoPlacementCallback): void;
removeSource?: (params: {source: string}) => void;
}
2 changes: 1 addition & 1 deletion src/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type StyleLayerIndex from '../style/style_layer_index';
import type {
WorkerTileParameters,
WorkerTileCallback,
} from '../source/source';
} from '../source/worker_source';

class WorkerTile {
coord: TileCoord;
Expand Down

0 comments on commit 52359d8

Please sign in to comment.