Skip to content

Commit fe819a8

Browse files
committed
fix 修改webmap3.0多投影代码位置,处理传入map的情况 review by xiongjj
1 parent 401df20 commit fe819a8

File tree

3 files changed

+99
-14
lines changed

3 files changed

+99
-14
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export class WebMap extends mapboxgl.Evented {
112112
initializeMap(mapInfo, map) {
113113
mapInfo = this._handleUnSupportedLayers(mapInfo);
114114
this._mapInfo = mapInfo;
115+
const proj = this._setBaseProjection();
116+
if(!proj) {
117+
return;
118+
}
115119
if (map) {
116120
this._appendLayers = true;
117121
this.map = map;
@@ -145,7 +149,6 @@ export class WebMap extends mapboxgl.Evented {
145149
_createMap() {
146150
let {
147151
name = '',
148-
crs,
149152
center = new mapboxgl.LngLat(0, 0),
150153
zoom = 0,
151154
bearing = 0,
@@ -154,18 +157,6 @@ export class WebMap extends mapboxgl.Evented {
154157
maxzoom,
155158
sprite = ''
156159
} = this._mapInfo;
157-
let baseProjection = crs;
158-
if (typeof crs === 'object') {
159-
baseProjection = crs.name;
160-
if (!mapboxgl.CRS) {
161-
const error = `The EPSG code ${baseProjection} needs to include mapbox-gl-enhance.js. Refer to the example: https://iclient.supermap.io/examples/mapboxgl/editor.html#mvtVectorTile_2362`;
162-
this.fire('getmapinfofailed', { error: error });
163-
console.error(error);
164-
return;
165-
}
166-
this._setCRS(crs);
167-
}
168-
this._baseProjection = baseProjection;
169160
center = this.mapOptions.center || center;
170161
zoom = this.mapOptions.zoom || zoom;
171162
bearing = this.mapOptions.bearing || bearing;
@@ -199,6 +190,23 @@ export class WebMap extends mapboxgl.Evented {
199190
});
200191
}
201192

193+
_setBaseProjection() {
194+
let crs = this._mapInfo.crs;
195+
let baseProjection = crs;
196+
if (typeof crs === 'object') {
197+
baseProjection = crs.name;
198+
if (!mapboxgl.CRS) {
199+
const error = `The EPSG code ${baseProjection} needs to include mapbox-gl-enhance.js. Refer to the example: https://iclient.supermap.io/examples/mapboxgl/editor.html#mvtVectorTile_2362`;
200+
this.fire('getmapinfofailed', { error: error });
201+
console.error(error);
202+
return;
203+
}
204+
this._setCRS(crs);
205+
}
206+
this._baseProjection = baseProjection;
207+
return this._baseProjection;
208+
}
209+
202210
_setCRS({ name, wkt, extent }) {
203211
const crs = new mapboxgl.CRS(name, wkt, extent, extent[2] > 180 ? 'meter' : 'degree');
204212
mapboxgl.CRS.set(crs);

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '../../resources/WebMapV3.js';
55
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
66
import * as L7 from '../../../src/mapboxgl/overlay/L7/l7-render';
77
import * as mockL7 from '../../tool/mock_l7';
8+
import mbglmap from '../../tool/mock_mapboxgl_map';
89

910
describe('mapboxgl-webmap3.0', () => {
1011
var originalTimeout, testDiv;
@@ -229,6 +230,82 @@ describe('mapboxgl-webmap3.0', () => {
229230
});
230231
});
231232

233+
it('projection is 4490 and with map', (done) => {
234+
spyOn(FetchRequest, 'get').and.callFake((url) => {
235+
if (url.indexOf('/sprite') > -1) {
236+
return Promise.resolve(new Response(msSpriteInfo));
237+
}
238+
return Promise.resolve();
239+
});
240+
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
241+
var testDiv = window.document.createElement("div");
242+
testDiv.setAttribute("id", "map");
243+
testDiv.style.styleFloat = "left";
244+
testDiv.style.marginLeft = "8px";
245+
testDiv.style.marginTop = "50px";
246+
testDiv.style.width = "1000px";
247+
testDiv.style.height = "500px";
248+
window.document.body.appendChild(testDiv);
249+
const mapInfo = JSON.parse(mapstudioWebMap_symbol);
250+
const nextMapInfo = {
251+
...mapInfo,
252+
crs: {
253+
name: 'EPSG:4490',
254+
extent: [-180, -270, 180, 90],
255+
wkt: 'GEOGCS["China Geodetic Coordinate System 2000", DATUM["China 2000", SPHEROID["CGCS2000", 6378137.0, 298.257222101, AUTHORITY["EPSG","1024"]], AUTHORITY["EPSG","1043"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4490"]]'
256+
}
257+
};
258+
mapboxgl.CRS = function (epsgCode, wkt, bounds, unit) {
259+
expect(epsgCode).toBe(nextMapInfo.crs.name);
260+
expect(wkt).toBe(nextMapInfo.crs.wkt);
261+
expect(bounds).toEqual(nextMapInfo.crs.extent);
262+
expect(unit).toBe(nextMapInfo.crs.extent[2] > 180 ? 'meter' : 'degree');
263+
};
264+
mapboxgl.CRS.set = function () {};
265+
mapstudioWebmap = new WebMapV3(nextMapInfo, {
266+
server: server,
267+
target: 'map'
268+
});
269+
const map = new mapboxgl.Map({
270+
container: testDiv,
271+
style: {
272+
"version": 8,
273+
"sources": {
274+
"raster-tiles": {
275+
"type": "raster",
276+
"tiles": [],
277+
"tileSize": 256
278+
}
279+
},
280+
"layers": [{
281+
"id": "simple-tiles",
282+
"type": "raster",
283+
"source": "raster-tiles",
284+
"minzoom": 0,
285+
"maxzoom": 22
286+
}]
287+
},
288+
crs: 'EPSG:4490',
289+
center: [116.640545, 40.531714],
290+
zoom: 7
291+
});
292+
map.getCRS = function () { return {epsgCode:'EPSG:4490'}};
293+
map.on('load', function () {
294+
mapstudioWebmap.initializeMap(nextMapInfo, map);
295+
});
296+
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
297+
expect(mapstudioWebmap._appendLayers).toBe(true);
298+
expect(map).not.toBeUndefined();
299+
expect(mapstudioWebmap.map).toEqual(map);
300+
const style = map.getStyle();
301+
expect(style.layers.length).toBe(nextMapInfo.layers.length + 1);
302+
const appreciableLayers = mapstudioWebmap.getAppreciableLayers();
303+
expect(appreciableLayers.length).toBeGreaterThanOrEqual(nextMapInfo.layers.length);
304+
delete mapboxgl.CRS;
305+
done();
306+
});
307+
});
308+
232309
it('overlayLayersManager', (done) => {
233310
spyOn(FetchRequest, 'get').and.callFake((url) => {
234311
if (url.indexOf('/sprite') > -1) {

test/tool/mock_mapboxgl_map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const Map = function (options) {
130130

131131
this.getSource = function (name) {
132132
this._sources[name];
133-
if (this._sources[name].type === 'video') {
133+
if (this._sources[name]?.type === 'video') {
134134
return {
135135
play: function () {}
136136
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy