Skip to content

Instantly share code, notes, and snippets.

@simmo
simmo / throttle.js
Last active Jun 22, 2018
JavaScript Throttle using requestAnimationFrame
View throttle.js
function throttle(type, name, obj) {
var running = false;
obj = obj || window;
var func = function() {
if (running) return;
running = true;
@Sumbera
Sumbera / L.CanvasOverlay.js
Last active Jul 9, 2021
Leaflet Canvas Overlay
View L.CanvasOverlay.js
/*
UPDATE July 2016 , moved and updated to here: https://github.com/Sumbera/gLayers.Leaflet
Generic Canvas Overlay for leaflet,
Stanislav Sumbera, April , 2014
- added userDrawFunc that is called when Canvas need to be redrawn
- added few useful params fro userDrawFunc callback
- fixed resize map bug
inspired & portions taken from : https://github.com/Leaflet/Leaflet.heat
@jjmu15
jjmu15 / in_viewport.js
Created Jan 27, 2014
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
View in_viewport.js
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@davoclavo
davoclavo / dataURItoBlob.js
Last active Jun 2, 2021
Convert dataURI to Blob so large images do not crash the browser. Based on: http://stackoverflow.com/questions/10412299 and http://stackoverflow.com/questions/6850276
View dataURItoBlob.js
/*
The MIT License (MIT)
Copyright (c) 2016 David Gomez-Urquiza
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION