Skip to content

Commit b089acb

Browse files
add ut
1 parent f8947fc commit b089acb

File tree

4 files changed

+127
-3
lines changed

4 files changed

+127
-3
lines changed

src/openlayers/overlay/VectorTileSuperMapRest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class VectorTileSuperMapRest extends VectorTile {
352352
const sourceInfo = await response.json();
353353
let tileUrl = sourceInfo.tiles[0];
354354
if (!CommonUtil.isAbsoluteURL(tileUrl)) {
355-
tileUrl = CommonUtil.relative2absolute(tileUrl, style.sources[source].url);
355+
tileUrl = CommonUtil.relative2absolute(tileUrl, tiles);
356356
}
357357
newUrl = SecurityManager.appendCredential(tileUrl);
358358
}

test/openlayers/overlay/VectorTileSuperMapRestSpec.js

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ describe('openlayers_VectorTileSuperMapRest', () => {
9898
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
9999
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
100100

101-
spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => mockCallback(url, 'GET'));
102101
spyPost = spyOn(FetchRequest, 'post').and.callFake((url) => mockCallback(url, 'POST'));
103102
spyCommit = spyOn(FetchRequest, 'commit').and.callFake((method, url) => mockCallback(url, method));
104103
});
@@ -116,6 +115,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
116115
});
117116

118117
it('initialize', (done) => {
118+
spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => mockCallback(url, 'GET'));
119119
new MapService(url).getMapInfo((serviceResult) => {
120120
map = new Map({
121121
target: 'map',
@@ -144,6 +144,7 @@ describe('openlayers_VectorTileSuperMapRest', () => {
144144
});
145145
});
146146
it('custom_tileLoadFunction', (done) => {
147+
spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => mockCallback(url, 'GET'));
147148
var spy = jasmine.createSpy('test');
148149
var tileLoadFunction = (tile) => {
149150
tile.setLoader(() => {
@@ -174,7 +175,75 @@ describe('openlayers_VectorTileSuperMapRest', () => {
174175
});
175176
});
176177

178+
it('handle relative url', (done) => {
179+
spyOn(FetchRequest, 'get').and.callFake((url) => {
180+
if (url.indexOf('fake') > -1) {
181+
return Promise.resolve(new Response(JSON.stringify({
182+
tiles: ['tile/{z}/{y}/{x}.pbf']
183+
})));
184+
}
185+
return Promise.resolve();
186+
});
187+
new MapService(url).getMapInfo((serviceResult) => {
188+
map = new Map({
189+
target: 'map',
190+
view: new View({
191+
center: [12957388, 4853991],
192+
zoom: 11
193+
})
194+
});
195+
vectorTileOptions = VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
196+
vectorTileOptions.tileLoadFunction = (tile) => {
197+
tile.setLoader(() => {
198+
tile.setFeatures([]);
199+
});
200+
};
201+
vectorTileOptions.format = new MVT();
202+
vectorTileOptions.baseUrl = 'http://fake/iportal/services';
203+
vectorTileOptions.style = {
204+
"version" : 8,
205+
"sprite" : "../sprites/sprite",
206+
"glyphs" : "../fonts/{fontstack}/{range}.pbf",
207+
"sources": {
208+
"esri": {
209+
"type": "vector",
210+
"url": "../../"
211+
}
212+
},
213+
"layers" : [{
214+
"id" : "Contour_11_main/0",
215+
"type" : "line",
216+
"source" : "esri",
217+
"source-layer" : "Contour",
218+
"filter" : ["all", ["==", "Index3", 1], ["==", "Index5", 1]],
219+
"minzoom" : 11,
220+
"maxzoom" : 12,
221+
"paint" : {
222+
"line-color" : "#61674a",
223+
"line-opacity" : 0.5,
224+
"line-width" : {
225+
"base" : 1.2,
226+
"stops" : [[11, 0.7], [16, 1.1]]
227+
}
228+
}
229+
}]
230+
}
231+
vectorTileSource = new VectorTileSuperMapRest(vectorTileOptions);
232+
vectorTileSource.once('tileloadend', () => {
233+
expect(vectorTileOptions).not.toBeNull();
234+
expect(vectorTileOptions.crossOrigin).toBe('anonymous');
235+
expect(vectorTileSource).not.toBeNull();
236+
done();
237+
});
238+
vectorLayer = new VectorTileLayer({
239+
source: vectorTileSource
240+
});
241+
map.addLayer(vectorLayer);
242+
});
243+
});
244+
177245
it('mvt_decrypt ', (done) => {
246+
spyGet = spyOn(FetchRequest, 'get').and.callFake((url) => mockCallback(url, 'GET'));
178247
const spy = jasmine.createSpy('test');
179248
const serviceKey = 'l3nQtAUM4li87qMfO68exInHVFQ5gS3a6pb8ySIbib8=';
180249
const spyEncrypt = spyOn(EncryptRequest.prototype, 'request').and.callFake(() => ({ json: () => Promise.resolve(serviceKey)}));

test/openlayers/overlay/vectortile/MapboxStylesSpec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,59 @@ describe("openlayers_MapboxStyles", () => {
279279
}
280280
});
281281
});
282+
283+
it("handle relative url", done => {
284+
spyOn(XMLHttpRequest.prototype, 'send').and.callThrough();
285+
spyOn(XMLHttpRequest.prototype, 'setRequestHeader').and.callThrough();
286+
var style = {
287+
"version" : 8,
288+
"sprite" : "../sprites/sprite",
289+
"glyphs" : "../fonts/{fontstack}/{range}.pbf",
290+
"sources": {
291+
"esri": {
292+
"type": "vector",
293+
"url": "../../"
294+
}
295+
},
296+
"layers" : [{
297+
"id" : "Contour_11_main/0",
298+
"type" : "line",
299+
"source" : "esri",
300+
"source-layer" : "Contour",
301+
"filter" : ["all", ["==", "Index3", 1], ["==", "Index5", 1]],
302+
"minzoom" : 11,
303+
"maxzoom" : 12,
304+
"paint" : {
305+
"line-color" : "#61674a",
306+
"line-opacity" : 0.5,
307+
"line-width" : {
308+
"base" : 1.2,
309+
"stops" : [[11, 0.7], [16, 1.1]]
310+
}
311+
}
312+
}]
313+
}
314+
mapboxStyles = new MapboxStyles({
315+
style: style,
316+
baseUrl: 'http://localhost:9876',
317+
map: map,
318+
source: "California",
319+
headers:{'appToken':'test'}
320+
});
321+
mapboxStyles.on("styleloaded", () => {
322+
try {
323+
style = mapboxStyles.getStyleFunction();
324+
expect(style).not.toBeNull();
325+
console.log('mapboxStyles', mapboxStyles);
326+
expect(mapboxStyles._mbStyle.glyphs).toBe('http://localhost:9876/fonts/{fontstack}/{range}.pbf');
327+
expect(mapboxStyles._mbStyle.sprite).toBe('http://localhost:9876/sprites/sprite');
328+
expect(mapboxStyles._mbStyle.sources['esri']['url']).toBe('http://localhost:9876/');
329+
done();
330+
} catch (e) {
331+
console.log("'init_Style_headers'案例失败" + e.name + ":" + e.message);
332+
expect(false).toBeTruthy();
333+
done();
334+
}
335+
});
336+
});
282337
});

test/resources/MapboxStyles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var vectorstylesEscapedJson={
88
}
99
},
1010
"name": "California",
11-
"sprite": "../../base/resources/img/sprite@2x",
11+
"sprite": "http://localhost:9876/base/resources/img/sprite@2x",
1212
"layers": [
1313
{
1414
"paint": {

0 commit comments

Comments
 (0)