Select to view content in your preferred language

Local Layer Widget

10605
21
Jump to solution
04-21-2015 07:37 AM
DanielStoelb
Frequent Contributor

I'm having issues trying to figure out how to set up a definition query for the layers that I'm loading into the local layer widget without having to redo the service from the server.  Do you have an idea on how this can be done using the local layer widget code?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  There is not an option for this currently in the widget, but you can add it in code pretty easily.

In the Widget.js file for layer type 'FEATURE' just add these lines:

            if(layer.hasOwnProperty('definitionExpression')){
              lOptions.definitionExpression = layer.definitionExpression;
            }

Then in the json add:

"definitionExpression": "some valid SQL expression",

Let me know if you need to add to a layer type other than 'FEATURE'

View solution in original post

21 Replies
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  There is not an option for this currently in the widget, but you can add it in code pretty easily.

In the Widget.js file for layer type 'FEATURE' just add these lines:

            if(layer.hasOwnProperty('definitionExpression')){
              lOptions.definitionExpression = layer.definitionExpression;
            }

Then in the json add:

"definitionExpression": "some valid SQL expression",

Let me know if you need to add to a layer type other than 'FEATURE'

DanielStoelb
Frequent Contributor

Robert,

Thanks for the code.  That worked.  Is it possible to see what it would be for other layer types, such as dynamic?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Daniel,

  'DYNAMIC' would look like this. Add these line right before "lLayer.on('load',function(evt){"

            if(layer.definitionExpressions){
              var layerDefinitions = [];
              array.forEach(layer.definitionExpressions, function(_def){
                layerDefinitions[parseInt(_def.id)] = _def.sql;
              });
              lLayer.setLayerDefinitions(layerDefinitions);
            }

And the JSON would look like:

        "definitionExpressions": [
          {"id": 1, "sql": "ZONE = 'A'"},
          {"id": 6, "sql": "POP00_SQMI >= 6368"}
        ],
LefterisKoumis
Frequent Contributor

Hello Robert. I applied a definitionexpression but it does seem to be working. Ideas? Thanks.

My service is a feature service and I added this script in widget.js

.......

lLayer = new FeatureLayer(layer.url, lOptions);

  if(layer.hasOwnProperty('definitionExpression')){

              lOptions.definitionExpression = layer.definitionExpression;

            }

            lLayer.on('load',function(evt){

          ......

and in json:

"url": "http://10.112.5.83/arcgis/rest/services/Biology/CNDDB/MapServer/0",

.......

.......

"definitionExpression": [

  {"id":0, "sql": "DIST=10"}],

.......

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   The code you are applying is for a Dynamic layer and I see that you are attempting to apply it to a FeatureLayer. You would need to follow my reply that is marked as the answer and not my last reply that was specific to 'DYNAMIC' layer type.

0 Kudos
LefterisKoumis
Frequent Contributor

Robert, the widget.js script I posted is indeed from the response marked as answer.

and I changed the json to:

"definitionExpression": "DIST=10",

but still no filtering.

Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   Are you editing the config_Local Layer Widget.json in the [install dir]\server\apps\[app num]\configs\LocalLayer folder?

0 Kudos
LefterisKoumis
Frequent Contributor

You mean:

C:\arcgis-web-appbuilder-1.1\server\apps\4\widgets\LocalLayer?

Yes, I do.

There is no configs folder under the app id.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   If you do not have a configs folder under the apps\4\ then you are probably not using version 1.1 of WAB and that is an issue.

0 Kudos