[GIS] Configure default styles in LeafletJS

javascriptleafletvector

I want to change the default styles for vector layers in my Leaflet version 0.7.3. I can't find anything about that in in the documentation, so I made this hack:

map.on('layeradd', function(e){
  if(typeof e.layer.setStyle === 'function'){
    e.layer.setStyle(myApp.Map.Styles['default']);
  }
});

I don't find that a sustainable way of setting a default style, since I may sometimes want e.g. to overrule the default style or some other scenario.

Any suggestions?

Best Answer

Overwrite the defaults in L.Path with:

L.Path.include({options: newDefaultStyle});

e.g.:

L.Path.include({options: {
    color: '#dd8855',
    fillOpacity: 0.5
}});
Related Question