1

I need to merge the attributes on a leaflet geojson layer and another geojson based on a common field. I have tried the following code, which does put the keys in the layer but all values are undefined. How do I also get the value to transfer to the layer. geojson is the variable that holds the attributes that I want merged in the layer.

var schemaL = new L.GeoJSON(schema);

// get RG attributes
schemaL.eachLayer(function (layer) {
  for (var i = 0; i < geojson.features.length; i++) {
    if (layer.feature.properties.CodeLink === geojson.features[i].properties.SiteId) {
      for (var key in geojson.features[i].properties) {
        layer.feature.properties[key] = geojson[key];
      }
    }
  }
});
0

Ok.. played around a bit and found the solution. The geojson[key] statement gets the key only. I had to add the following line add the end to the code to get and transfer the value.

  layer.feature.properties[key] = geojson.features[i].properties[key];

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.