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?
Solved! Go to Solution.
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'
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'
Robert,
Thanks for the code. That worked. Is it possible to see what it would be for other layer types, such as dynamic?
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"} ],
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"}],
.......
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.
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.
Lefteris,
Are you editing the config_Local Layer Widget.json in the [install dir]\server\apps\[app num]\configs\LocalLayer folder?
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.
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.