From ff269a5ecfbb27b72754dd16959de4afdcb6ff2f Mon Sep 17 00:00:00 2001 From: javi Date: Fri, 2 Oct 2015 17:29:53 +0200 Subject: [PATCH] added getValues to fetch values for step. Also adds some signals needed to be able to use it and some fixes to the makefile --- Makefile | 4 ++-- lib/torque/gmaps/torque.js | 15 +++++++++++++++ lib/torque/leaflet/torque.js | 15 +++++++++++++++ lib/torque/renderer/point.js | 22 ++++++++++++++++++++++ test/renderer/point.js | 19 +++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 37f73b0..b004cef 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ add-header: node lib/header.js prepare-test-suite: - browserify test/suite.js > test/suite-bundle.js + $(BROWSERIFY) test/suite.js > test/suite-bundle.js test: prepare-test-suite @echo "***tests***" @@ -43,7 +43,7 @@ test: prepare-test-suite test-acceptance: clean-results @echo "***acceptance***" - ./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name *.js` + ./node_modules/.bin/qunit -c lib/torque/ -t `find test/acceptance/ -name "*.js"` test-all: test test-acceptance diff --git a/lib/torque/gmaps/torque.js b/lib/torque/gmaps/torque.js index c6fbddc..8dbb45f 100644 --- a/lib/torque/gmaps/torque.js +++ b/lib/torque/gmaps/torque.js @@ -175,6 +175,7 @@ GMapsTorqueLayer.prototype = torque.extend({}, // don't load tiles that are not being shown if (t.zoom !== self.options.map.getZoom()) return; self._tileLoaded(t, tileData); + self.fire('tileLoaded'); if (tileData) { self.redraw(); } @@ -316,6 +317,20 @@ GMapsTorqueLayer.prototype = torque.extend({}, google.maps.event.removeListener(this._cacheListener); }, + /** + * return an array with the values for all the pixels active for the step + */ + getValues: function(step) { + var values = []; + step = step === undefined ? this.key: step; + var t, tile, pos, value = null, xx, yy; + for(t in this._tiles) { + tile = this._tiles[t]; + this.renderer.getValues(tile, step, values); + } + return values; + }, + getValueForPos: function(x, y, step) { step = step === undefined ? this.key: step; var t, tile, pos, value = null, xx, yy; diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index 1882773..8069267 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -94,6 +94,7 @@ L.TorqueLayer = L.CanvasLayer.extend({ if (tileData) { self.redraw(); } + self.fire('tileLoaded'); }); }, this); @@ -369,6 +370,20 @@ L.TorqueLayer = L.CanvasLayer.extend({ return positions; }, + /** + * return an array with the values for all the pixels active for the step + */ + getValues: function(step) { + var values = []; + step = step === undefined ? this.key: step; + var t, tile, pos, value = null, xx, yy; + for(t in this._tiles) { + tile = this._tiles[t]; + this.renderer.getValues(tile, step, values); + } + return values; + }, + /** * return the value for position relative to map coordinates. null for no value */ diff --git a/lib/torque/renderer/point.js b/lib/torque/renderer/point.js index 9e6007d..2019546 100644 --- a/lib/torque/renderer/point.js +++ b/lib/torque/renderer/point.js @@ -313,6 +313,28 @@ var Filters = require('./torque_filters'); return positions; }, + /** + * returns an array with all the values for the active pixels + * @tile tile object + * @step integer with the step + * @values (optional) an array where the values will be placed + */ + getValues: function(tile, step, values) { + values = values || []; + var res = this.options.resolution; + var res2 = res >> 1; + + var tileMax = this.options.resolution * (this.TILE_SIZE/this.options.resolution - 1); + //this.renderer.renderTile(tile, this.key, pos.x, pos.y); + var activePixels = tile.timeCount[step]; + var pixelIndex = tile.timeIndex[step]; + for(var p = 0; p < activePixels; ++p) { + var posIdx = tile.renderDataPos[pixelIndex + p]; + values.push(tile.renderData[pixelIndex + p]); + } + return values; + }, + // return the value for x, y (tile coordinates) // null for no value getValueFor: function(tile, step, px, py) { diff --git a/test/renderer/point.js b/test/renderer/point.js index 6bb05a8..2c45bee 100644 --- a/test/renderer/point.js +++ b/test/renderer/point.js @@ -115,3 +115,22 @@ test('get value for position', function() { v = renderer.getValueFor(tile, 0, 99, 255 - 3); equal(v, null); }); + +test('get values for tile', function() { + var mercator = new torque.Mercator(); + tile = { + timeCount: [2], + timeIndex: [0], + renderDataPos: [0, 0], + renderData: [5, 7], + x: [100], + y: [3], + coord: { x: 0, y: 0, z: 0 } + }; + renderer.options = { + resolution: 1 + }; + v = renderer.getValues(tile, 0); + equal(v[0], 5); + equal(v[1], 7); +});