
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
stac-layer
Advanced tools
npm install stac-layer
import stacLayer from 'stac-layer';
// create your Leaflet map
const map = L.map('map');
// set options for the STAC layer
const options = {
// see table below for supported options, for example:
resolution: 128
};
// create layer
const layer = await stacLayer(data, options);
// add layer to map
layer.addTo(map);
// fit map to layer
map.fitBounds(layer.getBounds());
The following options are supported:
| Option | Data Type | Default value | Description |
|---|---|---|---|
baseUrl | string | href of the self link in the STAC data | The base URL for relative links. Should be provided if the STAC data has no self link and links are not absolute, or you pass a STAC Asset only. |
buildTileUrlTemplate | function | undefined | For server-side rendering of imagery. See the chapter using a tiler and buildTileUrlTemplate for details. |
crossOrigin | string|null | undefined | The value for the crossorigin attribute that is set when loading images through the browser. |
displayGeoTiffByDefault | boolean | false | Allow to display non-cloud-optimized GeoTiffs by default, which might not work well for larger files. |
displayPreview | boolean | false | Allow to display the asset with role thumbnail or the link with relation type preview. The previews are usually not covering the full extents and as such may be placed incorrectly on the map. |
displayOverview | boolean | true | Allow to display the asset with role overview or visual. |
debugLevel | integer | 0 | The higher the value the more debugging messages will be logged to the console. 0 to disable logging. |
1. latLngBounds2. bounds3. bbox | 1. latLngBounds 2. bounds 3. [West, South, East, North] | undefined | Provide one of these options if the data is a STAC Assets only: The bounding box of the asset |
resolution | integer | 32 | Adjust the display resolution, a power of two such as 32, 64, 128 or 256. By default the value is set to render quickly, but with limited resolution. Increase this value for better resolution, but slower rendering speed (e.g., 128). |
tileUrlTemplate | string | undefined | For server-side rendering of imagery. See the chapter using a tiler and tileUrlTemplate for details. |
useTileLayerAsFallback | boolean | false | Enables server-side rendering of imagery in case an error has happened on the client-side. See the chapter using a tiler and useTileLayerAsFallback for details. |
There's are a couple different ways to use a tiler to serve images of assets that are Cloud-Optimized GeoTIFFs.
Note: To enforce using server-side rendering of imagery useTileLayerAsFallback must be set to false and either tileUrlTemplate or buildTileUrlTemplate must be given.
You can set tileUrlTemplate, which will be passed to Leaflet's TileLayer. This will apply to whichever asset stac-layer chooses as the best GeoTIFF for visualization.
// a STAC Feature
const layer = await stacLayer(data, {
tileUrlTemplate: "https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url={url}"
});
If you need more dynamic customization, consider passing in a buildTileUrlTemplate function. You can use this function to change the tile url and its parameters depending on the
type of asset.
const layer = await stacLayer(data, {
buildTileUrlTemplate: ({
href, // the url to the GeoTIFF
asset, // the STAC Asset object
key, // the key or name in the assets object that points to the particular asset
item, // the STAC item / feature
bounds, // LatLngBounds of the STAC asset
isCOG: true, // true if the asset is definitely a cloud-optimized GeoTIFF
isVisual: true, // true when the asset's key is "visual" (case-insensitive)
}) => {
// assets has three bands of RGB, so no need to specify bands
if (isVisual) return "https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url={url}";
// select first three bands for non-visual assets, such as NAIP 4-band imagery
// where we might want to ignore the Near-Infrared Band
else return "https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url={url}&bands=1,2,3"
}
});
If you'd like to only use a tiler if GeoRasterLayer fails, set useTileLayerAsFallback to true.
const layer = await stacLayer(data, {
tileUrlTemplate: "https://tiles.rdnt.io/tiles/{z}/{x}/{y}@2x?url={url}",
useTileLayerAsFallback: true
});
STAC Layer added a "stac" property to Leaflet's onClick events that include the STAC information of what the user clicked. It can be a STAC collection, feature, asset, or even an array of assets when a composite of multiple assets are being visualized.
const featureCollection = ....; // a GeoJSON Feature Collection of STAC Features
const layer = await stacLayer(featureCollection);
layer.on("click", e => {
const { type, data } = e.stac;
// type is one of "Collection", "Feature", "Assets", or "Asset"
// data is the item that was clicked in the collection
});
Sometimes you might like to know information about what is being visualized.
You can access this information through the stac key attached to the layer.
const layer = await stacLayer(data, options);
layer.stac could be the following
{
"assets": [
{
"key": "visual",
"asset": {
"href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif",
"type": "image/tiff; application=geotiff; profile=cloud-optimized",
"title": "3-Band Visual",
"roles": [
"visual"
],
"eo:bands": [
{
"name": "band3",
"common_name": "red",
"center_wavelength": 645,
"full_width_half_max": 90
},
{
"name": "band2",
"common_name": "green",
"center_wavelength": 560,
"full_width_half_max": 80
},
{
"name": "band1",
"common_name": "blue",
"center_wavelength": 470,
"full_width_half_max": 70
}
]
}
}
],
"bands": [
{
"name": "band3",
"common_name": "red",
"center_wavelength": 645,
"full_width_half_max": 90
},
{
"name": "band2",
"common_name": "green",
"center_wavelength": 560,
"full_width_half_max": 80
},
{
"name": "band1",
"common_name": "blue",
"center_wavelength": 470,
"full_width_half_max": 70
}
]
}
STAC Layer fires a custom "fallback" event when an error occurs rendering with GeoRasterLayer and it falls back to trying to use a tiler
const layer = await stacLayer(data, options);
layer.on("fallback", event => {
// event.error is the initial LeafletJS error event
// that triggered the fallback
// layer.stac metadata may change after fallback
// so good to check again now
});
FAQs
Visualize a STAC Item or Collection on a Leaflet Map
The npm package stac-layer receives a total of 77 weekly downloads. As such, stac-layer popularity was classified as not popular.
We found that stac-layer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.