我正在使用Esri ArcMap API 然后我做了一个查询图层并返回结果的函数, 我想让此函数返回结果以在制作小部件时使用它。
function queryLayer(filterType,value){
var x
schoolLayer.definitionExpression = filterType+" = '" + value + "'";
const queryParams = schoolLayer.createQuery();
queryParams.where = filterType +" = '" + value + "'";
queryParams.outFields = [filterType]
schoolLayer.queryFeatures(queryParams).then(function (results) {
x = results.features
});
return x
}
答案 0 :(得分:1)
这是一个承诺,并且承诺是异步的。
schoolLayer.queryFeatures(queryParams).then(function (results) {
x = results.features
});
您可以在您的resolve-function中返回结果:
function queryLayer(filterType,value){
schoolLayer.definitionExpression = filterType+" = '" + value + "'";
const queryParams = schoolLayer.createQuery();
queryParams.where = filterType +" = '" + value + "'";
queryParams.outFields = [filterType]
schoolLayer.queryFeatures(queryParams).then(function (results) {
return results.features;
});
}
如果这不起作用,您可以退还全部承诺:
function queryLayer(filterType,value){
schoolLayer.definitionExpression = filterType+" = '" + value + "'";
const queryParams = schoolLayer.createQuery();
queryParams.where = filterType +" = '" + value + "'";
queryParams.outFields = [filterType]
return schoolLayer.queryFeatures(queryParams);
}
并像这样使用它:
queryLayer(filterType,value).then(funtction(response){
// do whatever you want to do with your Response ...
}