Skip to content

Commit 5987421

Browse files
committed
【fix】ICL-1543 initmap支持带token的url
1 parent 0a48284 commit 5987421

File tree

8 files changed

+446
-189
lines changed

8 files changed

+446
-189
lines changed

src/leaflet/services/MapService.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import '../core/Base';
66
import {
77
ServiceBase
88
} from './ServiceBase';
9+
import { Util } from '@supermap/iclient-common/commontypes/Util';
910
import { MapService as CommonMapService } from '@supermap/iclient-common/iServer/MapService';
1011
import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsService';
1112
/**
@@ -69,7 +70,7 @@ export var MapService = ServiceBase.extend({
6970
*/
7071
getWKT(callback) {
7172
var me = this;
72-
var getMapStatusService = new CommonMapService(`${me.url}/prjCoordSys.wkt`, {
73+
var getMapStatusService = new CommonMapService(Util.urlPathAppend(me.url,'prjCoordSys.wkt'), {
7374
proxy: me.options.proxy,
7475
withCredentials: me.options.withCredentials,
7576
withoutFormatSuffix: true,

src/mapboxgl/services/MapService.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import '../core/Base';
5-
import {ServiceBase} from './ServiceBase';
5+
import { ServiceBase } from './ServiceBase';
6+
import { Util } from '@supermap/iclient-common/commontypes/Util';
67
import { MapService as CommonMapService } from '@supermap/iclient-common/iServer/MapService';
78
import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsService';
89

@@ -57,7 +58,7 @@ export class MapService extends ServiceBase {
5758
*/
5859
getWKT(callback) {
5960
var me = this;
60-
var getMapStatusService = new CommonMapService(`${me.url}/prjCoordSys.wkt`, {
61+
var getMapStatusService = new CommonMapService(Util.urlPathAppend(me.url,'prjCoordSys.wkt'), {
6162
proxy: me.options.proxy,
6263
withCredentials: me.options.withCredentials,
6364
withoutFormatSuffix: true,

src/maplibregl/services/MapService.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import {ServiceBase} from './ServiceBase';
5+
import { Util } from '@supermap/iclient-common/commontypes/Util';
56
import { MapService as CommonMapService } from '@supermap/iclient-common/iServer/MapService';
67
import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsService';
78

@@ -57,7 +58,7 @@ export class MapService extends ServiceBase {
5758
*/
5859
getWKT(callback) {
5960
var me = this;
60-
var getMapStatusService = new CommonMapService(`${me.url}/prjCoordSys.wkt`, {
61+
var getMapStatusService = new CommonMapService(Util.urlPathAppend(me.url,'prjCoordSys.wkt'), {
6162
proxy: me.options.proxy,
6263
withCredentials: me.options.withCredentials,
6364
withoutFormatSuffix: true,

src/openlayers/services/MapService.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import { ServiceBase } from './ServiceBase';
5+
import { Util } from '@supermap/iclient-common/commontypes/Util';
56
import { MapService as CommonMapService } from '@supermap/iclient-common/iServer/MapService';
67
import { TilesetsService } from '@supermap/iclient-common/iServer/TilesetsService';
78
/**
@@ -53,7 +54,7 @@ export class MapService extends ServiceBase {
5354
*/
5455
getWKT(callback) {
5556
var me = this;
56-
var getMapStatusService = new CommonMapService(`${me.url}/prjCoordSys.wkt`, {
57+
var getMapStatusService = new CommonMapService(Util.urlPathAppend(me.url,'prjCoordSys.wkt'), {
5758
proxy: me.options.proxy,
5859
withCredentials: me.options.withCredentials,
5960
withoutFormatSuffix: true,

test/leaflet/services/MapServiceSpec.js

Lines changed: 108 additions & 52 deletions
Large diffs are not rendered by default.

test/mapboxgl/services/MapServiceSpec.js

Lines changed: 107 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,119 @@
1-
import {MapService} from '../../../src/mapboxgl/services/MapService';
1+
import { MapService } from '../../../src/mapboxgl/services/MapService';
22
import { FetchRequest } from '../../../src/common/util/FetchRequest';
33

44
var url = GlobeParameter.WorldURL;
5-
var options = {
6-
};
5+
var options = {};
76
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+
);
1727
});
28+
service.getMapInfo((result) => {
29+
serviceResult = result;
1830

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+
});
2757

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(`[]`));
5263
});
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+
}
5377
});
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));
7484
});
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+
}
7597
});
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+
});
76119
});
77-
78-

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