1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- L.TileLayer.WMTS = L.TileLayer.extend({
- defaultWmtsParams: {
- service: 'WMTS',
- request: 'GetTile',
- version: '1.0.0',
- layers: '',
- styles: '',
- tilematrixSet: '',
- format: 'image/jpeg'
- },
- initialize: function (url, options) { // (String, Object)
- this._url = url;
- var wmtsParams = L.extend({}, this.defaultWmtsParams);
- var tileSize = options.tileSize || this.options.tileSize;
- if (options.detectRetina && L.Browser.retina) {
- wmtsParams.width = wmtsParams.height = tileSize * 2;
- } else {
- wmtsParams.width = wmtsParams.height = tileSize;
- }
- for (var i in options) {
- // all keys that are not TileLayer options go to WMTS params
- if (!this.options.hasOwnProperty(i) && i!="matrixIds" && i!= "jsonUrl") {
- wmtsParams[i] = options[i];
- }
- }
- this.wmtsParams = wmtsParams;
- this.matrixIds = options.matrixIds||this.getDefaultMatrix();
- L.setOptions(this, options);
- },
- onAdd: function (map) {
- this._crs = this.options.crs || map.options.crs;
- L.TileLayer.prototype.onAdd.call(this, map);
- },
- getParamString: function (obj, existingUrl, uppercase) {
- var params = [];
- for (var i in obj) {
- if (i == 'secret')
- continue;
- params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]));
- }
- return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
- },
- getTileUrl: function (coords) { // (Point, Number) -> String
- var url = L.Util.template(this._url, {s: this._getSubdomain(coords)});
- //argis版本的要-1
- url += this.getParamString(this.wmtsParams, url) + "&tilematrix=" + (coords.z) + "&tilerow=" + coords.y +"&tilecol=" + coords.x;
- if (this.wmtsParams.hnjhpt_rid) {
- var date = new Date();
- var time = date.getTime();
- var message = this.wmtsParams.hnjhpt_sid + this.wmtsParams.hnjhpt_rid + time;
- var hash = CryptoJS.HmacSHA256(message, this.wmtsParams.secret);
- var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
- url += "&hnjhpt_sign=" + encodeURIComponent(hashInBase64) + "&hnjhpt_rtime=" + time
- }
- return url;
- },
- setParams: function (params, noRedraw) {
- L.extend(this.wmtsParams, params);
- if (!noRedraw) {
- this.redraw();
- }
- return this;
- },
- getDefaultMatrix : function () {
- /**
- * the matrix3857 represents the projection
- * for in the IGN WMTS for the google coordinates.
- */
- var matrixIds3857 = new Array(22);
- for (var i= 0; i<22; i++) {
- matrixIds3857[i]= {
- identifier : "" + i,
- topLeftCorner : new L.LatLng(20037508.3428,-20037508.3428)
- };
- }
- return matrixIds3857;
- }
- });
- L.tileLayer.wmts = function (url, options) {
- return new L.TileLayer.WMTS(url, options);
- };
|