Skip to content

Commit 1850362

Browse files
committed
优化 leaflet CRS
1 parent 2efc688 commit 1850362

File tree

11 files changed

+1355
-1293
lines changed

11 files changed

+1355
-1293
lines changed

dist/iclient9-leaflet.js

Lines changed: 1307 additions & 1261 deletions
Large diffs are not rendered by default.

dist/iclient9-leaflet.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/iclient9-openlayers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51212,7 +51212,7 @@ var MapvCanvasLayer = function () {
5121251212

5121351213
/*
5121451214
* @function ol.supermap.MapvCanvasLayer.prototype.resize
51215-
* @param mapWidth - {number} ��ͼ���
51215+
* @param mapWidth - {number} ��ͼ���
5121651216
* @param mapHeight - {number} ��ͼ�߶�
5121751217
* @description ������ͼ��С
5121851218
*/
@@ -51240,7 +51240,7 @@ var MapvCanvasLayer = function () {
5124051240
/*
5124151241
* @function ol.supermap.MapvCanvasLayer.prototype.setZIndex
5124251242
* @param zIndex - {number} �㼶����
51243-
* @description ����ͼ��㼶
51243+
* @description ����ͼ��
5124451244
*/
5124551245

5124651246
}, {
@@ -51250,7 +51250,7 @@ var MapvCanvasLayer = function () {
5125051250
}
5125151251
/*
5125251252
* @function ol.supermap.MapvCanvasLayer.prototype.getZIndex
51253-
* @description ��ȡͼ��㼶
51253+
* @description ��ȡͼ��
5125451254
*/
5125551255

5125651256
}, {

examples/leaflet/01_tiledMapLayerProj4.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
</head>
99
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
1010
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
11-
11+
<!--[if lte IE 8]>
12+
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default-3.3&excludes=Event"></script>
13+
<![endif]-->
1214
<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.js"></script>
1315
<script type="text/javascript" src="../../dist/iclient9-leaflet.min.js"></script>
1416
<script type="text/javascript">
@@ -17,7 +19,7 @@
1719
var scaleDenominators = [100000, 50000, 25000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 1];
1820
var origin = [114.59, 42.31];
1921
//leaflet CRS投影设置
20-
var crs = new L.Proj.CRS("EPSG:4326", '', {
22+
var crs = L.Proj.CRS("EPSG:4326", {
2123
origin: origin,
2224
scaleDenominators: scaleDenominators
2325
});

examples/leaflet/WMTSLayer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
center: [0, 0],
2121
maxZoom: 18,
2222
zoom: 0,
23-
crs: new L.Proj.CRS("EPSG:3857", '',
23+
crs: new L.Proj.CRS("EPSG:3857",
2424
{
2525
origin: [-2.0037508342789244E7, 2.0037508342789244E7],
2626
resolutions: res,

src/leaflet/core/ExtendsCRS.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ for (var i = 0; i < 20; i++) {
2626
* @constant L.CRS.TianDiTu_WGS84CRS
2727
* @description 天地图WGS84坐标对象
2828
*/
29-
export var TianDiTu_WGS84CRS = L.CRS.TianDiTu_WGS84 = new L.Proj.CRS("EPSG:4326", '', {
29+
export var TianDiTu_WGS84CRS = L.CRS.TianDiTu_WGS84 = L.Proj.CRS("EPSG:4326",{
3030
origin: [-180, 90],
3131
resolutions: tdt_WGS84_resolutions,
3232
bounds: L.bounds([-180, -90], [180, 90])
@@ -41,7 +41,7 @@ for (var i = 0; i < 20; i++) {
4141
* @constant L.CRS.TianDiTu_MercatorCRS
4242
* @description 天地图墨卡托坐标对象
4343
*/
44-
export var TianDiTu_MercatorCRS = L.CRS.TianDiTu_Mercator = new L.Proj.CRS("EPSG:3857", '', {
44+
export var TianDiTu_MercatorCRS = L.CRS.TianDiTu_Mercator = L.Proj.CRS("EPSG:3857",{
4545
origin: [-20037508.3427892, 20037508.3427892],
4646
resolutions: tdt_Mercator_resolutions,
4747
bounds: L.bounds([-20037508.3427892, -20037508.3427892], [20037508.3427892, 20037508.3427892])

src/leaflet/core/Proj4Leaflet.js

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
22
* Inspired by https://github.com/kartena/Proj4Leaflet
3-
*/
4-
import L from "leaflet";
3+
*/
4+
import L from "leaflet";
55
import proj4 from "proj4";
6+
window.Proj4js = proj4;
67
L.Proj = {};
78

89
L.Proj._isProj4Obj = function (a) {
@@ -12,6 +13,7 @@ L.Proj._isProj4Obj = function (a) {
1213

1314
/**
1415
* @class L.Proj.Projection
16+
* @private
1517
* @classdesc Proj投影定义类
1618
* @extends L.Class{@linkdoc-leaflet/#class}
1719
* @param code - {number}地理编码
@@ -74,17 +76,17 @@ L.Proj.Projection = L.Class.extend({
7476
* @class L.Proj.CRS
7577
* @classdesc Proj坐标系统定义类
7678
* @extends L.Class{@linkdoc-leaflet/#class}
77-
* @param a -{string} proj srsCode。
78-
* @param b -{string} proj def。
79-
* @param c -{Object} options。可选参数:<br>
79+
* @param srsCode -{string} proj srsCode。
80+
* @param options -{Object} options。可选参数:<br>
81+
* def -{string} 投影的proj4定义。
8082
* origin -{Array|L.Point} 原点。必填<br>
8183
* scales -{Array} 比例尺数组 <br>
8284
* scaleDenominators -{Array} 比例尺分母数组 <br>
8385
* resolutions -{Array} 分辨率数组 <br>
8486
* bounds -{Array|L.Bounds} 范围
8587
* @example
8688
* 用法:
87-
* var crs =new L.Proj.CRS("EPSG:4326", '', {
89+
* var crs =L.Proj.CRS("EPSG:4326", '', {
8890
* origin: [-180,90],
8991
* scaleDenominators: [2000,1000,500,200,100,50,20,10],
9092
* });
@@ -93,36 +95,41 @@ L.Proj.Projection = L.Class.extend({
9395
* ...
9496
* })
9597
*/
96-
L.Proj.CRS = L.Class.extend({
98+
export var CRS = L.Class.extend({
9799
includes: L.CRS,
98100

99101
options: {
100102
transformation: new L.Transformation(1, 0, -1, 0)
101103
},
102104

103-
initialize: function (a, b, c) {
104-
var code,
105-
proj,
106-
def,
107-
options;
105+
initialize: function (srsCode, options) {
106+
var code, proj, def;
108107

109-
if (L.Proj._isProj4Obj(a)) {
110-
proj = a;
108+
if (L.Proj._isProj4Obj(srsCode)) {
109+
proj = srsCode;
111110
code = proj.srsCode;
112-
options = b || {};
111+
options = options || {};
113112

114113
this.projection = new L.Proj.Projection(proj, options.bounds);
115114
} else {
116-
code = a;
117-
def = b;
118-
options = c || {};
115+
code = srsCode;
116+
options = options || {};
117+
def = options.def || '';
119118
this.projection = new L.Proj.Projection(code, def, options.bounds);
120119
}
121120

122121
L.Util.setOptions(this, options);
123122
this.code = code;
124123
this.transformation = this.options.transformation;
124+
if (this.options.bounds) {
125125

126+
}
127+
if (this.options.bounds) {
128+
this.options.bounds = L.bounds(this.options.bounds);
129+
}
130+
if (!this.options.origin && this.options.bounds) {
131+
this.options.origin = [this.options.bounds.min.x, this.options.bounds.max.y];
132+
}
126133
if (this.options.origin) {
127134
if (this.options.origin instanceof L.Point) {
128135
this.options.origin = [this.options.origin.x, this.options.origin.y];
@@ -132,15 +139,15 @@ L.Proj.CRS = L.Class.extend({
132139
-1, this.options.origin[1]);
133140
}
134141

135-
if (this.options.scales&&this.options.scales.length>0) {
142+
if (this.options.scales && this.options.scales.length > 0) {
136143
this._scales = this._toProj4Scales(this.options.scales);
137-
} else if (this.options.scaleDenominators&&this.options.scaleDenominators.length>0) {
144+
} else if (this.options.scaleDenominators && this.options.scaleDenominators.length > 0) {
138145
var scales = [];
139146
for (var i = 0; i < this.options.scaleDenominators.length; i++) {
140147
scales[i] = 1 / this.options.scaleDenominators[i];
141148
}
142149
this._scales = this._toProj4Scales(scales);
143-
} else if (this.options.resolutions&&this.options.resolutions.length>0) {
150+
} else if (this.options.resolutions && this.options.resolutions.length > 0) {
144151
this._scales = [];
145152
for (var i = this.options.resolutions.length - 1; i >= 0; i--) {
146153
if (this.options.resolutions[i]) {
@@ -234,7 +241,7 @@ L.Proj.CRS = L.Class.extend({
234241
if (!bounds) {
235242
return [];
236243
}
237-
var boundsSize = L.bounds(bounds).getSize();
244+
var boundsSize = bounds.getSize();
238245
var extendsSize = Math.max(boundsSize.x, boundsSize.y);
239246
var resolution = extendsSize / 256;
240247
var scales = [];
@@ -245,3 +252,7 @@ L.Proj.CRS = L.Class.extend({
245252
return scales;
246253
}
247254
});
255+
export var crs = function (srsCode, options) {
256+
return new CRS(srsCode, options)
257+
};
258+
L.Proj.CRS = crs;

src/leaflet/mapping/WebMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export var WebMap = L.LayerGroup.extend({
165165
epsgCode = 4326
166166
//todo 火星
167167
}
168-
return new L.Proj.CRS("EPSG:" + epsgCode, '',
168+
return L.Proj.CRS("EPSG:" + epsgCode,
169169
{
170170
origin: origin,
171171
resolutions: resolutions,

src/leaflet/overlay/EChartMapLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export var EchartsMapLayer = L.Layer.extend({
157157

158158
/**
159159
* @class L.supermap.LeafletMapCoordSys
160+
* @private
160161
* @classdesc 地图坐标系统类
161162
* @param LeafletMap - {L.map} 地图
162163
* @param api - {Object} 接口

src/leaflet/overlay/vectortile/CanvasRenderer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import L from "leaflet";
22

33
/**
44
* @class L.supermap.CanvasRenderer
5+
* @private
56
* @classdesc 画布渲染器
67
* @extends L.Canvas{@linkdoc-leaflet/#canvas}
78
* @param tileCoord - {Object} 切片坐标系

0 commit comments

Comments
 (0)