0

there seem to be a number of questions out there but none have quite answered this for me.

How would one go about taking a custom set of values from a property like latitude, and then assign them to change the marker color for omnivore.CSV data based on that value. Is there a way of calling the pointtoLayers functions within an onready style section and pointing it to fill colors based on these value tiers?

function getColor(d) {
    return d > 42.2 ? '#800026' :
           d > 39  ? '#BD0026' :
           d > 30  ? '#E31A1C' :
                      '#FFEDA0'; }

var MarkerOptions = {
    radius: 8,
    fillColor: getColor(feature.properties.latitude),
    color: "#000",
    weight: 1,
    opacity: 1,
    fillOpacity: 0.8 };

window.data3 = omnivore.csv('File.csv')
        .on('ready', function(layer) {
            this.eachLayer(function(markeroptions) {
1

Welcome to GIS SE!

Note that the Leaflet omnivore plugin API lets you specify more arguments, including a 3rd argument which is an L.GeoJSON layer group that you have prepared before hand.

.csv(url, parser_options?, customLayer?)

In particular, you can set its onEachFeature and/or pointToLayer option(s), so that when omnivore gets the data, it will go through these options.

See: Passing values for a geojson filter in Leaflet

And this Leaflet omnivore example:

var customLayer = L.geoJson(null, {
  // http://leafletjs.com/reference.html#geojson-style
  style: function(feature) {
    return {
      color: '#f00'
    };
  }
});
// this can be any kind of omnivore layer
var runLayer = omnivore.kml('line.kml', null, customLayer)
  • Excellent lead, ended up finding what I needed from this, thank you! – M00shiM00sh Oct 25 '16 at 5:48

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.