Skip to content

Commit 06e7872

Browse files
【fix】 修复经纬网图层获取extent 错误
1 parent cf794e8 commit 06e7872

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

src/mapboxgl/overlay/GraticuleLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export class GraticuleLayer {
255255

256256
getDefaultExtent(extent, map = this.map) {
257257
const crs = (map.getCRS && map.getCRS()) || {};
258-
let { extent: crsExtent } = crs;
258+
let { lngLatExtent: crsExtent } = crs;
259259
if (!crsExtent) {
260260
crsExtent = [-180, -85.05119, 180, 85.05119];
261261
}

src/maplibregl/overlay/GraticuleLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class GraticuleLayer {
267267

268268
getDefaultExtent(extent, map = this.map) {
269269
const crs = (map.getCRS && map.getCRS()) || {};
270-
let { extent: crsExtent } = crs;
270+
let { lngLatExtent: crsExtent } = crs;
271271
if (!crsExtent) {
272272
crsExtent = [-180, -85.05119, 180, 85.05119];
273273
}

test/mapboxgl/overlay/GraticuleLayerSpec.js

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

66
describe('mapboxgl_GraticuleLayer', () => {
@@ -72,7 +72,7 @@ describe('mapboxgl_GraticuleLayer', () => {
7272
done();
7373
}, 0);
7474
});
75-
75+
7676
it('_initialize visible', (done) => {
7777
setTimeout(() => {
7878
const graticuleLayer = new GraticuleLayer({ layerID: 'graticuleLayer_test', visible: false });
@@ -136,6 +136,32 @@ describe('mapboxgl_GraticuleLayer', () => {
136136
expect(graticuleLayer.renderer.options.interval).toEqual(5);
137137
});
138138

139+
it('getDefaultExtent must return degree', () => {
140+
map.getCRS = () => {
141+
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+
]
154+
};
155+
};
156+
var extent = graticuleLayer.getDefaultExtent();
157+
expect(extent).toEqual([
158+
-179.99999999999963,
159+
-85.05112877980658,
160+
179.99999999999963,
161+
85.05112877980656
162+
]);
163+
});
164+
139165
it('_calcInterval', () => {
140166
const interval = map.getZoom();
141167
const calcInterval = (map) => {

test/maplibregl/overlay/GraticuleLayerSpec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ describe('maplibregl_GraticuleLayer', () => {
8484
expect(visible).toBe('visible');
8585
});
8686

87+
it('getDefaultExtent must return degree', () => {
88+
map.getCRS = () => {
89+
return {
90+
extent: [
91+
-20037508.3427892,
92+
-20037508.3427892,
93+
20037508.3427892,
94+
20037508.3427892
95+
],
96+
lngLatExtent: [
97+
-179.99999999999963,
98+
-85.05112877980658,
99+
179.99999999999963,
100+
85.05112877980656
101+
]
102+
};
103+
};
104+
var extent = graticuleLayer.getDefaultExtent();
105+
expect(extent).toEqual([
106+
-179.99999999999963,
107+
-85.05112877980658,
108+
179.99999999999963,
109+
85.05112877980656
110+
]);
111+
});
112+
87113
it('setMinZoom', () => {
88114
graticuleLayer.setMinZoom(0);
89115
expect(graticuleLayer.options.minZoom).toEqual(0);

0 commit comments

Comments
 (0)