Skip to content

Commit 69a8b30

Browse files
committed
【update】1) webMap升级。将iclien 通过sql查询feature接口升级。通过web添加rest data会受到影响。测试后没有问题
升级原因:1)之前url中直接有代理地址,iclient修改了代码,导致会报错。有开出proxy参数配置代理地址 2)iclient建议使用新接口,以免ol的类型传递,解析不了。虽然这个接口没有这种问题出现 (reviewed by chengl)
1 parent ce1dcc3 commit 69a8b30

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

src/openlayers/core/Util.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import {Unit, Bounds, GeoJSON as GeoJSONFormat, FilterParameter,
55
GetFeaturesBySQLParameters,
6-
GetFeaturesBySQLService,
76
QueryBySQLParameters,
87
QueryOption
98
} from '@supermap/iclient-common';
109
import { QueryService } from '../services/QueryService';
10+
import { FeatureService } from '../services/FeatureService';
1111
import * as olUtil from 'ol/util';
1212

1313
/**
@@ -336,36 +336,29 @@ export class Util {
336336
* @description 获取feature
337337
* @param {string} url - 获取feature的请求地址
338338
* @param {string} datasetNames - 数据集名称
339+
* @param {object} serviceOptions - 服务类需要的参数
339340
* @param {function} processCompleted - 成功请求的回调函数
340341
* @param {function} processFaild - 失败请求的回调函数
341342
*/
342-
static getFeatureBySQL(url, datasetNames, processCompleted, processFaild) {
343-
let getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
344-
getFeatureParam = new FilterParameter({
343+
static getFeatureBySQL(url, datasetNames, serviceOptions ,processCompleted, processFaild) {
344+
let getFeatureParam = new FilterParameter({
345345
name: datasetNames.join().replace(":", "@")
346346
// attributeFilter: 'SMID > 0' // shp第三方发布的数据没有SMID字段,http://yt.ispeco.com:8099/issue/DV-131
347-
});
348-
getFeatureBySQLParams = new GetFeaturesBySQLParameters({
349-
queryParameter: getFeatureParam,
350-
datasetNames: datasetNames,
351-
fromIndex: 0,
352-
toIndex: 100000,
353-
maxFeatures: 100000,
354-
returnContent: true
355-
});
356-
let options = {
357-
eventListeners: {
358-
processCompleted: function (getFeaturesEventArgs) {
359-
processCompleted && processCompleted(getFeaturesEventArgs);
360-
},
361-
processFailed: function (e) {
362-
processFaild && processFaild(e);
363-
}
364-
},
365-
withCredentials: true
347+
}), getFeatureBySQLParams = new GetFeaturesBySQLParameters({
348+
queryParameter: getFeatureParam,
349+
datasetNames: datasetNames,
350+
fromIndex: 0,
351+
toIndex: 100000,
352+
maxFeatures: 100000,
353+
returnContent: true
354+
}), callback = (serviceResult) => {
355+
if(serviceResult.type === "processCompleted") {
356+
processCompleted && processCompleted(serviceResult);
357+
} else {
358+
processFaild && processFaild(serviceResult);
359+
}
366360
};
367-
getFeatureBySQLService = new GetFeaturesBySQLService(url, options);
368-
getFeatureBySQLService.processAsync(getFeatureBySQLParams);
361+
new FeatureService(url, serviceOptions).getFeaturesBySQL(getFeatureBySQLParams, callback);
369362
}
370363

371364
static queryFeatureBySQL(url, layerName, attributeFilter, fields, epsgCode, processCompleted, processFaild, startRecord, recordLength, onlyAttribute) {

src/openlayers/mapping/WebMap.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export class WebMap extends Observable {
900900
url: layerInfo.url,
901901
wrapX: false,
902902
serverType: serverType,
903-
crossOrigin: 'anonymous',
903+
// crossOrigin: 'anonymous', //在IE11.0.9600版本,会影响通过注册服务打开的iserver地图,不出图。因为没有携带cookie会报跨域问题
904904
// extent: this.baseLayerExtent,
905905
prjCoordSys:{ epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1] },
906906
format: layerInfo.format
@@ -1763,9 +1763,12 @@ export class WebMap extends Observable {
17631763
let that = this,dataSource = layer.dataSource,
17641764
url = layer.dataSource.url,
17651765
dataSourceName= dataSource.dataSourceName || layer.name;
1766-
let requestUrl = that.getRequestUrl(url);
1766+
let requestUrl = that.formatUrlWithCredential(url), serviceOptions = {};
1767+
if(!this.excludePortalProxyUrl && !CommonUtil.isInTheSameDomain(requestUrl)) {
1768+
serviceOptions.proxy = this.getProxy();
1769+
}
17671770
//因为itest上使用的https,iserver是http,所以要加上代理
1768-
Util.getFeatureBySQL(requestUrl, [dataSourceName], function (result) {
1771+
Util.getFeatureBySQL(requestUrl, [dataSourceName], serviceOptions, function (result) {
17691772
let features = that.parseGeoJsonData2Feature({
17701773
allDatas: {
17711774
features: result.result.features.features
@@ -2241,9 +2244,12 @@ export class WebMap extends Observable {
22412244
if(dataSource.type === "USER_DATA" || dataSource.accessType==="DIRECT" ) {
22422245
that.addGeojsonFromUrl(layerInfo, null, layerIndex)
22432246
} else {
2244-
let requestUrl = that.getRequestUrl(url);
2247+
let requestUrl = that.formatUrlWithCredential(url), serviceOptions = {};
2248+
if(!this.excludePortalProxyUrl && !CommonUtil.isInTheSameDomain(requestUrl)) {
2249+
serviceOptions.proxy = this.getProxy();
2250+
}
22452251
//因为itest上使用的https,iserver是http,所以要加上代理
2246-
Util.getFeatureBySQL(requestUrl, [dataSourceName], function (result) {
2252+
Util.getFeatureBySQL(requestUrl, [dataSourceName], serviceOptions, function (result) {
22472253
let features = that.parseGeoJsonData2Feature({
22482254
allDatas: {
22492255
features: result.result.features.features
@@ -3516,18 +3522,27 @@ export class WebMap extends Observable {
35163522
* @returns {Promise<T | never>} 请求地址
35173523
*/
35183524
getRequestUrl(url) {
3519-
if(this.credentialValue) {
3520-
//有token之类的配置项
3521-
url = url.indexOf("?") === -1 ? `${url}?${this.credentialKey}=${this.credentialValue}` :
3522-
`${url}&${this.credentialKey}=${this.credentialValue}`;
3523-
}
3525+
this.formatUrlWithCredential(url);
35243526
//如果传入进来的url带了代理则不需要处理
35253527
if(this.excludePortalProxyUrl) {
35263528
return;
35273529
}
35283530
return CommonUtil.isInTheSameDomain(url) ? url : `${this.getProxy()}${encodeURIComponent(url)}`;
35293531
}
35303532

3533+
/**
3534+
* 给url带上凭证密钥
3535+
* @param {*} url 地址
3536+
*/
3537+
formatUrlWithCredential(url) {
3538+
if(this.credentialValue) {
3539+
//有token之类的配置项
3540+
url = url.indexOf("?") === -1 ? `${url}?${this.credentialKey}=${this.credentialValue}` :
3541+
`${url}&${this.credentialKey}=${this.credentialValue}`;
3542+
}
3543+
return url;
3544+
}
3545+
35313546
/**
35323547
* @private
35333548
* @function ol.supermap.WebMap.prototype.getProxy

0 commit comments

Comments
 (0)