Skip to content

Commit d72150f

Browse files
authored
Increase the level of the default space reference (#1276)
* Increase the level of the default space reference * update test case * update ImageLayerSpec opacity test case * debug imagelayer test case * update spec abount imagelayer * update TextBox spec * ua lib offline
1 parent 2b2ee8c commit d72150f

File tree

8 files changed

+131
-96
lines changed

8 files changed

+131
-96
lines changed

build/karma.base.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module.exports = {
33
basePath: '..',
44
client: {
55
mocha: {
6-
timeout : 8000
6+
timeout: 8000
77
}
88
},
9-
files : [
9+
files: [
1010
'dist/maptalks.js',
11+
// js for UA
12+
'test/resources/ua-parser.min.js',
1113
//js for TileOffsetSpec.js
1214
'test/resources/chncrs.js',
1315
'test/core/ClassSpec.js',

src/map/spatial-reference/SpatialReference.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import Extent from '../../geo/Extent';
44
import * as projections from '../../geo/projection';
55
import Transformation from '../../geo/transformation/Transformation';
66
import { Measurer } from '../../geo/measurer';
7+
const MAX_ZOOM = 23;
78

89
const DefaultSpatialReference = {
910
'EPSG:3857': {
1011
'resolutions': (function () {
1112
const resolutions = [];
1213
const d = 2 * 6378137 * Math.PI;
13-
for (let i = 0; i < 21; i++) {
14+
for (let i = 0; i < MAX_ZOOM; i++) {
1415
resolutions[i] = d / (256 * Math.pow(2, i));
1516
}
1617
return resolutions;
@@ -31,7 +32,7 @@ const DefaultSpatialReference = {
3132
},
3233
'resolutions': (function () {
3334
const resolutions = [];
34-
for (let i = 0; i < 20; i++) {
35+
for (let i = 0; i < MAX_ZOOM; i++) {
3536
resolutions[i] = 180 / (Math.pow(2, i) * 128);
3637
}
3738
return resolutions;
@@ -41,7 +42,7 @@ const DefaultSpatialReference = {
4142
'resolutions': (function () {
4243
let res = Math.pow(2, 18);
4344
const resolutions = [];
44-
for (let i = 0; i < 20; i++) {
45+
for (let i = 0; i < MAX_ZOOM; i++) {
4546
resolutions[i] = res;
4647
res *= 0.5;
4748
}
@@ -54,11 +55,11 @@ const DefaultSpatialReference = {
5455
'right': 33554432
5556
}
5657
},
57-
'IDENTITY' : {
58+
'IDENTITY': {
5859
'resolutions': (function () {
5960
let res = Math.pow(2, 8);
6061
const resolutions = [];
61-
for (let i = 0; i < 18; i++) {
62+
for (let i = 0; i < MAX_ZOOM; i++) {
6263
resolutions[i] = res;
6364
res *= 0.5;
6465
}
@@ -258,14 +259,14 @@ export default class SpatialReference {
258259
toJSON() {
259260
if (!this.json) {
260261
this.json = {
261-
'resolutions' : this._resolutions,
262-
'fullExtent' : {
262+
'resolutions': this._resolutions,
263+
'fullExtent': {
263264
'top': this._fullExtent.top,
264265
'left': this._fullExtent.left,
265266
'bottom': this._fullExtent.bottom,
266267
'right': this._fullExtent.right
267268
},
268-
'projection' : this._projection.code
269+
'projection': this._projection.code
269270
};
270271
}
271272
return this.json;

test/geometry/TextBoxSpec.js

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('Geometry.TextBox', function () {
77

88
beforeEach(function () {
99
var setups = COMMON_CREATE_MAP(center, null, {
10-
width : 800,
11-
height : 600
10+
width: 800,
11+
height: 600
1212
});
1313
container = setups.container;
1414
map = setups.map;
@@ -69,10 +69,10 @@ describe('Geometry.TextBox', function () {
6969
var content = '中文标签';
7070
var vector = new maptalks.TextBox(content, center, 100, 40);
7171
var textStyle = {
72-
'wrap' : true,
73-
'padding' : [12, 8],
74-
'verticalAlignment' : 'middle',
75-
'horizontalAlignment' : 'middle'
72+
'wrap': true,
73+
'padding': [12, 8],
74+
'verticalAlignment': 'middle',
75+
'horizontalAlignment': 'middle'
7676
};
7777
vector.setTextStyle(textStyle);
7878
//default textalign
@@ -162,19 +162,19 @@ describe('Geometry.TextBox', function () {
162162
var padding = [12, 8];
163163
it('left', function () {
164164
var vector = new maptalks.TextBox('■■■', center, 100, 100, {
165-
textStyle : {
166-
'wrap' : true,
167-
'padding' : padding,
168-
'verticalAlignment' : 'middle',
169-
'horizontalAlignment' : 'left'
165+
textStyle: {
166+
'wrap': true,
167+
'padding': padding,
168+
'verticalAlignment': 'middle',
169+
'horizontalAlignment': 'left'
170170
},
171-
boxSymbol : {
172-
'markerType' : 'square',
173-
'markerFillOpacity' : 0,
174-
'markerLineOpacity' : 0
171+
boxSymbol: {
172+
'markerType': 'square',
173+
'markerFillOpacity': 0,
174+
'markerLineOpacity': 0
175175
}
176176
});
177-
layer = new maptalks.VectorLayer('id', { 'drawImmediate' : true });
177+
layer = new maptalks.VectorLayer('id', { 'drawImmediate': true });
178178
map.addLayer(layer);
179179
layer.addGeometry(vector);
180180
expect(layer).to.be.painted(-100 / 2 + padding[0] + 1, 0);
@@ -184,19 +184,19 @@ describe('Geometry.TextBox', function () {
184184

185185
it('right', function () {
186186
var vector = new maptalks.TextBox('■■■', center, 100, 100, {
187-
textStyle : {
188-
'wrap' : true,
189-
'padding' : padding,
190-
'verticalAlignment' : 'middle',
191-
'horizontalAlignment' : 'right'
187+
textStyle: {
188+
'wrap': true,
189+
'padding': padding,
190+
'verticalAlignment': 'middle',
191+
'horizontalAlignment': 'right'
192192
},
193-
boxSymbol : {
194-
'markerType' : 'square',
195-
'markerFillOpacity' : 0,
196-
'markerLineOpacity' : 0
193+
boxSymbol: {
194+
'markerType': 'square',
195+
'markerFillOpacity': 0,
196+
'markerLineOpacity': 0
197197
}
198198
});
199-
layer = new maptalks.VectorLayer('id', { 'drawImmediate' : true });
199+
layer = new maptalks.VectorLayer('id', { 'drawImmediate': true });
200200
map.addLayer(layer);
201201
layer.addGeometry(vector);
202202
expect(layer).to.be.painted(100 / 2 - padding[0] - 2, 0);
@@ -206,19 +206,19 @@ describe('Geometry.TextBox', function () {
206206

207207
it('top', function () {
208208
var vector = new maptalks.TextBox('■■■', center, 100, 100, {
209-
textStyle : {
210-
'wrap' : true,
211-
'padding' : padding,
212-
'verticalAlignment' : 'top',
213-
'horizontalAlignment' : 'middle'
209+
textStyle: {
210+
'wrap': true,
211+
'padding': padding,
212+
'verticalAlignment': 'top',
213+
'horizontalAlignment': 'middle'
214214
},
215-
boxSymbol : {
216-
'markerType' : 'square',
217-
'markerFillOpacity' : 0,
218-
'markerLineOpacity' : 0
215+
boxSymbol: {
216+
'markerType': 'square',
217+
'markerFillOpacity': 0,
218+
'markerLineOpacity': 0
219219
}
220220
});
221-
layer = new maptalks.VectorLayer('id', { 'drawImmediate' : true });
221+
layer = new maptalks.VectorLayer('id', { 'drawImmediate': true });
222222
map.addLayer(layer);
223223
layer.addGeometry(vector);
224224
expect(layer).to.be.painted(0, -100 / 2 + padding[1] + 7);
@@ -230,22 +230,32 @@ describe('Geometry.TextBox', function () {
230230
return;
231231
}
232232
var vector = new maptalks.TextBox('■■■', center, 100, 100, {
233-
textStyle : {
234-
'wrap' : true,
235-
'padding' : padding,
236-
'verticalAlignment' : 'bottom',
237-
'horizontalAlignment' : 'middle'
233+
textStyle: {
234+
'wrap': true,
235+
'padding': padding,
236+
'verticalAlignment': 'bottom',
237+
'horizontalAlignment': 'middle'
238238
},
239-
boxSymbol : {
240-
'markerType' : 'square',
241-
'markerFillOpacity' : 0,
242-
'markerLineOpacity' : 0
239+
boxSymbol: {
240+
'markerType': 'square',
241+
'markerFillOpacity': 0,
242+
'markerLineOpacity': 0
243243
}
244244
});
245-
layer = new maptalks.VectorLayer('id', { 'drawImmediate' : true });
245+
layer = new maptalks.VectorLayer('id', { 'drawImmediate': true });
246246
map.addLayer(layer);
247247
layer.addGeometry(vector);
248-
expect(layer).to.be.painted(0, 100 / 2 - padding[1] - 9);
248+
var parser = new UAParser();
249+
var offset = 8;
250+
var result = parser.getOS();
251+
console.log(result);
252+
if (result.name) {
253+
if (result.name.toLowerCase().indexOf('linux') > -1) {
254+
offset = 9;
255+
}
256+
}
257+
258+
expect(layer).to.be.painted(0, 100 / 2 - padding[1] - offset);
249259
expect(layer).not.be.painted();
250260
});
251261
});
@@ -316,7 +326,7 @@ describe('Geometry.TextBox', function () {
316326
});
317327

318328
it('JSON of previous version\'s TextBox', function () {
319-
var json = {"content":"岭南站/SM/A","feature":{"geometry":{"coordinates":[113.120816,23.033914],"type":"Point"},"id":"NWP_LABEL_3","type":"Feature"},"options":{"boxAutoSize":true,"boxMinHeight":30,"boxMinWidth":100,"boxPadding":{"height":8,"width":15},"draggable":true,"visible":true,"zIndex":1},"subType":"TextBox","symbol":{"markerFill":"#ffffff","markerFillOpacity":1,"markerHeight":40,"markerLineColor":"#cccccc","markerLineOpacity":0.8,"markerLineWidth":1,"markerOpacity":0.8,"markerType":"square","markerWidth":140,"opacity":1,"textDx":0,"textDy":0,"textFaceName":"microsoft yahei","textFill":"#000000","textHorizontalAlignment":"middle","textLineSpacing":1,"textName":"岭南站/SM/A","textOpacity":0.8,"textSize":18,"textSpacing":0,"textVerticalAlignment":"middle","textWrapBefore":false,"textWrapCharacter":"\n"}};
329+
var json = { "content": "岭南站/SM/A", "feature": { "geometry": { "coordinates": [113.120816, 23.033914], "type": "Point" }, "id": "NWP_LABEL_3", "type": "Feature" }, "options": { "boxAutoSize": true, "boxMinHeight": 30, "boxMinWidth": 100, "boxPadding": { "height": 8, "width": 15 }, "draggable": true, "visible": true, "zIndex": 1 }, "subType": "TextBox", "symbol": { "markerFill": "#ffffff", "markerFillOpacity": 1, "markerHeight": 40, "markerLineColor": "#cccccc", "markerLineOpacity": 0.8, "markerLineWidth": 1, "markerOpacity": 0.8, "markerType": "square", "markerWidth": 140, "opacity": 1, "textDx": 0, "textDy": 0, "textFaceName": "microsoft yahei", "textFill": "#000000", "textHorizontalAlignment": "middle", "textLineSpacing": 1, "textName": "岭南站/SM/A", "textOpacity": 0.8, "textSize": 18, "textSpacing": 0, "textVerticalAlignment": "middle", "textWrapBefore": false, "textWrapCharacter": "\n" } };
320330
var textBox = maptalks.Geometry.fromJSON(json);
321331
expect(textBox instanceof maptalks.TextBox).to.be.ok();
322332
expect(maptalks.Util.extend({}, textBox.getTextStyle().symbol, textBox.getBoxSymbol())).to.be.eql(json.symbol);

0 commit comments

Comments
 (0)