Skip to content

Commit 49c0a15

Browse files
committed
add more debugging
1 parent cbf50aa commit 49c0a15

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ const map = L.map('fractal', {
1515

1616
map.addLayer(new MandelbrotLayer({ tileSize }));
1717
map.mandelbrotHash.enable();
18+
map.mouseDebug.enable();
1819

1920
window.map = map;

mandelbrot-hash-handler.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ const Hash = L.Handler.extend({
6565
}
6666
});
6767

68+
const MouseDebugHandler = L.Handler.extend({
69+
addHooks() {
70+
L.DomEvent.on(document, 'click', this._onMouse, this);
71+
},
72+
_onMouse(event) {
73+
console.log(this._map.mouseEventToLatLng(event));
74+
}
75+
});
76+
6877
L.Map.addInitHook('addHandler', 'mandelbrotHash', Hash);
78+
L.Map.addInitHook('addHandler', 'mouseDebug', MouseDebugHandler);

mandelbrot-layer.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,38 @@ export default L.GridLayer.extend({
3535
onAdd(map) {
3636
L.GridLayer.prototype.onAdd.apply(this, arguments);
3737
map._mandelbrotLayer = this;
38-
map.on('zoom', () => {
38+
map.on('zoomend', () => {
3939
const roundZoom = Math.round(map.getZoom());
4040
this._renderer.clearJobs(job => job.message.zoom !== roundZoom);
4141
});
42+
map.on('moveend', () => {
43+
const start = this._map._mandelbrotLayer._renderer._jobs.size;
44+
const bounds = this._map.getBounds();
45+
let lastRemoved;
46+
this._renderer.clearJobs(job => {
47+
const {
48+
realMin,
49+
imagMin,
50+
realMax,
51+
imagMax,
52+
} = job.message.coords;
53+
const jobBounds = L.latLngBounds(
54+
L.latLng(imagMax, realMax),
55+
L.latLng(imagMin, realMin),
56+
);
57+
const inBounds = bounds.overlaps(jobBounds);
58+
if (!inBounds) {
59+
lastRemoved = {
60+
bounds,
61+
jobBounds,
62+
job,
63+
}
64+
}
65+
return inBounds;
66+
});
67+
const end = this._map._mandelbrotLayer._renderer._jobs.size;
68+
console.log(`ditched ${start - end} out of ${start} jobs!`, lastRemoved);
69+
});
4270
map.fire('iterationschange', { value: this.options.iterations });
4371
},
4472

0 commit comments

Comments
 (0)