Skip to content

Commit 3f7deb0

Browse files
2 parents 571ec07 + 5a5dd13 commit 3f7deb0

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/classic/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { OutputSetting } from '@supermap/iclient-common/iServer/OutputSetting';
1616
export { MappingParameters } from '@supermap/iclient-common/iServer/MappingParameters';
1717
export { GeoCodingParameter } from '@supermap/iclient-common/iServer/GeoCodingParameter';
1818
export { GeoDecodingParameter } from '@supermap/iclient-common/iServer/GeoDecodingParameter';
19+
export { Util } from '@supermap/iclient-common/commontypes/Util';
1920
export * from './overlay';
2021
export * from './services';
2122
export { SuperMap } from './SuperMap';

src/classic/namespace.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
MappingParameters,
1414
GeoCodingParameter,
1515
GeoDecodingParameter,
16-
SuperMap
16+
SuperMap,
17+
Util
1718
} from './index';
1819

1920
SuperMap.ElasticSearch = ElasticSearch;
@@ -30,5 +31,5 @@ SuperMap.OutputSetting = OutputSetting;
3031
SuperMap.MappingParameters = MappingParameters;
3132
SuperMap.GeoCodingParameter = GeoCodingParameter;
3233
SuperMap.GeoDecodingParameter = GeoDecodingParameter;
33-
34+
SuperMap.Util = {...SuperMap.Util, ...Util};
3435
export * from './index';

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/TiandituTileLayerSpec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('leaflet_TiandituTileLayer', () => {
127127
expect(layer.options.key).toBe('123456');
128128
expect(layer._url).toBe('https://t{s}.tianditu.gov.cn/cia_w/wmts?tk=123456');
129129
expect(layer.getTileUrl(coords)).toBe(
130-
'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0'
130+
'https://t0.tianditu.gov.cn/cia_w/wmts?service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0&tk=123456'
131131
);
132132
});
133133

@@ -139,12 +139,12 @@ describe('leaflet_TiandituTileLayer', () => {
139139
key: '123456'
140140
}).addTo(map);
141141
expect(layer.getTileUrl(coords)).toBe(
142-
'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0'
142+
'https://t0.tianditu.gov.cn/cia_w/wmts?service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0&tk=123456'
143143
);
144144
layer.remove();
145145
layer.addTo(map);
146146
expect(layer.getTileUrl(coords)).toBe(
147-
'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0'
147+
'https://t0.tianditu.gov.cn/cia_w/wmts?service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0&tk=123456'
148148
);
149149
});
150150
it('initialize_noWrap_false', () => {
@@ -156,7 +156,7 @@ describe('leaflet_TiandituTileLayer', () => {
156156
key: '123456'
157157
}).addTo(map);
158158
expect(layer.getTileUrl(coords)).toBe(
159-
'https://t0.tianditu.gov.cn/cia_w/wmts?tk=123456&service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0'
159+
'https://t0.tianditu.gov.cn/cia_w/wmts?service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=w&format=tiles&width=256&height=256&layer=cia&tilematrix=2&tilerow=0&tilecol=0&tk=123456'
160160
);
161161
expect( document.querySelectorAll('.leaflet-tile').length).toBeGreaterThan(4);
162162
});

test/leaflet/mapping/TileLayer.WMTSSpec.js

Lines changed: 35 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,38 @@ 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+
SecurityManager.destroyToken(url);
107+
SecurityManager.destroyAllCredentials();
108+
});
74109
});

0 commit comments

Comments
 (0)