3

I have the following code:

var legend = new L.Control({position: 'bottomright'});
             legend.onAdd = function (map,max,min) {
             var div = L.DomUtil.create('div', 'info legend');
             var grades = [];
             console.log("Maximium ligne 139: "+ max);
             console.log("increament ligne 329" + min);
             var min;
             var ccount;
             var increament = (61544-4161)/8;
             for(var i=0;i<8;i++){
                 console.log("What we got! " +increament);
                 grades.push(Math.round(increament*i));
             }
            // grades = [0, 200, 1000, 1500, 2000, 3500, 5000],
            var labels = [];

                 // loop through our density intervals and generate a label with a colored square for each interval
                 for (var i = 0; i < grades.length; i++) {
                     div.innerHTML +=
                     '<i style="background:' + getColor(grades[i] + 1, 61544,4161) + '"></i> ' +
                     grades[i] + (grades[i + 1] ? '&ndash;' + grades[i + 1] + '<br>' : '+');
                 }

                 return div;
             };

I'm trying to customize my map legend in leaflet. Therefore I need to pass some parameters and treat them inside the function in ligne 2.

I've tried to read the variables using this.max // this.min but its not working. Also I tried to pass the parameters inside the function (see line 2) but with no success. How can I achieve this ?

1

Please take a look at this question. You can use the legend.update function for extra parameters, if you'll give the extra parameters a default value.

|improve this answer|||||

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.