Select to view content in your preferred language

Why doesn't an arcade expression work on a mapImageLayer

1625
4
Jump to solution
03-09-2018 10:37 AM
JackFairfield
Frequent Contributor

When I apply an arcade expression to the value expression property of my unique value renderer, it doesn't seem to work as expected.

Here is a jsbin example using a modifyed sample that esri provides:

JS Bin - Collaborative JavaScript Debugging 

Here is the line in question:

valueExpression: "When($feature.type == 'Gravel', 'test')",

I would expect this to filter the layer down and only show 7 features, just like when the filter is applied in the rest endpoint. 

But instead, all of the features in the map adopt the uvr symbol:

0 Kudos
1 Solution

Accepted Solutions
MunachisoOgbuchiekwe
Regular Contributor

Hello Jack, 

As per documentation, Arcade expressions are not supported with MapImageLayers. Only FeatureLayers and SceneLayers are supported.

View solution in original post

4 Replies
MunachisoOgbuchiekwe
Regular Contributor

Hello Jack, 

As per documentation, Arcade expressions are not supported with MapImageLayers. Only FeatureLayers and SceneLayers are supported.

JackFairfield
Frequent Contributor

Thank you for your reply.  Do you know if this feature will be supported in a future release?  If so, when?

0 Kudos
JackFairfield
Frequent Contributor

And are there any possible workarounds to make something similar to this work?

0 Kudos
MunachisoOgbuchiekwe
Regular Contributor

Hello Jack, 

If I am understanding what you are trying to do, you could do the following....

  1. Do a queryTask on the Map Service. This will return a Feature Set. 
  2. You can use the Feature Set as the source for a Feature Layer object.
  3. Then apply a unique value renderer to that Feature Layer and add it to the map. 

This would display only what you queried, as a custom Feature Layer. Below is sample code I came up with. Let me know if this is a misunderstanding of your question.

require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/MapImageLayer",
        "esri/tasks/support/Query",
        "esri/tasks/QueryTask",
        "esri/layers/FeatureLayer",
        "dojo/domReady!"
    ],
    function (Map, MapView, MapImageLayer, Query, QueryTask, FeatureLayer) {


        //Create a new map and set the basemap to Dark gray
        var map = new Map({
            basemap: "dark-gray",
            //layers: [featureLayer]
        });

        //set a new view and set the properties of the view
        var view = new MapView({
            container: "viewDiv",
            map: map,
            center: [-86.049, 38.485],
            zoom: 3
        });

        var queryStatesTask = new QueryTask({
            url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"
        });

        var quakesRenderer = {
            type: "simple", // autocasts as new SimpleRenderer()
            symbol: {
                type: "simple-fill", // autocasts as new SimpleMarkerSymbol()
                //style: "circle",
                size: 20,
                color: [211, 255, 0, 0],
                outline: {
                    width: 1,
                    color: "#FF0055",
                    style: "solid"
                }
            }
        }

        var query = new Query();
        query.where = "state_name = 'California'";
        query.returnGeometry = true;
        queryStatesTask.execute(query).then(function (result) {
            //console.log(result);
            var fl = new FeatureLayer({
                source: result.features, // autocast as an array of esri/Graphic
                // create an instance of esri/layers/support/Field for each field object
                fields: result.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
                spatialReference: result.spatialReference,
                geometryType: result.geometryType // Must be set when creating a layer from Graphics
            });
            map.add(fl);
        });
    });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍