Skip to content

Commit 5ee67cd

Browse files
committed
leaflet平面无投影坐标系的扩展
1 parent fc73b25 commit 5ee67cd

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

src/Leaflet/NonEarthCRS.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
L.Projection = {};
2+
3+
NonProjection = L.Class.extend({
4+
initialize: function (bounds) {
5+
this.b = bounds;
6+
},
7+
project: function (latlng) {
8+
return new L.Point(latlng.lng, latlng.lat);
9+
},
10+
11+
unproject: function (point) {
12+
return new L.LatLng(point.y, point.x);
13+
},
14+
15+
bounds: this.b
16+
});
17+
L.supermap.NonProjection = function (bounds) {
18+
return new NonProjection(bounds)
19+
}
20+
module.exports = L.supermap.NonProjection;
21+
NonEarthCRS = L.Class.extend({
22+
includes: L.CRS,
23+
24+
initialize: function (options) {
25+
if (options.origin) {
26+
this.transformation =
27+
new L.Transformation(1, options.origin.x,
28+
-1, options.origin.y);
29+
}
30+
this.projection = L.supermap.NonProjection(options.bounds);
31+
this.bounds = options.bounds;
32+
this.origin = options.origin;
33+
this.resolutions = options.resolutions;
34+
},
35+
36+
scale: function (zoom) {
37+
if (!this.resolutions || this.resolutions.length === 0) {
38+
var width = Math.max(this.bounds.getSize().x, this.bounds.getSize().y);
39+
var defaultScale = 1 / (width / 256);
40+
return defaultScale * Math.pow(2, zoom);
41+
}
42+
return 1 / this.resolutions[zoom];
43+
},
44+
45+
zoom: function (scale) {
46+
if (!this.resolutions || this.resolutions.length === 0) {
47+
var width = Math.max(this.bounds.getSize().x, this.bounds.getSize().y);
48+
var defaultScale = 1 / (width / 256);
49+
return scale / defaultScale;
50+
}
51+
for (var i = 0; i < this.resolutions.length; i++) {
52+
if (1 / this.resolutions == scale) {
53+
return i
54+
}
55+
}
56+
return -1;
57+
},
58+
59+
distance: function (latlng1, latlng2) {
60+
var dx = latlng2.lng - latlng1.lng,
61+
dy = latlng2.lat - latlng1.lat;
62+
63+
return Math.sqrt(dx * dx + dy * dy);
64+
},
65+
66+
infinite: true
67+
});
68+
L.supermap = L.supermap || {};
69+
L.supermap.NonEarthCRS = function (options) {
70+
return new NonEarthCRS(options)
71+
}
72+
module.exports = L.supermap.NonEarthCRS;

src/Leaflet/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* 2、提供必要的转换工具
55
*/
66
require('../Core/format/GeoJSON');
7+
require('./NonEarthCRS');
78
L.supermap = L.supermap || {};
8-
99
L.Util.toSuperMapGeometry = function (geometry) {
1010
if (!geometry) {
1111
return geometry;

0 commit comments

Comments
 (0)