28 Jul 2017

getBulkProperties method

Default blog image

The .getBulkProperties method return only the specified properties for a list of dbIds, different from .getProperties that return all properties for a single element at a time. The following sample code search for elements with "Steel" on the "Material" attribute, which returns a list of dbIds. Then getBulkProperties query only the "Mass" property on these elements, finally, the for loop sums the values. Note the getBulkProperties requires a list of attributes on the second parameter.

viewer.search('Steel', 
function(dbIds){
   viewer.model.getBulkProperties(dbIds, ['Mass'],
   function(elements){
     var totalMass = 0;
     for(var i=0; i<elements.length; i++){
       totalMass += elements[i].properties[0].displayValue;
     }
     console.log(totalMass);
   })
}, null, ['Material'])

Simpler than getting a full list of properties with .getProperties in individual callbacks for each dbId.

Related Article