set layer definition in custom module
I am trying to set a layer definition for a layer in the custom module. But it is not working. Following is the code I am using in the custom module:
var gcLayer = _this.app.site.essentialsMap.findMapServiceById(mapserviceID).findLayerById(layerID);
gcLayer.getFeatureLayer().then(function (esriFeatureLayer) {
if (esriFeatureLayer.hasOwnProperty("type")) {
if (esriFeatureLayer.type == "Feature Layer") {
esriFeatureLayer.setDefinitionExpression("1=0");
_this.app.site.essentialsMap.findMapServiceById(mapserviceID).refresh();
}
}
});
I am the getting the esri Featurelayer object but somehow it is not setting the layer definition.
Thanks,
Mahender
0
-
Hi Mahender,
What results are you expecting? What is 1=0?
Regards,
Mohammad Ashraf0 -
"1=0" is the where clause for the definition expression.
"1=0" should return nothing. Where clause is not an issue. I have tried other where clause too but it did not work.0 -
Hi Mahender,
I was having the same problem and I suspect it is down to the getFeatureLayer() method which returns a promise with an esri.layers.FeatureLayer object. I had tried using this method to retrieve a FeatureLayer to query, but found the query would fail with:
FeatureLayer::_query - query contains one or more unsupported parameters
I found this was most likely due to the fact that in the background the FeatureLayer was being constructed from a FeatureCollection, which lead to it having limited functionality. See the (https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#featurelayer2) help file page:
The feature layer, when initialized with a feature collection object... does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.
Basically I'm not sure the FeatureLayer being returned by getFeatureLayer() is a fully composed object, and so the functionality on it is limited. With that in mind, I used code similar to the following instead to set a layer definition on a map service containing only one layer:
let mapSvc: esri.layers.ArcGISDynamicMapServiceLayer = this.app.site.getMap().getLayer(0);
mapSvc.setLayerDefinitions([“1=0”]);
mapSvc.refresh();
setLayerDefinitions() expects an array [] of ‘where’ clauses correlating with each sub-layer within the service.
I only had one layer, hence the one entry in the array.
It worked for me anyway, so hope that helps you.
Cheers,
Ewan0 -
Hi Mahender,
So that means, the issue is with refreshing the layer on the map? Or setting the definition?
If it is refreshing the layer on the map, then you could try this:
_this.app.map.setExtent(_this.app.map.extent);
Kindly provide some more details, like do you get any error?
Regards,
Mohammad Ashraf0 -
Hi Ewan,
Thanks for the response.
Regarding the featurelayer query, I am not sure whether the underlying object is the featurecollection. Because I am able to query the featurelayer returned by getFeatureLayer() and it works fine.
In your sample code you are assigning an ArcGISDynamicLayer to an esri Layer which is not possible. And my site has several mapservices.
Cheers,
Mahender0 -
Hi Mahender,
Sorry to be late. Here is the code snippet to set the definition expression in Geocortex Custom Module:
this.app.registerActivityIdHandler("SetCustomLayerDefinition", function CustomEventHandler(workflowContext, contextFunctions) {
myWorkflowContext = $.extend({}, workflowContext);
var mServiceId = myWorkflowContext.getValue("MapServiceId"), layerId = myWorkflowContext.getValue("LayerId"),
layerName = myWorkflowContext.getValue("LayerName"), definitionQuery = myWorkflowContext.getValue("Definition")
if (!mServiceId)
throw Error("Set Layer Definition: required MapServiceId argument was not supplied.");
if (!layerId && !layerName)
throw Error("Set Layer Definition: a LayerId or a LayerName argument must be supplied.");
var mService = myApp.site.essentialsMap.findMapServiceById(mServiceId);
if (!mService || !mService.serviceLayer)
throw Error("Set Layer Definition: Unable to find map service with ID '" + mServiceId + "'");
if (!layerId && layerName)
if (layerId = mService.findLayerByName(layerName))
layerId = layerId.id;
else
throw Error("Set Layer Definition: Unable to find layer with Name '" + layerName + "'.");
if (mService.serviceLayer instanceof esri.layers.ArcGISDynamicMapServiceLayer) {
var tServiceLayer = mService.serviceLayer;
if (!tServiceLayer.layerDefinitions)
tServiceLayer.layerDefinitions = [];
tServiceLayer.layerDefinitions[parseInt(layerId)] = definitionQuery;
tServiceLayer.setLayerDefinitions(tServiceLayer.layerDefinitions, true)
mService.refresh();
}
else if (mService.serviceLayer instanceof esri.layers.FeatureLayer) {
mService.serviceLayer.setDefinitionExpression(definitionQuery);
mService.refresh();
}
else
throw Error("Set Layer Definition: Map service type does not support layer definitions.");
myWorkflowContext.completeActivity()
});
Please let me know if you need any clarifications.
Regards,
Mohammad Ashraf0
Please sign in to leave a comment.
Comments
6 comments