diff --git a/lib/torque/leaflet/torque.js b/lib/torque/leaflet/torque.js index 4b66df5..e64cb4e 100644 --- a/lib/torque/leaflet/torque.js +++ b/lib/torque/leaflet/torque.js @@ -337,6 +337,28 @@ L.TorqueLayer = L.CanvasLayer.extend({ canvas.width = canvas.width; }, + getDataForPoint:function(x,y,callback, maxNo, tolerance){ + var maxNo = maxNo || 10 + var tolerance = tolerance || 10 + + for(var t in this._tiles ){ + tile = this._tiles[t]; + pos = this.getTilePos(tile.coord); + + var tileWidth = 255.0/this.options.resolution + + xx = x - pos.x; + yy = y - pos.y; + + if(xx >= 0 && yy >= 0 && xx < 255 && yy <= 255) { + this.provider.getDataForTorquePixel(tile.coord,xx,yy,maxNo,tolerance,callback) + return this + } + } + callback(null) + return this + + }, /* _filterTile:function(tile){ var noPoints = tile.x.length diff --git a/lib/torque/provider/filterableJson.js b/lib/torque/provider/filterableJson.js index 7b6d50f..77edf2f 100644 --- a/lib/torque/provider/filterableJson.js +++ b/lib/torque/provider/filterableJson.js @@ -424,11 +424,53 @@ var Profiler = require('../profiler'); }); }, + /** + * `tile` the tile the point resides on + * `x` the x pixel coord on the tile + * 'y' the y pixel coord on the tile + * 'maxNo' the maximum number of points to return + * 'pixel tollerance around click' How many pixels to search around the click point + * 'callback' function(rows) returns an array of the data for that point + */ + getDataForTorquePixel:function(tile,x,y,maxNo,tolerance,callback){ + shift = 23 - tile.z + tolerance = tolerance || 20 + var sql =""+ + "with qr as (select * from xyz2range({x},{y},{z})) "+ + "select *, ((quadkey_x & (255 << {shift})) >> {shift}) AS torque_tile_x, "+ + "(255 - ((quadkey_y & (255 << {shift})) >> {shift})) AS torque_tile_y "+ + "from {table}, qr "+ + "where (quadkey between qr.min and qr.max) "+ + "and ((((quadkey_x & (255 << {shift})) >> {shift}) - {torque_tile_x}) between -{tolerance} and {tolerance}) and (((255 - ((quadkey_y & (255 << {shift})) >> {shift})) - {torque_tile_y}) between -{tolerance} and {tolerance}) "+ + "limit {maxNo}" + + var query = format(sql,{ + x: tile.x, + y: tile.y, + z: tile.z, + table: this.options.table, + torque_tile_x: x, + torque_tile_y: y, + maxNo: maxNo, + shift: shift, + tolerance: tolerance + }) + + this.sql(query,function(data){ + if(data){ + var rows = JSON.parse(data.responseText).rows; + callback(rows) + } + else{ + callback(null) + } + }) + }, + /** * `coord` object like {x : tilex, y: tiley } * `zoom` quadtree zoom level */ - _getTileData: function(coord, zoom, callback) { var prof_fetch_time = Profiler.metric('ProviderJSON:tile_fetch_time').start() this.table = this.options.table;