Skip to content

Commit b5210be

Browse files
[fix]经纬网ut修复,添加多个图层
1 parent bc52c57 commit b5210be

File tree

2 files changed

+70
-40
lines changed

2 files changed

+70
-40
lines changed

test/mapboxgl/overlay/GraticuleLayerSpec.js

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('mapboxgl_GraticuleLayer', () => {
4545
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
4646
if (!map.getLayer('graticuleLayer_1')) {
4747
graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_1' });
48-
graticuleLayer.onAdd(map);
48+
map.addLayer(graticuleLayer);
4949
}
5050
});
5151

@@ -73,16 +73,6 @@ describe('mapboxgl_GraticuleLayer', () => {
7373
}, 0);
7474
});
7575

76-
it('_initialize visible', (done) => {
77-
setTimeout(() => {
78-
const graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_test', visible: false });
79-
graticuleLayer.onAdd(map);
80-
var visible = map.getLayoutProperty('graticuleLayer_test_line', 'visibility');
81-
expect(visible).toBe('none');
82-
done();
83-
}, 0);
84-
});
85-
8676
it('setVisibility', () => {
8777
graticuleLayer.setVisibility(false);
8878
var visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
@@ -108,12 +98,17 @@ describe('mapboxgl_GraticuleLayer', () => {
10898
});
10999

110100
it('setExtent', () => {
111-
graticuleLayer.setExtent([
112-
[0, 0],
113-
[50, 50]
114-
]);
115-
expect(graticuleLayer.options.extent[0]).toEqual(0);
116-
expect(graticuleLayer.options.extent[3]).toEqual(50);
101+
try {
102+
graticuleLayer.setExtent([
103+
[0, 0],
104+
[50, 50]
105+
]);
106+
expect(graticuleLayer.options.extent[0]).toEqual(0);
107+
expect(graticuleLayer.options.extent[3]).toEqual(50);
108+
} catch (e) {
109+
expect(false).toBeTruthy();
110+
console.log(e);
111+
}
117112
});
118113

119114
it('setStrokeStyle', () => {
@@ -132,34 +127,24 @@ describe('mapboxgl_GraticuleLayer', () => {
132127
});
133128

134129
it('setIntervals', () => {
135-
graticuleLayer.setIntervals(5);
136-
expect(graticuleLayer.renderer.options.interval).toEqual(5);
130+
try {
131+
graticuleLayer.setIntervals(5);
132+
expect(graticuleLayer.renderer.options.interval).toEqual(5);
133+
} catch (e) {
134+
expect(false).toBeTruthy();
135+
console.log(e);
136+
}
137137
});
138138

139139
it('getDefaultExtent must return degree', () => {
140140
map.getCRS = () => {
141141
return {
142-
extent: [
143-
-20037508.3427892,
144-
-20037508.3427892,
145-
20037508.3427892,
146-
20037508.3427892
147-
],
148-
lngLatExtent: [
149-
-179.99999999999963,
150-
-85.05112877980658,
151-
179.99999999999963,
152-
85.05112877980656
153-
]
142+
extent: [-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892],
143+
lngLatExtent: [-179.99999999999963, -85.05112877980658, 179.99999999999963, 85.05112877980656]
154144
};
155145
};
156146
var extent = graticuleLayer.getDefaultExtent();
157-
expect(extent).toEqual([
158-
-179.99999999999963,
159-
-85.05112877980658,
160-
179.99999999999963,
161-
85.05112877980656
162-
]);
147+
expect(extent).toEqual([-179.99999999999963, -85.05112877980658, 179.99999999999963, 85.05112877980656]);
163148
});
164149

165150
it('_calcInterval', () => {
@@ -189,8 +174,45 @@ describe('mapboxgl_GraticuleLayer', () => {
189174
expect(points[0][1]).toEqual(80);
190175
});
191176

177+
xit('_setLayerTop add newlayer', () => {
178+
console.log('_setLayerTop add newlayer');
179+
try {
180+
map.addSource('queryDatas', {
181+
type: 'geojson',
182+
data: {
183+
type: 'FeatureCollection',
184+
features: [{ type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[0, 0][(10, 5)], [-10, 5]]] } }]
185+
}
186+
});
187+
map.addLayer({
188+
id: 'queryDatas',
189+
type: 'fill',
190+
source: 'queryDatas',
191+
paint: {
192+
'fill-color': '#008080',
193+
'fill-opacity': 0.4
194+
},
195+
filter: ['==', '$type', 'Polygon']
196+
});
197+
expect(true).toBeTruthy();
198+
} catch (e) {
199+
expect(false).toBeTruthy();
200+
console.log(e);
201+
}
202+
});
203+
192204
it('onRemove', () => {
193205
graticuleLayer.onRemove();
194206
expect(graticuleLayer.renderer.canvas).toBeNull();
195207
});
208+
209+
it('_initialize visible', (done) => {
210+
setTimeout(() => {
211+
const graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_test', visible: false });
212+
map.addLayer(graticuleLayer);
213+
var visible = map.getLayoutProperty('graticuleLayer_test_line', 'visibility');
214+
expect(visible).toBe('none');
215+
done();
216+
}, 0);
217+
});
196218
});

test/maplibregl/overlay/GraticuleLayerSpec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { GraticuleLayer } from '../../../src/maplibregl/overlay/GraticuleLayer';
22
import maplibregl from 'maplibre-gl';
3-
import { Feature } from '@supermapgis/iclient-common';
43
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
54

65
describe('maplibregl_GraticuleLayer', () => {
@@ -43,10 +42,9 @@ describe('maplibregl_GraticuleLayer', () => {
4342
beforeEach(() => {
4443
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
4544
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
46-
debugger
4745
if (!map.getLayer('graticuleLayer_1')) {
4846
graticuleLayer = new GraticuleLayer({layerID :'graticuleLayer_1'});
49-
graticuleLayer.onAdd(map);
47+
map.addLayer(graticuleLayer);
5048
}
5149
});
5250

@@ -126,12 +124,17 @@ describe('maplibregl_GraticuleLayer', () => {
126124
});
127125

128126
it('setExtent', () => {
127+
try{
129128
graticuleLayer.setExtent([
130129
[0, 0],
131130
[50, 50]
132131
]);
133132
expect(graticuleLayer.options.extent[0]).toEqual(0);
134133
expect(graticuleLayer.options.extent[3]).toEqual(50);
134+
} catch (e) {
135+
expect(false).toBeTruthy();
136+
console.log(e);
137+
}
135138
});
136139

137140
it('setStrokeStyle', () => {
@@ -150,8 +153,13 @@ describe('maplibregl_GraticuleLayer', () => {
150153
});
151154

152155
it('setIntervals', () => {
156+
try{
153157
graticuleLayer.setIntervals(5);
154158
expect(graticuleLayer.renderer.options.interval).toEqual(5);
159+
} catch (e) {
160+
expect(false).toBeTruthy();
161+
console.log(e);
162+
}
155163
});
156164

157165
it('_calcInterval', () => {

0 commit comments

Comments
 (0)