diff --git a/pacotes/heatmap/src/heatmap-openlayers.js b/pacotes/heatmap/src/heatmap-openlayers.js index 7096e9c..b17acc1 100755 --- a/pacotes/heatmap/src/heatmap-openlayers.js +++ b/pacotes/heatmap/src/heatmap-openlayers.js @@ -1,16 +1,16 @@ -/* +/* * heatmap.js OpenLayers Heatmap Class * * Copyright (c) 2011, Patrick Wied (http://www.patrick-wied.at) * Dual-licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and the Beerware (http://en.wikipedia.org/wiki/Beerware) license. - * + * * Modified on Jun,06 2011 by Antonio Santiago (http://www.acuriousanimal.com) * - Heatmaps as independent map layer. * - Points based on OpenLayers.LonLat. * - Data initialization in constructor. * - Improved 'addDataPoint' to add new lonlat based points. - */ + */ OpenLayers.Layer.Heatmap = OpenLayers.Class(OpenLayers.Layer, { // the heatmap isn't a basic layer by default - you usually want to display the heatmap over another map ;) isBaseLayer: false, @@ -34,18 +34,18 @@ OpenLayers.Layer.Heatmap = OpenLayers.Class(OpenLayers.Layer, { // create the heatmap with passed heatmap-options this.heatmap = h337.create(hmoptions); - handler = function(){ + handler = function(){ if(this.map && this.tmpData.max){ - this.updateLayer(); + this.updateLayer(); } }; - handler1 = function(){ + handler1 = function(){ if(this.tmpData && this.tmpData.max){ this.toggle(); this.updateLayer(); } }; - + // on zoomend and moveend we have to move the canvas element and redraw the datapoints with new positions //map.events.register("zoomend", this, handler); map.events.register("moveend", this, handler); @@ -53,16 +53,16 @@ OpenLayers.Layer.Heatmap = OpenLayers.Class(OpenLayers.Layer, { map.events.register( "removed", this, - function(){ + function(){ if(this.tmpData.max){ - this.destroy(); + this.destroy(); } }); }, updateLayer: function(){ var pixelOffset = this.getPixelOffset(), el = this.heatmap.get('element'); - // if the pixeloffset e.g. for x was positive move the canvas element to the left by setting left:-offset.y px + // if the pixeloffset e.g. for x was positive move the canvas element to the left by setting left:-offset.y px // otherwise move it the right by setting it a positive value. same for top el.style.top = ((pixelOffset.y > 0)?('-'+pixelOffset.y):(Math.abs(pixelOffset.y)))+'px'; el.style.left = ((pixelOffset.x > 0)?('-'+pixelOffset.x):(Math.abs(pixelOffset.x)))+'px'; @@ -80,9 +80,9 @@ OpenLayers.Layer.Heatmap = OpenLayers.Class(OpenLayers.Layer, { c_lonlat = new OpenLayers.LonLat(c.lon, c.lat), c_pixel = this.mapLayer.getViewPortPxFromLonLat(c_lonlat); - return { + return { x: o_pixel.x - c_pixel.x, - y: o_pixel.y - c_pixel.y + y: o_pixel.y - c_pixel.y }; }, @@ -90,20 +90,31 @@ OpenLayers.Layer.Heatmap = OpenLayers.Class(OpenLayers.Layer, { var set = {}, dataset = obj.data, dlen = dataset.length, - entry, lonlat, pixel; + entry, lonlat, pixel, proj, tproj, vp; set.max = obj.max; set.data = []; + // get the pixels for all the lonlat entries + proj = this.map.getProjectionObject(); + tproj = this.projection; while(dlen--){ - entry = dataset[dlen], - lonlat = entry.lonlat.clone().transform(this.projection, this.map.getProjectionObject()), - pixel = this.roundPixels(this.getViewPortPxFromLonLat(lonlat)); + entry = dataset[dlen]; + try{ + lonlat = entry.lonlat.clone().transform(tproj, proj); + if(lonlat){ + vp = this.getViewPortPxFromLonLat(lonlat); - if(pixel){ - set.data.push({x: pixel.x, y: pixel.y, count: entry.count}); + pixel = this.roundPixels(vp); + + if(pixel){ + set.data.push({x: pixel.x, y: pixel.y, count: entry.count}); + } + } } + catch(e){} } + this.tmpData = obj; this.heatmap.store.setDataSet(set); }, -- libgit2 0.21.2