0.2.159 • Published 5 months ago

leaflet.webgl-temperature-map-forked v0.2.159

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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.

0.2.159

5 months ago

0.2.158

5 months ago

0.2.157

5 months ago

0.2.156

5 months ago

0.2.155

5 months ago

0.2.154

5 months ago

0.2.153

5 months ago

0.2.152

5 months ago

0.2.151

5 months ago

0.2.150

5 months ago

0.2.149

5 months ago

0.2.148

5 months ago

0.2.147

5 months ago

0.2.146

5 months ago

0.2.145

5 months ago

0.2.144

5 months ago

0.2.143

5 months ago

0.2.142

5 months ago

0.2.141

5 months ago

0.2.140

5 months ago

0.2.139

5 months ago

0.2.138

5 months ago

0.2.137

5 months ago

0.2.136

5 months ago

0.2.135

5 months ago

0.2.134

5 months ago

0.2.133

5 months ago

0.2.132

5 months ago

0.2.131

5 months ago

0.2.130

5 months ago

0.2.129

5 months ago

0.2.128

5 months ago

0.2.127

5 months ago

0.2.126

5 months ago

0.2.125

5 months ago

0.2.124

5 months ago

0.2.123

5 months ago

0.2.122

5 months ago

0.2.121

5 months ago

0.2.120

5 months ago

0.2.119

5 months ago

0.2.118

5 months ago

0.2.117

5 months ago

0.2.116

5 months ago

0.2.115

5 months ago

0.2.114

5 months ago

0.2.113

5 months ago

0.2.112

5 months ago

0.2.111

5 months ago

0.2.110

5 months ago

0.2.109

5 months ago

0.2.108

5 months ago

0.2.107

5 months ago

0.2.106

5 months ago

0.2.105

5 months ago

0.2.104

5 months ago

0.2.103

5 months ago

0.2.102

5 months ago

0.2.101

5 months ago

0.2.100

5 months ago

0.2.99

5 months ago

0.2.98

5 months ago

0.2.97

5 months ago

0.2.96

5 months ago

0.2.95

5 months ago

0.2.94

5 months ago

0.2.93

5 months ago

0.2.92

5 months ago

0.2.91

5 months ago

0.2.90

5 months ago

0.2.89

5 months ago

0.2.88

5 months ago

0.2.87

5 months ago

0.2.86

5 months ago

0.2.85

5 months ago

0.2.84

5 months ago

0.2.83

5 months ago

0.2.82

5 months ago

0.2.81

5 months ago

0.2.80

5 months ago

0.2.79

5 months ago

0.2.78

5 months ago

0.2.77

5 months ago

0.2.76

5 months ago

0.2.75

5 months ago

0.2.74

5 months ago

0.2.73

5 months ago

0.2.72

5 months ago

0.2.71

5 months ago

0.2.70

5 months ago

0.2.69

5 months ago

0.2.68

5 months ago

0.2.67

5 months ago

0.2.66

5 months ago

0.2.65

5 months ago

0.2.64

5 months ago

0.2.63

5 months ago

0.2.62

5 months ago

0.2.61

5 months ago

0.2.60

5 months ago

0.2.59

5 months ago

0.2.57

5 months ago

0.2.56

5 months ago

0.2.55

5 months ago

0.2.54

5 months ago

0.2.53

5 months ago

0.2.52

5 months ago

0.2.51

5 months ago

0.2.50

5 months ago

0.2.49

5 months ago

0.2.48

5 months ago

0.2.47

5 months ago

0.2.46

5 months ago

0.2.45

5 months ago

0.2.44

5 months ago

0.2.43

5 months ago

0.2.42

5 months ago

0.2.41

5 months ago

0.2.40

5 months ago

0.2.39

5 months ago

0.2.38

5 months ago

0.2.37

5 months ago

0.2.36

5 months ago

0.2.35

5 months ago

0.2.34

5 months ago

0.2.33

5 months ago

0.2.32

5 months ago

0.2.31

5 months ago

0.2.30

5 months ago

0.2.29

5 months ago

0.2.28

5 months ago

0.2.27

5 months ago

0.2.26

5 months ago

0.2.25

5 months ago

0.2.24

5 months ago

0.2.23

5 months ago

0.2.22

5 months ago

0.2.21

5 months ago

0.2.20

5 months ago

0.2.19

5 months ago

0.2.18

5 months ago

0.2.17

5 months ago

0.2.16

5 months ago

0.2.15

5 months ago

0.2.14

5 months ago

0.2.13

5 months ago

0.2.12

5 months ago

0.2.11

5 months ago

0.2.10

5 months ago

0.2.9

5 months ago

0.2.8

5 months ago

0.2.7

5 months ago

0.2.6

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago