@@ -21,13 +21,18 @@ import { WebMap as WebMapV3 } from './webmap/v3/WebMap';
2121 * </div>
2222 * @modulecategory Mapping
2323 * @param {number } id - iPortal|Online 地图 ID。
24- * @param {Object } options - 参数 。
24+ * @param {Object } options - 基础参数 。
2525 * @param {string } [options.target='map'] - 地图容器 ID。
2626 * @param {string } [options.server="https://www.supermapol.com"] - 地图的地址。
2727 * @param {string } [options.credentialKey] - 凭证密钥。
2828 * @param {string } [options.credentialValue] - 凭证值。
2929 * @param {boolean } [options.withCredentials=false] - 请求是否携带 cookie。
3030 * @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] - 倾角。
3136 * @fires WebMap#getmapfailed
3237 * @fires WebMap#getwmtsfailed
3338 * @fires WebMap#getlayersfailed
@@ -37,16 +42,14 @@ import { WebMap as WebMapV3 } from './webmap/v3/WebMap';
3742 * @usage
3843 */
3944export class WebMap extends mapboxgl . Evented {
40- constructor ( id , options ) {
45+ constructor ( id , options = { } , mapOptions ) {
4146 super ( ) ;
4247 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 ;
5053 this . _createWebMap ( ) ;
5154 this . on ( 'mapinitialized' , ( ) => {
5255 this . map . on ( 'remove' , ( ) => {
@@ -79,7 +82,6 @@ export class WebMap extends mapboxgl.Evented {
7982 */
8083 setWebMapOptions ( webMapOptions ) {
8184 const server = this . _formatServerUrl ( webMapOptions . server ) ;
82- this . server = server ;
8385 this . options . server = server ;
8486 this . _createWebMap ( ) ;
8587 }
@@ -107,7 +109,7 @@ export class WebMap extends mapboxgl.Evented {
107109 * @description 登陆窗口后添加地图图层。
108110 */
109111 _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 ) ) ;
111113 this . _getMapInfo ( mapUrl ) ;
112114 }
113115
@@ -169,7 +171,7 @@ export class WebMap extends mapboxgl.Evented {
169171 * @description 获取地图投影。
170172 */
171173 _getMapProjection ( mapInfo ) {
172- if ( mapInfo . version === '3.0.0' ) {
174+ if ( this . _isWebMapV3 ( mapInfo . version ) ) {
173175 return mapInfo . crs ;
174176 }
175177 return mapInfo . projection ;
@@ -182,8 +184,8 @@ export class WebMap extends mapboxgl.Evented {
182184 * @description 初始化 WebMap 实例
183185 */
184186 _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 ) ;
187189 webMapInstance . setEventedParent ( this ) ;
188190 return webMapInstance ;
189191 }
@@ -208,4 +210,8 @@ export class WebMap extends mapboxgl.Evented {
208210 _getWebMapInstance ( ) {
209211 return this . webMapInstance ;
210212 }
213+
214+ _isWebMapV3 ( version ) {
215+ return version . startsWith ( '3.' ) ;
216+ }
211217 }
0 commit comments