Skip to content

Commit

Permalink
featureService 新增获取要素数量,数据集信息方法,getFeature 参数类新增 returnFeaturesOnly 参…
Browse files Browse the repository at this point in the history
…数 review by luox
  • Loading branch information
xilanhuaweidapao committed Jan 30, 2024
1 parent 69d2ccb commit 4f4f0d7
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 9 deletions.
54 changes: 54 additions & 0 deletions src/common/iServer/FeatureService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import { FeatureAttachmentsService } from './FeatureAttachmentsService';
import { EditFeaturesService } from './EditFeaturesService';
import { DataFormat } from '../REST';

const FEATURE_SERVICE_MAP = {
id: GetFeaturesByIDsService,
sql: GetFeaturesBySQLService ,
bounds: GetFeaturesByBoundsService,
buffer: GetFeaturesByBufferService,
geometry: GetFeaturesByGeometryService
}

/**
* @class FeatureService
* @constructs FeatureService
Expand Down Expand Up @@ -235,6 +243,52 @@ export class FeatureService {
return featureAttachmentsService.processAsync(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesCount
* @description 获取要素数量。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesCount(params, callback) {
var me = this;
var newParams = { ...params, returnCountOnly: true, returnContent: true, returnFeaturesOnly: false };
let queryType = Object.keys(FEATURE_SERVICE_MAP).find((type) => {
return newParams.CLASS_NAME.toLowerCase().includes(type);
});
var getFeaturesServiceBase = new FEATURE_SERVICE_MAP[queryType](me.url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers
});
return getFeaturesServiceBase.processAsync(newParams, callback);
}

/**
* @function FeatureService.prototype.getFeaturesDatasetInfo
* @description 获取要素数据集信息。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesDatasetInfo(params, callback) {
var me = this;
var newParams = { ...params, returnDatasetInfoOnly: true, returnContent: true, returnFeaturesOnly: false };
let queryType = Object.keys(FEATURE_SERVICE_MAP).find((type) => {
return newParams.CLASS_NAME.toLowerCase().includes(type);
});
var getFeaturesServiceBase = new FEATURE_SERVICE_MAP[queryType](me.url, {
proxy: me.options.proxy,
withCredentials: me.options.withCredentials,
crossOrigin: me.options.crossOrigin,
headers: me.options.headers
});
return getFeaturesServiceBase.processAsync(newParams, callback);
}

_processFormat(resultFormat) {
return resultFormat ? resultFormat : DataFormat.GEOJSON;
}
Expand Down
1 change: 1 addition & 0 deletions src/common/iServer/GetFeaturesByBoundsParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GetFeaturesParametersBase } from './GetFeaturesParametersBase';
* @param {Array.<string>} [options.fields] - 查询结果返回字段。默认返回所有字段。
* @param {SpatialQueryMode} [options.spatialQueryMode=SpatialQueryMode.CONTAIN] - 空间查询模式。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down
1 change: 1 addition & 0 deletions src/common/iServer/GetFeaturesByBufferParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ServerGeometry } from './ServerGeometry';
* @param {Array.<string>} [options.fields] - 查询结果返回字段。默认返回所有字段。
* @param {string} [options.attributeFilter] - 属性查询条件。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down
1 change: 1 addition & 0 deletions src/common/iServer/GetFeaturesByGeometryParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ServerGeometry } from './ServerGeometry';
* @param {Array.<string>} [options.fields] - 查询结果返回字段。默认返回所有字段。
* @param {SpatialQueryMode} [options.spatialQueryMode=SpatialQueryMode.CONTAIN] - 空间查询模式。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down
1 change: 1 addition & 0 deletions src/common/iServer/GetFeaturesByIDsParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GetFeaturesParametersBase } from './GetFeaturesParametersBase';
* @param {Array.<string>} [options.fields] - 查询结果返回字段。默认返回所有字段。
* @param {Array.<string>} options.dataSetNames - 数据集集合中的数据集名称列表。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down
1 change: 1 addition & 0 deletions src/common/iServer/GetFeaturesBySQLParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { GetFeaturesParametersBase } from './GetFeaturesParametersBase';
* @param {FilterParameter} options.queryParameter - 查询过滤条件参数。
* @param {Array.<string>} options.datasetNames - 数据集集合中的数据集名称列表。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down
9 changes: 5 additions & 4 deletions src/common/iServer/GetFeaturesParametersBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Util } from '../commontypes/Util';
* @param {Object} options - 参数。
* @param {Array.<string>} options.datasetNames - 数据集名称列表。
* @param {boolean} [options.returnContent=true] - 是否直接返回查询结果。
* @param {boolean} [options.returnFeaturesOnly=false] - 是否仅返回要素信息。当 returnContent 为 true 时设置有效。
* @param {number} [options.fromIndex=0] - 查询结果的最小索引号。
* @param {number} [options.toIndex=19] - 查询结果的最大索引号。
* @param {string|number} [options.targetEpsgCode] - 动态投影的目标坐标系对应的 EPSG Code,使用此参数时,returnContent 参数需为 true。
Expand Down Expand Up @@ -59,11 +60,11 @@ export class GetFeaturesParametersBase {
*/
this.toIndex = 19;

/**
* @member {boolean} [GetFeaturesParametersBase.prototype.returnCountOnly=false]
* @description 只返回查询结果的总数
/**
* @member {boolean} [GetFeaturesParametersBase.prototype.returnFeaturesOnly=false]
* @description 仅返回要素信息
*/
this.returnCountOnly = false;
this.returnFeaturesOnly = false;

/**
* @member {number} [GetFeaturesParametersBase.prototype.maxFeatures=1000]
Expand Down
30 changes: 25 additions & 5 deletions src/common/iServer/GetFeaturesServiceBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
*/
this.returnContent = true;

/**
* @member {boolean} [GetFeaturesServiceBase.prototype.returnFeaturesOnly=false]
* @description 是否仅返回要素信息。
*/
this.returnFeaturesOnly = false;

/**
* @member {number} [GetFeaturesServiceBase.prototype.fromIndex=0]
* @description 查询结果的最小索引号。如果该值大于查询结果的最大索引号,则查询结果为空。
Expand Down Expand Up @@ -105,6 +111,7 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
firstPara = true;

me.returnContent = params.returnContent;
me.returnFeaturesOnly = params.returnFeaturesOnly;
me.fromIndex = params.fromIndex;
me.toIndex = params.toIndex;
me.maxFeatures = params.maxFeatures;
Expand All @@ -117,9 +124,19 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
me.url = Util.urlAppend(me.url, `fromIndex=${me.fromIndex}&toIndex=${me.toIndex}`);
}

if (params.returnCountOnly) {
me.url = Util.urlAppend(me.url, "&returnCountOnly=" + params.returnContent)
}
if (me.returnContent) {
if (params.returnCountOnly) {
me.url = Util.urlAppend(me.url, "&returnCountOnly=" + params.returnCountOnly)
}

if (params.returnDatasetInfoOnly) {
me.url = Util.urlAppend(me.url, "&returnDatasetInfoOnly=" + params.returnDatasetInfoOnly)
}

if (params.returnFeaturesOnly) {
me.url = Util.urlAppend(me.url, "&returnFeaturesOnly=" + params.returnFeaturesOnly)
}
}

jsonParameters = me.getJsonParameters(params);
return me.request({
Expand All @@ -141,10 +158,13 @@ export class GetFeaturesServiceBase extends CommonServiceBase {
transformResult(result, options) {
var me = this;
result = Util.transformResult(result);
if (me.format === DataFormat.GEOJSON && result.features) {
var geoJSONFormat = new GeoJSON();
var geoJSONFormat = new GeoJSON();
if (me.format === DataFormat.GEOJSON && result.features) {
result.features = geoJSONFormat.toGeoJSON(result.features);
}
if (me.returnFeaturesOnly && Array.isArray(result)) {
result = geoJSONFormat.toGeoJSON(result);
}
return { result, options };
}

Expand Down
25 changes: 25 additions & 0 deletions src/leaflet/services/FeatureService.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ export var FeatureService = ServiceBase.extend({
return this._featureService.editFeatureAttachments(params, callback);
},

/**
* @function FeatureService.prototype.getFeaturesCount
* @description 获取要素数量。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesCount(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesCount(params, callback);
},
/**
* @function FeatureService.prototype.getFeaturesDatasetInfo
* @description 获取要素数据集信息。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesDatasetInfo(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesDatasetInfo(params, callback);
},

_processParams: function (params) {
if (!params) {
return {};
Expand Down
27 changes: 27 additions & 0 deletions src/mapboxgl/services/FeatureService.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ export class FeatureService extends ServiceBase {
editFeatureAttachments(params, callback) {
return this._featureService.editFeatureAttachments(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesCount
* @description 获取要素数量。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesCount(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesCount(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesDatasetInfo
* @description 获取要素数据集信息。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesDatasetInfo(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesDatasetInfo(params, callback);
}

/**
* @private
* @description 参数类型转换。
Expand Down
26 changes: 26 additions & 0 deletions src/maplibregl/services/FeatureService.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ export class FeatureService extends ServiceBase {
editFeatureAttachments(params, callback) {
return this._featureService.editFeatureAttachments(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesCount
* @description 获取要素数量。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesCount(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesCount(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesDatasetInfo
* @description 获取要素数据集信息。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesDatasetInfo(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesDatasetInfo(params, callback);
}

/**
* @private
Expand Down
26 changes: 26 additions & 0 deletions src/openlayers/services/FeatureService.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,32 @@ export class FeatureService extends ServiceBase {
editFeatureAttachments(params, callback) {
return this._featureService.editFeatureAttachments(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesCount
* @description 获取要素数量。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesCount(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesCount(params, callback);
}

/**
* @function FeatureService.prototype.getFeaturesDatasetInfo
* @description 获取要素数据集信息。
* @version 11.2.0
* @param {GetFeaturesByIDsParameters|GetFeaturesByBoundsParameters|GetFeaturesByBufferParameters|GetFeaturesByGeometryParameters|GetFeaturesBySQLParameters} params - 查询参数类。
* @param {RequestCallback} [callback] 回调函数,该参数未传时可通过返回的 promise 获取结果。
* @returns {Promise} Promise 对象。
*/
getFeaturesDatasetInfo(params, callback) {
params = this._processParams(params);
return this._featureService.getFeaturesDatasetInfo(params, callback);
}

_processParams(params) {
if (!params) {
Expand Down
31 changes: 31 additions & 0 deletions test/common/iServer/GetFeaturesByBoundsServiceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,35 @@ describe('GetFeaturesByBoundsService', () => {
});
getFeaturesByBoundsService.processAsync(boundsParams, serviceCompleted);
});
it('GetFeaturesByBoundsParameters:returnFeaturesOnly', done => {
var serviceCompleted = serviceSucceedEventArgsSystem => {
console.log('serviceSucceedEventArgsSystem', serviceSucceedEventArgsSystem);
try {
getFeaturesByBoundsService.destroy();
boundsParams.destroy();
expect(serviceSucceedEventArgsSystem.result.type).toBe('FeatureCollection');
expect(serviceSucceedEventArgsSystem.result.features.length).toBe(4);
done();
} catch (exception) {
expect(false).toBeTruthy();
console.log('GetFeaturesByBoundsService_' + exception.name + ':' + exception.message);
getFeaturesByBoundsService.destroy();
boundsParams.destroy();
done();
}
};
var getFeaturesByBoundsService = initGetFeaturesByBoundsService_RegisterListener();
var boundsParams = new GetFeaturesByBoundsParameters({
datasetNames: ['World:Countries'],
bounds: new Bounds(0, 0, 90, 90),
targetPrj: { "epsgCode": 4326 },
returnFeaturesOnly: true
});
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
if (testUrl.indexOf('returnFeaturesOnly') > -1) {
return Promise.resolve(new Response(JSON.stringify(getReturnFeaturesOnlyResultJson)));
}
});
getFeaturesByBoundsService.processAsync(boundsParams, serviceCompleted);
})
});
Loading

0 comments on commit 4f4f0d7

Please sign in to comment.