Skip to content

Instantly share code, notes, and snippets.

View mourner's full-sized avatar
🔥
making stuff faster

Volodymyr Agafonkin mourner

🔥
making stuff faster
View GitHub Profile
@mourner
mourner / patch.js
Created October 15, 2015 20:37
Temporary workaround for Leaflet 0.7.5 disappearing tiles on iOS
L.Map.prototype._onZoomTransitionEnd = function () {
if (!this._animatingZoom) { return; }
this._animatingZoom = false;
L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim');
L.Util.requestAnimFrame(function () {
this._resetView(this._animateToCenter, this._animateToZoom, true, true);
@mourner
mourner / convert.js
Created September 30, 2015 08:37
A proof of concept for efficient point encoding in vector tiles
var tile = require('./points.json');
tile.layers.forEach(function (layer) {
layer.id = [];
layer.geometry = [];
layer.tags = [];
var x0 = 0;
/*
@class Control.Attribution
@aka L.Control.Attribution; @inherits Control
The attribution control allows you to display attribution data in a small text box on a map.
It is put on the map by default unless you set its [`attributionControl` option](#map-attributioncontrol) to `false`,
and it fetches attribution texts from layers with the [`getAttribution` method](#layer-getattribution) automatically.
Extends Control.
*/
@mourner
mourner / index.html
Last active August 29, 2015 14:16
reqAnimFrame animation vs CSS transition performance
<!DOCTYPE html>
<html>
<head>
<title>Animation Test</title>
<style>
html, body {
height: 100%;
}
button {
diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js
index d98994f..596d47f 100644
--- a/src/layer/tile/GridLayer.js
+++ b/src/layer/tile/GridLayer.js
@@ -301,26 +301,29 @@ L.GridLayer = L.Layer.extend({
},
_viewReset: function (e) {
- var map = this._map;
- this._reset(map.getCenter(), map.getZoom(), e && e.hard);
@mourner
mourner / earcut.d.ts
Last active August 29, 2015 14:15
mapbox/earcut type definitions
// TypeScript type definitions to use for reference when porting Earcut to other languages
declare module 'earcut' {
interface Point extends Array<number> {}
interface Ring extends Array<Point> {}
interface Polygon extends Array<Ring> {}
interface Triangles extends Array<Point> {}
@mourner
mourner / bench-node.js
Last active August 29, 2015 14:15
A simple benchmark snippet for Node; simple alternative to benchmark.js
var start = now(),
ops = 0;
while (now() - start < 1) {
// [...] routine to bench goes here
ops++;
}
console.log(Math.round(ops / (now() - start)) + ' ops/s');
@mourner
mourner / test.js
Last active August 29, 2015 14:15
simple benchmarking snippet for v8 & node
function test() {
for (var i = 0, array = []; i < 1000; i++) array.push(i, i);
}
var start = Date.now(), ops = 0;
do { test(); ops++; } while (Date.now() - start < 1000);
(typeof console !== 'undefined' ? console.log : print)(ops + ' ops/s');
@mourner
mourner / vector_tile.js
Last active August 29, 2015 14:12
How a generated pbf encoding/decoding code should look
'use strict';
exports.Tile = {read: readTile, write: writeTile};
exports.Layer = {read: readLayer, write: writeLayer};
exports.Feature = {read: readFeature, write: writeFeature};
exports.Value = {read: readValue, write: writeValue};
// decoding vector tile
function readTile(pbf, end) {
@mourner
mourner / geobuf2.proto
Last active June 5, 2023 06:38
A new take on Geobuf compact geospatial encoding format
option optimize_for = LITE_RUNTIME;
message Data {
message FeatureCollection {
repeated Feature features = 1;
}
message Feature {