[GIS] Openlayers 3 heatmap with weight function

heat mapjavascriptopenlayersopenlayers-2

I have created an OpenLayers 3 heatmap. Because my weight column is not in the range 0-1, I need to use a function to divide it by the maximum value (which I know). I am doing the following:

var lyr_airports = new ol.layer.Heatmap({
    source:jsonSource_airports, 
    radius: 20,
    weight: function(){'ELEV'/1569},
    title: "airports"
});

Is that correct? In other words, does it recognize column names like that in the function, or do I need to reference the column fully? If the latter (in this example), how?

Edit
Just spotted a horribly basic error: no return. Will fix that and retest.

Best Answer

The weight function takes a feature as an attribute (Code can be found on GitHub). You can use it like that:

var lyr_airports = new ol.layer.Heatmap({
    // ...
    weight: function(feature){
        // get your feature property
        var weightProperty = feature.get('ELEV');
        // perform some calculation to get weightProperty between 0 - 1
        weightProperty = weightProperty /1569; // this was your suggestion - make sure this makes sense
        return weightProperty;
    }
});
Related Question