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

leaflet.webgl-temperature-map

v0.2.0

Published

Minimalist heat map Leaflet.js library using WebGL inspired by [temperature-map-gl](https://github.com/ham-systems/temperature-map-gl)

Downloads

99

Readme

Leaflet.WebglTemperatureMap

A simple and fast Leaflet Library to draw temperature maps (heat maps) using WebGL in pure Javascript. Except a O(N) pre-process step which is done in Javascipt, all calculations and drawing are done with shaders in WebGL, so it is pretty fast.

Inspired by temperature-map-gl

Triangulation of mask powered by earcut

In plans rewrite hole package to pixi or three.js (or may be pts) from naked webGL

Demo

Basic Usage

    npm i --save leaflet.webgl-temperature-map
import L from 'leaflet';
import 'leaflet.webgl-temprature-map';

const map = L.map(); // creates map

const tempMap = L.webGlTemperatureMapLayer().addTo(map);

tempMap.setPoints([
  [2630.0850293955414, 7132.896936250415, 64.16567943765965],
  [4065.465306828053, 600.8491068712285, 41.28007958055719],
  [4559.413280590601, 6877.027363962465, 30.497164030229907]
]);

points are in this format:

// x, y - can be lat lng (must set second param in setPoints as { isLatLng: true}), or screen coords
const points = [[x0, y0, v0], [x1, y1, v1], ...[xN, yN, vN]];

Requirements

Reference

L.webGlTemperatureMapLayer(options)

Return Object of class

Options

  • All options from Leaflet setOptions
  • idwOptions - options to temperature map: {
    • p: 5,
    • canvas: null,
    • zIndex: 10,
    • opacity: 0.35,
    • range_factor: 0.00390625,
    • gamma: 2.2,
    • debug_points: false, // work only for debug - not right position on zoom after move
    • framebuffer_factor: 1,
    • isNullColorized: true, // to transparent background set false
    • point_text:
      let v;
      if (val < 1) v = val.toFixed(2);
      else if (val < 10) v = val.toFixed(1);
      else v = Math.round(val);
      return v;
      }
    }

Methods

  • onAdd(map): Sets temperature map to leaflet map.
  • setPoints(points: [x, y, value], options: { isLatLng: false }): Adds array of points to the temperature map and draws it. X, y - can be lat lng, or screen coords.
  • needRedraw(): Redraws the temperature map.

Callbacks

  • onDrawLayer({ layer, canvas, bounds, size, zoom, center, ce, ce_b, corner }): Call when layer did redraw.
  • onLayerWillUnmount(): Call when layer will unmount.
  • onLayerDidMount(): Call when layer did mount.

Changelog

0.1.0 — July 05, 2020

  • Fix default options

0.1.0 — July 05, 2020

  • Add options to temperature map.
  • Add ability to set background transparent
  • Add ability to set points as lat,lng or L.Point

0.0.1 — May 06, 2020

  • Initial release.

License

MIT License

Technical explanation

Values are calculated using 'Inverse Distance Weighting (IDW)' algorithm:

Wikipedia - Inverse Distance Weighting

The rest of the explanation makes sense only in the context of the wikipedia article above...

For every point, we perform a render pass to a texture. Using IDW, we calculate the point "influence" to every fragment using a fragment shader. We store the ui*wi at the r channel of the texture and w_i at the g channel. Using blending with "accumulator" configuration, we end end up with a texture, where we have the top sum of IDW in r channel, and the bottom sum at the g channel. Since channels WebGL are clamped in [0,1], we multiply both channels with range_factor to avoid clamping.

At last, we perform a last pass where we get the IDW value by reading the calculation texture and do a r/g at every fragment. We then use this value to determine the color of the fragment.