Howdy!
So I'm interested in turning on a layer after a feature is queried by a URL parameter. As an example, if you hit this URL:
The app executes the query just fine (woohoo), but since that layer is not turned on by default, the actual symbol is not drawn, which will likely be confusing for end-users.
I imagine this is as simple as calling the showLayers function of the LayerList widget, but I'm still getting my feet under me in this capacity.
Any insight would be appreciated!
Solved! Go to Solution.
Andrew,
In your apps jimu/MapUrlParamsHandler.js in the queryFeature function you just need to turn on your layer (lines 26 and 31).
function queryFeature(queryObject, map){
/************************
?query=<layerName/layerId, fieldName, fieldValue>
?query=<layerName/layerId, whereClause>
*************************/
//?query=Cities,pop>1000&level=10
//?query=Cities,city_name,Rome&level=10
var queryArray = queryObject.query.split(";");
if (queryArray.length === 1) {
queryArray = queryObject.query.split(",");
}
if(queryArray.length !== 2 && queryArray.length !== 3){
console.error('query URL parameter is not correct.');
return;
}
var layerNameOrId = queryArray[0];
//by name first
getLayerByNameOrId('name', layerNameOrId, map).then(function(layer){
if(layer === null){
getLayerByNameOrId('id', layerNameOrId, map).then(function(layer2){
if(layer2 === null){
console.error('Invalid layer name or id.');
}else{
layer2.layerInfo.setTopLayerVisible(true);
selectFeatures(map, layer2, queryArray);
}
});
}else{
layer.layerInfo.setTopLayerVisible(true);
selectFeatures(map, layer, queryArray);
}
});
}
Andrew,
In your apps jimu/MapUrlParamsHandler.js in the queryFeature function you just need to turn on your layer (lines 26 and 31).
function queryFeature(queryObject, map){
/************************
?query=<layerName/layerId, fieldName, fieldValue>
?query=<layerName/layerId, whereClause>
*************************/
//?query=Cities,pop>1000&level=10
//?query=Cities,city_name,Rome&level=10
var queryArray = queryObject.query.split(";");
if (queryArray.length === 1) {
queryArray = queryObject.query.split(",");
}
if(queryArray.length !== 2 && queryArray.length !== 3){
console.error('query URL parameter is not correct.');
return;
}
var layerNameOrId = queryArray[0];
//by name first
getLayerByNameOrId('name', layerNameOrId, map).then(function(layer){
if(layer === null){
getLayerByNameOrId('id', layerNameOrId, map).then(function(layer2){
if(layer2 === null){
console.error('Invalid layer name or id.');
}else{
layer2.layerInfo.setTopLayerVisible(true);
selectFeatures(map, layer2, queryArray);
}
});
}else{
layer.layerInfo.setTopLayerVisible(true);
selectFeatures(map, layer, queryArray);
}
});
}