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

geowarp-canvas

v0.2.0

Published

Adds HTML Canvas Support to GeoWarp

Downloads

163

Readme

geowarp-canvas

motivation

Make it easier to display geospatial data on an HTML Canvas Element

design philosophy

geowarp-canvas is designed as a decorator. This library is highly experimental, so this may change in the future. The idea is to find a way to add capabilities to geowarp without adding too much complexity to geowarp core.

usage

import geowarp_core from "geowarp";
import geowarp_canvas from "geowarp-canvas";

const geowarp = geowarp_canvas(geowarp_core);

const canvas = document.createElement("CANVAS");
canvas.height = 256;
canvas.width = 256;

geowarp({
  // required
  // activate geowarp-canvas plugin
  plugins: ["geowarp-canvas"],

  // required
  // this is the canvas that we will paint on
  out_canvas: canvas,

  // optional
  // array of statistics by band
  // could greatly increase speed
  in_stats: [{ min: 0, max: 12345 }, { min: 0, max: 10567 }],

  // optional
  // paint the background of the canvas this color
  // before painting valid data
  out_no_data_color: "pink",

  // optional - experimental
  // draw at a quarter of the real resolution
  out_resolution: [0.25, 0.25],

  // optional
  // custom draw function
  draw: ({ 
    bbox: [xmin, ymin, xmax, ymax], // location of pixel rectangble in un-rounded canvas image coordinates from top-left
    canvas, // same as out_canvas, the canvas you are painting to
    context, // context for the out_canvas
    color, // CSS Color Value, like "rgba(0, 12, 54, 255)"
    pixel, // raw pixel values (before band expression applied)
    rect: [x, y, width, height], // params for fillRect or strokeRect
    rgba, // pixel as [r, g, b, a]
    cell: [row, column], // cell location at current resolution
    resolution: [x_resolution, y_resolution],
    scale: [x_scale, y_scale],
    points: [source_point, target_point], // pixel centroid in projection of data and canvas, only available when method is "near" and turbo is false
    sample: [column_in_data, row_in_data]
  }) => {
    context.fillStyle(color);
    context.fillRect(...rect);
  },

  // optional
  // called with mutable options object that will be passed to geowarp
  before_warp: (options) => {
    const { expr, out_height, skip_no_data_strategy, ...rest } = options;
    // ...
  },

  // optional
  // called after warping with result returned by geowarp
  after_warp: (result) => {
    console.log("result returned by geowarp:", result);
  },

  // optional
  // paint or modify the canvas before
  // drawing the rectangle for the reprojected pixel
  before_draw: ({ bbox, ...rest }) => { },

  // optional
  after_draw: ({ bbox, canvas, context, color, pixel, point, rect, rgba, resolution, scale }) => {
    // put red outline around drawn pixel rectangle
    context.strokeStyle = "red";
    context.strokeRect(...rect);
  },

  // optional
  // array of colors where each index number corresponds to a pixel value
  // each color can be [r, g, b, a], [r, g, b] or "rgb(112, 108, 96)" (CSS Color Values)
  palette: [
    [ 112, 108, 96, 255 ],
    [ 112, 104, 80, 255 ]
    // ...
  ],

  // flip between black-to-white and white-to-black
  flip: true

  // all other params are inherited from
  // https://github.com/danieljdufour/geowarp
});