Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;var HeatmapImageryProvider = (function CreateHeatmapImageryProvider(){
- var defaultHeatmapConfig = {
- radius: 40,
- renderer: 'canvas2d',
- gradient: { 0.25: "rgb(0,0,255)", 0.55: "rgb(0,255,0)", 0.85: "yellow", 1.0: "rgb(255,0,0)"},
- maxOpacity: 1,
- minOpacity: 0,
- blur: 0.85,
- xField: 'x',
- yField: 'y',
- valueField: 'value'
- };
- var defaultOptions = {
- useLocalMaximum: true,
- canvasWidth: 256,
- canvasHeight: 256
- };
- function lon2x(a) { return (a + 180) / 360; }
- function lat2y(a) { return 1 - (Math.log(Math.tan(Math.PI/4)+a*Math.PI/360))/Math.PI; }
- function lon2tilex(a) { return (a + 180) / 360; }
- function lat2tiley(a) { return 1 - (Math.log(Math.tan(a*Math.PI/180)+1/Math.cos(a*Math.PI/360)))/Math.PI; }
- function preprocessingData(data){
- var obj = JSON.parse(data);
- var object = obj["tokens.geopoints_full.geohash_type"];
- var arrayname = object["_type"];
- var points = object[arrayname];
- var maxValue = -1;
- var minValue = Number.MAX_VALUE;
- var value = 0, x = -1, y = -1;
- var latlng = null;
- var newpoints = [];
- for(var p in points) {
- value = 0;
- latlng = null;
- for (var key in p) {
- if (p.hasOwnProperty(key)) {
- if(key == "count") {
- value = p[key];
- maxValue = value > maxValue? value : maxValue;
- minValue = value < minValue? value : minValue;
- }
- else if(key == "term") {
- arr = p[key].split('_');
- latlng = decodeGeoHash(arr[0]);
- x = lon2x(latlng.longitude);
- y = lat2y(latlng.latitude);
- }
- else {
- }
- }
- }
- newpoints.push({x: x, y: y, tilex: lon2tilex(latlng.longitude), tiley: lat2tiley(latlng.latitude), value: value});
- }
- return {min: minValue, max: maxValue, data: newpoints};
- }
- var HeatmapImageryProvider = function HeatmapImageryProvider(hmconfig, options, data) {
- d = preprocessingData(data);
- this._data = d.data;
- this._maxValue = d.max;
- this._minValue = d.min;
- this._canvas = document.createElement('canvas');
- this._canvas.width = options.canvasWidth;
- this._canvas.height = options.canvasHeight;
- this._heatmap = h337.create(this._canvas);
- this._heatmap.configure(hmonfig);
- };
- Object.defineProperty(HeatmapImageryProvider, "ready", {
- get: function () {
- return true;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "hasAlphaChannel", {
- get: function () {
- return true;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "credit", {
- get: function () {
- return undefined;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "rectangle", {
- get: function () {
- return undefined;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "tileWidth", {
- get: function () {
- return this._canvas.width;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "tileHeight", {
- get: function () {
- return this._canvas.height;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "maximumLevel", {
- get: function () {
- return undefined;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "minimumLevel", {
- get: function () {
- return undefined;
- },
- });
- Object.defineProperty(HeatmapImageryProvider, "tilingScheme", {
- get: function () {
- return undefined;
- },
- });
- HeatmapImageryProvider.prototype._drawTile = function(x, y, level) {
- var context = this._canvas.getContext('2d');
- var newdata = [];
- var zoom = Math.pow(2, level - 1);
- for(var p in this._data){
- if((Math.abs(Math.floor(p.tilex*2*zoom) - x) < 2)&&(Math.abs(Math.floor(p.tiley*zoom) - y) < 2)){
- newdata.push({
- x: p.x*2*zoom - this._canvas.width*x,
- y: p.y*zoom - this._canvas.height*y,
- value: p.value
- });
- //maxValue = value > maxValue? value : maxValue;
- //minValue = value < minValue? value : minValue;
- }
- }
- this._heatmap.setData({max: this._maxValue, min: this._minValue, data:newdata});
- return this._canvas;
- };
- HeatmapImageryProvider.prototype.getTileCredits = function(x, y, level) {
- return undefined;
- };
- HeatmapImageryProvider.prototype.requestImage = function(x, y, level) {
- return this._drawTile(x, y, level);
- };
- HeatmapImageryProvider.prototype.pickFeatures = function() {
- return undefined;
- };
- return HeatmapImageryProvider;
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement