Skip to content

Commit df73dbb

Browse files
[fix]经纬网visible参数不生效 review by songym
1 parent 81e2c9a commit df73dbb

File tree

2 files changed

+164
-179
lines changed

2 files changed

+164
-179
lines changed

src/common/overlay/graticule/GraticuleLayerRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class GraticuleLayerRenderer {
185185
this.oldExtent = this.options.extent;
186186
this._calcInterval();
187187
this.isRotate = false;
188-
this.visible = true;
188+
this.visible = this.options.visible;
189189
this.features = this._getGraticuleFeatures();
190190
}
191191

test/mapboxgl/overlay/GraticuleLayerSpec.js

Lines changed: 163 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -4,183 +4,168 @@ import mapboxgl from 'mapbox-gl';
44
var url = GlobeParameter.ChinaURL + '/zxyTileImage.png?z={z}&x={x}&y={y}';
55

66
describe('mapboxgl_GraticuleLayer', () => {
7-
var originalTimeout;
8-
var testDiv, map, graticuleLayer;
9-
beforeAll(() => {
10-
testDiv = window.document.createElement('div');
11-
testDiv.setAttribute('id', 'map');
12-
testDiv.style.styleFloat = 'left';
13-
testDiv.style.marginLeft = '8px';
14-
testDiv.style.marginTop = '50px';
15-
testDiv.style.width = '500px';
16-
testDiv.style.height = '500px';
17-
window.document.body.appendChild(testDiv);
18-
map = new mapboxgl.Map({
19-
container: 'map',
20-
style: {
21-
version: 8,
22-
sources: {
23-
'raster-tiles': {
24-
type: 'raster',
25-
tiles: [url],
26-
tileSize: 256
27-
}
28-
},
29-
layers: [
30-
{
31-
id: 'simple-tiles',
32-
type: 'raster',
33-
source: 'raster-tiles',
34-
minzoom: 0,
35-
maxzoom: 22
36-
}
37-
]
38-
},
39-
center: [112, 37.94],
40-
zoom: 3
41-
});
42-
});
43-
beforeEach(() => {
44-
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
45-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
46-
if (!map.getLayer('graticuleLayer_1')) {
47-
graticuleLayer = new GraticuleLayer({layerID :'graticuleLayer_1'});
48-
graticuleLayer.onAdd(map);
49-
}
50-
});
51-
52-
afterEach(() => {
53-
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
54-
});
55-
56-
afterAll(() => {
57-
if (map.getLayer('graticuleLayer_1')) {
58-
map.removeLayer('graticuleLayer_1');
59-
}
60-
document.body.removeChild(testDiv);
61-
map = null;
62-
});
63-
64-
it('_initialize', done => {
65-
setTimeout(() => {
66-
expect(graticuleLayer).not.toBeNull();
67-
expect(graticuleLayer.renderer.canvas).not.toBeNull();
68-
expect(graticuleLayer.map).not.toBeNull();
69-
expect(graticuleLayer.mapContainer).not.toBeNull();
70-
expect(graticuleLayer.features).not.toBeNull();
71-
expect(graticuleLayer.options).not.toBeNull();
72-
done();
73-
}, 0);
74-
});
75-
76-
it('setVisibility', () => {
77-
graticuleLayer.setVisibility(false);
78-
var visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
79-
expect(visible).toBe('none');
80-
graticuleLayer.setVisibility(true);
81-
visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
82-
expect(visible).toBe('visible');
83-
});
84-
85-
it('setMinZoom', () => {
86-
graticuleLayer.setMinZoom(0);
87-
expect(graticuleLayer.options.minZoom).toEqual(0);
88-
});
89-
90-
it('setMaxZoom', () => {
91-
graticuleLayer.setMaxZoom(10);
92-
expect(graticuleLayer.options.maxZoom).toEqual(10);
93-
});
94-
95-
it('setShowLabel', () => {
96-
graticuleLayer.setShowLabel(false);
97-
expect(graticuleLayer.options.showLabel).toEqual(false);
98-
});
99-
100-
it('setExtent', () => {
101-
graticuleLayer.setExtent([
102-
[0, 0],
103-
[50, 50]
104-
]);
105-
expect(graticuleLayer.options.extent[0]).toEqual(0);
106-
expect(graticuleLayer.options.extent[3]).toEqual(50);
107-
});
108-
109-
it('setStrokeStyle', () => {
110-
graticuleLayer.setStrokeStyle({ lineWidth: 3 });
111-
expect(graticuleLayer.options.strokeStyle.lineWidth).toEqual(3);
112-
});
113-
114-
it('setLngLabelStyle', () => {
115-
graticuleLayer.setLngLabelStyle({ textSize: '12px' });
116-
expect(graticuleLayer.options.lngLabelStyle.textSize).toEqual('12px');
117-
});
118-
119-
it('setLatLabelStyle', () => {
120-
graticuleLayer.setLatLabelStyle({ textSize: '12px' });
121-
expect(graticuleLayer.options.latLabelStyle.textSize).toEqual('12px');
122-
});
123-
124-
it('setIntervals', () => {
125-
graticuleLayer.setIntervals(5);
126-
expect(graticuleLayer.renderer.options.interval).toEqual(5);
127-
});
128-
129-
it('getDefaultExtent must return degree', () => {
130-
map.getCRS = () => {
131-
return {
132-
extent: [
133-
-20037508.3427892,
134-
-20037508.3427892,
135-
20037508.3427892,
136-
20037508.3427892
7+
var originalTimeout;
8+
var testDiv, map, graticuleLayer;
9+
beforeAll(() => {
10+
testDiv = window.document.createElement('div');
11+
testDiv.setAttribute('id', 'map');
12+
testDiv.style.styleFloat = 'left';
13+
testDiv.style.marginLeft = '8px';
14+
testDiv.style.marginTop = '50px';
15+
testDiv.style.width = '500px';
16+
testDiv.style.height = '500px';
17+
window.document.body.appendChild(testDiv);
18+
map = new mapboxgl.Map({
19+
container: 'map',
20+
style: {
21+
version: 8,
22+
sources: {
23+
'raster-tiles': {
24+
type: 'raster',
25+
tiles: [url],
26+
tileSize: 256
27+
}
28+
},
29+
layers: [
30+
{
31+
id: 'simple-tiles',
32+
type: 'raster',
33+
source: 'raster-tiles',
34+
minzoom: 0,
35+
maxzoom: 22
36+
}
37+
]
38+
},
39+
center: [112, 37.94],
40+
zoom: 3
41+
});
42+
});
43+
beforeEach(() => {
44+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
45+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
46+
if (!map.getLayer('graticuleLayer_1')) {
47+
graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_1' });
48+
graticuleLayer.onAdd(map);
49+
}
50+
});
51+
52+
afterEach(() => {
53+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
54+
});
55+
56+
afterAll(() => {
57+
if (map.getLayer('graticuleLayer_1')) {
58+
map.removeLayer('graticuleLayer_1');
59+
}
60+
document.body.removeChild(testDiv);
61+
map = null;
62+
});
63+
64+
it('_initialize', (done) => {
65+
setTimeout(() => {
66+
expect(graticuleLayer).not.toBeNull();
67+
expect(graticuleLayer.renderer.canvas).not.toBeNull();
68+
expect(graticuleLayer.map).not.toBeNull();
69+
expect(graticuleLayer.mapContainer).not.toBeNull();
70+
expect(graticuleLayer.features).not.toBeNull();
71+
expect(graticuleLayer.options).not.toBeNull();
72+
done();
73+
}, 0);
74+
});
75+
76+
it('_initialize visible', (done) => {
77+
setTimeout(() => {
78+
expect(graticuleLayer).not.toBeNull();
79+
const graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_test', visible: false });
80+
graticuleLayer.onAdd(map);
81+
var visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
82+
expect(visible).toBe('false');
83+
done();
84+
}, 0);
85+
});
86+
87+
it('setVisibility', () => {
88+
graticuleLayer.setVisibility(false);
89+
var visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
90+
expect(visible).toBe('none');
91+
graticuleLayer.setVisibility(true);
92+
visible = map.getLayoutProperty('graticuleLayer_1_line', 'visibility');
93+
expect(visible).toBe('visible');
94+
});
95+
96+
it('setMinZoom', () => {
97+
graticuleLayer.setMinZoom(0);
98+
expect(graticuleLayer.options.minZoom).toEqual(0);
99+
});
100+
101+
it('setMaxZoom', () => {
102+
graticuleLayer.setMaxZoom(10);
103+
expect(graticuleLayer.options.maxZoom).toEqual(10);
104+
});
105+
106+
it('setShowLabel', () => {
107+
graticuleLayer.setShowLabel(false);
108+
expect(graticuleLayer.options.showLabel).toEqual(false);
109+
});
110+
111+
it('setExtent', () => {
112+
graticuleLayer.setExtent([
113+
[0, 0],
114+
[50, 50]
115+
]);
116+
expect(graticuleLayer.options.extent[0]).toEqual(0);
117+
expect(graticuleLayer.options.extent[3]).toEqual(50);
118+
});
119+
120+
it('setStrokeStyle', () => {
121+
graticuleLayer.setStrokeStyle({ lineWidth: 3 });
122+
expect(graticuleLayer.options.strokeStyle.lineWidth).toEqual(3);
123+
});
124+
125+
it('setLngLabelStyle', () => {
126+
graticuleLayer.setLngLabelStyle({ textSize: '12px' });
127+
expect(graticuleLayer.options.lngLabelStyle.textSize).toEqual('12px');
128+
});
129+
130+
it('setLatLabelStyle', () => {
131+
graticuleLayer.setLatLabelStyle({ textSize: '12px' });
132+
expect(graticuleLayer.options.latLabelStyle.textSize).toEqual('12px');
133+
});
134+
135+
it('setIntervals', () => {
136+
graticuleLayer.setIntervals(5);
137+
expect(graticuleLayer.renderer.options.interval).toEqual(5);
138+
});
139+
140+
it('_calcInterval', () => {
141+
const interval = map.getZoom();
142+
const calcInterval = (map) => {
143+
return map.getZoom();
144+
};
145+
graticuleLayer.renderer._calcInterval(calcInterval);
146+
expect(graticuleLayer.renderer._currLngInterval).toBe(interval);
147+
});
148+
149+
it('_getLatPoints', () => {
150+
const features = [
151+
{
152+
type: 'Feature',
153+
geometry: {
154+
coordinates: [
155+
[160, 80],
156+
[180, 80]
137157
],
138-
lngLatExtent: [
139-
-179.99999999999963,
140-
-85.05112877980658,
141-
179.99999999999963,
142-
85.05112877980656
143-
]
144-
};
145-
};
146-
var extent = graticuleLayer.getDefaultExtent();
147-
expect(extent).toEqual([
148-
-179.99999999999963,
149-
-85.05112877980658,
150-
179.99999999999963,
151-
85.05112877980656
152-
]);
153-
});
154-
155-
it('_calcInterval', () => {
156-
const interval = map.getZoom();
157-
const calcInterval = map => {
158-
return map.getZoom();
159-
};
160-
graticuleLayer.renderer._calcInterval(calcInterval);
161-
expect(graticuleLayer.renderer._currLngInterval).toBe(interval);
162-
});
163-
164-
it('_getLatPoints', () => {
165-
const features = [
166-
{
167-
type: 'Feature',
168-
geometry: {
169-
coordinates: [
170-
[160, 80],
171-
[180, 80]
172-
],
173-
type: 'LineString'
174-
}
175-
}
176-
];
177-
const points = graticuleLayer._getLatPoints([170, 180], '', 180, features);
178-
expect(points[0][0]).toEqual(180);
179-
expect(points[0][1]).toEqual(80);
180-
});
181-
182-
it('onRemove', () => {
183-
graticuleLayer.onRemove();
184-
expect(graticuleLayer.renderer.canvas).toBeNull();
185-
});
158+
type: 'LineString'
159+
}
160+
}
161+
];
162+
const points = graticuleLayer._getLatPoints([170, 180], '', 180, features);
163+
expect(points[0][0]).toEqual(180);
164+
expect(points[0][1]).toEqual(80);
165+
});
166+
167+
it('onRemove', () => {
168+
graticuleLayer.onRemove();
169+
expect(graticuleLayer.renderer.canvas).toBeNull();
170+
});
186171
});

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