Skip to content

Commit 66cbdfc

Browse files
fix 修复webmapv3 传入地图实例的情况下没处理 sprite review by xiongjj
1 parent 9e82d33 commit 66cbdfc

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ export class WebMap extends mapboxgl.Evented {
172172
if (map) {
173173
this._appendLayers = true;
174174
this.map = map;
175+
// 处理图层管理添加 sprite
176+
const { sources, sprite } = this._mapInfo;
177+
if (sprite && sources) {
178+
Object.keys(sources).forEach((sourceName) => {
179+
if (sources[sourceName].type === 'vector') {
180+
this.map.style.addSprite(sourceName, sprite);
181+
}
182+
});
183+
}
175184
this._initLayers();
176185
return;
177186
}

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,4 +886,65 @@ describe('mapboxgl-webmap3.0', () => {
886886
});
887887
mapstudioWebmap.initializeMap(mapInfo);
888888
});
889+
890+
it('add sprite when map instance as param', (done) => {
891+
spyOn(FetchRequest, 'get').and.callFake((url) => {
892+
if (url.indexOf('/sprite') > -1) {
893+
return Promise.resolve(new Response(msSpriteInfo));
894+
}
895+
return Promise.resolve();
896+
});
897+
spyOn(mapboxgl, 'Map').and.callFake(mbglmap);
898+
const mapInfo = JSON.parse(mapstudioWebMap_symbol);
899+
const nextMapInfo = {
900+
...mapInfo,
901+
crs: {
902+
name: 'EPSG:4490',
903+
extent: [-180, -270, 180, 90],
904+
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"]]'
905+
}
906+
};
907+
mapboxgl.CRS = function (epsgCode, wkt, bounds, unit) {
908+
expect(epsgCode).toBe(nextMapInfo.crs.name);
909+
expect(wkt).toBe(nextMapInfo.crs.wkt);
910+
expect(bounds).toEqual(nextMapInfo.crs.extent);
911+
expect(unit).toBe(nextMapInfo.crs.extent[2] > 180 ? 'meter' : 'degree');
912+
};
913+
mapboxgl.CRS.set = function () {};
914+
mapstudioWebmap = new WebMapV3(nextMapInfo, {
915+
server: server,
916+
target: 'map'
917+
});
918+
const existedMap = new mapboxgl.Map({
919+
container: testDiv,
920+
style: {
921+
version: 8,
922+
sources: {},
923+
layers: [
924+
{
925+
paint: {
926+
'background-color': '#242424'
927+
},
928+
id: 'background1',
929+
type: 'background'
930+
}
931+
]
932+
},
933+
crs: 'EPSG:4490',
934+
center: [116.640545, 40.531714],
935+
zoom: 7
936+
});
937+
const addSprite = spyOn(existedMap.style, 'addSprite');
938+
existedMap.on('load', function () {
939+
mapstudioWebmap.initializeMap(nextMapInfo, existedMap);
940+
});
941+
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
942+
expect(mapstudioWebmap._appendLayers).toBe(true);
943+
expect(map).toEqual(existedMap);
944+
expect(mapstudioWebmap.map).toEqual(map);
945+
expect(addSprite).toHaveBeenCalledTimes(6);
946+
delete mapboxgl.CRS;
947+
done();
948+
});
949+
});
889950
});

test/tool/mock_mapboxgl_map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const Map = function (options) {
5151
this.resize = function () {};
5252
this.style = {
5353
...options.style,
54-
addGlyphs: function() {}
54+
addGlyphs: function() {},
55+
addSprite: function() {}
5556
};
5657
this.setStyle = function (style, options) {
5758
if (style.layers) {

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