@icgcat/layer-types v0.0.9
@icgcat/layer-types
Introduction
@icgcat/layer-types is a JavaScript package that simplifies integrating geospatial data into a Map library, supporting FlatGeobuf (FGB), WMS, PMTiles, and Raster COG file formats. It handles vector and raster tiles, offering easy customization for styling and layer rendering.
Installation
To install the package, use npm or yarn:
npm install @icgcat/layer-typesUsage
Import and Basic Example
Here's how to use the stats functions in your application:
<script>
import { getSrcLayerFromFGB } from '@layer-types/layer-types';
const fgbLayer = getSrcLayerFromFGB("https://tilemaps.icgc.cat/vector/fgb/arees_hidrogeologiques_aquifers_vigent.fgb", 'aquifers_fgb');
</script>Component Functions
getSrcLayerFromFGB(url, idLayer) ⇒ Promise.<Object>
Fetches a FlatGeobuf (FGB) file and converts its contents into a Map layer, based on the geometry type of the features within the file. The layer is created using the provided layer ID. The resulting layer can be used in a MapLibre map.
Kind: global function
Returns: Promise.<Object> - A promise that resolves to an object containing sourceContent and layerContent.
Throws:
- Error Throws an error if the geometry type cannot be determined from the features in the file.
| Param | Type | Description |
|---|---|---|
| url | string | The URL of the FlatGeobuf (FGB) file to be fetched. |
| idLayer | string | The ID to be used for the source and layer in the map. |
Example
const fgbLayer = await getSrcLayerFromFGB("https://example.com/data.fgb", "myLayer");getSrcLayerFromWMS(url, idLayer) ⇒ Object
Creates a Map layer from a WMS (Web Map Service) source using the provided URL and layer ID.
Kind: global function
Returns: Object - An object containing sourceContent and layerContent.
| Param | Type | Description |
|---|---|---|
| url | string | Base URL of the WMS service, which may include a placeholder for {bbox-epsg-3857} that will be replaced dynamically. |
| idLayer | string | The ID to be used for the source and layer in the map. |
Example
const wmsLayer = getSrcLayerFromWMS("https://example.com/wms?service=WMS&request=GetMap&version=1.1.1&layers={layer}&format=image/png&transparent=true&width=512&height=512&srs=EPSG:3857&bbox={bbox-epsg-3857}", "myWmsLayer");getSrcLayerFromPMTiles(url, idLayer) ⇒ Object
Converts a PMTiles file into a Map layer based on its content type (vector or raster). Supports both vector and raster tiles within the PMTiles format.
Kind: global function
Returns: Object - An object containing sourceContent and layerContent.
| Param | Type | Description |
|---|---|---|
| url | string | URL of the PMTiles file to be fetched. |
| idLayer | string | The ID to be used for the source and layers in the map. |
Example
const pmtilesLayer = await getSrcLayerFromPMTiles("https://example.com/tiles.pmtiles", "myPmtilesLayer");getSrcLayerFromCOG(url, idLayer) ⇒ Object
Converts a Cloud Optimized GeoTIFF (COG) into a Map raster layer.
Supports optional customization of layer properties using the provided idLayer.
Kind: global function
Returns: Object - An object containing sourceContent and layerContent.
| Param | Type | Description |
|---|---|---|
| url | string | URL of the Raster COG file to be fetched. |
| idLayer | string | The ID to be used for the source and layer in the map. |
Example
const cogLayer = getSrcLayerFromCOG("https://example.com/image.tif", "myCogLayer");Dependencies
@icgc/stats integrates the following libraries:
- pmtiles
- flatgeobuf
- cogProtocol
- maplibre-gl
Developed by:
License
This project is licensed under the MIT License.
6 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago