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/doc/API.md b/doc/API.md index 8180f1c..53e73b3 100644 --- a/doc/API.md +++ b/doc/API.md @@ -105,6 +105,7 @@ torqueLayer.setSQL("SELECT * FROM table LIMIT 100"); | ```getValueForPos(x, y[, step])```| | an object like { bbox:[], value: VALUE } if there is value for the pos, null otherwise | allows to get the value for the coordinate (in map reference system) for a concrete step. If step is not specified the animation one is used. This method is expensive in terms of CPU so be careful. It returns the value from the raster data not the rendered data | | ```getValueForBBox(xstart, ystart, xend, yend)```| | a number | returns an accumulated numerical value from all the torque areas within the specified bounds | | ```getActivePointsBBox(step)```| | list of bbox | returns the list of bounding boxes active for ``step`` +| ```getValues(step)```| | list of values| returns the list of values for the pixels active in ``step`` | ```invalidate()```| | | forces a reload of the layer data. ### Interaction methods (only available for Leaflet) diff --git a/lib/torque/gmaps/torque.js b/lib/torque/gmaps/torque.js index fe93b57..1f3f39f 100644 --- a/lib/torque/gmaps/torque.js +++ b/lib/torque/gmaps/torque.js @@ -178,6 +178,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(); } @@ -319,6 +320,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; + 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 e5be027..1c26719 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -97,6 +97,7 @@ L.TorqueLayer = L.CanvasLayer.extend({ if (tileData) { self.redraw(); } + self.fire('tileLoaded'); }); }, this); @@ -372,6 +373,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; + 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..4b07d14 100644 --- a/lib/torque/renderer/point.js +++ b/lib/torque/renderer/point.js @@ -313,6 +313,23 @@ 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 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..fa96a04 100644 --- a/test/renderer/point.js +++ b/test/renderer/point.js @@ -115,3 +115,21 @@ test('get value for position', function() { v = renderer.getValueFor(tile, 0, 99, 255 - 3); equal(v, null); }); + +test('get values for tile', function() { + 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); +});