Skip to content

Commit 084ae71

Browse files
committed
增加WMTSLayer支持REST请求 & 补充对应UT reviewBy songyumeng
1 parent 534267b commit 084ae71

File tree

5 files changed

+143
-9
lines changed

5 files changed

+143
-9
lines changed

dist/iclient9-leaflet.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20094,7 +20094,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
2009420094
* crs - {{@link L.Proj.CRS}} 坐标系统类。<br>
2009520095
* serverType - {{@link SuperMap.ServerType}} 服务来源 iServer|iPortal|online。<br>
2009620096
* attribution - {string} 版权信息。
20097-
* tileProxy - {string} 启用托管地址
20097+
* tileProxy - {string} 启用托管地址。
20098+
* requestEncoding - {string} KVP或者REST的请求方式,默认是KVP。
2009820099
*/
2009920100
var WMTSLayer = exports.WMTSLayer = _leaflet2["default"].TileLayer.extend({
2010020101

@@ -20106,6 +20107,7 @@ var WMTSLayer = exports.WMTSLayer = _leaflet2["default"].TileLayer.extend({
2010620107
tileSize: 256,
2010720108
matrixIds: null,
2010820109
layer: '',
20110+
requestEncoding: 'KVP',
2010920111
attribution: "with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"
2011020112
},
2011120113

@@ -20114,6 +20116,26 @@ var WMTSLayer = exports.WMTSLayer = _leaflet2["default"].TileLayer.extend({
2011420116
// (String, Object)
2011520117
this._url = url;
2011620118
_leaflet2["default"].setOptions(this, options);
20119+
20120+
var opt = this.options;
20121+
if (opt.requestEncoding === "REST") {
20122+
20123+
var formatSuffixMap = {
20124+
"image/png": "png",
20125+
"image/png8": "png",
20126+
"image/png24": "png",
20127+
"image/png32": "png",
20128+
"png": "png",
20129+
"image/jpeg": "jpg",
20130+
"image/jpg": "jpg",
20131+
"jpeg": "jpg",
20132+
"jpg": "jpg"
20133+
};
20134+
this.formatSuffix = "." + (formatSuffixMap[opt.format] || opt.format.split("/").pop() || "png");
20135+
} else {
20136+
20137+
opt.requestEncoding = "KVP";
20138+
}
2011720139
},
2011820140

2011920141
/**
@@ -20126,7 +20148,9 @@ var WMTSLayer = exports.WMTSLayer = _leaflet2["default"].TileLayer.extend({
2012620148
// (Point, Number) -> String
2012720149
var zoom = this._getZoomForUrl();
2012820150
var ident = this.options.matrixIds ? this.options.matrixIds[zoom].identifier : zoom;
20151+
2012920152
var url = _leaflet2["default"].Util.template(this._url, { s: this._getSubdomain(coords) });
20153+
2013020154
var obj = {
2013120155
service: 'WMTS',
2013220156
request: 'GetTile',
@@ -20143,9 +20167,14 @@ var WMTSLayer = exports.WMTSLayer = _leaflet2["default"].TileLayer.extend({
2014320167
};
2014420168

2014520169
if (this.options.tileProxy) {
20146-
url = this.options.tileProxy + encodeURIComponent(url + _leaflet2["default"].Util.getParamString(obj, url));
20147-
} else {
20170+
url = this.options.tileProxy + url;
20171+
}
20172+
20173+
if (this.options.requestEncoding === 'KVP') {
2014820174
url += _leaflet2["default"].Util.getParamString(obj, url);
20175+
} else if (this.options.requestEncoding === 'REST') {
20176+
var params = "/" + obj.layer + "/" + obj.style + "/" + obj.tilematrixSet + "/" + obj.tilematrix + "/" + obj.tilerow + "/" + obj.tilecol + this.formatSuffix;
20177+
url += params;
2014920178
}
2015020179
return url;
2015120180
}
@@ -94607,7 +94636,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
9460794636
/* 501 */
9460894637
/***/ (function(module, exports) {
9460994638

94610-
module.exports = {"_args":[["proj4@2.3.15","G:\\iClient9"]],"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"http://registry.npm.taobao.org/proj4/download/proj4-2.3.15.tgz","_spec":"2.3.15","_where":"G:\\iClient9","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"contributors":[{"name":"Mike Adair","email":"madair@dmsolutions.ca"},{"name":"Richard Greenwood","email":"rich@greenwoodmap.com"},{"name":"Calvin Metcalf","email":"calvin.metcalf@gmail.com"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"~0.0.2"},"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"}
94639+
module.exports = {"_from":"proj4@2.3.15","_id":"proj4@2.3.15","_inBundle":false,"_integrity":"sha1-WtBui8owvg/6OJpJ5FZfUfBtCJ4=","_location":"/proj4","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"proj4@2.3.15","name":"proj4","escapedName":"proj4","rawSpec":"2.3.15","saveSpec":null,"fetchSpec":"2.3.15"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/proj4/-/proj4-2.3.15.tgz","_shasum":"5ad06e8bca30be0ffa389a49e4565f51f06d089e","_spec":"proj4@2.3.15","_where":"G:\\iClient9","author":"","bugs":{"url":"https://github.com/proj4js/proj4js/issues"},"bundleDependencies":false,"contributors":[{"name":"Mike Adair","email":"madair@dmsolutions.ca"},{"name":"Richard Greenwood","email":"rich@greenwoodmap.com"},{"name":"Calvin Metcalf","email":"calvin.metcalf@gmail.com"},{"name":"Richard Marsden","url":"http://www.winwaed.com"},{"name":"T. Mittan"},{"name":"D. Steinwand"},{"name":"S. Nelson"}],"dependencies":{"mgrs":"~0.0.2"},"deprecated":false,"description":"Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.","devDependencies":{"browserify":"~12.0.1","chai":"~1.8.1","curl":"git://github.com/cujojs/curl.git","grunt":"~0.4.2","grunt-browserify":"~4.0.1","grunt-cli":"~0.1.13","grunt-contrib-connect":"~0.6.0","grunt-contrib-jshint":"~0.8.0","grunt-contrib-uglify":"~0.11.1","grunt-mocha-phantomjs":"~0.4.0","istanbul":"~0.2.4","mocha":"~1.17.1","tin":"~0.4.0"},"directories":{"test":"test","doc":"docs"},"homepage":"https://github.com/proj4js/proj4js#readme","jam":{"main":"dist/proj4.js","include":["dist/proj4.js","README.md","AUTHORS","LICENSE.md"]},"license":"MIT","main":"lib/index.js","name":"proj4","repository":{"type":"git","url":"git://github.com/proj4js/proj4js.git"},"scripts":{"test":"./node_modules/istanbul/lib/cli.js test ./node_modules/mocha/bin/_mocha test/test.js"},"version":"2.3.15"}
9461194640

9461294641
/***/ }),
9461394642
/* 502 */

dist/iclient9-leaflet.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/leaflet/WMTSLayer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<script type="text/javascript" src="../../dist/include-leaflet.js"></script>
1111
<script type="text/javascript">
1212
var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
13+
1314
var res = [];
1415
for (var i = 0; i < 22; i++) {
1516
res.push(165664.43905455674 / (Math.pow(2, i)));
@@ -31,9 +32,11 @@
3132
style: "default",
3233
tilematrixSet: "Custom_China",
3334
format: "image/png",
35+
requestEncoding: 'REST',
3436
attribution: "Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"
3537
}
3638
).addTo(map);
39+
3740
</script>
3841
</body>
3942
</html>

src/leaflet/mapping/TileLayer.WMTS.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import "../core/Base";
1919
* crs - {{@link L.Proj.CRS}} 坐标系统类。<br>
2020
* serverType - {{@link SuperMap.ServerType}} 服务来源 iServer|iPortal|online。<br>
2121
* attribution - {string} 版权信息。
22-
* tileProxy - {string} 启用托管地址
22+
* tileProxy - {string} 启用托管地址。
23+
* requestEncoding - {string} KVP或者REST的请求方式,默认是KVP。
2324
*/
2425
export var WMTSLayer = L.TileLayer.extend({
2526

@@ -31,13 +32,34 @@ export var WMTSLayer = L.TileLayer.extend({
3132
tileSize: 256,
3233
matrixIds: null,
3334
layer: '',
35+
requestEncoding: 'KVP',
3436
attribution: "with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"
3537
},
3638

3739
//todo 自动获取Capabilities
3840
initialize: function (url, options) { // (String, Object)
3941
this._url = url;
4042
L.setOptions(this, options);
43+
44+
var opt = this.options;
45+
if (opt.requestEncoding === "REST") {
46+
47+
var formatSuffixMap = {
48+
"image/png": "png",
49+
"image/png8": "png",
50+
"image/png24": "png",
51+
"image/png32": "png",
52+
"png": "png",
53+
"image/jpeg": "jpg",
54+
"image/jpg": "jpg",
55+
"jpeg": "jpg",
56+
"jpg": "jpg"
57+
};
58+
this.formatSuffix = "." + (formatSuffixMap[opt.format] || opt.format.split("/").pop() || "png");
59+
} else {
60+
61+
opt.requestEncoding = "KVP";
62+
}
4163
},
4264

4365
/**
@@ -49,7 +71,9 @@ export var WMTSLayer = L.TileLayer.extend({
4971
getTileUrl: function (coords) { // (Point, Number) -> String
5072
var zoom = this._getZoomForUrl();
5173
var ident = this.options.matrixIds ? this.options.matrixIds[zoom].identifier : zoom;
74+
5275
var url = L.Util.template(this._url, {s: this._getSubdomain(coords)});
76+
5377
var obj = {
5478
service: 'WMTS',
5579
request: 'GetTile',
@@ -66,9 +90,14 @@ export var WMTSLayer = L.TileLayer.extend({
6690
};
6791

6892
if (this.options.tileProxy) {
69-
url = this.options.tileProxy + encodeURIComponent(url + L.Util.getParamString(obj, url));
70-
} else {
93+
url = this.options.tileProxy + url;
94+
}
95+
96+
if (this.options.requestEncoding === 'KVP') {
7197
url += L.Util.getParamString(obj, url);
98+
} else if (this.options.requestEncoding === 'REST') {
99+
var params = "/" + obj.layer + "/" + obj.style + "/" + obj.tilematrixSet + "/" + obj.tilematrix + "/" + obj.tilerow + "/" + obj.tilecol + this.formatSuffix;
100+
url += params;
72101
}
73102
return url;
74103
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require('../../../src/leaflet/mapping/TileLayer.WMTS');
2+
3+
var url = GlobeParameter.WMTSURL;
4+
describe('leaflet_TileLayerWMTS', function () {
5+
var originalTimeout;
6+
var WMTStiledMapLayerObject;
7+
8+
beforeEach(function () {
9+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
10+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
11+
});
12+
afterEach(function () {
13+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
14+
});
15+
16+
it('initialize_badRequestEncoding', function () {
17+
var option = {
18+
layer: "China",
19+
style: "default",
20+
tilematrixSet: "Custom_China",
21+
format: "image/png",
22+
requestEncoding: '',
23+
attribution: "Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"
24+
};
25+
WMTStiledMapLayerObject = L.supermap.wmtsLayer(url, option);
26+
expect(WMTStiledMapLayerObject).not.toBeNull();
27+
expect(WMTStiledMapLayerObject.options.layer).toBe(option.layer);
28+
expect(WMTStiledMapLayerObject.options.style).toBe(option.style);
29+
expect(WMTStiledMapLayerObject.options.tilematrixSet).toBe(option.tilematrixSet);
30+
expect(WMTStiledMapLayerObject.options.format).toBe(option.format);
31+
expect(WMTStiledMapLayerObject.options.requestEncoding).toBe("KVP");
32+
});
33+
34+
it("getTileUrl_KVPRequestEncoding", function () {
35+
var coords = {x: 0, y: 0, z: 0};
36+
var option = {
37+
layer: "China",
38+
style: "default",
39+
tilematrixSet: "Custom_China",
40+
format: "image/png",
41+
requestEncoding: 'KVP'
42+
};
43+
WMTStiledMapLayerObject = L.supermap.wmtsLayer(url, option);
44+
expect(WMTStiledMapLayerObject).not.toBeNull();
45+
expect(WMTStiledMapLayerObject.options.layer).toBe(option.layer);
46+
expect(WMTStiledMapLayerObject.options.style).toBe(option.style);
47+
expect(WMTStiledMapLayerObject.options.tilematrixSet).toBe(option.tilematrixSet);
48+
expect(WMTStiledMapLayerObject.options.format).toBe(option.format);
49+
expect(WMTStiledMapLayerObject.options.requestEncoding).toBe(option.requestEncoding);
50+
expect(WMTStiledMapLayerObject.getTileUrl(coords)).not.toBeNull();
51+
expect(WMTStiledMapLayerObject.getTileUrl(coords)).toBe('http://localhost:8090/iserver/services/map-world/wmts100?service=WMTS&request=GetTile&version=1.0.0&style=default&tilematrixSet=Custom_China&format=image%2Fpng&width=256&height=256&layer=China&tilematrix=NaN&tilerow=0&tilecol=0');
52+
});
53+
54+
it("getTileUrl_RESTRequestEncoding", function () {
55+
var coords = {x: 0, y: 0, z: 0};
56+
var option = {
57+
layer: "China",
58+
style: "default",
59+
tilematrixSet: "Custom_China",
60+
format: "image/png",
61+
requestEncoding: 'REST'
62+
};
63+
WMTStiledMapLayerObject = L.supermap.wmtsLayer(url, option);
64+
expect(WMTStiledMapLayerObject).not.toBeNull();
65+
expect(WMTStiledMapLayerObject.options.layer).toBe(option.layer);
66+
expect(WMTStiledMapLayerObject.options.style).toBe(option.style);
67+
expect(WMTStiledMapLayerObject.options.tilematrixSet).toBe(option.tilematrixSet);
68+
expect(WMTStiledMapLayerObject.options.format).toBe(option.format);
69+
expect(WMTStiledMapLayerObject.options.requestEncoding).toBe(option.requestEncoding);
70+
expect(WMTStiledMapLayerObject.getTileUrl(coords)).not.toBeNull();
71+
expect(WMTStiledMapLayerObject.getTileUrl(coords)).toBe('http://localhost:8090/iserver/services/map-world/wmts100/China/default/Custom_China/NaN/0/0.png');
72+
});
73+
74+
});

0 commit comments

Comments
 (0)