Skip to content

Commit ffd6c9f

Browse files
committed
【feature】对接webmap3.0图例
1 parent 47d149a commit ffd6c9f

File tree

4 files changed

+616
-181
lines changed

4 files changed

+616
-181
lines changed

src/mapboxgl/mapping/WebMap.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
3944
export 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
}

src/mapboxgl/mapping/webmap/v2/WebMap.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ const MB_SCALEDENOMINATOR_4326 = [
6363
const DEFAULT_WELLKNOWNSCALESET = ['GoogleCRS84Quad', 'GoogleMapsCompatible'];
6464

6565
export class WebMap extends mapboxgl.Evented {
66-
constructor(mapId, options) {
66+
constructor(mapId, options, mapOptions = {}) {
6767
super();
6868
this.mapId = mapId;
6969
this.server = options.server;
7070
this.withCredentials = options.withCredentials;
7171
this.target = options.target;
72+
this.mapOptions = mapOptions;
7273
this._canvgsV = [];
7374
}
7475

@@ -115,7 +116,7 @@ export class WebMap extends mapboxgl.Evented {
115116
layer.labelStyle && fonts.push(layer.labelStyle.fontFamily);
116117
}, this);
117118
}
118-
fonts.push("'supermapol-icons'");
119+
fonts.push("supermapol-icons");
119120
let fontFamilys = fonts.join(',');
120121

121122
// zoom center
@@ -136,12 +137,14 @@ export class WebMap extends mapboxgl.Evented {
136137
zoomBase = +Math.log(e) / Math.LN2.toFixed(2);
137138
}
138139
zoom += zoomBase;
139-
center = oldcenter ? Util._unproject([oldcenter.x, oldcenter.y]) : new mapboxgl.LngLat(0, 0);
140+
center = oldcenter ? Util.unproject([oldcenter.x, oldcenter.y]) : new mapboxgl.LngLat(0, 0);
140141
// 初始化 map
141142
this.map = new mapboxgl.Map({
142143
container: this.target,
143-
center: center,
144-
zoom: zoom,
144+
center: this.mapOptions.center || center,
145+
zoom: this.mapOptions.zoom || zoom,
146+
bearing: this.mapOptions.bearing || 0,
147+
pitch: this.mapOptions.pitch || 0,
145148
style: {
146149
version: 8,
147150
sources: {},
@@ -820,7 +823,7 @@ export class WebMap extends mapboxgl.Evented {
820823
'text-offset': labelStyle.offsetX
821824
? [labelStyle.offsetX / 10 || 0, labelStyle.offsetY / 10 || 0]
822825
: [0, -1.5],
823-
'text-font': ['DIN Offc Pro Italic', 'Arial Unicode MS Regular'],
826+
'text-font': labelStyle.fontFamily ? [labelStyle.fontFamily] : [],
824827
visibility: layerInfo.visible
825828
}
826829
});
@@ -858,7 +861,7 @@ export class WebMap extends mapboxgl.Evented {
858861
},
859862
layout: {
860863
'text-field': text,
861-
'text-font': ['DIN Offc Pro Italic', 'Arial Unicode MS Regular'],
864+
'text-font': ['supermapol-icons'],
862865
visibility: layerInfo.visible
863866
}
864867
});

0 commit comments

Comments
 (0)