Skip to content

Commit 3b64e53

Browse files
committed
【fix】升级xlsx 修复leaflet平面无投影设置非2倍关系的固定比例尺时不起作用的问题 review by luoxiao
1 parent 9cf9214 commit 3b64e53

File tree

9 files changed

+30
-16
lines changed

9 files changed

+30
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"proj4": "2.6.3",
133133
"promise-polyfill": "8.2.0",
134134
"three": "0.126.1",
135-
"xlsx": "0.16.9",
135+
"xlsx": "0.17.0",
136136
"xml-js": "1.6.11"
137137
},
138138
"pre-commit": [

src/classic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"license": "Apache-2.0",
1515
"dependencies": {
1616
"mapv": "2.0.62",
17-
"xlsx": "0.16.9",
17+
"xlsx": "0.17.0",
1818
"@supermap/iclient-common": "11.0.0-beta"
1919
}
2020
}

src/leaflet/core/NonEarthCRS.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ export var NonEarthCRS = L.Class.extend({
6969
if (!this.resolutions || this.resolutions.length === 0) {
7070
const width = Math.max(this.bounds.getSize().x, this.bounds.getSize().y);
7171
defaultScale = 1.0 / (width / 256);
72-
} else {
73-
defaultScale = 1.0 / this.resolutions[0];
72+
return defaultScale * Math.pow(2, zoom);
7473
}
75-
return defaultScale * Math.pow(2, zoom);
74+
if (this.resolutions[zoom]) {
75+
return 1.0 / this.resolutions[zoom];
76+
}
77+
return (1.0 / this.resolutions[0]) * Math.pow(2, zoom);
7678
},
7779

7880
/**
@@ -86,10 +88,13 @@ export var NonEarthCRS = L.Class.extend({
8688
if (!this.resolutions || this.resolutions.length === 0) {
8789
const width = Math.max(this.bounds.getSize().x, this.bounds.getSize().y);
8890
defaultScale = 1.0 / (width / 256);
89-
} else {
90-
defaultScale = 1.0 / this.resolutions[0];
91+
return Math.log(scale / defaultScale) / Math.LN2;
92+
}
93+
const index = this.resolutions.indexOf(1.0 / scale);
94+
if (index > -1) {
95+
return index;
9196
}
92-
return Math.log(scale / defaultScale) / Math.LN2;
97+
return Math.log(scale / (1.0 / this.resolutions[0])) / Math.LN2;
9398
},
9499
/**
95100
* @function L.CRS.NonEarthCRS.prototype.distance

src/leaflet/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export var toSuperMapGeometry = function(geometry) {
2929
result = geojson ? format.read(geojson, geojson.type) : geometry;
3030
}
3131

32-
var serverResult = result;
32+
var serverResult = result || geometry;
3333
if (L.Util.isArray(result)) {
3434
if (result.length === 1) {
3535
serverResult = result[0];

src/leaflet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
"jsonsql": "0.2.5",
2424
"pbf": "3.2.1",
2525
"proj4": "2.6.3",
26-
"xlsx": "0.16.9"
26+
"xlsx": "0.17.0"
2727
}
2828
}

src/mapboxgl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"mapv": "2.0.62",
1919
"mapbox-gl": "1.12.0",
2020
"three": "0.126.1",
21-
"xlsx": "0.16.9",
21+
"xlsx": "0.17.0",
2222
"@supermap/iclient-common": "11.0.0-beta",
2323
"canvg": "3.0.7",
2424
"xml-js": "1.6.11"

src/openlayers/mapping/WebMap.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class WebMap extends Observable {
368368
let that = this, handleResult = {};
369369
let newCrs = crs, action = "OpenMap";
370370

371-
if (crs === "EPSG:-1") {
371+
if (this.isCustomProjection(crs)) {
372372
// 去iServer请求wkt 否则只能预览出图
373373
await FetchRequest.get(that.getRequestUrl(`${baseLayerUrl}/prjCoordSys.wkt`), null, {
374374
withCredentials: that.withCredentials,
@@ -377,7 +377,7 @@ export class WebMap extends Observable {
377377
return response.text();
378378
}).then(async function (result) {
379379
if(result.indexOf("<!doctype html>") === -1) {
380-
that.addProjctionFromWKT(result, "EPSG:-1");
380+
that.addProjctionFromWKT(result, crs);
381381
handleResult = {action, newCrs};
382382
} else {
383383
throw 'ERROR';
@@ -1140,7 +1140,7 @@ export class WebMap extends Observable {
11401140
// prjCoordSys: {epsgCode: isBaseLayer ? layerInfo.projection.split(':')[1] : this.baseProjection.split(':')[1]},
11411141
format: layerInfo.format
11421142
};
1143-
if(!isBaseLayer && this.baseProjection !== "EPSG:-1"){
1143+
if(!isBaseLayer && !this.isCustomProjection(this.baseProjection )){
11441144
options.prjCoordSys = { epsgCode : this.baseProjection.split(':')[1]};
11451145
}
11461146
if (layerInfo.visibleScales && layerInfo.visibleScales.length > 0) {
@@ -1343,7 +1343,7 @@ export class WebMap extends Observable {
13431343
let projection = {
13441344
epsgCode: that.baseProjection.split(":")[1]
13451345
}
1346-
if (that.baseProjection !== "EPSG:-1") {
1346+
if (!that.isCustomProjection(that.baseProjection)) {
13471347
// bug IE11 不会自动编码
13481348
url += '.json?prjCoordSys=' + encodeURI(JSON.stringify(projection));
13491349
}
@@ -5122,4 +5122,10 @@ export class WebMap extends Observable {
51225122
}
51235123
return lang;
51245124
}
5125+
isCustomProjection(projection) {
5126+
if(Util.isNumber(projection)){
5127+
return [-1000,-1].includes(+projection)
5128+
}
5129+
return ['EPSG:-1000','EPSG:-1'].includes(projection);
5130+
}
51255131
}

src/openlayers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"ol": "6.4.3",
2121
"@supermap/iclient-common": "11.0.0-beta",
2222
"proj4": "2.6.3",
23-
"xlsx": "0.16.9",
23+
"xlsx": "0.17.0",
2424
"canvg": "3.0.7",
2525
"lodash.remove": "^4.7.0"
2626
}

test/leaflet/core/NonEarthCRSSpec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ describe('leaflet_NonEarthCRS', () => {
4040
expect(nonEarthCRSObject.projection.bounds).toEqual(nonEarthCRSObject.bounds);
4141
expect(nonEarthCRSObject.resolutions[0]).toEqual(1000);
4242
expect(nonEarthCRSObject.resolutions[1]).toEqual(100000);
43+
expect(nonEarthCRSObject.scale(0)).toEqual(1/1000);
44+
expect(nonEarthCRSObject.scale(1)).toEqual(1/100000);
45+
expect(nonEarthCRSObject.zoom(1/1000)).toEqual(0);
4346
expect(nonEarthCRSObject.transformation).not.toBeNull();
4447
expect(nonEarthCRSObject._initHooksCalled).toBeTruthy();
4548
});

0 commit comments

Comments
 (0)