Skip to content

Commit 199cc61

Browse files
[fix]leaflet wmts token不对 review by qiw
1 parent 2c8bb4c commit 199cc61

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/leaflet/mapping/TileLayer.WMTS.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import L from "leaflet";
55
import "../core/Base";
6+
import { SecurityManager } from '@supermap/iclient-common/security/SecurityManager';
7+
import { Util as CommonUtil } from '@supermap/iclient-common/commontypes/Util';
68

79
/**
810
* @class WMTSLayer
@@ -81,8 +83,11 @@ export var WMTSLayer = L.TileLayer.extend({
8183
getTileUrl: function (coords) { // (Point, Number) -> String
8284
var zoom = this._getZoomForUrl();
8385
var ident = this.options.matrixIds ? this.options.matrixIds[zoom].identifier : zoom;
86+
var index = this._url.indexOf('?');
87+
var url = index > -1 ? this._url.substring(0, this._url.indexOf('?')) : this._url;
88+
var urlParams = index > -1 ? this._url.substring(this._url.indexOf('?')) : '';
8489

85-
var url = L.Util.template(this._url, {s: this._getSubdomain(coords)});
90+
url = L.Util.template(url, {s: this._getSubdomain(coords)});
8691

8792
var obj = {
8893
service: 'WMTS',
@@ -108,7 +113,9 @@ export var WMTSLayer = L.TileLayer.extend({
108113
} else if (this.options.requestEncoding === 'REST') {
109114
var params = "/" + obj.layer + "/" + obj.style + "/" + obj.tilematrixSet + "/" + obj.tilematrix + "/" + obj.tilerow + "/" + obj.tilecol + this.formatSuffix;
110115
url += params;
111-
}
116+
}
117+
url = CommonUtil.urlAppend(url, urlParams);
118+
url = SecurityManager.appendCredential(url);
112119
return url;
113120
}
114121
});

test/leaflet/mapping/TileLayer.WMTSSpec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {wmtsLayer} from '../../../src/leaflet/mapping/TileLayer.WMTS';
2+
import { SecurityManager } from '../../../src/common/security/SecurityManager';
23

34
var url = GlobeParameter.WMTSURL;
45
describe('leaflet_TileLayerWMTS', () => {
@@ -71,4 +72,36 @@ describe('leaflet_TileLayerWMTS', () => {
7172
expect(WMTStiledMapLayerObject.getTileUrl(coords)).toBe(url + '/China/default/Custom_China/NaN/0/0.png');
7273
});
7374

75+
it("getTileUrl_params Token", () => {
76+
var coords = {x: 0, y: 0, z: 0};
77+
var option = {
78+
layer: "China",
79+
style: "default",
80+
tilematrixSet: "Custom_China",
81+
format: "image/png",
82+
requestEncoding: 'REST'
83+
};
84+
var url = GlobeParameter.WMTSURL+'?token=test';
85+
WMTStiledMapLayerObject = wmtsLayer(url, option);
86+
const tileUrl = WMTStiledMapLayerObject.getTileUrl(coords)
87+
expect(tileUrl).not.toBeNull();
88+
expect(tileUrl).toBe(GlobeParameter.WMTSURL + '/China/default/Custom_China/NaN/0/0.png?token=test');
89+
});
90+
91+
it("getTileUrl_registerToken", () => {
92+
var coords = {x: 0, y: 0, z: 0};
93+
var option = {
94+
layer: "China",
95+
style: "default",
96+
tilematrixSet: "Custom_China",
97+
format: "image/png",
98+
requestEncoding: 'REST'
99+
};
100+
var url = GlobeParameter.WMTSURL;
101+
SecurityManager.registerToken(url, 'test');
102+
WMTStiledMapLayerObject = wmtsLayer(url, option);
103+
const tileUrl = WMTStiledMapLayerObject.getTileUrl(coords)
104+
expect(tileUrl).not.toBeNull();
105+
expect(tileUrl).toBe(GlobeParameter.WMTSURL + '/China/default/Custom_China/NaN/0/0.png?token=test');
106+
});
74107
});

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