Skip to content

Commit 6e91563

Browse files
committed
【fix】优化各Service类拼装url的逻辑,支持携带自定义参数(ICL-1207)review by xiongjj
1 parent 5d6b0b3 commit 6e91563

File tree

230 files changed

+1651
-1116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+1651
-1116
lines changed

dist/leaflet/workers/TurfWorker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44

5-
importScripts('https://cdnjs.cloudflare.com/ajax/libs/Turf.js/5.1.6/turf.js')
5+
importScripts('https://cdn.bootcss.com/Turf.js/5.1.6/turf.min.js')
66

77
/**
88
* 空间分析所需工具类

src/common/commontypes/Util.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,17 @@ SuperMap.Util.getParameterString = function (params) {
292292
};
293293

294294
/**
295-
* @description 给 URL 追加参数
295+
* @description 给 URL 追加查询参数
296296
* @param {string} url - 待追加参数的 URL 字符串。
297-
* @param {string} paramStr - 待追加的参数
297+
* @param {string} paramStr - 待追加的查询参数
298298
* @returns {string} 新的 URL。
299299
*/
300300
SuperMap.Util.urlAppend = function (url, paramStr) {
301301
var newUrl = url;
302302
if (paramStr) {
303+
if(paramStr.startsWith('?')){
304+
paramStr = paramStr.substring(1);
305+
}
303306
var parts = (url + " ").split(/[?&]/);
304307
newUrl += (parts.pop() === " " ?
305308
paramStr :
@@ -308,6 +311,28 @@ SuperMap.Util.urlAppend = function (url, paramStr) {
308311
return newUrl;
309312
};
310313

314+
/**
315+
* @description 给 URL 追加 path 参数。
316+
* @param {string} url - 待追加参数的 URL 字符串。
317+
* @param {string} paramStr - 待追加的path参数。
318+
* @returns {string} 新的 URL。
319+
*/
320+
SuperMap.Util.urlPathAppend = function (url, pathStr) {
321+
let newUrl = url;
322+
if (!pathStr) {
323+
return newUrl;
324+
}
325+
if (pathStr.startsWith('/')) {
326+
pathStr = pathStr.substring(1);
327+
}
328+
const parts = url.split('?');
329+
if(!parts[0].endsWith('/')){
330+
parts[0] += '/'
331+
}
332+
newUrl = `${parts[0]}${pathStr}${parts.length > 1 ? `?${parts[1]}` : ''}`;
333+
return newUrl;
334+
};
335+
311336
/**
312337
* @description 为了避免浮点精度错误而保留的有效位数。
313338
* @type {number}

src/common/iServer/AreaSolarRadiationService.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,17 @@ export class AreaSolarRadiationService extends SpatialAnalystBase {
5252
return;
5353
}
5454
var me = this;
55-
56-
var end = me.url.substr(me.url.length - 1, 1);
57-
if (end !== '/') {
58-
me.url += "/";
59-
}
60-
6155
var parameterObject = {};
6256

6357
if (parameter instanceof AreaSolarRadiationParameters) {
64-
me.url += 'datasets/' + parameter.dataset + '/solarradiation';
58+
me.url = Util.urlPathAppend(me.url, `datasets/${parameter.dataset}/solarradiation`);
6559
}
66-
60+
me.url = Util.urlAppend(me.url, 'returnContent=true');
6761
AreaSolarRadiationParameters.toObject(parameter, parameterObject);
6862
var jsonParameters = Util.toJSON(parameterObject);
69-
me.url += '.json?returnContent=true';
7063

7164
me.request({
72-
method: "POST",
65+
method: 'POST',
7366
data: jsonParameters,
7467
scope: me,
7568
success: me.serviceProcessCompleted,

src/common/iServer/BufferAnalystService.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,18 @@ export class BufferAnalystService extends SpatialAnalystBase {
6666
processAsync(parameter) {
6767
var parameterObject = {};
6868
var me = this;
69-
70-
var end = me.url.substr(me.url.length - 1, 1);
71-
if (end !== '/') {
72-
me.url += "/";
73-
}
74-
7569
if (parameter instanceof DatasetBufferAnalystParameters) {
76-
me.mode = "datasets";
77-
me.url += 'datasets/' + parameter.dataset + '/buffer';
70+
me.mode = 'datasets';
71+
me.url = Util.urlPathAppend(me.url, 'datasets/' + parameter.dataset + '/buffer');
7872
DatasetBufferAnalystParameters.toObject(parameter, parameterObject);
7973
} else if (parameter instanceof GeometryBufferAnalystParameters) {
80-
me.mode = "geometry";
81-
me.url += 'geometry/buffer';
74+
me.mode = 'geometry';
75+
me.url = Util.urlPathAppend(me.url, 'geometry/buffer');
8276
GeometryBufferAnalystParameters.toObject(parameter, parameterObject);
8377
}
8478

8579
var jsonParameters = Util.toJSON(parameterObject);
86-
me.url += '.json?returnContent=true';
80+
me.url = Util.urlAppend(me.url, 'returnContent=true');
8781
me.request({
8882
method: "POST",
8983
data: jsonParameters,

src/common/iServer/BuffersAnalystJobsService.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import {SuperMap} from '../SuperMap';
5-
import {ProcessingServiceBase} from './ProcessingServiceBase';
6-
import {BuffersAnalystJobsParameter} from './BuffersAnalystJobsParameter';
4+
import { SuperMap } from '../SuperMap';
5+
import { Util } from '../commontypes/Util';
6+
import { ProcessingServiceBase } from './ProcessingServiceBase';
7+
import { BuffersAnalystJobsParameter } from './BuffersAnalystJobsParameter';
78

89
/**
910
* @class SuperMap.BuffersAnalystJobsService
@@ -18,8 +19,8 @@ import {BuffersAnalystJobsParameter} from './BuffersAnalystJobsParameter';
1819
export class BuffersAnalystJobsService extends ProcessingServiceBase {
1920
constructor(url, options) {
2021
super(url, options);
21-
this.url += "/spatialanalyst/buffers";
22-
this.CLASS_NAME = "SuperMap.BuffersAnalystJobsService";
22+
this.url = Util.urlPathAppend(this.url, 'spatialanalyst/buffers');
23+
this.CLASS_NAME = 'SuperMap.BuffersAnalystJobsService';
2324
}
2425

2526
/**
@@ -43,7 +44,7 @@ export class BuffersAnalystJobsService extends ProcessingServiceBase {
4344
* @param {string} id - 指定要获取数据的id。
4445
*/
4546
getBuffersJob(id) {
46-
super.getJobs(this.url + '/' + id);
47+
super.getJobs(Util.urlPathAppend(this.url, id));
4748
}
4849

4950
/**
@@ -57,4 +58,4 @@ export class BuffersAnalystJobsService extends ProcessingServiceBase {
5758
}
5859
}
5960

60-
SuperMap.BuffersAnalystJobsService = BuffersAnalystJobsService;
61+
SuperMap.BuffersAnalystJobsService = BuffersAnalystJobsService;

src/common/iServer/BurstPipelineAnalystService.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* Copyright© 2000 - 2020 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import {SuperMap} from '../SuperMap';
5-
import {NetworkAnalystServiceBase} from './NetworkAnalystServiceBase';
6-
import {BurstPipelineAnalystParameters} from './BurstPipelineAnalystParameters';
4+
import { SuperMap } from '../SuperMap';
5+
import { Util } from '../commontypes/Util';
6+
import { NetworkAnalystServiceBase } from './NetworkAnalystServiceBase';
7+
import { BurstPipelineAnalystParameters } from './BurstPipelineAnalystParameters';
78

89
/**
910
* @class SuperMap.BurstPipelineAnalystService
@@ -43,9 +44,7 @@ export class BurstPipelineAnalystService extends NetworkAnalystServiceBase {
4344
return null;
4445
}
4546
var me = this, jsonObject;
46-
var end = me.url.substr(me.url.length - 1, 1);
47-
me.url = me.url + ((end === "/") ? "burstAnalyse" : "/burstAnalyse") + ".json?";
48-
47+
me.url = Util.urlPathAppend(me.url, 'burstAnalyse');
4948
jsonObject = {
5049
sourceNodeIDs: params.sourceNodeIDs,
5150
isUncertainDirectionValid: params.isUncertainDirectionValid

src/common/iServer/ChartFeatureInfoSpecsService.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ export class ChartFeatureInfoSpecsService extends CommonServiceBase {
4848
* 2. 通过监听 ChartFeatureInfoSpecsEvent.PROCESS_COMPLETE 事件获取。
4949
*/
5050
processAsync() {
51-
var me = this, method = "GET",
52-
end = me.url.substr(me.url.length - 1, 1);
51+
var me = this, method = "GET";
5352
if (!me.isTempLayers) {
54-
me.url += (end === "/") ? '' : '/';
55-
me.url += "chartFeatureInfoSpecs.json?";
56-
} else {
57-
me.url += ".json?";
53+
Util.urlPathAppend(me.url,'chartFeatureInfoSpecs');
5854
}
5955
me.request({
6056
method: method,

src/common/iServer/ChartQueryService.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,15 @@ export class ChartQueryService extends CommonServiceBase {
7171
this.format = DataFormat.GEOJSON;
7272

7373
Util.extend(this, options);
74-
var me = this, end;
74+
var me = this;
7575
if (options.format) {
7676
me.format = options.format.toUpperCase();
7777
}
7878

7979
if (!me.url) {
8080
return;
8181
}
82-
end = me.url.substr(me.url.length - 1, 1);
83-
84-
// TODO 待iServer featureResul资源GeoJSON表述bug修复当使用以下注释掉的逻辑
85-
// if (me.format==="geojson") {
86-
// me.url += (end == "/") ? "featureResults.geojson?" : "/featureResults.geojson?";
87-
// } else {
88-
// me.url += (end == "/") ? "featureResults.json?" : "/featureResults.json?";
89-
// }
90-
me.url += (end === "/") ? "queryResults.json?" : "/queryResults.json?";
82+
me.url = Util.urlPathAppend(me.url, 'queryResults');
9183

9284
this.CLASS_NAME = "SuperMap.ChartQueryService";
9385
}
@@ -119,7 +111,7 @@ export class ChartQueryService extends CommonServiceBase {
119111
me.returnContent = params.returnContent;
120112
jsonParameters = params.getVariablesJson();
121113
if (me.returnContent) {
122-
me.url += "returnContent=" + me.returnContent;
114+
me.url = Util.urlAppend(me.url, 'returnContent=true');
123115
}
124116
me.request({
125117
method: "POST",

src/common/iServer/CommonServiceBase.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,7 @@ export class CommonServiceBase {
173173
//为url添加安全认证信息片段
174174
let credential = this.getCredential(options.url);
175175
if (credential) {
176-
//当url中含有?,并且?在url末尾的时候直接添加token *网络分析等服务请求url会出现末尾是?的情况*
177-
//当url中含有?,并且?不在url末尾的时候添加&token
178-
//当url中不含有?,在url末尾添加?token
179-
let endStr = options.url.substring(options.url.length - 1, options.url.length);
180-
if (options.url.indexOf("?") > -1 && endStr === "?") {
181-
options.url += credential.getUrlParameters();
182-
} else if (options.url.indexOf("?") > -1 && endStr !== "?") {
183-
options.url += "&" + credential.getUrlParameters();
184-
} else {
185-
options.url += "?" + credential.getUrlParameters();
186-
}
176+
options.url = Util.urlAppend(options.url, credential.getUrlParameters());
187177
}
188178

189179
me.calculatePollingTimes();

src/common/iServer/ComputeWeightMatrixService.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ export class ComputeWeightMatrixService extends NetworkAnalystServiceBase {
5555
if (!(params instanceof ComputeWeightMatrixParameters)) {
5656
return;
5757
}
58-
var me = this, jsonObject,
59-
end = me.url.substr(me.url.length - 1, 1);
60-
me.url = me.url + ((end === "/") ? "weightmatrix" : "/weightmatrix") + ".json?";
58+
var me = this,
59+
jsonObject;
60+
me.url = Util.urlPathAppend(me.url, 'weightmatrix');
6161
jsonObject = {
6262
parameter: Util.toJSON(params.parameter),
6363
nodes: me.getJson(params.isAnalyzeById, params.nodes)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy