Skip to content

Commit

Permalink
update snow
Browse files Browse the repository at this point in the history
  • Loading branch information
atlefren committed Dec 7, 2015
1 parent cf0e52b commit 029a1dd
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bower_components/L.SnowLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
initialize: function (userDrawFunc, options) {
this._userDrawFunc = userDrawFunc;
L.setOptions(this, options);
this.isStatic = true;
},

drawing: function (userDrawFunc) {
Expand Down Expand Up @@ -52,11 +53,14 @@
}

this._reset();
if (this.isStatic) {
this._redrawCanvas();
}
},

onRemove: function (map) {
map.getPanes().overlayPane.removeChild(this._canvas);

map.off('moveend', this._reset, this);
map.off('resize', this._resize, this);

Expand Down Expand Up @@ -84,6 +88,12 @@
},

_redraw: function () {
if (!this.isStatic) {
this._redrawCanvas();
}
},

_redrawCanvas: function () {
var size = this._map.getSize();
var bounds = this._map.getBounds();
var zoomScale = (size.x * 180) / (20037508.34 * (bounds.getEast() - bounds.getWest())); // resolution = 1/zoomScale
Expand Down Expand Up @@ -114,19 +124,21 @@
return new L.CanvasOverlay(userDrawFunc, options);
};

function getDrawSnow(color) {
color = color || 'rgba(255, 255, 255, 0.8)';
function getDrawSnow(color, mp) {

color = color || 'rgba(255, 255, 255, 0.8)';
mp = mp || 25; //max particles
//snow drawing function from http://thecodeplayer.com/walkthrough/html5-canvas-snow-effect
return function drawSnow(canvasOverlay, params) {
console.log("draw")
var ctx = params.canvas.getContext('2d');

//canvas dimensions
var W = window.innerWidth;
var H = window.innerHeight;

//snowflake particles
var mp = 25; //max particles

var particles = [];
for(var i = 0; i < mp; i++) {
particles.push({
Expand Down Expand Up @@ -190,8 +202,8 @@
};
}

L.snowLayer = function (color) {
return new L.CanvasOverlay(getDrawSnow(color));
L.snowLayer = function (options) {
return new L.CanvasOverlay(getDrawSnow(options.color, options.maxFlakes));
};

}());

0 comments on commit 029a1dd

Please sign in to comment.