@@ -21,13 +21,18 @@ import { WebMap as WebMapV3 } from './webmap/v3/WebMap';
21
21
* </div>
22
22
* @modulecategory Mapping
23
23
* @param {number } id - iPortal|Online 地图 ID。
24
- * @param {Object } options - 参数 。
24
+ * @param {Object } options - 基础参数 。
25
25
* @param {string } [options.target='map'] - 地图容器 ID。
26
26
* @param {string } [options.server="https://www.supermapol.com"] - 地图的地址。
27
27
* @param {string } [options.credentialKey] - 凭证密钥。
28
28
* @param {string } [options.credentialValue] - 凭证值。
29
29
* @param {boolean } [options.withCredentials=false] - 请求是否携带 cookie。
30
30
* @param {boolean } [options.excludePortalProxyUrl] - 服务端传递过来的 URL 是否带有代理。
31
+ * @param {Object } mapOptions - 地图参数。
32
+ * @param {string } [mapOptions.center] - 中心点。
33
+ * @param {string } [mapOptions.zoom] - 缩放级别。
34
+ * @param {string } [mapOptions.bearing] - 旋转角度。
35
+ * @param {string } [mapOptions.pitch] - 倾角。
31
36
* @fires WebMap#getmapfailed
32
37
* @fires WebMap#getwmtsfailed
33
38
* @fires WebMap#getlayersfailed
@@ -37,16 +42,14 @@ import { WebMap as WebMapV3 } from './webmap/v3/WebMap';
37
42
* @usage
38
43
*/
39
44
export class WebMap extends mapboxgl . Evented {
40
- constructor ( id , options ) {
45
+ constructor ( id , options = { } , mapOptions ) {
41
46
super ( ) ;
42
47
this . mapId = id ;
43
- options = options || { } ;
44
- this . server = options . server ;
45
- this . credentialKey = options . credentialKey ;
46
- this . credentialValue = options . credentialValue ;
47
- this . withCredentials = options . withCredentials || false ;
48
- this . target = options . target || 'map' ;
49
- this . _canvgsV = [ ] ;
48
+ this . options = Object . assign ( { } , options ) ;
49
+ this . options . server = this . _formatServerUrl ( options . server ) ;
50
+ this . options . target = options . target || 'map' ;
51
+ this . options . withCredentials = options . withCredentials || false ;
52
+ this . mapOptions = mapOptions ;
50
53
this . _createWebMap ( ) ;
51
54
this . on ( 'mapinitialized' , ( ) => {
52
55
this . map . on ( 'remove' , ( ) => {
@@ -79,7 +82,6 @@ export class WebMap extends mapboxgl.Evented {
79
82
*/
80
83
setWebMapOptions ( webMapOptions ) {
81
84
const server = this . _formatServerUrl ( webMapOptions . server ) ;
82
- this . server = server ;
83
85
this . options . server = server ;
84
86
this . _createWebMap ( ) ;
85
87
}
@@ -107,7 +109,7 @@ export class WebMap extends mapboxgl.Evented {
107
109
* @description 登陆窗口后添加地图图层。
108
110
*/
109
111
_createWebMap ( ) {
110
- const mapUrl = Util . transformUrl ( Object . assign ( { url : `${ this . server } web/maps/${ this . mapId } /map` } , this . options ) ) ;
112
+ const mapUrl = Util . transformUrl ( Object . assign ( { url : `${ this . options . server } web/maps/${ this . mapId } /map` } , this . options ) ) ;
111
113
this . _getMapInfo ( mapUrl ) ;
112
114
}
113
115
@@ -169,7 +171,7 @@ export class WebMap extends mapboxgl.Evented {
169
171
* @description 获取地图投影。
170
172
*/
171
173
_getMapProjection ( mapInfo ) {
172
- if ( mapInfo . version === '3.0.0' ) {
174
+ if ( this . _isWebMapV3 ( mapInfo . version ) ) {
173
175
return mapInfo . crs ;
174
176
}
175
177
return mapInfo . projection ;
@@ -182,8 +184,8 @@ export class WebMap extends mapboxgl.Evented {
182
184
* @description 初始化 WebMap 实例
183
185
*/
184
186
_initMap ( mapInfo ) {
185
- const WebMapFactory = mapInfo . version === '3.0.0' ? WebMapV3 : WebMapV2 ;
186
- const webMapInstance = new WebMapFactory ( this . mapId , this . options ) ;
187
+ const WebMapFactory = this . _isWebMapV3 ( mapInfo . version ) ? WebMapV3 : WebMapV2 ;
188
+ const webMapInstance = new WebMapFactory ( this . mapId , this . options , this . mapOptions ) ;
187
189
webMapInstance . setEventedParent ( this ) ;
188
190
return webMapInstance ;
189
191
}
@@ -208,4 +210,8 @@ export class WebMap extends mapboxgl.Evented {
208
210
_getWebMapInstance ( ) {
209
211
return this . webMapInstance ;
210
212
}
213
+
214
+ _isWebMapV3 ( version ) {
215
+ return version . startsWith ( '3.' ) ;
216
+ }
211
217
}
0 commit comments