Best way to omit missing data in client-side feature layer?

219
5
01-08-2019 09:40 AM
TonyGraham
New Contributor III

In the online example "Create a FeatureLayer with client-side graphics", it’s sizing a SimpleMarkerSymbol by the "mag" (magnitude) attribute of the data (earthquakes circa 2016).

 

For six features in Nevada, the value of "mag" is null.  As a result, it looks like the renderer is applying the default size of the SimpleMarkerSymbol (here, set to 20) instead of using the corresponding SizeVariable.  So all Nevada’s features missing data are size 20.

 

My requirement is to omit features with missing data.

 

In API version 4.6, I was setting the SimpleMarkerSymbol’s default size to 0, which worked.  All missing data was size 0.

 

In API version 4.10, when I set the default size to 0 (l. 185 of the example), no data is drawn for any feature—regardless of the value of "mag".

 

Is the 4.10 behavior correct?  If so, what’s the recommended way to omit missing data?  Pre-filter?

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Tony,

   I am not sure if that is how it is suppose to work in 4.10 but one way to handle it is to use this line in the graphic creation portion:

mag: feature.properties.mag || 0,

So if mag is null it will get 0 instead.

0 Kudos
TonyGraham
New Contributor III

Thank you.  However, if I understood you correctly, changing the feature's null value to zero will still show a (minimum size) marker for it, where I need to omit its marker altogether.

Also, in my own case, any non-null value still needs to be plotted--even zero.  

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tony,

  Oh. In that case make this change then:

        // Create an array of Graphics from each GeoJSON feature
        return geoJson.features.map(function(feature, i) {
          if(feature.properties.mag === null){
            return {};
          }
        ...‍‍‍‍‍‍‍‍‍‍‍‍
ReneRubalcava
Frequent Contributor II

The FeatureLayer in 4x is so awesome, that you can do it like you would with a Feature Service, with a definitionExpression.

layer = new FeatureLayer({
  source: graphics, // autocast as an array of esri/Graphic
  // create an instance of esri/layers/support/Field for each field object
  fields: fields, // This is required when creating a layer from Graphics
  objectIdField: "ObjectID", // This must be defined when creating a layer from Graphics
  renderer: quakesRenderer, // set the visualization on the layer
  popupTemplate: pTemplate,
  // Works on client side data too
  definitionExpression: "mag > 0"
  // alternative!!!
  // definitionExpression: "mag IS NOT NULL"
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

How cool is that?!

TonyGraham
New Contributor III

Many thanks to you both.  Either I'll pre-filter, or I'll set the feature layer's definitionExpression.

0 Kudos