8000 【feature】webmap3.0 l7图层添加restdata服务优化withcredentials · SuperMap/iClient-JavaScript@33478fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 33478fe

Browse files
committed
【feature】webmap3.0 l7图层添加restdata服务优化withcredentials
1 parent f3fd337 commit 33478fe

File tree

2 files changed

+124
-44
lines changed

2 files changed

+124
-44
lines changed

src/mapboxgl/mapping/utils/L7LayerUtil.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ async function requestRestDataFieldsInfo(datasetUrl, credential, options) {
268268
* 获取restDatafield
269269
* @param datasetUrl
270270
* @param credential
271-
* @param withCredentials
271+
* @param options
272272
*/
273273
async function getRestDataFieldInfo(datasetUrl, credential, options) {
274274
const fieldsInfos = await requestRestDataFieldsInfo(datasetUrl, credential, options);
@@ -375,6 +375,13 @@ function transformFeaturesNameAndType(originFeatures, fieldNames, fieldTypes) {
375375
return formatFeatures(features, fieldInfo);
376376
}
377377

378+
function handleWithRequestOptions(url, options) {
379+
if (options.iportalServiceProxyUrl && url.indexOf(options.iportalServiceProxyUrl) >= 0) {
380+
return { ...options, withCredentials: true };
381+
}
382+
return { ...options, withCredentials: undefined };
383+
}
384+
378385
/**
379386
* 通过webMapsource获取restData-geojson
380387
* @param data
@@ -389,8 +396,9 @@ async function getRestDataGeojsonByWebMap(data, options) {
389396
queryParameter: { name: datasetName + '@' + dataSourceName }
390397
};
391398
const datasetUrl = `${url.split('featureResults')[0]}datasources/${dataSourceName}/datasets/${datasetName}`;
392-
const { fieldNames, fieldTypes } = await getRestDataFieldInfo(datasetUrl, credential, options);
393-
const attrDataInfo = await FetchRequest.post(url, JSON.stringify(SQLParams), options);
399+
const nextOptions = handleWithRequestOptions(datasetUrl, options);
400+
const { fieldNames, fieldTypes } = await getRestDataFieldInfo(datasetUrl, credential, nextOptions);
401+
const attrDataInfo = await FetchRequest.post(url, JSON.stringify(SQLParams), nextOptions);
394402
const featuresRes = await attrDataInfo.json();
395403

396404
return {
@@ -412,9 +420,6 @@ function getStructDataItemJson(href, option) {
412420
throw data.error.errorMsg;
413421
}
414422
return data;
415-
})
416-
.catch((error) => {
417-
console.error(error);
418423
});
419424
}
420425

test/mapboxgl/mapping/utils/L7LayerUtilSpec.js

Lines changed: 113 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ describe('L7LayerUtil', () => {
3434
options
3535
};
3636

37-
beforeAll(() => {
38-
spyOn(FetchRequest, 'get').and.callFake((url) => {
39-
if (url.indexOf('map.json') > -1) {
40-
return Promise.resolve(new Response(mapstudioWebMap_L7Layers));
41-
}
42-
if (url.indexOf('617580084.json') > -1) {
43-
return Promise.resolve(new Response(msProjectINfo_L7Layers));
44-
}
37+
it('add od layer', (done) => {
38+
spyOn(FetchRequest, 'get').and.callFake((url, _, options) => {
39+
expect(options.withCredentials).toBe(options.withCredentials);
40+
expect(options.withoutFormatSuffix).toBeTruthy();
4541
if (url.indexOf('/sprite') > -1) {
4642
return Promise.resolve(new Response(msSpriteInfo));
4743
}
@@ -54,37 +50,9 @@ describe('L7LayerUtil', () => {
5450
if (url.indexOf('/web/datas/1554834293/structureddata.json') > -1) {
5551
return Promise.resolve(new Response(l7StructureData1052943054));
5652
}
57-
if (url.indexOf('/web/datas/1767084124/structureddata/ogc-features/collections/all/items.json') > -1) {
58-
return Promise.resolve(new Response(l7StructureData1767084124Items));
59-
}
60-
if (url.indexOf('/web/datas/1767084124/structureddata.json') > -1) {
61-
return Promise.resolve(new Response(l7StructureData1767084124));
62-
}
63-
if (
64-
url.indexOf('iserver/services/data-Building/rest/data/datasources/newBuilding/datasets/New_LINE/fields.json') >
65-
-1
66-
) {
67-
return Promise.resolve(new Response(RESTDATA_FIELDS_RES));
68-
}
69-
if (
70-
url.indexOf('iserver/services/data-Building/rest/data/datasources/newBuilding/datasets/New_LINE/domain.json') >
71-
-1
72-
) {
73-
return Promise.resolve(new Response(RESTDATA_DOMAINS_RES));
74-
}
7553
console.log(url);
7654
return Promise.resolve();
7755
});
78-
spyOn(FetchRequest, 'post').and.callFake((url) => {
79-
if (url.indexOf('/iserver/services/data-Building/rest/data/featureResults.geojson') > -1) {
80-
return Promise.resolve(new Response(RESTDATA_FEATURES_RES));
81-
}
82-
console.log(url);
83-
return Promise.resolve();
84-
});
85-
});
86-
87-
it('add od layer', (done) => {
8856
const layers = [
8957
{
9058
layout: {
@@ -172,6 +140,27 @@ describe('L7LayerUtil', () => {
172140
});
173141

174142
it('animate line layer', (done) => {
143+
spyOn(FetchRequest, 'get').and.callFake((url, _, options) => {
144+
expect(options.withCredentials).toBeUndefined();
145+
expect(options.withoutFormatSuffix).toBeTruthy();
146+
if (url.indexOf('/data-Building/rest/data/datasources/newBuilding/datasets/New_LINE/fields.json') > -1) {
147+
return Promise.resolve(new Response(RESTDATA_FIELDS_RES));
148+
}
149+
if (url.indexOf('/data-Building/rest/data/datasources/newBuilding/datasets/New_LINE/domain.json') > -1) {
150+
return Promise.resolve(new Response(RESTDATA_DOMAINS_RES));
151+
}
152+
console.log(url);
153+
return Promise.resolve();
154+
});
155+
spyOn(FetchRequest, 'post').and.callFake((url, _, options) => {
156+
expect(options.withCredentials).toBeUndefined();
157+
expect(options.withoutFormatSuffix).toBeTruthy();
158+
if (url.indexOf('/data-Building/rest/data/featureResults.geojson') > -1) {
159+
return Promise.resolve(new Response(RESTDATA_FEATURES_RES));
160+
}
161+
console.log(url);
162+
return Promise.resolve();
163+
});
175164
const layers = [
176165
{
177166
layout: {
@@ -204,8 +193,8 @@ describe('L7LayerUtil', () => {
204193
ms_New_LINE_ms_datasetId_1716864444834_6_1716864449917_10: {
205194
data: {
206195
credential: {
207-
"key": "token",
208-
"value": "kF0ZmjLFg-P56UQdHVIkl1tDDnUTsuy5ayBcAHrmdmM6BmLMLHNvk7aul83z2twM8m5rtD3ExQguW0jlThhWkEoWr27Dzw.."
196+
key: 'token',
197+
value: 'kF0ZmjLFg-P56UQdHVIkl1tDDnUTsuy5ayBcAHrmdmM6BmLMLHNvk7aul83z2twM8m5rtD3ExQguW0jlThhWkEoWr27Dzw..'
209198
},
210199
datasetName: 'New_LINE',
211200
type: 'supermap-rest-data',
@@ -227,4 +216,90 @@ describe('L7LayerUtil', () => {
227216
done();
228217
});
229218
});
219+
220+
it('servcie proxy', (done) => {
221+
spyOn(FetchRequest, 'get').and.callFake((url, _, options) => {
222+
expect(options.withCredentials).toBeTruthy();
223+
expect(options.withoutFormatSuffix).toBeTruthy();
224+
if (url.indexOf('/data-ZhongGuoDiTu/rest/data/datasources/中国矢量数据/datasets/飞机场/fields.json') > -1) {
225+
return Promise.resolve(new Response(RESTDATA_FIELDS_RES));
226+
}
227+
if (url.indexOf('/data-ZhongGuoDiTu/rest/data/datasources/中国矢量数据/datasets/飞机场/domain.json') > -1) {
228+
return Promise.resolve(new Response(JSON.stringify([])));
229+
}
230+
console.log(url);
231+
return Promise.resolve();
232+
});
233+
spyOn(FetchRequest, 'post').and.callFake((url) => {
234+
if (url.indexOf('/data-ZhongGuoDiTu/rest/data/featureResults.geojson') > -1) {
235+
return Promise.resolve(new Response(RESTDATA_FEATURES_RES));
236+
}
237+
return Promise.resolve();
238+
});
239+
const layers = [
240+
{
241+
layout: {
242+
visibility: 'visible'
243+
},
244+
metadata: {
245+
MapStudio: {
246+
title: '飞机场'
247+
}
248+
},
249+
paint: {
250+
'heatmap-extrusion-intensity': 2,
251+
'heatmap-extrusion-radius': 10,
252+
'heatmap-extrusion-opacity': 1,
253+
'heatmap-extrusion-weight': 'SmID',
254+
'heatmap-extrusion-color': [
255+
'interpolate',
256+
['linear'],
257+
['heatmap-density'],
258+
0,
259+
'rgba(0,0,0,0)',
260+
0.2,
261+
'#0000ff',
262+
0.4,
263+
'#00ffff',
264+
0.6000000000000001,
265+
'#00ff00',
266+
0.8,
267+
'#ffff00',
268+
1,
269+
'#ff0000'
270+
]
271+
},
272+
source: 'ms_飞机场_ms_datasetId_1716979413748_4_1716979443420_8',
273+
id: 'ms_飞机场_1716979443420_7',
274+
type: 'heatmap-extrusion'
275+
}
276+
];
277+
const sources = {
278+
ms_飞机场_ms_datasetId_1716979413748_4_1716979443420_8: {
279+
data: {
280+
datasetName: '飞机场',
281+
type: 'supermap-rest-data',
282+
url: 'http://localhost:8195/portalproxy/761c40c7268f75a5/iserver/services/data-ZhongGuoDiTu/rest/data/featureResults.geojson?returnContent=true&fromIndex=0&maxFeatures=2147483647',
283+
dataSourceName: '中国矢量数据'
284+
},
285+
type: 'geojson'
286+
}
287+
};
288+
const nextOptions = {
289+
...addOptions,
290+
webMapInfo: { ...mapstudioWebMap_L7LayersRes, layers, sources },
291+
l7Layers: layers,
292+
options: {
293+
withCredentials: false,
294+
server: '/iportal/',
295+
iportalServiceProxyUrl: 'http://localhost:8195/portalproxy'
296+
}
297+
};
298+
const spy = spyOn(nextOptions.map, 'addLayer').and.callThrough();
299+
addL7Layers(nextOptions).then(() => {
300+
expect(nextOptions.map.addLayer.calls.count()).toEqual(1);
301+
spy.calls.reset();
302+
done();
303+
});
304+
});
230305
});

0 commit comments

Comments
 (0)
0