Skip to content

Commit 021fd50

Browse files
committed
add missed spec for EPSG:9807
1 parent 3d21a2d commit 021fd50

File tree

1 file changed

+98
-36
lines changed

1 file changed

+98
-36
lines changed

packages/map/test/map/ProjectionSpec.js

Lines changed: 98 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Map.Projection', function () {
1010
container.style.height = '100px';
1111
document.body.appendChild(container);
1212
var option = {
13-
zoomAnimation:false,
13+
zoomAnimation: false,
1414
zoom: 17,
1515
center: center
1616
};
@@ -24,11 +24,11 @@ describe('Map.Projection', function () {
2424

2525
it('customize projection', function () {
2626
var custom = {
27-
project : function (c) {
27+
project: function (c) {
2828
return c.add(1, 1);
2929
},
3030

31-
unproject : function (c) {
31+
unproject: function (c) {
3232
return c.sub(1, 1);
3333
}
3434
};
@@ -43,10 +43,10 @@ describe('Map.Projection', function () {
4343
return resolutions;
4444
})(),
4545
'fullExtent': {
46-
'top' : 100000,
47-
'left' : 0,
48-
'right' : 100000,
49-
'bottom' : 0
46+
'top': 100000,
47+
'left': 0,
48+
'right': 100000,
49+
'bottom': 0
5050
}
5151
});
5252

@@ -71,15 +71,15 @@ describe('Map.Projection', function () {
7171
describe('change to EPSG:4326', function () {
7272
it('change to EPSG:4326', function () {
7373
map.setSpatialReference({
74-
projection:'EPSG:4326'
74+
projection: 'EPSG:4326'
7575
});
7676
expect(map.getProjection().code).to.be.eql('EPSG:4326');
7777
expect(map.getCenter()).to.closeTo(center);
7878
});
7979

8080
it('change to EPSG:4490', function () {
8181
map.setSpatialReference({
82-
projection:'EPSG:4490'
82+
projection: 'EPSG:4490'
8383
});
8484
expect(map.getProjection().code).to.be.eql('EPSG:4490');
8585
expect(map.getCenter()).to.closeTo(center);
@@ -89,8 +89,8 @@ describe('Map.Projection', function () {
8989
var newCenter = new maptalks.Coordinate(100, 0);
9090
map.setCenter(newCenter);
9191
map.config({
92-
spatialReference : {
93-
projection:'EPSG:4326'
92+
spatialReference: {
93+
projection: 'EPSG:4326'
9494
}
9595
});
9696
expect(map.getProjection().code).to.be.eql('EPSG:4326');
@@ -101,13 +101,13 @@ describe('Map.Projection', function () {
101101
describe('change to IDENTITY', function () {
102102
it('change to IDENTITY', function () {
103103
map.setSpatialReference({
104-
projection:'IDENTITY',
105-
resolutions : [1, 10, 20],
106-
fullExtent:{
107-
'top':0,
108-
'left':0,
109-
'bottom':1000000,
110-
'right':1000000
104+
projection: 'IDENTITY',
105+
resolutions: [1, 10, 20],
106+
fullExtent: {
107+
'top': 0,
108+
'left': 0,
109+
'bottom': 1000000,
110+
'right': 1000000
111111
}
112112
});
113113
expect(map.getProjection().code).to.be.eql('IDENTITY');
@@ -125,7 +125,7 @@ describe('Map.Projection', function () {
125125
it('fit to extent in IDENTITY projection', function () {
126126
// a bug reported by @1dent1ty in 2017-11-09
127127
map.setSpatialReference({
128-
projection:'identity',
128+
projection: 'identity',
129129
resolutions: [
130130
156543.03392804097,
131131
78271.51696402048,
@@ -148,50 +148,50 @@ describe('Map.Projection', function () {
148148
0.5971642834779395,
149149
0.29858214173896974
150150
],
151-
fullExtent : {
151+
fullExtent: {
152152
'top': 6378137 * Math.PI,
153153
'left': -6378137 * Math.PI,
154154
'bottom': -6378137 * Math.PI,
155155
'right': 6378137 * Math.PI
156156
}
157157
});
158-
map.setMaxExtent(new maptalks.Extent([453136.979,4078961.066,533971.862,4145348.864]));
158+
map.setMaxExtent(new maptalks.Extent([453136.979, 4078961.066, 533971.862, 4145348.864]));
159159
var z = map.getFitZoom(map.getMaxExtent());
160160
expect(z).to.be.eql(7);
161161
});
162162

163163
it('rotate polygon with IDENTITY projection, #726', function () {
164164
map.setSpatialReference({
165-
projection:'IDENTITY',
166-
resolutions : [1, 10, 20],
167-
fullExtent:{
168-
'top':0,
169-
'left':0,
170-
'bottom':1000000,
171-
'right':1000000
165+
projection: 'IDENTITY',
166+
resolutions: [1, 10, 20],
167+
fullExtent: {
168+
'top': 0,
169+
'left': 0,
170+
'bottom': 1000000,
171+
'right': 1000000
172172
}
173173
});
174174

175175
var vecLayer = new maptalks.VectorLayer('field').addTo(map);
176-
var baseGeom = new maptalks.Polygon([[[0,0],[0,20],[20,30],[20,0]]], {
177-
symbol : {
178-
lineWidth : 2,
179-
lineColor : '#000',
180-
polygonFill : 'rgb(129, 0, 0)'
176+
var baseGeom = new maptalks.Polygon([[[0, 0], [0, 20], [20, 30], [20, 0]]], {
177+
symbol: {
178+
lineWidth: 2,
179+
lineColor: '#000',
180+
polygonFill: 'rgb(129, 0, 0)'
181181
}
182182
})
183183
baseGeom.copy().addTo(vecLayer)
184-
.translate(90,90)
184+
.translate(90, 90)
185185
.rotate(30).rotate(30).rotate(30);
186-
var geojson = {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[0,0],[0,20],[20,30],[20,0],[0,0]]]},"properties":null};
186+
var geojson = { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[[0, 0], [0, 20], [20, 30], [20, 0], [0, 0]]] }, "properties": null };
187187
expect(baseGeom.toGeoJSON()).to.be.eqlGeoJSON(geojson);
188188
});
189189
});
190190

191191
describe('change to Baidu', function () {
192192
it('change to baidu', function () {
193193
map.setSpatialReference({
194-
projection:'baidu'
194+
projection: 'baidu'
195195
});
196196
map.options['minZoom'] = null;
197197
expect(map.getMinZoom()).to.be.eql(0);
@@ -206,6 +206,68 @@ describe('Map.Projection', function () {
206206
});
207207
});
208208

209+
describe('EPSG:9807 projection', function () {
210+
it('EPSG:9807 project and unproject', function () {
211+
//china suzhou
212+
var spatialReference = {
213+
projection: {
214+
code: 'EPSG:9807',
215+
// zone: 51,
216+
// code: 'utm',
217+
falseEasting: 350000,
218+
falseNorthing: -2800000,
219+
scaleFactor: 1,
220+
centralMeridian: 120.7833333333333,
221+
latitudeOfOrigin: 0
222+
223+
224+
},
225+
resolutions: (function () {
226+
// let res = Math.pow(2, 8);
227+
const RES = 156367.78906250003;
228+
229+
const resolutions = [];
230+
for (let i = 0; i <= 20; i++) {
231+
resolutions.push(RES / Math.pow(2, i));
232+
}
233+
// for (let i = 0; i < 23; i++) {
234+
// resolutions[i] = res;
235+
// res *= 0.5;
236+
// }
237+
return resolutions;
238+
})(),
239+
fullExtent: {
240+
"left": -38219.52622692019,
241+
"bottom": 545398.8815674061,
242+
"right": 882668.8582661198,
243+
"top": 913228.7641038558,
244+
}
245+
};
246+
map.remove();
247+
map = new maptalks.Map(container, {
248+
"center": [120.7056647, 31.31506313], "zoom": 14.698865640099315, "pitch": 0, "bearing": 0,
249+
spatialReference,
250+
zoomControl: true
251+
});
252+
// var center = map.getCenter();
253+
var projection = map.getProjection();
254+
255+
256+
var pj0 = projection.project(map.getCenter());
257+
258+
259+
expect(pj0.toArray()).to.be.eql([342606.8132459836, 665908.6630797521]);
260+
261+
// left bottom
262+
var pp0 = projection.unproject(new maptalks.Coordinate([-38219.52622692019, 545398.8815674061]))
263+
264+
265+
expect(pp0.toArray()).to.be.eql([116.75468490333797, 30.166163498493603]);
266+
267+
});
268+
});
269+
270+
209271
describe('utm projection', function () {
210272
it('utm project and unproject', function () {
211273
var spatialReference = {

0 commit comments

Comments
 (0)