├── README.md └── tileLayer.wmts.js /README.md: -------------------------------------------------------------------------------- 1 | # leaflet加载wmts图层 2 | 3 | [在线Demo](http://mars2d.cn/example/13_layer_wmts.html) 4 | 5 | 6 | ```javascript 7 | 8 | L.tileLayer.wmts("http://www.ais.msa.gov.cn/MapService",{ 9 | "layer": "default", 10 | "style": "default", 11 | "format": "image/png", 12 | "tilematrixSet": "advsea" //高级海图 advsea ,基础海陆混合 basicsearoad ,高级海陆混合 advsearoad 13 | }).addTo(map); 14 | 15 | 16 | ``` 17 | 18 | 19 | 20 | 21 | ## 其他 22 | 更多Leaflet示例请点击: [http://mars2d.cn](http://mars2d.cn) 23 | -------------------------------------------------------------------------------- /tileLayer.wmts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WMTS服务调用插件 3 | * @author 木遥原创(qq:346819890) 4 | */ 5 | L.TileLayer.WMTS = L.TileLayer.extend({ 6 | options: { 7 | version: '1.0.0', 8 | style: 'default', 9 | tilematrixSet: '', 10 | format: 'image/png', 11 | tileSize: 256, 12 | layer: '', 13 | }, 14 | //todo 自动获取Capabilities 15 | initialize: function (url, options) { // (String, Object) 16 | this._url = url; 17 | L.setOptions(this, options); 18 | }, 19 | getParamString: function (obj, existingUrl, uppercase) { 20 | var params = []; 21 | for (var i in obj) { 22 | params.push((uppercase ? i.toUpperCase() : i) + '=' + (obj[i])); 23 | } 24 | return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&'); 25 | }, 26 | getTileUrl: function (coords) { // (Point, Number) -> String 27 | var zoom = this._getZoomForUrl(); 28 | if (this.options.zOffset) 29 | zoom = zoom + this.options.zOffset; 30 | 31 | var ident; 32 | if (this.options.matrixIds) 33 | ident = this.options.matrixIds[zoom]; 34 | else if (this.options.tilematrixBefore) 35 | ident = this.options.tilematrixBefore + zoom; 36 | else 37 | ident = zoom; 38 | 39 | var url = L.Util.template(this._url, { s: this._getSubdomain(coords) }); 40 | var obj = { 41 | service: 'WMTS', 42 | request: 'GetTile', 43 | version: this.options.version, 44 | style: this.options.style, 45 | tilematrixSet: this.options.tilematrixSet, 46 | format: this.options.format, 47 | width: this.options.tileSize, 48 | height: this.options.tileSize, 49 | layer: this.options.layer, 50 | tilematrix: ident, 51 | tilerow: coords.y, 52 | tilecol: coords.x 53 | }; 54 | return url + this.getParamString(obj, url); 55 | } 56 | }); 57 | 58 | L.tileLayer.wmts = function (url, options) { 59 | return new L.TileLayer.WMTS(url, options); 60 | }; 61 | 62 | --------------------------------------------------------------------------------