Skip to content

Commit 53ee332

Browse files
committed
【bug】1) 解决webmap,从iortal添加小范围的wmts地图,出图失败以及缩放至报错
2)webmap credentialKey参数的注释详细点 (reviewed by chengl)
1 parent 4bc4e63 commit 53ee332

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ const MAX_MIGRATION_ANIMATION_COUNT = 1000;
3131
/**
3232
* @class ol.supermap.WebMap
3333
* @category iPortal/Online
34-
* @classdesc 对接 iPortal/Online 地图类
34+
* @classdesc 对接 iPortal/Online 地图类
3535
* @param {number} id - 地图的id
36-
* @param {Object} options - 参数
37-
* @param {string} [options.target='map'] - 地图容器id
38-
* @param {string} [options.server="http://www.supermapol.com"] - 地图的地址
39-
* @param {function} [options.successCallback] - 成功加载地图后调用的函数
40-
* @param {function} [options.errorCallback] - 加载地图失败调用的函数
41-
* @param {string} [options.credentialKey] - 凭证密钥。
42-
* @param {string} [options.credentialValue] - 凭证值。
43-
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie
36+
* @param {Object} options - 参数
37+
* @param {string} [options.target='map'] - 地图容器id
38+
* @param {string} [options.server="http://www.supermapol.com"] - 地图的地址
39+
* @param {function} [options.successCallback] - 成功加载地图后调用的函数
40+
* @param {function} [options.errorCallback] - 加载地图失败调用的函数
41+
* @param {string} [options.credentialKey] - 凭证密钥。例如为"key"、"token",或者用户自定义的密钥。用户申请了密钥,此参数必填
42+
* @param {string} [options.credentialValue] - 凭证密钥对应的值,credentialKey和credentialValue必须一起使用
43+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie
4444
* @param {boolean} [options.excludePortalProxyUrl] - server传递过来的url是否带有代理
4545
* @param {string} [options.tiandituKey] - 天地图的key
4646
* @param {function} [options.mapSetting.mapClickCallback] - 地图被点击的回调函数
@@ -117,10 +117,6 @@ export class WebMap extends ol.Observable {
117117
}
118118

119119
let mapUrl = this.server + 'web/maps/' + this.mapId + '/map';
120-
if (this.credentialValue) {
121-
mapUrl += ('.json?' + this.credentialKey + '=' + this.credentialValue);
122-
123-
}
124120
let filter = 'getUrlResource.json?url=';
125121
if (this.excludePortalProxyUrl && this.server.indexOf(filter) > -1) {
126122
//大屏需求,或者有加上代理的
@@ -332,7 +328,11 @@ export class WebMap extends ol.Observable {
332328
if(layer){
333329
this.map.addLayer(layer);
334330
}
335-
331+
if(this.mapParams) {
332+
let extent = [mapInfo.extent.leftBottom.x, mapInfo.extent.leftBottom.y, mapInfo.extent.rightTop.x, mapInfo.extent.rightTop.y];
333+
this.mapParams.extent = extent;
334+
this.mapParams.projection = mapInfo.projection;
335+
}
336336
if (mapInfo.baseLayer && mapInfo.baseLayer.labelLayerVisible) {
337337
let layerInfo = mapInfo.baseLayer;
338338
//存在天地图路网
@@ -922,9 +922,13 @@ export class WebMap extends ol.Observable {
922922
let scales = [];
923923
for (let i = 0; i < tileMatrixSet.length; i++) {
924924
if (tileMatrixSet[i].Identifier === layerInfo.tileMatrixSet) {
925+
let wmtsLayerEpsg = `EPSG:${tileMatrixSet[i].SupportedCRS.split('::')[1]}`;
925926
for (let h = 0; h < tileMatrixSet[i].TileMatrix.length; h++) {
926927
scales.push(tileMatrixSet[i].TileMatrix[h].ScaleDenominator)
927928
}
929+
//bug wmts出图需要加上origin,否则会出现出图不正确的情况。偏移或者瓦片出不了
930+
let origin = tileMatrixSet[i].TileMatrix[0].TopLeftCorner;
931+
layerInfo.origin = wmtsLayerEpsg === "EPSG:4326" ? [origin[1], origin[0]] : origin;
928932
break;
929933
}
930934
}
@@ -971,11 +975,11 @@ export class WebMap extends ol.Observable {
971975
let unit = ol.proj.get(this.baseProjection).getUnits();
972976
return new ol.source.WMTS({
973977
url: layerInfo.url,
974-
layer: layerInfo.name,
978+
layer: layerInfo.layer,
975979
format: 'image/png',
976980
matrixSet: layerInfo.tileMatrixSet,
977981
requestEncoding: layerInfo.requestEncoding || 'KVP',
978-
tileGrid: this.getWMTSTileGrid(extent, layerInfo.scales, unit, layerInfo.dpi),
982+
tileGrid: this.getWMTSTileGrid(extent, layerInfo.scales, unit, layerInfo.dpi, layerInfo.origin),
979983
tileLoadFunction: function (imageTile, src) {
980984
imageTile.getImage().src = src
981985
}
@@ -990,11 +994,13 @@ export class WebMap extends ol.Observable {
990994
* @param {number} scales - 图层比例尺
991995
* @param {string} unit - 单位
992996
* @param {number} dpi - dpi
997+
* @param {Array} origin 瓦片的原点
993998
* @returns {ol.tilegrid.WMTS}
994999
*/
995-
getWMTSTileGrid(extent, scales, unit, dpi) {
1000+
getWMTSTileGrid(extent, scales, unit, dpi, origin) {
9961001
let resolutionsInfo = this.getReslutionsFromScales(scales, dpi || 96, unit);
9971002
return new ol.tilegrid.WMTS({
1003+
origin,
9981004
extent: extent,
9991005
resolutions: resolutionsInfo.res,
10001006
matrixIds: resolutionsInfo.matrixIds
@@ -2882,7 +2888,8 @@ export class WebMap extends ol.Observable {
28822888
getRequestUrl(url) {
28832889
if(this.credentialValue) {
28842890
//有token之类的配置项
2885-
url = `${url}&${this.credentialKey}=${this.credentialValue}`;
2891+
url = url.indexOf("?") === -1 ? `${url}?${this.credentialKey}=${this.credentialValue}` :
2892+
`${url}&${this.credentialKey}=${this.credentialValue}`;
28862893
}
28872894
//如果传入进来的url带了代理则不需要处理
28882895
if(this.excludePortalProxyUrl) {

0 commit comments

Comments
 (0)