Skip to content

Commit 159c6d5

Browse files
committed
fix GraticuleLayer UT; review by qiw
1 parent e2b0ac5 commit 159c6d5

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

src/common/overlay/graticule/GraticuleLayerRenderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class GraticuleLayerRenderer {
7676
this.getMapStateByKey = callbackOptions.getMapStateByKey;
7777
this.getDefaultExtent = callbackOptions.getDefaultExtent;
7878
this.setVisibility = callbackOptions.setVisibility;
79+
this._updateGraticuleLayer = callbackOptions._updateGraticuleLayer;
7980
this.init();
8081
}
8182

src/mapboxgl/overlay/GraticuleLayer.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class GraticuleLayer {
104104
this.renderer = new GraticuleLayerRenderer(this.map, this.options, {
105105
getMapStateByKey: this.getMapStateByKey,
106106
getDefaultExtent: this.getDefaultExtent,
107+
updateGraticuleLayer: this._updateGraticuleLayer.bind(this),
107108
setVisibility: this.setVisibility.bind(this)
108109
}, {
109110
mapCanvas: this.map.getCanvas(),
@@ -132,7 +133,7 @@ export class GraticuleLayer {
132133
}
133134

134135
onRemove() {
135-
this.mapContainer.removeChild(this.canvas);
136+
this.renderer.onRemove();
136137
this._unbindEvent();
137138
}
138139

@@ -152,7 +153,7 @@ export class GraticuleLayer {
152153
this.renderer.visible = this.visible;
153154
}
154155
if (this.map.getLayer(this.sourceId)) {
155-
this.map.setLayoutProperty(this.sourceId, 'visibility', this.renderer.visible ? 'visible' : 'none');
156+
this.map.setLayoutProperty(this.sourceId, 'visibility', this.visible ? 'visible' : 'none');
156157
}
157158
this.renderer && this.renderer._drawLabel();
158159
}
@@ -193,7 +194,7 @@ export class GraticuleLayer {
193194
* @param {mapboxgl.LngLatBounds} extent - 经纬网渲染的边界范围。
194195
*/
195196
setExtent(extent) {
196-
this.options.extent = this._getDefaultExtent(extent, this.map);
197+
this.options.extent = this.getDefaultExtent(extent, this.map);
197198
// this.features = this._getGraticuleFeatures();
198199
this._updateGraticuleLayer();
199200
this.renderer._drawLabel();
@@ -249,6 +250,10 @@ export class GraticuleLayer {
249250
}
250251
}
251252

253+
_getLatPoints(lngRange, firstLng, lastLng, features) {
254+
return this.renderer._getLatPoints(lngRange, firstLng, lastLng, features);
255+
}
256+
252257
_bindEvent() {
253258
this.map.on('styledata', this.styleDataEevent);
254259
this.map.on('resize', this.resizeEvent);

src/maplibregl/overlay/GraticuleLayer.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class GraticuleLayer {
104104
this.renderer = new GraticuleLayerRenderer(this.map, this.options, {
105105
getMapStateByKey: this.getMapStateByKey,
106106
getDefaultExtent: this.getDefaultExtent,
107+
_updateGraticuleLayer: this._updateGraticuleLayer.bind(this),
107108
setVisibility: this.setVisibility.bind(this)
108109
}, {
109110
mapCanvas: this.map.getCanvas(),
@@ -132,7 +133,7 @@ export class GraticuleLayer {
132133
}
133134

134135
onRemove() {
135-
this.mapContainer.removeChild(this.canvas);
136+
this.renderer.onRemove();
136137
this._unbindEvent();
137138
}
138139

@@ -152,7 +153,7 @@ export class GraticuleLayer {
152153
this.renderer.visible = this.visible;
153154
}
154155
if (this.map.getLayer(this.sourceId)) {
155-
this.map.setLayoutProperty(this.sourceId, 'visibility', this.renderer.visible ? 'visible' : 'none');
156+
this.map.setLayoutProperty(this.sourceId, 'visibility', this.visible ? 'visible' : 'none');
156157
}
157158
this.renderer && this.renderer._drawLabel();
158159
}
@@ -193,7 +194,7 @@ export class GraticuleLayer {
193194
* @param {maplibregl.LngLatBounds} extent - 经纬网渲染的边界范围。
194195
*/
195196
setExtent(extent) {
196-
this.options.extent = this._getDefaultExtent(extent, this.map);
197+
this.options.extent = this.getDefaultExtent(extent, this.map);
197198
// this.features = this._getGraticuleFeatures();
198199
this._updateGraticuleLayer();
199200
this.renderer._drawLabel();
@@ -279,6 +280,10 @@ export class GraticuleLayer {
279280
}
280281
}
281282

283+
_getLatPoints(lngRange, firstLng, lastLng, features) {
284+
return this.renderer._getLatPoints(lngRange, firstLng, lastLng, features);
285+
}
286+
282287
getDefaultExtent(extent, map = this.map) {
283288
const crs = (map.getCRS && map.getCRS()) || {};
284289
let { extent: crsExtent } = crs;

test/mapboxgl/overlay/GraticuleLayerSpec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('mapboxgl_GraticuleLayer', () => {
6464
it('_initialize', done => {
6565
setTimeout(() => {
6666
expect(graticuleLayer).not.toBeNull();
67-
expect(graticuleLayer.canvas).not.toBeNull();
67+
expect(graticuleLayer.renderer.canvas).not.toBeNull();
6868
expect(graticuleLayer.map).not.toBeNull();
6969
expect(graticuleLayer.mapContainer).not.toBeNull();
7070
expect(graticuleLayer.features).not.toBeNull();
@@ -123,16 +123,16 @@ describe('mapboxgl_GraticuleLayer', () => {
123123

124124
it('setIntervals', () => {
125125
graticuleLayer.setIntervals(5);
126-
expect(graticuleLayer.options.interval).toEqual(5);
126+
expect(graticuleLayer.renderer.options.interval).toEqual(5);
127127
});
128128

129129
it('_calcInterval', () => {
130130
const interval = map.getZoom();
131131
const calcInterval = map => {
132132
return map.getZoom();
133133
};
134-
graticuleLayer._calcInterval(calcInterval);
135-
expect(graticuleLayer._currLngInterval).toBe(interval);
134+
graticuleLayer.renderer._calcInterval(calcInterval);
135+
expect(graticuleLayer.renderer._currLngInterval).toBe(interval);
136136
});
137137

138138
it('_getLatPoints', () => {
@@ -153,8 +153,8 @@ describe('mapboxgl_GraticuleLayer', () => {
153153
expect(points[0][1]).toEqual(80);
154154
});
155155

156-
it('removeFromMap', () => {
157-
graticuleLayer.removeFromMap();
158-
expect(graticuleLayer.canvas).toBeNull();
156+
it('onRemove', () => {
157+
graticuleLayer.onRemove();
158+
expect(graticuleLayer.renderer.canvas).toBeNull();
159159
});
160160
});

test/maplibregl/overlay/GraticuleLayerSpec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('maplibregl_GraticuleLayer', () => {
6464
it('_initialize', done => {
6565
setTimeout(() => {
6666
expect(graticuleLayer).not.toBeNull();
67-
expect(graticuleLayer.canvas).not.toBeNull();
67+
expect(graticuleLayer.renderer.canvas).not.toBeNull();
6868
expect(graticuleLayer.map).not.toBeNull();
6969
expect(graticuleLayer.mapContainer).not.toBeNull();
7070
expect(graticuleLayer.features).not.toBeNull();
@@ -108,7 +108,7 @@ describe('maplibregl_GraticuleLayer', () => {
108108

109109
it('setStrokeStyle', () => {
110110
graticuleLayer.setStrokeStyle({ lineWidth: 3 });
111-
expect(graticuleLayer.renderer.options.strokeStyle.lineWidth).toEqual(3);
111+
expect(graticuleLayer.options.strokeStyle.lineWidth).toEqual(3);
112112
});
113113

114114
it('setLngLabelStyle', () => {
@@ -131,7 +131,7 @@ describe('maplibregl_GraticuleLayer', () => {
131131
const calcInterval = map => {
132132
return map.getZoom();
133133
};
134-
graticuleLayer._calcInterval(calcInterval);
134+
graticuleLayer.renderer._calcInterval(calcInterval);
135135
expect(graticuleLayer.renderer._currLngInterval).toBe(interval);
136136
});
137137

@@ -153,8 +153,8 @@ describe('maplibregl_GraticuleLayer', () => {
153153
expect(points[0][1]).toEqual(80);
154154
});
155155

156-
it('removeFromMap', () => {
157-
graticuleLayer.removeFromMap();
156+
it('onRemove', () => {
157+
graticuleLayer.onRemove();
158158
expect(graticuleLayer.renderer.canvas).toBeNull();
159159
});
160160
});

0 commit comments

Comments
 (0)