1- import { Zondy } from '../../service/common/Base' ;
2- import { L } from 'leaflet' ;
1+ import { Zondy } from '../../service/common/Base' ;
2+ import { L } from 'leaflet' ;
33
44/**
55 * @author 基础平台/产品2部 龚跃健
@@ -19,6 +19,8 @@ import {L} from 'leaflet';
1919 * @param {String } [option.format = image/png ] 可选。图块输出格式。image/png或image/jpeg
2020 * @param {String } [option.tileSize = 256] 可选。瓦片大小
2121 * @param {String } [option.version = 1.0.0] 可选。WMTS版本
22+ * @param {String } [option.tokenKey = ""] 可选。token的key值(token/tk)
23+ * @param {String } [option.token = ""] 可选。token值
2224 * @example
2325 new Zondy.Map.MapWMTSLayer({
2426 //IGServer所在ip地址
@@ -34,116 +36,123 @@ import {L} from 'leaflet';
3436 })
3537 */
3638var MapWMTSLayer = window . L . TileLayer . extend ( {
37- options : {
38- version : '1.0.0' ,
39- style : '' ,
40- serverName : '' , //服务名
41- tilematrixSet : '' , //矩阵集名称
42- layer : '' , //图层名
43- format : 'image/png' ,
44- tileSize : 256 ,
45- attribution : "Zondy WMTS Data" ,
46- noWrap : true
47- } ,
48- //var layer3 = new ZondyMapWMTSLayer("http://localhost:6163/igs/rest/ogc/WMTSServer", { tilematrixSet: "EPSG:4326_世界地图经纬度LEVEL7_028mm_GB", layer: 'World_level7_WMTS' }).addTo(mymap);
49- //
50- initialize : function ( options ) { // (String, Object)
51- if ( options . url ) {
52- if ( options . url . indexOf ( "?" ) > - 1 ) {
53- this . _url = options . url . split ( "?" ) [ 0 ]
54- } else {
55- this . _url = options . url
56- }
57- } else {
58- var partUrl = '/igs/rest/ogc/WMTSServer'
59- if ( options . serverName && options . serverName !== '' ) {
60- partUrl = '/igs/rest/ogc/' + options . serverName + '/WMTSServer'
61- }
62- var domain = options && options . domain ? options . domain : '' ;
63- if ( domain === '' ) {
64- this . networkProtocol = options . networkProtocol !== undefined ? options . networkProtocol : location . protocol . split ( ":" ) [ 0 ] || "http" ;
65- var ip = options && options . ip ? options . ip : 'localhost' ;
66- var port = options && options . port ? options . port : '6163' ;
67- this . _url = encodeURI ( this . networkProtocol + '://' + ip + ':' + port + partUrl ) ;
68- } else {
69- this . _url = encodeURI ( domain + partUrl ) ;
70- }
71- }
72- if ( this . _url . toLowerCase ( ) . indexOf ( "ime-cloud" ) > - 1 ) { //吉威的数据
73- this . _url += '?service=WMTS&REQUEST=GetTile'
74- } else {
75- this . _url += '?service=WMTS&request=GetTile'
76- }
77- this . options . origin = options . origin ? options . origin : null ;
78- window . L . setOptions ( this , options ) ;
79- } ,
80- onAdd : function ( map ) {
81- this . _crs = this . options . crs || map . options . crs ;
82- let bounds = this . _crs . projection . bounds ;
83- let northWest = [ bounds . min . x , bounds . max . y ]
84- this . _origin = this . options . origin ? this . options . origin : northWest
85- window . L . TileLayer . prototype . onAdd . call ( this , map ) ;
86- } ,
87- /**
88- * @private
89- * @function Zondy.Map.MapWMTSLayer.prototype.getTileUrl
90- * @description 根据行列号获取瓦片地址。考虑发布的wmts的瓦片不按左上角为原点的情况,需另外处理
91- * @param coords - {Object} 行列号
92- * @return {string } 瓦片地址
93- */
94- getTileUrl : function ( coords ) { // (Point, Number) -> String
95- // var tileBounds = this._tileCoordsToBounds(coords);
96- // var ne = this._crs.project(tileBounds.getNorthEast());
97- // var sw = this._crs.project(tileBounds.getSouthWest());
98- // var tileSize = this.options.tileSize;
99- // var resolution = Math.max(Math.abs(ne.x - sw.x) / tileSize, Math.abs(ne.y - sw.y) / tileSize);
100- //
101- // var centerPnt = [(ne.x + sw.x) / 2, (ne.y + sw.y) / 2];
102- // var dx = centerPnt[0] - (this._origin)[0];
103- // var dy = centerPnt[1] - (this._origin)[1];
104- //
105- // var xGrid = -1e8;
106- // var yGrid = -1e8;
107- //
108- // xGrid = Math.floor(dx / (tileSize * resolution));
109- // if (this.options.yAxis === 'down') {
110- // yGrid = Math.floor(-dy / (tileSize * resolution));
111- // } else {
112- // yGrid = Math.floor(dy / (tileSize * resolution));
113- // }
39+ options : {
40+ version : '1.0.0' ,
41+ style : '' ,
42+ serverName : '' , //服务名
43+ tilematrixSet : '' , //矩阵集名称
44+ layer : '' , //图层名
45+ format : 'image/png' ,
46+ tileSize : 256 ,
47+ attribution : 'Zondy WMTS Data' ,
48+ noWrap : true
49+ } ,
50+ //var layer3 = new ZondyMapWMTSLayer("http://localhost:6163/igs/rest/ogc/WMTSServer", { tilematrixSet: "EPSG:4326_世界地图经纬度LEVEL7_028mm_GB", layer: 'World_level7_WMTS' }).addTo(mymap);
51+ //
52+ initialize : function ( options ) {
53+ // (String, Object)
54+ if ( options . url ) {
55+ if ( options . url . indexOf ( '?' ) > - 1 ) {
56+ this . _url = options . url . split ( '?' ) [ 0 ] ;
57+ } else {
58+ this . _url = options . url ;
59+ }
60+ } else {
61+ var partUrl = '/igs/rest/ogc/WMTSServer' ;
62+ if ( options . serverName && options . serverName !== '' ) {
63+ partUrl = '/igs/rest/ogc/' + options . serverName + '/WMTSServer' ;
64+ }
65+ var domain = options && options . domain ? options . domain : '' ;
66+ if ( domain === '' ) {
67+ this . networkProtocol = options . networkProtocol !== undefined ? options . networkProtocol : location . protocol . split ( ':' ) [ 0 ] || 'http' ;
68+ var ip = options && options . ip ? options . ip : 'localhost' ;
69+ var port = options && options . port ? options . port : '6163' ;
70+ this . _url = encodeURI ( this . networkProtocol + '://' + ip + ':' + port + partUrl ) ;
71+ } else {
72+ this . _url = encodeURI ( domain + partUrl ) ;
73+ }
74+ }
75+ if ( this . _url . toLowerCase ( ) . indexOf ( 'ime-cloud' ) > - 1 ) {
76+ //吉威的数据
77+ this . _url += '?service=WMTS&REQUEST=GetTile' ;
78+ } else {
79+ this . _url += '?service=WMTS&request=GetTile' ;
80+ }
81+ this . options . origin = options . origin ? options . origin : null ;
82+ window . L . setOptions ( this , options ) ;
83+ } ,
84+ onAdd : function ( map ) {
85+ this . _crs = this . options . crs || map . options . crs ;
86+ let bounds = this . _crs . projection . bounds ;
87+ let northWest = [ bounds . min . x , bounds . max . y ] ;
88+ this . _origin = this . options . origin ? this . options . origin : northWest ;
89+ window . L . TileLayer . prototype . onAdd . call ( this , map ) ;
90+ } ,
91+ /**
92+ * @private
93+ * @function Zondy.Map.MapWMTSLayer.prototype.getTileUrl
94+ * @description 根据行列号获取瓦片地址。考虑发布的wmts的瓦片不按左上角为原点的情况,需另外处理
95+ * @param coords - {Object} 行列号
96+ * @return {string } 瓦片地址
97+ */
98+ getTileUrl : function ( coords ) {
99+ // (Point, Number) -> String
100+ // var tileBounds = this._tileCoordsToBounds(coords);
101+ // var ne = this._crs.project(tileBounds.getNorthEast());
102+ // var sw = this._crs.project(tileBounds.getSouthWest());
103+ // var tileSize = this.options.tileSize;
104+ // var resolution = Math.max(Math.abs(ne.x - sw.x) / tileSize, Math.abs(ne.y - sw.y) / tileSize);
105+ //
106+ // var centerPnt = [(ne.x + sw.x) / 2, (ne.y + sw.y) / 2];
107+ // var dx = centerPnt[0] - (this._origin)[0];
108+ // var dy = centerPnt[1] - (this._origin)[1];
109+ //
110+ // var xGrid = -1e8;
111+ // var yGrid = -1e8;
112+ //
113+ // xGrid = Math.floor(dx / (tileSize * resolution));
114+ // if (this.options.yAxis === 'down') {
115+ // yGrid = Math.floor(-dy / (tileSize * resolution));
116+ // } else {
117+ // yGrid = Math.floor(dy / (tileSize * resolution));
118+ // }
114119
115- var zoom = this . _getZoomForUrl ( ) ;
116- var url = window . L . Util . template ( this . _url , { s : this . _getSubdomain ( coords ) } ) ;
120+ var zoom = this . _getZoomForUrl ( ) ;
121+ var url = window . L . Util . template ( this . _url , { s : this . _getSubdomain ( coords ) } ) ;
117122
118- var obj = {
119- version : this . options . version ,
120- style : this . options . style ,
121- tilematrixSet : this . options . tilematrixSet ,
122- format : this . options . format ,
123- layer : this . options . layer ,
124- tilematrix : zoom ,
125- tilerow : coords . y ,
126- tilecol : coords . x
127- } ;
123+ var obj = {
124+ version : this . options . version ,
125+ style : this . options . style ,
126+ tilematrixSet : this . options . tilematrixSet ,
127+ format : this . options . format ,
128+ layer : this . options . layer ,
129+ tilematrix : zoom ,
130+ tilerow : coords . y ,
131+ tilecol : coords . x
132+ } ;
128133
129- //根据地图的不同,拼装不同的url参数
130- if ( url . indexOf ( 'tianditu' ) > - 1 ) {
131- obj . tilematrixSet = 'c' ;
132- } else if ( url . indexOf ( 'geoserver' ) > - 1 ) {
133- obj . tilematrix = this . options . tilematrixSet + ':' + zoom ;
134- }
134+ //根据地图的不同,拼装不同的url参数
135+ if ( url . indexOf ( 'tianditu' ) > - 1 ) {
136+ obj . tilematrixSet = 'c' ;
137+ } else if ( url . indexOf ( 'geoserver' ) > - 1 ) {
138+ obj . tilematrix = this . options . tilematrixSet + ':' + zoom ;
139+ }
135140
136- if ( this . options . token ) {
137- if ( url . indexOf ( 'tianditu' ) > - 1 ) {
138- obj . tk = this . options . token
139- } else {
140- obj . token = this . options . token
141- }
142- }
141+ if ( this . options . token ) {
142+ if ( this . options . tokenKey ) {
143+ obj [ this . options . tokenKey ] = this . options . token ;
144+ } else {
145+ if ( url . indexOf ( 'tianditu' ) > - 1 ) {
146+ obj . tk = this . options . token ;
147+ } else {
148+ obj . token = this . options . token ;
149+ }
150+ }
151+ }
143152
144- return url + window . L . Util . getParamString ( obj , url ) ;
145- }
153+ return url + window . L . Util . getParamString ( obj , url ) ;
154+ }
146155} ) ;
147156
148- export { MapWMTSLayer } ;
157+ export { MapWMTSLayer } ;
149158Zondy . Map . MapWMTSLayer = MapWMTSLayer ;
0 commit comments