npm package: @icgcat/layer-types
Description: Layer-types is a library to integrate geospatial data supporting FGB, WMS, PMTiles, Raster COG.
Author: Institut Cartogràfic i Geològic de Catalunya
Latest version: 0.0.13

<div style="text-align:center">
<p>
  <img src="https://eines.icgc.cat/recursos/logos/icgc_logo_color.png"  alt="ICGC Logo" width="250px">
</p>
</div>

<div style="text-align:center">

  [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg?style=flat)](LICENSE.txt) 
  [![Version](https://img.shields.io/npm/v/@icgcat/layer-types?style=flat)](https://www.npmjs.com/package/@icgcat/layer-types) 
  [![LinkedIn](https://img.shields.io/badge/LinkedIn-icgcat-blue?style=flat)](https://www.linkedin.com/company/icgcat)
  <img src="https://eines.icgc.cat/recursos//images/JS-logo.svg" width="20px"/>
  <!--posar aqui svelte image -->
</div>


# @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:

```bash
npm install @icgcat/layer-types
```

---

## Usage

### Import and Basic Example
Here's how to use the stats functions in your application:

```svelte
<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) ⇒ <code>Promise.&lt;Object&gt;</code>
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**: <code>Promise.&lt;Object&gt;</code> - A promise that resolves to an object containing `sourceContent` and `layerContent`.  
**Throws**:

- <code>Error</code> Throws an error if the geometry type cannot be determined from the features in the file.


| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | The URL of the FlatGeobuf (FGB) file to be fetched. |
| idLayer | <code>string</code> | The ID to be used for the source and layer in the map. |

**Example**  
```js
const fgbLayer = await getSrcLayerFromFGB("https://example.com/data.fgb", "myLayer");
```


## getSrcLayerFromWMS(url, idLayer) ⇒ <code>Object</code>
Creates a Map layer from a WMS (Web Map Service) source using the provided URL and layer ID.

**Kind**: global function  
**Returns**: <code>Object</code> - An object containing `sourceContent` and `layerContent`.  

| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | Base URL of the WMS service, which may include a placeholder for `{bbox-epsg-3857}` that will be replaced dynamically. |
| idLayer | <code>string</code> | The ID to be used for the source and layer in the map. |

**Example**  
```js
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) ⇒ <code>Object</code>
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**: <code>Object</code> - An object containing `sourceContent` and `layerContent`.  

| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | URL of the PMTiles file to be fetched. |
| idLayer | <code>string</code> | The ID to be used for the source and layers in the map. |

**Example**  
```js
const pmtilesLayer = await getSrcLayerFromPMTiles("https://example.com/tiles.pmtiles", "myPmtilesLayer");
```


## getSrcLayerFromCOG(url, idLayer) ⇒ <code>Object</code>
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**: <code>Object</code> - An object containing `sourceContent` and `layerContent`.  

| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | URL of the Raster COG file to be fetched. |
| idLayer | <code>string</code> | The ID to be used for the source and layer in the map. |

**Example**  
```js
const cogLayer = getSrcLayerFromCOG("https://example.com/image.tif", "myCogLayer");
```

---

## Dependencies 
`@icgc/stats` integrates the following libraries: 
- <a href="https://www.npmjs.com/package/pmtiles" target="_blank"> pmtiles </a>
- <a href="https://www.npmjs.com/package/flatgeobuf" target="_blank"> flatgeobuf </a>
- <a href="https://www.npmjs.com/package/@geomatico/maplibre-cog-protocol" target="_blank"> cogProtocol </a>
- <a href="https://www.npmjs.com/package/maplibre-gl" target="_blank"> maplibre-gl </a>

## Developed by:

 <a href="https://www.icgc.cat/" target="_blank"><img src="https://eines.icgc.cat/recursos/logos/ICGC_color_norma.svg"  alt="ICGC Logo" width="150"></img></a>      

  <a href="https://web.gencat.cat/" target="_blank"><img src="https://eines.icgc.cat/recursos/logos/gencat_logo_color.png"  alt="Gencat Logo" width="190"></img></a>


## License
This project is licensed under the MIT License.