Skip to content

Commit b7eec08

Browse files
committed
【fix】fix误提交空间分析leaflet/openlayers测试案例 review by sunxiaoyu
1 parent 02e1f0a commit b7eec08

11 files changed

+871
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
2+
import {DensityKernelAnalystParameters} from '../../../src/common/iServer/DensityKernelAnalystParameters';
3+
import request from 'request';
4+
import {FetchRequest} from "@supermap/iclient-common";
5+
6+
var spatialAnalystURL = GlobeParameter.spatialAnalystURL_Changchun;
7+
var options = {
8+
serverType: 'iServer'
9+
};
10+
11+
describe('leaflet_SpatialAnalystService_densityAnalysis', () => {
12+
var serviceResult;
13+
var originalTimeout;
14+
beforeEach(() => {
15+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
16+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
17+
serviceResult = null;
18+
});
19+
afterEach(() => {
20+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
21+
});
22+
var resultDataset = "KernelDensity_leafletTest";
23+
//点密度分析
24+
it('densityAnalysis', (done) => {
25+
var densityAnalystParameters = new DensityKernelAnalystParameters({
26+
//指定数据集
27+
dataset: "Railway@Changchun",
28+
//指定范围
29+
bounds: L.bounds([3800, -3800], [8200, -2200]),
30+
//指定数据集中用于核密度分析的字段
31+
fieldName: "SmLength",
32+
searchRadius: 50, //Railway@Changchun的单位是米
33+
// 结果数据集名称
34+
resultGridName: resultDataset,
35+
deleteExistResultDataset: true
36+
});
37+
var densityAnalystService = spatialAnalystService(spatialAnalystURL, options);
38+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
39+
expect(method).toBe("POST");
40+
expect(testUrl).toBe(spatialAnalystURL + "/datasets/Railway@Changchun/densityanalyst/kernel.json?returnContent=true");
41+
var expectParams = `{'bounds':{'left':3800,'bottom':-3800,'right':8200,'top':-2200,'centerLonLat':null},'fieldName':"SmLength",'resultGridDatasetResolution':null,'searchRadius':50,'targetDatasource':null,'resultGridName':"KernelDensity_leafletTest",'deleteExistResultDataset':true}`;
42+
expect(params).toBe(expectParams);
43+
expect(options).not.toBeNull();
44+
var resultJson=`{"succeed":true,"recordset":null,"message":null,"dataset":"KernelDensity_leafletTest@Changchun"}`;
45+
return Promise.resolve(new Response(resultJson));
46+
});
47+
densityAnalystService.densityAnalysis(densityAnalystParameters, (result) => {
48+
serviceResult = result;
49+
});
50+
setTimeout(() => {
51+
try {
52+
expect(serviceResult).not.toBeNull();
53+
expect(serviceResult.type).toBe('processCompleted');
54+
expect(serviceResult.result.succeed).toBeTruthy();
55+
expect(serviceResult.result.dataset).toEqual(resultDataset + "@Changchun");
56+
densityAnalystService.destroy();
57+
done();
58+
} catch (exception) {
59+
console.log("'densityAnalysis'案例失败" + exception.name + ":" + exception.message);
60+
densityAnalystService.destroy();
61+
expect(false).toBeTruthy();
62+
done();
63+
}
64+
}, 5000);
65+
});
66+
67+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
2+
import {GeoRelationAnalystParameters} from '../../../src/common/iServer/GeoRelationAnalystParameters';
3+
import {FilterParameter} from '../../../src/common/iServer/FilterParameter';
4+
import {SpatialRelationType} from '../../../src/common/REST';
5+
import {FetchRequest} from "@supermap/iclient-common";
6+
7+
var url = GlobeParameter.spatialAnalystURL_Changchun;
8+
9+
describe('leaflet_SpatialAnalystService_geoRelationAnalysis', () => {
10+
var serviceResults;
11+
var originalTimeout;
12+
beforeEach(() => {
13+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
14+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
15+
serviceResults = null;
16+
});
17+
afterEach(() => {
18+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
19+
});
20+
//空间关系分析
21+
it('geoRelationAnalysis', (done) => {
22+
var geoRelationAnalystParameters = new GeoRelationAnalystParameters({
23+
dataset: "Park@Changchun",
24+
startRecord: 0,
25+
expectCount: 5,
26+
//空间关系分析中的源数据集查询参数
27+
sourceFilter: new FilterParameter({attributeFilter: "SMID>0"}),
28+
referenceFilter: new FilterParameter({name: "Frame_R@Changchun", attributeFilter: "SMID>0"}),
29+
spatialRelationType: SpatialRelationType.INTERSECT,
30+
//位于面边线上的点是否被面包含
31+
isBorderInside: true,
32+
//是否返回Feature信息
33+
returnFeature: false,
34+
returnGeoRelatedOnly: true
35+
});
36+
var service = spatialAnalystService(url);
37+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
38+
expect(method).toBe("POST");
39+
expect(testUrl).toBe(url + "/datasets/Park@Changchun/georelation.json?returnContent=true");
40+
var expectParams = `{'dataset':"Park@Changchun",'sourceFilter':{'attributeFilter':"SMID%26gt;0",'name':null,'joinItems':null,'linkItems':null,'ids':null,'orderBy':null,'groupBy':null,'fields':null},'referenceFilter':{'attributeFilter':"SMID%26gt;0",'name':"Frame_R@Changchun",'joinItems':null,'linkItems':null,'ids':null,'orderBy':null,'groupBy':null,'fields':null},'spatialRelationType':"INTERSECT",'isBorderInside':true,'returnFeature':false,'returnGeoRelatedOnly':true,'startRecord':0,'expectCount':5}`;
41+
expect(params).toBe(expectParams);
42+
expect(options).not.toBeNull();
43+
var geoRelationAnalystEscapedJson = `[{"result":[1],"count":1,"source":1},{"result":[1],"count":1,"source":2},{"result":[1],"count":1,"source":3},{"result":[1],"count":1,"source":4},{"result":[1],"count":1,"source":5}]`;
44+
return Promise.resolve(new Response(geoRelationAnalystEscapedJson));
45+
});
46+
service.geoRelationAnalysis(geoRelationAnalystParameters, (result) => {
47+
serviceResults = result;
48+
});
49+
setTimeout(() => {
50+
expect(service).not.toBeNull();
51+
expect(serviceResults).not.toBeNull();
52+
expect(serviceResults.type).toEqual("processCompleted");
53+
expect(serviceResults.result.succeed).toBeTruthy();
54+
expect(serviceResults.result.length).toEqual(5);
55+
for (var i = 0; i < serviceResults.result.length; i++) {
56+
expect(serviceResults.result[i].count).toEqual(1);
57+
expect(serviceResults.result[i].source).toEqual(i + 1);
58+
expect(serviceResults.result[i].result.length).toEqual(1);
59+
}
60+
done();
61+
}, 5000)
62+
});
63+
});
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
2+
import {GeometryBufferAnalystParameters} from '../../../src/common/iServer/GeometryBufferAnalystParameters';
3+
import {GeometryOverlayAnalystParameters} from '../../../src/common/iServer/GeometryOverlayAnalystParameters';
4+
import {BufferSetting} from '../../../src/common/iServer/BufferSetting';
5+
import {BufferDistance} from '../../../src/common/iServer/BufferDistance';
6+
import {BufferEndType} from '../../../src/common/REST';
7+
import {OverlayOperationType} from '../../../src/common/REST';
8+
import {FetchRequest} from "@supermap/iclient-common";
9+
10+
var serviceUrl = GlobeParameter.spatialAnalystURL;
11+
describe('leaflet_SpatialAnalystService_geometryBatchAnalysis', () => {
12+
var originalTimeout;
13+
var serviceResult;
14+
beforeEach(() => {
15+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
16+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
17+
serviceResult = null;
18+
});
19+
afterEach(() => {
20+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
21+
});
22+
23+
//空间关系分析
24+
it('geometryBatchAnalysis', (done) => {
25+
//缓冲区分析参数
26+
var bufferLine = {
27+
"type": "Feature",
28+
"geometry": {
29+
"type": "LineString",
30+
"coordinates": [[117, 40.50], [118, 40]]
31+
}
32+
};
33+
var geoBufferAnalystParams = {
34+
analystName: "buffer",
35+
param: new GeometryBufferAnalystParameters({
36+
sourceGeometry: bufferLine,
37+
sourceGeometrySRID: 4326,
38+
bufferSetting: new BufferSetting({
39+
endType: BufferEndType.ROUND,
40+
leftDistance: new BufferDistance({value: 0.05}),
41+
rightDistance: new BufferDistance({value: 0.05}),
42+
semicircleLineSegment: 10
43+
})
44+
})
45+
};
46+
47+
//叠加分析参数
48+
var sourceGeometry = {
49+
"type": "Feature",
50+
"geometry": {
51+
"type": "Polygon",
52+
"coordinates": [[[116, 39.75],
53+
[116, 39.15],
54+
[117, 39.15],
55+
[117, 39.85],
56+
[116, 39.85]]]
57+
}
58+
};
59+
var operateGeometry = {
60+
"type": "Feature",
61+
"geometry": {
62+
"type": "Polygon",
63+
"coordinates": [[[116.25, 40.5],
64+
[116.25, 38.5],
65+
[116.75, 38.5],
66+
[116.75, 40.5],
67+
[116.25, 40.5]]]
68+
}
69+
};
70+
var OverlayBatchAnalystParameters = {
71+
analystName: "overlay",
72+
param: new GeometryOverlayAnalystParameters({
73+
sourceGeometry: sourceGeometry,
74+
operateGeometry: operateGeometry,
75+
operation: OverlayOperationType.CLIP
76+
})
77+
};
78+
79+
//批量分析参数
80+
var paramter = [geoBufferAnalystParams, OverlayBatchAnalystParameters];
81+
//批量分析
82+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
83+
expect(method).toBe("POST");
84+
expect(testUrl).toBe(serviceUrl + "/geometry/batchanalyst.json?returnContent=true&ignoreAnalystParam=true");
85+
var expectParams = `[{'analystName':"buffer",'param':{'analystParameter':{'endType':"ROUND",'leftDistance':{'exp':null,'value':0.05},'rightDistance':{'exp':null,'value':0.05},'semicircleLineSegment':10,'radiusUnit':"METER"},'sourceGeometry':{'id':0,'style':null,'parts':[2],'points':[{'id':"SuperMap.Geometry_25",'bounds':null,'SRID':null,'x':117,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_26",'bounds':null,'SRID':null,'x':118,'y':40,'tag':null,'type':"Point"}],'type':"LINE",'prjCoordSys':{'epsgCode':4326}},'sourceGeometrySRID':4326}},{'analystName':"overlay",'param':{'operation':"CLIP",'sourceGeometry':{'id':0,'style':null,'parts':[6],'points':[{'id':"SuperMap.Geometry_27",'bounds':null,'SRID':null,'x':116,'y':39.75,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_28",'bounds':null,'SRID':null,'x':116,'y':39.15,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_29",'bounds':null,'SRID':null,'x':117,'y':39.15,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_30",'bounds':null,'SRID':null,'x':117,'y':39.85,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_31",'bounds':null,'SRID':null,'x':116,'y':39.85,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_32",'bounds':null,'SRID':null,'x':116,'y':39.75,'tag':null,'type':"Point"}],'type':"REGION",'prjCoordSys':{'epsgCode':null}},'operateGeometry':{'id':0,'style':null,'parts':[5],'points':[{'id':"SuperMap.Geometry_33",'bounds':null,'SRID':null,'x':116.25,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_34",'bounds':null,'SRID':null,'x':116.25,'y':38.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_35",'bounds':null,'SRID':null,'x':116.75,'y':38.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_36",'bounds':null,'SRID':null,'x':116.75,'y':40.5,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_37",'bounds':null,'SRID':null,'x':116.25,'y':40.5,'tag':null,'type':"Point"}],'type':"REGION",'prjCoordSys':{'epsgCode':null}}}}]`;
86+
expect(params).toBe(expectParams);
87+
expect(options).not.toBeNull();
88+
var geometryBatchAnalystEscapedJson = `[{"image":null,"resultGeometry":{"center":{"x":117.50000000003955,"y":40.25000002045569},"parts":[23],"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":[1],"points":[{"x":118.00000032273458,"y":40.000000396177164},{"x":118.0000004639434,"y":40.00000029515889},{"x":118.00000055482083,"y":40.000000164338125},{"x":118.00000058550799,"y":40.00000001790711},{"x":118.00000056027227,"y":39.999999889643746},{"x":118.0000004885416,"y":39.99999977223523},{"x":118.0000003571933,"y":39.99999966363337},{"x":118.00000018709451,"y":39.9999995937407},{"x":117.99999999669859,"y":39.99999957013961},{"x":117.99999982992506,"y":39.999999589548075},{"x":117.99999967726544,"y":39.999999644715196},{"x":116.99999968045223,"y":40.49999964203086},{"x":116.9999995367174,"y":40.49999974180941},{"x":116.99999944324225,"y":40.49999987182243},{"x":116.9999994101675,"y":40.50000001796533},{"x":116.99999943369343,"y":40.50000014642827},{"x":116.99999950421508,"y":40.500000264441226},{"x":116.999999634921,"y":40.50000037416583},{"x":116.99999980523283,"y":40.50000044552309},{"x":116.9999999966742,"y":40.50000047077176},{"x":117.0000001649555,"y":40.50000045281249},{"x":117.00000031954775,"y":40.50000039897753},{"x":118.00000032273458,"y":40.000000396177164}]},"succeed":true,"message":null},{"image":null,"resultGeometry":{"center":{"x":116.5,"y":39.5},"parts":[5],"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":[1],"points":[{"x":116.25,"y":39.85},{"x":116.75,"y":39.85},{"x":116.75,"y":39.15},{"x":116.25,"y":39.15},{"x":116.25,"y":39.85}]},"succeed":true,"message":null}]`;
89+
return Promise.resolve(new Response(geometryBatchAnalystEscapedJson));
90+
});
91+
spatialAnalystService(serviceUrl).geometrybatchAnalysis(paramter, (result) => {
92+
serviceResult = result;
93+
});
94+
setTimeout(() => {
95+
expect(serviceResult).not.toBeNull();
96+
expect(serviceResult.type).toBe("processCompleted");
97+
expect(serviceResult.result.succeed).toEqual(true);
98+
expect(serviceResult.result.length).toEqual(2);
99+
for (var i = 0; i < serviceResult.result.length; i++) {
100+
expect(serviceResult.result[i].resultGeometry).not.toBeNull();
101+
expect(serviceResult.result[i].resultGeometry.geometry).not.toBeNull();
102+
expect(serviceResult.result[i].resultGeometry.geometry.coordinates.length).toBeGreaterThan(0);
103+
expect(serviceResult.result[i].resultGeometry.geometry.type).toBe("MultiPolygon");
104+
expect(serviceResult.result[i].resultGeometry.type).toBe("Feature");
105+
expect(serviceResult.result[i].succeed).toBeTruthy();
106+
}
107+
done();
108+
}, 3000)
109+
});
110+
});

test/leaflet/services/SurfaceAnalysisSpec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalys
22
import {DatasetSurfaceAnalystParameters} from '../../../src/common/iServer/DatasetSurfaceAnalystParameters';
33
import {SurfaceAnalystParametersSetting} from '../../../src/common/iServer/SurfaceAnalystParametersSetting';
44
import {SmoothMethod} from '../../../src/common/REST';
5+
import {FetchRequest} from "@supermap/iclient-common";
56

67
var spatialAnalystURL = GlobeParameter.spatialAnalystURL;
78
var options = {
@@ -40,6 +41,14 @@ describe('leaflet_SpatialAnalystService_surfaceAnalysis', ()=> {
4041
zValueFieldName: "AVG_TMP"
4142
});
4243
var surfaceAnalystService = spatialAnalystService(spatialAnalystURL, options);
44+
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) => {
45+
expect(method).toBe("POST");
46+
expect(testUrl).toBe(spatialAnalystURL + "/datasets/SamplesP@Interpolation/isoline.json?returnContent=true");
47+
var expectParams = `{'resolution':3000,'extractParameter':{'datumValue':0,'interval':2,'resampleTolerance':0,'smoothMethod':"BSPLINE",'smoothness':3,'clipRegion':{'id':0,'style':null,'parts':[5],'points':[{'id':"SuperMap.Geometry_12",'bounds':null,'SRID':null,'x':0,'y':4010338,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_13",'bounds':null,'SRID':null,'x':1063524,'y':4010338,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_14",'bounds':null,'SRID':null,'x':1063524,'y':3150322,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_15",'bounds':null,'SRID':null,'x':0,'y':3150322,'tag':null,'type':"Point"},{'id':"SuperMap.Geometry_16",'bounds':null,'SRID':null,'x':0,'y':4010338,'tag':null,'type':"Point"}],'type':"REGION",'prjCoordSys':{'epsgCode':null}}},'resultSetting':{'expectCount':1000,'dataset':null,'dataReturnMode':"RECORDSET_ONLY",'deleteExistResultDataset':true},'zValueFieldName':"AVG_TMP",'filterQueryParameter':{'attributeFilter':null,'name':null,'joinItems':null,'linkItems':null,'ids':null,'orderBy':null,'groupBy':null,'fields':null}}`;
48+
expect(params).toBe(expectParams);
49+
expect(options).not.toBeNull();
50+
return Promise.resolve(new Response(surfaceAnalystEscapedJson));
51+
});
4352
surfaceAnalystService.surfaceAnalysis(surfaceAnalystParameters, (result)=> {
4453
serviceResult = result;
4554

@@ -49,7 +58,7 @@ describe('leaflet_SpatialAnalystService_surfaceAnalysis', ()=> {
4958
expect(surfaceAnalystService).not.toBeNull();
5059
expect(serviceResult.type).toBe("processCompleted");
5160
expect(serviceResult.result).not.toBeNull();
52-
expect(serviceResult.result.succeed).toBe(true);
61+
expect(serviceResult.result.succeed).toBeTruthy();
5362
var recordset = serviceResult.result.recordset;
5463
expect(recordset).not.toBeNull();
5564
expect(recordset.features).not.toBeNull();

0 commit comments

Comments
 (0)