|
1 |
| -import {MapService} from '../../../src/mapboxgl/services/MapService'; |
| 1 | +import { MapService } from '../../../src/mapboxgl/services/MapService'; |
2 | 2 | import { FetchRequest } from '../../../src/common/util/FetchRequest';
|
3 | 3 |
|
4 | 4 | var url = GlobeParameter.WorldURL;
|
5 |
| -var options = { |
6 |
| -}; |
| 5 | +var options = {}; |
7 | 6 | describe('mapboxgl_MapService', () => {
|
8 |
| - var serviceResult; |
9 |
| - var originalTimeout; |
10 |
| - beforeEach(() => { |
11 |
| - originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; |
12 |
| - jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000; |
13 |
| - serviceResult = null; |
14 |
| - }); |
15 |
| - afterEach(() => { |
16 |
| - jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; |
| 7 | + var serviceResult; |
| 8 | + var originalTimeout; |
| 9 | + beforeEach(() => { |
| 10 | + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; |
| 11 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000; |
| 12 | + serviceResult = null; |
| 13 | + }); |
| 14 | + afterEach(() => { |
| 15 | + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; |
| 16 | + }); |
| 17 | + |
| 18 | + //地图信息查询服务 |
| 19 | + it('getMapInfo', (done) => { |
| 20 | + var service = new MapService(url, options); |
| 21 | + spyOn(FetchRequest, 'get').and.callFake(() => { |
| 22 | + return Promise.resolve( |
| 23 | + new Response( |
| 24 | + `{"viewBounds":{"top":51.458251340507125,"left":-51.458251340507125,"bottom":-51.458251340507125,"leftBottom":{"x":-51.458251340507125,"y":-51.458251340507125},"right":51.458251340507125,"rightTop":{"x":51.458251340507125,"y":51.458251340507125}},"viewer":{"leftTop":{"x":0,"y":0},"top":0,"left":0,"bottom":256,"rightBottom":{"x":256,"y":256},"width":256,"right":256,"height":256},"distanceUnit":"METER","minVisibleTextSize":0.1,"coordUnit":"DEGREE","scale":5.912160537196359E-9,"description":"","paintBackground":true,"maxVisibleTextSize":1000,"maxVisibleVertex":3600000,"clipRegionEnabled":false,"antialias":true,"textOrientationFixed":false,"angle":0,"prjCoordSys":{"distanceUnit":"METER","projectionParam":null,"epsgCode":4326,"coordUnit":"DEGREE","name":"Longitude / Latitude Coordinate System---GCS_WGS_1984","projection":null,"type":"PCS_EARTH_LONGITUDE_LATITUDE","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"minScale":0,"markerAngleFixed":false,"overlapDisplayedOptions":{"allowPointWithTextDisplay":true,"horizontalOverlappedSpaceSize":0,"allowPointOverlap":true,"allowThemeGraduatedSymbolOverlap":false,"verticalOverlappedSpaceSize":0,"allowTextOverlap":false,"allowThemeGraphOverlap":false,"allowTextAndPointOverlap":true},"visibleScales":[1.6901635716026555E-9,3.375595414562003E-9,6.751190829124006E-9,1.3502381658248012E-8,2.7004763316496024E-8,5.400952663299205E-8,1.080190532659841E-7,2.1603810653196843E-7,4.320762130639359E-7,8.641524261278681E-7],"visibleScalesEnabled":false,"customEntireBoundsEnabled":false,"clipRegion":{"center":null,"parts":null,"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":null,"points":null},"maxScale":1.0E12,"customParams":"","center":{"x":0,"y":0},"dynamicPrjCoordSyses":[{"distanceUnit":null,"projectionParam":null,"epsgCode":0,"coordUnit":null,"name":null,"projection":null,"type":"PCS_ALL","coordSystem":null}],"colorMode":"DEFAULT","textAngleFixed":false,"overlapDisplayed":false,"userToken":{"userID":""},"cacheEnabled":true,"dynamicProjection":false,"autoAvoidEffectEnabled":true,"customEntireBounds":null,"name":"World","bounds":{"top":90,"left":-180,"bottom":-90,"leftBottom":{"x":-180,"y":-90},"right":180,"rightTop":{"x":180,"y":90}},"backgroundStyle":{"fillGradientOffsetRatioX":0,"markerSize":2.4,"fillForeColor":{"red":179,"green":209,"blue":255,"alpha":255},"fillGradientOffsetRatioY":0,"markerWidth":0,"markerAngle":0,"fillSymbolID":0,"lineColor":{"red":0,"green":0,"blue":0,"alpha":255},"markerSymbolID":0,"lineWidth":0.1,"markerHeight":0,"fillOpaqueRate":100,"fillBackOpaque":false,"fillBackColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientMode":"NONE","lineSymbolID":0,"fillGradientAngle":0}}` |
| 25 | + ) |
| 26 | + ); |
17 | 27 | });
|
| 28 | + service.getMapInfo((result) => { |
| 29 | + serviceResult = result; |
18 | 30 |
|
19 |
| - //地图信息查询服务 |
20 |
| - it('getMapInfo', (done) => { |
21 |
| - var service = new MapService(url, options); |
22 |
| - spyOn(FetchRequest, 'get').and.callFake(() => { |
23 |
| - return Promise.resolve(new Response(`{"viewBounds":{"top":51.458251340507125,"left":-51.458251340507125,"bottom":-51.458251340507125,"leftBottom":{"x":-51.458251340507125,"y":-51.458251340507125},"right":51.458251340507125,"rightTop":{"x":51.458251340507125,"y":51.458251340507125}},"viewer":{"leftTop":{"x":0,"y":0},"top":0,"left":0,"bottom":256,"rightBottom":{"x":256,"y":256},"width":256,"right":256,"height":256},"distanceUnit":"METER","minVisibleTextSize":0.1,"coordUnit":"DEGREE","scale":5.912160537196359E-9,"description":"","paintBackground":true,"maxVisibleTextSize":1000,"maxVisibleVertex":3600000,"clipRegionEnabled":false,"antialias":true,"textOrientationFixed":false,"angle":0,"prjCoordSys":{"distanceUnit":"METER","projectionParam":null,"epsgCode":4326,"coordUnit":"DEGREE","name":"Longitude / Latitude Coordinate System---GCS_WGS_1984","projection":null,"type":"PCS_EARTH_LONGITUDE_LATITUDE","coordSystem":{"datum":{"name":"D_WGS_1984","type":"DATUM_WGS_1984","spheroid":{"flatten":0.00335281066474748,"name":"WGS_1984","axis":6378137,"type":"SPHEROID_WGS_1984"}},"unit":"DEGREE","spatialRefType":"SPATIALREF_EARTH_LONGITUDE_LATITUDE","name":"GCS_WGS_1984","type":"GCS_WGS_1984","primeMeridian":{"longitudeValue":0,"name":"Greenwich","type":"PRIMEMERIDIAN_GREENWICH"}}},"minScale":0,"markerAngleFixed":false,"overlapDisplayedOptions":{"allowPointWithTextDisplay":true,"horizontalOverlappedSpaceSize":0,"allowPointOverlap":true,"allowThemeGraduatedSymbolOverlap":false,"verticalOverlappedSpaceSize":0,"allowTextOverlap":false,"allowThemeGraphOverlap":false,"allowTextAndPointOverlap":true},"visibleScales":[1.6901635716026555E-9,3.375595414562003E-9,6.751190829124006E-9,1.3502381658248012E-8,2.7004763316496024E-8,5.400952663299205E-8,1.080190532659841E-7,2.1603810653196843E-7,4.320762130639359E-7,8.641524261278681E-7],"visibleScalesEnabled":false,"customEntireBoundsEnabled":false,"clipRegion":{"center":null,"parts":null,"style":null,"prjCoordSys":null,"id":0,"type":"REGION","partTopo":null,"points":null},"maxScale":1.0E12,"customParams":"","center":{"x":0,"y":0},"dynamicPrjCoordSyses":[{"distanceUnit":null,"projectionParam":null,"epsgCode":0,"coordUnit":null,"name":null,"projection":null,"type":"PCS_ALL","coordSystem":null}],"colorMode":"DEFAULT","textAngleFixed":false,"overlapDisplayed":false,"userToken":{"userID":""},"cacheEnabled":true,"dynamicProjection":false,"autoAvoidEffectEnabled":true,"customEntireBounds":null,"name":"World","bounds":{"top":90,"left":-180,"bottom":-90,"leftBottom":{"x":-180,"y":-90},"right":180,"rightTop":{"x":180,"y":90}},"backgroundStyle":{"fillGradientOffsetRatioX":0,"markerSize":2.4,"fillForeColor":{"red":179,"green":209,"blue":255,"alpha":255},"fillGradientOffsetRatioY":0,"markerWidth":0,"markerAngle":0,"fillSymbolID":0,"lineColor":{"red":0,"green":0,"blue":0,"alpha":255},"markerSymbolID":0,"lineWidth":0.1,"markerHeight":0,"fillOpaqueRate":100,"fillBackOpaque":false,"fillBackColor":{"red":255,"green":255,"blue":255,"alpha":255},"fillGradientMode":"NONE","lineSymbolID":0,"fillGradientAngle":0}}`)); |
24 |
| - }); |
25 |
| - service.getMapInfo((result) => { |
26 |
| - serviceResult = result |
| 31 | + try { |
| 32 | + expect(service).not.toBeNull(); |
| 33 | + expect(serviceResult).not.toBeNull(); |
| 34 | + expect(serviceResult.type).toEqual('processCompleted'); |
| 35 | + expect(serviceResult.result.succeed).toEqual(true); |
| 36 | + expect(serviceResult.result.antialias).toEqual(true); |
| 37 | + expect(serviceResult.result.bounds).not.toBeNull(); |
| 38 | + expect(serviceResult.result.clipRegion).not.toBeNull(); |
| 39 | + expect(serviceResult.result.clipRegion.type).toEqual('REGION'); |
| 40 | + expect(serviceResult.result.colorMode).toEqual('DEFAULT'); |
| 41 | + expect(serviceResult.result.coordUnit).toEqual('DEGREE'); |
| 42 | + expect(serviceResult.result.distanceUnit).toEqual('METER'); |
| 43 | + expect(serviceResult.result.name).toEqual('World'); |
| 44 | + expect(serviceResult.result.prjCoordSys.coordSystem).not.toBeNull(); |
| 45 | + expect(serviceResult.result.prjCoordSys.coordUnit).toEqual('DEGREE'); |
| 46 | + expect(serviceResult.result.prjCoordSys.distanceUnit).toEqual('METER'); |
| 47 | + expect(serviceResult.result.prjCoordSys.epsgCode).toEqual(4326); |
| 48 | + expect(serviceResult.result.viewer).not.toBeNull(); |
| 49 | + done(); |
| 50 | + } catch (e) { |
| 51 | + console.log("'getMapInfo'案例失败" + e.name + ':' + e.message); |
| 52 | + expect(false).toBeTruthy(); |
| 53 | + done(); |
| 54 | + } |
| 55 | + }); |
| 56 | + }); |
27 | 57 |
|
28 |
| - try { |
29 |
| - expect(service).not.toBeNull(); |
30 |
| - expect(serviceResult).not.toBeNull(); |
31 |
| - expect(serviceResult.type).toEqual("processCompleted"); |
32 |
| - expect(serviceResult.result.succeed).toEqual(true); |
33 |
| - expect(serviceResult.result.antialias).toEqual(true); |
34 |
| - expect(serviceResult.result.bounds).not.toBeNull(); |
35 |
| - expect(serviceResult.result.clipRegion).not.toBeNull(); |
36 |
| - expect(serviceResult.result.clipRegion.type).toEqual("REGION"); |
37 |
| - expect(serviceResult.result.colorMode).toEqual("DEFAULT"); |
38 |
| - expect(serviceResult.result.coordUnit).toEqual("DEGREE"); |
39 |
| - expect(serviceResult.result.distanceUnit).toEqual("METER"); |
40 |
| - expect(serviceResult.result.name).toEqual("World"); |
41 |
| - expect(serviceResult.result.prjCoordSys.coordSystem).not.toBeNull(); |
42 |
| - expect(serviceResult.result.prjCoordSys.coordUnit).toEqual("DEGREE"); |
43 |
| - expect(serviceResult.result.prjCoordSys.distanceUnit).toEqual("METER"); |
44 |
| - expect(serviceResult.result.prjCoordSys.epsgCode).toEqual(4326); |
45 |
| - expect(serviceResult.result.viewer).not.toBeNull(); |
46 |
| - done(); |
47 |
| - } catch (e) { |
48 |
| - console.log("'getMapInfo'案例失败" + e.name + ":" + e.message); |
49 |
| - expect(false).toBeTruthy(); |
50 |
| - done(); |
51 |
| - } |
| 58 | + //切片列表信息查询服务 |
| 59 | + it('getTilesets', (done) => { |
| 60 | + var service = new MapService(url, options); |
| 61 | + spyOn(FetchRequest, 'get').and.callFake(() => { |
| 62 | + return Promise.resolve(new Response(`[]`)); |
52 | 63 | });
|
| 64 | + service.getTilesets((result) => { |
| 65 | + serviceResult = result; |
| 66 | + try { |
| 67 | + expect(service).not.toBeNull(); |
| 68 | + expect(serviceResult).not.toBeNull(); |
| 69 | + expect(serviceResult.type).toEqual('processCompleted'); |
| 70 | + expect(serviceResult.result.succeed).toEqual(true); |
| 71 | + done(); |
| 72 | + } catch (e) { |
| 73 | + console.log("'getMapInfo'案例失败" + e.name + ':' + e.message); |
| 74 | + expect(false).toBeTruthy(); |
| 75 | + done(); |
| 76 | + } |
53 | 77 | });
|
54 |
| - |
55 |
| - //切片列表信息查询服务 |
56 |
| - it('getTilesets', (done) => { |
57 |
| - var service = new MapService(url, options); |
58 |
| - spyOn(FetchRequest, 'get').and.callFake(() => { |
59 |
| - return Promise.resolve(new Response(`[]`)); |
60 |
| - }); |
61 |
| - service.getTilesets((result) => { |
62 |
| - serviceResult = result |
63 |
| - try { |
64 |
| - expect(service).not.toBeNull(); |
65 |
| - expect(serviceResult).not.toBeNull(); |
66 |
| - expect(serviceResult.type).toEqual("processCompleted"); |
67 |
| - expect(serviceResult.result.succeed).toEqual(true); |
68 |
| - done(); |
69 |
| - } catch (e) { |
70 |
| - console.log("'getMapInfo'案例失败" + e.name + ":" + e.message); |
71 |
| - expect(false).toBeTruthy(); |
72 |
| - done(); |
73 |
| - } |
| 78 | + }); |
| 79 | + it('getWKT promise', (done) => { |
| 80 | + const wkt = `GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]]`; |
| 81 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { |
| 82 | + expect(testUrl).toBe(`${url}/prjCoordSys.wkt`); |
| 83 | + return Promise.resolve(new Response(wkt)); |
74 | 84 | });
|
| 85 | + const mapService = new MapService(url); |
| 86 | + mapService.getWKT().then((serviceResult) => { |
| 87 | + try { |
| 88 | + expect(serviceResult.result.data).toEqual(wkt); |
| 89 | + expect(serviceResult.options.method).toBe('GET'); |
| 90 | + done(); |
| 91 | + } catch (exception) { |
| 92 | + expect(false).toBeTruthy(); |
| 93 | + console.log('getWKT案例失败:' + exception.name + ':' + exception.message); |
| 94 | + mapService.destroy(); |
| 95 | + done(); |
| 96 | + } |
75 | 97 | });
|
| 98 | + }); |
| 99 | + it('getWKT customQueryParam', (done) => { |
| 100 | + const wkt = `GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]]`; |
| 101 | + spyOn(FetchRequest, 'get').and.callFake((testUrl) => { |
| 102 | + expect(testUrl).toBe(`${url}/prjCoordSys.wkt?token=111`); |
| 103 | + return Promise.resolve(new Response(wkt)); |
| 104 | + }); |
| 105 | + const mapService = new MapService(`${url}?token=111`); |
| 106 | + mapService.getWKT().then((serviceResult) => { |
| 107 | + try { |
| 108 | + expect(serviceResult.result.data).toEqual(wkt); |
| 109 | + expect(serviceResult.options.method).toBe('GET'); |
| 110 | + done(); |
| 111 | + } catch (exception) { |
| 112 | + expect(false).toBeTruthy(); |
| 113 | + console.log('getWKT案例失败:' + exception.name + ':' + exception.message); |
| 114 | + mapService.destroy(); |
| 115 | + done(); |
| 116 | + } |
| 117 | + }); |
| 118 | + }); |
76 | 119 | });
|
77 |
| - |
78 |
| - |
|
0 commit comments