class
GeoJSONLayer
extends LayerBase
implements IFeatureLayer, IQueryableLayer
Load and render GeoJSON data. Supports URL fetch or inline data. Automatically detects geometry types (Point, LineString, Polygon) and applies renderer symbology.
Constructor
new GeoJSONLayer(options: GeoJSONLayerOptions) | Parameter | Type | Description | |
|---|---|---|---|
options | GeoJSONLayerOptions | required | Layer configuration |
GeoJSONLayerOptions
| Field | Type | Description | |
|---|---|---|---|
id | string | optional | Layer ID (auto-generated if omitted) |
url | string | optional | URL to a GeoJSON file (mutually exclusive with data) |
data | GeoJsonFeatureCollection | optional | Inline GeoJSON data (mutually exclusive with url) |
fetchFn | typeof fetch | optional | Custom fetch function for loading |
visible | boolean | optional | Initial visibility Default: true |
opacity | number | optional | Layer opacity (0-1) Default: 1 |
zIndex | number | optional | Display order |
interactive | boolean | optional | Enable hit testing Default: true |
blendMode | 'normal' | 'screen' | 'multiply' | 'overlay' | optional | GPU blend mode Default: 'normal' |
filters | { brightness?, contrast?, saturate? } | optional | Visual filters |
Properties
| Name | Type | Access | Description |
|---|---|---|---|
type | 'geojson' | readonly | Layer type discriminant |
renderer | IRenderer | undefined | read/write | Feature renderer (set to apply symbology) |
Methods
getFeatures()
getFeatures(): readonly Feature[] Get all loaded features.
Returns
readonly Feature[] queryFeatures()
queryFeatures(params: QueryParams): Promise<Feature[]> Query features with optional bbox, where filter, and limit.
Returns
Promise<Feature[]> queryExtent()
queryExtent(params?: QueryParams): Promise<Extent> Get bounding extent of query results.
Returns
Promise<Extent> refresh()
refresh(): void Clear cached features and reload data from the source URL. Layer re-fetches and re-renders automatically.
Returns
void Example
const layer = new GeoJSONLayer({
id: 'cities',
url: '/data/cities.geojson',
});
layer.renderer = new SimpleRenderer({
type: 'simple-marker',
color: [255, 100, 50, 255],
size: 8,
});
view.map.add(layer);