From 1820aef3fb5c926664de1d4d484f64a5c9ba7099 Mon Sep 17 00:00:00 2001
From: YANGDL <114714267@qq.com>
Date: 星期二, 05 一月 2021 17:06:08 +0800
Subject: [PATCH] 优化逻辑
---
src/components/plugin/wmts_plugins.js | 172 ++++++++++++++++++++++++++++----------------------------
1 files changed, 86 insertions(+), 86 deletions(-)
diff --git a/src/components/plugin/wmts_plugins.js b/src/components/plugin/wmts_plugins.js
index 7c6e370..55fe18a 100644
--- a/src/components/plugin/wmts_plugins.js
+++ b/src/components/plugin/wmts_plugins.js
@@ -1,96 +1,96 @@
/* eslint-disable no-prototype-builtins */
'use strict'
const init = (L) => {
- L.TileLayer.WMTS = L.TileLayer.extend({
- defaultWmtsParams: {
- service: 'WMTS',
- request: 'GetTile',
- version: '1.0.0',
- layer: '',
- style: '',
- tilematrixset: '',
- format: 'image/jpeg'
- },
-
- initialize: function (url, options) { // (String, Object)
- this._url = url;
- var lOptions= {};
- var cOptions = Object.keys(options);
- cOptions.forEach(element=>{
- lOptions[element.toLowerCase()]=options[element];
- });
- var wmtsParams = L.extend({}, this.defaultWmtsParams);
- var tileSize = lOptions.tileSize || this.options.tileSize;
- if (lOptions.detectRetina && L.Browser.retina) {
- wmtsParams.width = wmtsParams.height = tileSize * 2;
- } else {
- wmtsParams.width = wmtsParams.height = tileSize;
- }
- for (var i in lOptions) {
- // all keys that are in defaultWmtsParams options go to WMTS params
- if (wmtsParams.hasOwnProperty(i) && i!="matrixIds") {
- wmtsParams[i] = lOptions[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);
- },
-
- getTileUrl: function (coords) { // (Point, Number) -> String
- var tileSize = this.options.tileSize;
- var nwPoint = coords.multiplyBy(tileSize);
- nwPoint.x+=1;
- nwPoint.y-=1;
- var sePoint = nwPoint.add(new L.Point(tileSize, tileSize));
- var zoom = this._tileZoom;
- var nw = this._crs.project(this._map.unproject(nwPoint, zoom));
- var se = this._crs.project(this._map.unproject(sePoint, zoom));
- var tilewidth = se.x-nw.x;
- var ident = this.matrixIds[zoom].identifier;
- var tilematrix = this.wmtsParams.tilematrixset + ":" + ident;
- var X0 = this.matrixIds[zoom].topLeftCorner.lng;
- var Y0 = this.matrixIds[zoom].topLeftCorner.lat;
- var tilecol=Math.floor((nw.x-X0)/tilewidth);
- var tilerow=-Math.floor((nw.y-Y0)/tilewidth);
- var url = L.Util.template(this._url, {s: this._getSubdomain(coords)});
- return url + L.Util.getParamString(this.wmtsParams, url) + "&tilematrix=" + tilematrix + "&tilerow=" + tilerow +"&tilecol=" + tilecol;
- },
-
- setParams: function (params, noRedraw) {
- L.extend(this.wmtsParams, params);
- if (!noRedraw) {
- this.redraw();
- }
- return this;
- },
-
- getDefaultMatrix : function () {
- /**
- * the matrix3857 represents the projection
+ L.TileLayer.WMTS = L.TileLayer.extend({
+ defaultWmtsParams: {
+ service: 'WMTS',
+ request: 'GetTile',
+ version: '1.0.0',
+ layer: '',
+ style: '',
+ tilematrixset: '',
+ format: 'image/jpeg'
+ },
+
+ initialize: function (url, options) { // (String, Object)
+ this._url = url
+ var lOptions = {}
+ var cOptions = Object.keys(options)
+ cOptions.forEach(element => {
+ lOptions[element.toLowerCase()] = options[element]
+ })
+ var wmtsParams = L.extend({}, this.defaultWmtsParams)
+ var tileSize = lOptions.tileSize || this.options.tileSize
+ if (lOptions.detectRetina && L.Browser.retina) {
+ wmtsParams.width = wmtsParams.height = tileSize * 2
+ } else {
+ wmtsParams.width = wmtsParams.height = tileSize
+ }
+ for (var i in lOptions) {
+ // all keys that are in defaultWmtsParams options go to WMTS params
+ if (wmtsParams.hasOwnProperty(i) && i != 'matrixIds') {
+ wmtsParams[i] = lOptions[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)
+ },
+
+ getTileUrl: function (coords) { // (Point, Number) -> String
+ var tileSize = this.options.tileSize
+ var nwPoint = coords.multiplyBy(tileSize)
+ nwPoint.x += 1
+ nwPoint.y -= 1
+ var sePoint = nwPoint.add(new L.Point(tileSize, tileSize))
+ var zoom = this._tileZoom
+ var nw = this._crs.project(this._map.unproject(nwPoint, zoom))
+ var se = this._crs.project(this._map.unproject(sePoint, zoom))
+ var tilewidth = se.x - nw.x
+ var ident = this.matrixIds[zoom].identifier
+ var tilematrix = this.wmtsParams.tilematrixset + ':' + ident
+ var X0 = this.matrixIds[zoom].topLeftCorner.lng
+ var Y0 = this.matrixIds[zoom].topLeftCorner.lat
+ var tilecol = Math.floor((nw.x - X0) / tilewidth)
+ var tilerow = -Math.floor((nw.y - Y0) / tilewidth)
+ var url = L.Util.template(this._url, { s: this._getSubdomain(coords) })
+ return url + L.Util.getParamString(this.wmtsParams, url) + '&tilematrix=' + tilematrix + '&tilerow=' + tilerow + '&tilecol=' + tilecol
+ },
+
+ 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;
+ var matrixIds3857 = new Array(22)
+ for (var i = 0; i < 22; i++) {
+ matrixIds3857[i] = {
+ identifier: '' + i,
+ topLeftCorner: new L.LatLng(20037508.3428, -20037508.3428)
}
- });
-
- L.tileLayer.wmts = function (url, options) {
- return new L.TileLayer.WMTS(url, options);
- };
+ }
+ return matrixIds3857
+ }
+ })
+
+ L.tileLayer.wmts = function (url, options) {
+ return new L.TileLayer.WMTS(url, options)
+ }
}
export default {
- init
+ init
}
--
Gitblit v1.8.0