npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@naivemap/mapbox-gl-grid-layer

v0.2.0

Published

Render colorful grid data.

Downloads

14

Readme

GridLayer class

npm i @naivemap/mapbox-gl-grid-layer proj4

Signature:

export default class GridLayer implements mapboxgl.CustomLayerInterface

Implements: mapboxgl.CustomLayerInterface

Constructors

| Constructor | Description | | --- | --- | | (constructor)(id: string, option: GridOption) | Constructs a new instance of the GridLayer class |

Parameters

id (string) The ID of the layer.

option (GridOption) The option of the grid.

| Name | Description | | --- | --- | | option.data (GridData) | The grid data. | | option.colorOption (ColorOption) | The color options used to render the grid. | | option.resampling (Optional enum. One of "linear", "nearest". Defaults to "linear") | The resampling/interpolation method to use for overscaling, also known as texture magnification filter. ref: raster-resampling | | option.opacity (Optional number between 0 and 1 inclusive. Defaults to 1. | The opacity at which the grid will be drawn. | | option.mask (MaskProperty) | The polygonal mask or multipolygonal mask for the grid. |

export type GridOption = {
  data: GridData
  colorOption: ColorOption
  resampling?: 'linear' | 'nearest'
  opacity?: number
  mask?: MaskProperty
}

export type GridData = {
  data: number[][]
  metadata: Metadata
}

export type Metadata = {
  ncols: number // Number of cell columns
  nrows: number // Number of cell rows
  cellsize: number // Cell size
  xll: number // X-coordinate of the origin (by center or lower left corner of the cell)
  yll: number // Y-coordinate of the origin (by center or lower left corner of the cell)
  lltype?: 'center' | 'corner' // Is the origin the center or corner of the cell. Defaults to 'center'
  nodata_value?: number // The input values to be NoData in the output raster。Defaults to -9999.。
  projection?: string // Projection with EPSG code. Defaults to `'EPSG:4326'`.
}

export type ColorOption = {
  type: ColorType
  colors: Color[]
  values: number[]
  boundsType?: BOUNDS_TYPE
}

export type MaskProperty = {
  type?: 'in' | 'out' // Default is 'in'
  data: GeoJSON.Polygon | GeoJSON.MultiPolygon
}

export type ColorType = 'unique' | 'classified' | 'stretched'
export type Color = [number, number, number, number] | string

export enum BOUNDS_TYPE {
  INCLUDE_MIN_AND_MAX, // min <= value <= max
  INCLUDE_MAX, // min < value <= max
  INCLUDE_MIN, // min <= value < max
  EXCLUSIVE, // min < value < max
}

Methods

updateColorOption

Updates the colorOption.

updateColorOption(option: Partial<ColorOption>): this

updateMask

Updates the mask property.

updateMask(mask: Partial<MaskProperty>): this

Example

const gridLayer = new GridLayer('grid-layer', {
  data: {
    data: [
      [1, -2, 3, 5, 4],
      [2, -9999, 2, 2, 4],
      [3, 5, 1, 0, 0],
    ],
    metadata: {
      xll: 106,
      yll: 30,
      cellsize: 1,
      ncols: 5,
      nrows: 3,
    },
  },
  colorOption: {
    type: 'classified',
    colors: ['#f00', '#0f0', '#00f', '#ff0'],
    values: [1, 2, 3, 4, 5],
  },
})

map.addLayer(gridLayer)