Where Clause - DynamicMapService

1189
6
Jump to solution
07-01-2014 05:03 AM
BrandonIves
New Contributor
Hi,

Is it possible to set a where clause on a Dynamic Map Service Layer?

I would like to filter my display by a field that changes depending on user interactions or user privledges to see certain data.

I have used a feature service to do this but thought it would be nice for "read-only" users. I also wouldn't have to create a second feature service with update, add, delete unchecked for read only users.

Thanks
0 Kudos
1 Solution

Accepted Solutions
ManishkumarPatel
Occasional Contributor II
Hi Brandon,

You can try to set the layerDefinitions for the dynamic map service layer you are trying to add to the map.

for eg:

  var imageParameters = new ImageParameters();
  imageParameters.layerIds = [0,1];
  var layerDef = [];
  layerDef[] = "upper(MAPNOTE_TYPE)='PUBLIC' and RECORD_STATUS='A'";  //where clause here
  imageParameters.layerDefinitions = layerDef;
  imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
  imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.
  var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(MapServiceLyrURL, {
                                "imageParameters": imageParameters,
                                "id": MapServiceLyrId,
                                "visible": true
                            });
map.addLayer(dynamicMapServiceLayer);

For further info refer to the below links:

Image Parameters
https://developers.arcgis.com/javascript/jsapi/imageparameters-amd.html

Layer Definitions:
https://developers.arcgis.com/javascript/jsapi/imageparameters-amd.html#layerdefinitions

Hope this helps.

Regards,
Manish

View solution in original post

0 Kudos
6 Replies
TracySchloss
Frequent Contributor
I have been working through the sample https://developers.arcgis.com/javascript/jssamples/renderer_dynamic_layer_change_attribute.html which allows the user to select a field from the specified service and generate a classification based on that field.

It is based on a ArcGISDynamicMapServiceLayer. In order to activate the 'dynamic layers' functionality you have

  1. create a geodatabase or shape file workspace and author that as a geodata service

  2. Check the box under Capabilities > Mapping in Properties to "Allow per request modification ..."

  3. click "Manage" to browse the the geodata service you just made.


The geodata service is just a temporary workspace, near as I can tell. It doesn't have anything in it.

In my data, I have some values of -999 which indicates 'No data'. I didn't want these to be included when I generated my renderer, so I needed a where clause. In the sample, the function classBreaks is where the GenerateRendererParameters is defined. I added a where clause, shown in red, which takes the field the user selected and excludes the -999 data so it doesn't get used when I generate the renderer. I also needed to round my numbers, since some have too many decimals. It seems to be working just fine. I still need to figure out if you can symbolize this excluded data, with maybe a gray color or something.

        function classBreaks(c1, c2) {
          var classDef = new ClassBreaksDefinition();
          classDef.classificationField = registry.byId("fieldNames").get("value") || "CROP_2002_ACRES_TREATED";//this is a field in my data
          classDef.classificationMethod = "natural-breaks"; 
          classDef.breakCount = 5; // always five classes

          var colorRamp = new AlgorithmicColorRamp();
          colorRamp.fromColor = new Color.fromHex(c1);
          colorRamp.toColor = new Color.fromHex(c2);
          colorRamp.algorithm = "hsv"; // options are:  "cie-lab", "hsv", "lab-lch"
          
          classDef.baseSymbol = new SimpleFillSymbol("solid", null, null);
          classDef.colorRamp = colorRamp;

          var params = new GenerateRendererParameters();
          params.classificationDefinition = classDef;
          params.precision = 2;
          params.formatLabel = true;
          var clauseInput = classDef.classificationField;
          params.where= clauseInput + " > 0";
          var generateRenderer = new GenerateRendererTask(app.dataUrl);
          generateRenderer.execute(params, applyRenderer, errorHandler);
        }


I just happened to be working on this for the first time this AM, so I don't know much more than "I got it to work".

You must have ArcGIS Server version 10.1 or higher to use this.
0 Kudos
BrandonIves
New Contributor
Thanks for the response Schlot.

I have been working through the sample https://developers.arcgis.com/javascript/jssamples/renderer_dynamic_layer_change_attribute.html which allows the user to select a field from the specified service and generate a classification based on that field.

It is based on a ArcGISDynamicMapServiceLayer.  In order to activate the 'dynamic layers' functionality you have

  1. create a geodatabase or shape file workspace and author that as a geodata service

  2. Check the box under Capabilities > Mapping in Properties to "Allow per request modification ..."

  3. click "Manage" to browse the the geodata service you just made.


The geodata service is just a temporary workspace, near as I can tell.  It doesn't have anything in it.

In my data, I have some values of -999 which indicates 'No data'.  I didn't want these to be included when I generated my renderer, so I needed a where clause.  In the sample, the function classBreaks is where the GenerateRendererParameters is defined.  I added a where clause, shown in red, which takes the field the user selected and excludes the -999 data so it doesn't get used when I generate the renderer.  I also needed to round my numbers, since some have too many decimals.  It seems to be working just fine.  I still need to figure out if you can symbolize this excluded data, with maybe a gray color or something.



Is this the only way that you know of  to implement a where clause? This seems very involved considering a feature service is this simple:

 
FeatureLayer l = new FeatureLayer()
                {
                    ID = "MyFeatureLayer",
                    Url = "http://serverNameBlahBlah/WPFTestFeatureLayer/FeatureServer/0",
                    //Where = "1=1"
                    Where = "ASSIGNED_TO = 'GIS_USER'"

                    //,
                    //Renderer = "{StaticResource MySimplePointRenderer}"

                };
0 Kudos
ManishkumarPatel
Occasional Contributor II
Hi Brandon,

You can try to set the layerDefinitions for the dynamic map service layer you are trying to add to the map.

for eg:

  var imageParameters = new ImageParameters();
  imageParameters.layerIds = [0,1];
  var layerDef = [];
  layerDef[] = "upper(MAPNOTE_TYPE)='PUBLIC' and RECORD_STATUS='A'";  //where clause here
  imageParameters.layerDefinitions = layerDef;
  imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
  imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.
  var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer(MapServiceLyrURL, {
                                "imageParameters": imageParameters,
                                "id": MapServiceLyrId,
                                "visible": true
                            });
map.addLayer(dynamicMapServiceLayer);

For further info refer to the below links:

Image Parameters
https://developers.arcgis.com/javascript/jsapi/imageparameters-amd.html

Layer Definitions:
https://developers.arcgis.com/javascript/jsapi/imageparameters-amd.html#layerdefinitions

Hope this helps.

Regards,
Manish
0 Kudos
BrandonIves
New Contributor
Thanks for the information.
0 Kudos
TracySchloss
Frequent Contributor
Sorry I misread your question.  I thought you were asking about dynamically generating symbology for a selected layer.  My instructions were for that.
0 Kudos
BrandonIves
New Contributor
Sorry I misread your question.  I thought you were asking about dynamically generating symbology for a selected layer.  My instructions were for that.


No problem. Your answer led me to  consider some other options for another application. Thanks!
0 Kudos