Skip to content

Commit

Permalink
fix 修复webmapv3 传入地图实例的情况下没处理 sprite review by xiongjj
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Jul 17, 2024
1 parent 9e82d33 commit 66cbdfc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/mapboxgl/mapping/webmap/v3/WebMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ export class WebMap extends mapboxgl.Evented {
if (map) {
this._appendLayers = true;
this.map = map;
// 处理图层管理添加 sprite
const { sources, sprite } = this._mapInfo;
if (sprite && sources) {
Object.keys(sources).forEach((sourceName) => {
if (sources[sourceName].type === 'vector') {
this.map.style.addSprite(sourceName, sprite);
}
});
}
this._initLayers();
return;
}
Expand Down
61 changes: 61 additions & 0 deletions test/mapboxgl/mapping/WebMapV3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,65 @@ describe('mapboxgl-webmap3.0', () => {
});
mapstudioWebmap.initializeMap(mapInfo);
});

it('add sprite when map instance as param', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('/sprite') > -1) {
return Promise.resolve(new Response(msSpriteInfo));
}
return Promise.resolve();
});
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
const mapInfo = JSON.parse(mapstudioWebMap_symbol);
const nextMapInfo = {
...mapInfo,
crs: {
name: 'EPSG:4490',
extent: [-180, -270, 180, 90],
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"]]'
}
};
mapboxgl.CRS = function (epsgCode, wkt, bounds, unit) {
expect(epsgCode).toBe(nextMapInfo.crs.name);
expect(wkt).toBe(nextMapInfo.crs.wkt);
expect(bounds).toEqual(nextMapInfo.crs.extent);
expect(unit).toBe(nextMapInfo.crs.extent[2] > 180 ? 'meter' : 'degree');
};
mapboxgl.CRS.set = function () {};
mapstudioWebmap = new WebMapV3(nextMapInfo, {
server: server,
target: 'map'
});
const existedMap = new mapboxgl.Map({
container: testDiv,
style: {
version: 8,
sources: {},
layers: [
{
paint: {
'background-color': '#242424'
},
id: 'background1',
type: 'background'
}
]
},
crs: 'EPSG:4490',
center: [116.640545, 40.531714],
zoom: 7
});
const addSprite = spyOn(existedMap.style, 'addSprite');
existedMap.on('load', function () {
mapstudioWebmap.initializeMap(nextMapInfo, existedMap);
});
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
expect(mapstudioWebmap._appendLayers).toBe(true);
expect(map).toEqual(existedMap);
expect(mapstudioWebmap.map).toEqual(map);
expect(addSprite).toHaveBeenCalledTimes(6);
delete mapboxgl.CRS;
done();
});
});
});
3 changes: 2 additions & 1 deletion test/tool/mock_mapboxgl_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const Map = function (options) {
this.resize = function () {};
this.style = {
...options.style,
addGlyphs: function() {}
addGlyphs: function() {},
addSprite: function() {}
};
this.setStyle = function (style, options) {
if (style.layers) {
Expand Down

0 comments on commit 66cbdfc

Please sign in to comment.