I am currently working on a JavaScript application that creates heatmaps using the Google Visualization API, but for some reason whenever I add my array of data to the heatmap the 2nd to last element always throws this error:
Invalid value at position X [object Object]' when calling method: [nsIDOMEventListener::handleEvent]
Can anyone explain this error to me? I have never seen it before and my search of SO and Google turned up nothing useful.
Any help would be appreciated.
var heatMapOptions =
{
data: weightedLocations,
dissipating: false,
map: this.googleMap,
gradient: [
'rgba(0, 0, 0, 0)', //black - transparent
'rgba(0, 0, 255, 1)', //blue
'rgba(0, 255, 255, 1)', //cyan
'rgba(0, 238, 0, 1)', //green
'rgba(0, 255, 0, 1)', //lime-green
'rgba(255, 255, 0, 1)', //yellow
'rgba(255, 165, 0, 1)', //orange
'rgba(255, 0, 0, 1)', //red
'rgba(139, 0, 0, 1)' //dark-red
],
maxIntensity: 150,
opacity: 0.6,
radius: 4 //4 pixels
};
//create a Heatmap overlay to sit on top of the google map, passing it the initialization object created above
var heatmap = new google.maps.visualization.HeatmapLayer({ options: heatMapOptions});
Where the object is created
function Box(inBox, count)
{
var box = inBox.toString();
//strip off any sort keys if they exist
if(box.indexOf("~") >= 0) {
box = box.substr(0, box.indexOf('~'));
}
//split box into box number and coordinates of four corners
var splitBox = box.split("_");
//console.log(splitBox);
var boxNumber = splitBox[0];
this.boxNumber = boxNumber.replace("count|", "");
this.swlatlon = new google.maps.LatLng( splitBox[1], splitBox[2]); // a Google LatLng object
this.selatlon = new google.maps.LatLng( splitBox[3], splitBox[4]); // a Google LatLng object
this.nwlatlon = new google.maps.LatLng( splitBox[5], splitBox[6]); // a Google LatLng object
this.nelatlon = new google.maps.LatLng( splitBox[7], splitBox[8]); // a Google LatLng object
this.points = [this.swlatlon, this.selatlon, this.nwlatlon, this.nelatlon] //store all points for easy access
this.count = count; // number of ships in this box
//calculate center of this box
this.bounds = new google.maps.LatLngBounds(this.swlatlon, this.nelatlon);
this.center = this.bounds.getCenter();
this.weightedLocation = { location : this.center, weight : this.count }; // <-- object created here
}
Where the objects are pushed into an array
function parseJsonForModelData(json, datatype) {
for(index in json) {
obj = json[index];
if (index == "Model Data")
{
$j.each(obj, function(k, v)
{
if (datatype == 'heat')
{
box = new Box(k, v);
// Check boxNumber. If null, skip messes up world map!
if (box.boxNumber == 'null')
{
badDataCnt++;
}
else
{
modelData.push(box.weightedLocation); <<- pushed here
}
}
});
}
}
return modelData;
}
WeightedLocations
327: {"location":{"$a":-35.5,"ab":172},"weight":"11"} object music.js:730
328: {"location":{"$a":-36.5,"ab":151},"weight":"1"} object music.js:730
329: {"location":{"$a":-37.5,"ab":151},"weight":"1"} object music.js:730
330: {"location":{"$a":-37.5,"ab":168},"weight":"3"} object music.js:730
331: {"location":{"$a":-37.5,"ab":169},"weight":"6"} object music.js:730
332: {"location":{"$a":-39.5,"ab":161},"weight":"4"} object music.js:730
333: {"location":{"$a":-39.5,"ab":162},"weight":"5"} object music.js:730
334: {"location":{"$a":-39.5,"ab":165},"weight":"6"} object music.js:730
I noticed the WeightedLocations you posted has strings for weight. When testing with hardcoded data, I did run into problems when
weightis a string, so try using parseInt/float inside thefunction Box, hopefully this will make things work.