@@ -10,18 +10,15 @@ import VectorTileWorkerSource from './vector_tile_worker_source';
1010import { createExpression } from '../style-spec/expression/index' ;
1111
1212import type {
13+ WorkerSourceOptions ,
1314 WorkerSourceVectorTileRequest ,
1415 WorkerSourceVectorTileCallback ,
1516} from '../source/worker_source' ;
16- import type Actor from '../util/actor' ;
17- import type StyleLayerIndex from '../style/style_layer_index' ;
1817import type { Feature } from './geojson_wrapper' ;
1918import type { Feature as ExpressionFeature } from '../style-spec/expression/index' ;
2019import type { LoadVectorDataCallback } from './load_vector_tile' ;
2120import type { RequestParameters , ResponseCallback } from '../util/ajax' ;
2221import type { Callback } from '../types/callback' ;
23- import type { ImageId } from '../style-spec/expression/types/image_id' ;
24- import type { StyleModelMap } from '../style/style_mode' ;
2522
2623export type GeoJSONWorkerOptions = {
2724 source : string ;
@@ -49,8 +46,6 @@ type ResourceTiming = Record<string, PerformanceResourceTiming[]>;
4946
5047export type LoadGeoJSONResult = FeatureCollectionOrFeature & { resourceTiming ?: ResourceTiming } ;
5148
52- export type LoadGeoJSON = ( params : LoadGeoJSONParameters , callback : ResponseCallback < LoadGeoJSONResult > ) => void ;
53-
5449export interface GeoJSONIndex {
5550 // eslint-disable-next-line @typescript-eslint/no-explicit-any
5651 getTile : ( z : number , x : number , y : number ) => any ;
@@ -111,9 +106,7 @@ function loadGeoJSONTile(this: GeoJSONWorkerSource, params: WorkerSourceVectorTi
111106 * The {@link WorkerSource} implementation that supports {@link GeoJSONSource}.
112107 * This class is designed to be easily reused to support custom source types
113108 * for data formats that can be parsed/converted into an in-memory GeoJSON
114- * representation. To do so, create it with
115- * `new GeoJSONWorkerSource(actor, layerIndex, customLoadGeoJSONFunction)`.
116- * For a full example, see [mapbox-gl-topojson](https://github.com/developmentseed/mapbox-gl-topojson).
109+ * representation.
117110 *
118111 * @private
119112 */
@@ -122,16 +115,10 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
122115 _dynamicIndex : GeoJSONRT ;
123116
124117 /**
125- * @param [loadGeoJSON] Optional method for custom loading/parsing of
126- * GeoJSON based on parameters passed from the main-thread Source.
127- * See {@link GeoJSONWorkerSource#loadGeoJSON}.
128118 * @private
129119 */
130- constructor ( actor : Actor , layerIndex : StyleLayerIndex , availableImages : ImageId [ ] , availableModels : StyleModelMap , isSpriteLoaded : boolean , loadGeoJSON ?: LoadGeoJSON | null , brightness ?: number | null ) {
131- super ( actor , layerIndex , availableImages , availableModels , isSpriteLoaded , loadGeoJSONTile , brightness ) ;
132- if ( loadGeoJSON ) {
133- this . loadGeoJSON = loadGeoJSON ;
134- }
120+ constructor ( { actor, layerIndex, availableImages, availableModels, isSpriteLoaded, brightness} : WorkerSourceOptions ) {
121+ super ( { actor, layerIndex, availableImages, availableModels, isSpriteLoaded, loadTileData : loadGeoJSONTile , brightness} ) ;
135122 this . _dynamicIndex = new GeoJSONRT ( ) ;
136123 }
137124
@@ -241,15 +228,11 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
241228 }
242229
243230 /**
244- * Fetch and parse GeoJSON according to the given params. Calls `callback`
245- * with `(err, data)`, where `data` is a parsed GeoJSON object.
231+ * Fetch and parse GeoJSON according to the given params.
246232 *
247233 * GeoJSON is loaded and parsed from `params.url` if it exists, or else
248234 * expected as a literal (string or object) `params.data`.
249235 *
250- * @param params
251- * @param [params.url] A URL to the remote GeoJSON data.
252- * @param [params.data] Literal GeoJSON data. Must be provided if `params.url` is not.
253236 * @private
254237 */
255238 loadGeoJSON ( params : LoadGeoJSONParameters , callback : ResponseCallback < FeatureCollectionOrFeature > ) : void {
@@ -263,8 +246,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
263246 // delay loading by one tick to hopefully let GC clean up the previous index (if present)
264247 setTimeout ( ( ) => {
265248 try {
266- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
267- return callback ( null , JSON . parse ( params . data ) ) ;
249+ return callback ( null , JSON . parse ( params . data ) as FeatureCollectionOrFeature ) ;
268250 } catch ( e ) {
269251 return callback ( new Error ( `Input data given to '${ params . source } ' is not a valid GeoJSON object.` ) ) ;
270252 }
0 commit comments