I am advised to reference my layers as variables rather than as functions, so I can order the layers using .bringtofront.

I have tried several combinations of var skull = L.geoJSON(fatalities)etc.) but everything I have tried simply causes all the layers to vanish from the map.

Here's the map: https://pdxcyclesafetymap.neocities.org/

And here's the .js for one of the layers, as it works now:

var skull = L.icon({
    iconUrl: 'images/blackSkull.svg',
    iconSize: [38, 95],
    popupAnchor: [-10, -30],

function fatalitiesLayer (feature, 
layer) {
    layer.bindPopup("<h1>Cyclist Fatality</h1><p> "+feature.properties.name+
    "</p>Date: "+feature.properties.date+ 
    "</p>Location: "+feature.properties.location+ 
    "</p>Cause: "+feature.properties.cause+ 

    onEachFeature: fatalitiesLayer
  • Just to make things clear, do you want to achieve the ability to use featureGroup? I think this link can be very helpful.
    – NettaB
    Commented Jun 28, 2017 at 11:43
  • For point data you will probably need to use pointToLayer - here's a nice example link
    – NettaB
    Commented Jun 28, 2017 at 12:08
  • I just want to achieve the ability to order my layers - Commented Jun 28, 2017 at 15:45
  • Can you try creating an empty L.featureGroup() for each layer type(skulls, hazards etc) and than add the layers to each featureGroup by example:skulls.layerAdd(layer) in the onEachFeature function? By that you will create a featureGroup for each accident type (a collection of layers is featureGroup
    – NettaB
    Commented Jun 28, 2017 at 16:02
  • I am happy to attempt it: the hard, very hard, part, is figuring out how. Commented Jun 28, 2017 at 16:20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.