@@ -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});
0 commit comments