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({
    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.

  • Is it weight: function(feature){return feature.properties['ELEV'];}? Sep 15, 2016 at 22:47

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.