From 9666af30c63df0641edc9f7ed25d848f465875b9 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 23 Oct 2014 01:06:50 -0400 Subject: [PATCH] better point/building culling based on viewport size --- js/id/renderer/features.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/js/id/renderer/features.js b/js/id/renderer/features.js index 1a87a683a..3d9c5e9fa 100644 --- a/js/id/renderer/features.js +++ b/js/id/renderer/features.js @@ -42,7 +42,8 @@ iD.Features = function(context) { }; var dispatch = d3.dispatch('change', 'redraw'), - feature = {}; + feature = {}, + cullFactor = 1; function defineFeature(k, filter, max) { feature[k] = { @@ -53,7 +54,7 @@ iD.Features = function(context) { defaultMax: (max || Infinity), enable: function() { this.enabled = true; this.currentMax = this.defaultMax; }, disable: function() { this.enabled = false; this.currentMax = 0; }, - hidden: function() { return this.count > this.currentMax; } + hidden: function() { return this.count > this.currentMax * cullFactor; } }; } @@ -66,7 +67,7 @@ iD.Features = function(context) { defineFeature('points', function(entity) { return entity.geometry(context.graph()) === 'point'; - }, 100); + }, 200); defineFeature('major_roads', function(entity) { return entity.geometry(context.graph()) === 'line' && major_roads[entity.tags.highway]; @@ -91,7 +92,7 @@ iD.Features = function(context) { entity.tags.parking === 'garage_boxes' ) ) || !!entity.tags['building:part']; - }, 100); + }, 250); defineFeature('landuse', function(entity) { return entity.geometry(context.graph()) === 'area' && @@ -221,7 +222,12 @@ iD.Features = function(context) { }; features.resetStats = function() { + var dimensions = context.map().dimensions(); _.each(feature, function(f) { f.count = 0; }); + + // adjust the threshold for point/building culling based on viewport size.. + // a cullFactor of 1 corresponds to a 1000x1000px viewport.. + cullFactor = dimensions[0] * dimensions[1] / 1000000; }; features.gatherStats = function(d) {