Skip to content

Commit 6740f03

Browse files
committed
leaflet 对接baidulayer
1 parent c1e739f commit 6740f03

File tree

10 files changed

+7289
-654
lines changed

10 files changed

+7289
-654
lines changed

build/deps.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ var deps = {
7979
"title": "OGC",
8080
"description": "--对接OGC标准服务"
8181
},
82+
"mapping": {
83+
"title": "互联网地图",
84+
"description": "--对接互联网地图",
85+
"Baidu": {
86+
"name": "百度图层",
87+
"src": ['./src/Leaflet/mapping/BaiduTileLayer.js']
88+
}
89+
90+
},
8291
"SuperMap": {
8392
"title": "SuperMap",
8493
"description": "--对接SuperMap服务",

dist/iclient9-leaflet.js

Lines changed: 6906 additions & 641 deletions
Large diffs are not rendered by default.

examples/leaflet/baiduLayer.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>百度地图</title>
6+
<link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
7+
<link rel="stylesheet" href="http://cdn.bootcss.com/leaflet/1.0.3/leaflet.css">
8+
</head>
9+
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
10+
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>
11+
<script type="text/javascript" src="../../node_modules/leaflet/dist/leaflet-src.js"></script>
12+
<script type="text/javascript" src="../../dist/iclient9-leaflet.js"></script>
13+
<script type="text/javascript">
14+
map = L.map('map', {
15+
center: [0, 0],
16+
maxZoom: 21,
17+
minZoom: 3,
18+
zoom: 3,
19+
crs: L.CRS.BaiduCRS
20+
});
21+
L.supermap.baiduTileLayer().addTo(map);
22+
</script>
23+
</body>
24+
</html>

examples/leaflet/config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ var exampleConfig = {
329329
"OGC": {
330330
name: "OGC",
331331
content: null
332+
},
333+
"mapping": {
334+
name: "互联网地图",
335+
content: {
336+
"Baidu": {
337+
name: "",
338+
content: [{
339+
name: "百度地图",
340+
thumbnail: "l_baiduLayer.png",
341+
fileName: "baiduLayer"
342+
}]
343+
}
344+
}
332345
}
333-
334-
};
346+
}
158 KB
Loading

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"imports-loader":"^0.7.0"
4848
},
4949
"dependencies": {
50-
50+
"proj4": "^2.4.3",
51+
"fetch-jsonp":"^1.0.6"
5152
}
5253
}

src/Leaflet/ExtendsCRS.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
L.CRS.BaiduCRS = L.extend({}, L.CRS.EPSG3857, {
2+
3+
code: 'BaiduCRS',
4+
scale: function (zoom) {
5+
return (6378137 * Math.PI * 2) / Math.pow(2, 18 - zoom)
6+
},
7+
8+
transformation: (function () {
9+
var scale = 0.5 / (Math.PI * 6378137);
10+
return new L.Transformation(scale, 0, -scale, 0);
11+
}())
12+
});
13+
var tdt_WGS84_resolutions = [];
14+
for (var i = 0; i < 20; i++) {
15+
tdt_WGS84_resolutions.push(0.703125 * 2 / (Math.pow(2, i)));
16+
}
17+
L.CRS.TianDiTu_WGS84 = new L.Proj.CRS("EPSG:4326", '',
18+
{
19+
origin: [-180, 90],
20+
resolutions: tdt_WGS84_resolutions,
21+
bounds: L.bounds([-180, -90], [180, 90])
22+
})
23+
24+
var tdt_Mercator_resolutions = [];
25+
for (var i = 0; i < 20; i++) {
26+
27+
tdt_Mercator_resolutions.push(78271.5169640203125 * 2 / (Math.pow(2, i)));
28+
}
29+
L.CRS.TianDiTu_Mercator = new L.Proj.CRS("EPSG:3857", '',
30+
{
31+
origin: [-20037508.3427892, 20037508.3427892],
32+
resolutions: tdt_Mercator_resolutions,
33+
bounds: L.bounds([-20037508.3427892, -20037508.3427892], [20037508.3427892, 20037508.3427892])
34+
})

src/Leaflet/base.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@
66
L.supermap = L.supermap || {};
77
require('../Core/format/GeoJSON');
88
require('./NonEarthCRS');
9-
9+
require('./proj4leaflet');
10+
require('./ExtendsCRS');
1011
L.Util.toGeoJSON = function (feature) {
1112
if (!feature) {
1213
return feature;
1314
}
14-
var result, format = new SuperMap.Format.GeoJSON();
15-
if (feature.geometry) {
16-
result = JSON.parse(format.write(feature.geometry));
17-
} else {
18-
result = JSON.parse(format.write(feature));
19-
}
20-
return result;
15+
return JSON.parse(new SuperMap.Format.GeoJSON().write(feature));
2116
};
22-
17+
L.Util.supermap_callbacks = {};
2318
L.Util.toSuperMapGeometry = function (geometry) {
2419
if (!geometry) {
2520
return geometry;
@@ -47,7 +42,30 @@ L.Util.toSuperMapGeometry = function (geometry) {
4742
return (serverResult && serverResult.geometry) ? serverResult.geometry : serverResult;
4843

4944
};
50-
45+
L.Util.GetResolutionFromScaleDpi = function (scale, dpi, coordUnit, datumAxis) {
46+
var resolution = null,
47+
ratio = 10000;
48+
//用户自定义地图的Options时,若未指定该参数的值,则系统默认为6378137米,即WGS84参考系的椭球体长半轴。
49+
datumAxis = datumAxis || 6378137;
50+
coordUnit = coordUnit || "";
51+
if (scale > 0 && dpi > 0) {
52+
scale = L.Util.NormalizeScale (scale);
53+
if (coordUnit.toLowerCase() === "degree" || coordUnit.toLowerCase() === "degrees" || coordUnit.toLowerCase() === "dd") {
54+
//scale = SuperMap.Util.normalizeScale(scale);
55+
resolution = 0.0254 * ratio / dpi / scale / ((Math.PI * 2 * datumAxis) / 360) / ratio;
56+
return resolution;
57+
} else {
58+
resolution = 0.0254 * ratio / dpi / scale / ratio;
59+
return resolution;
60+
}
61+
}
62+
return -1;
63+
};
64+
L.Util.NormalizeScale = function (scale) {
65+
var normScale = (scale > 1.0) ? (1.0 / scale)
66+
: scale;
67+
return normScale;
68+
};
5169
L.Util.Csv2GeoJSON = function (csv, options) {
5270
var defaultOptions = {
5371
titles: ['lon', 'lat'],
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BaiduTileLayer = L.TileLayer.extend({
2+
url: "http://online{num}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&udt=20150815&scaler=1",
3+
options: {
4+
minZoom: 3,
5+
maxZoom: 19,
6+
bounds: L.latLngBounds(L.latLng(-85.0511287798, -180), L.latLng(85.0511287798, 180))
7+
},
8+
initialize: function (url, options) {
9+
if (url) {
10+
this.url = url;
11+
}
12+
L.setOptions(this, options);
13+
L.stamp(this);
14+
},
15+
getTileUrl: function (coords) {
16+
return L.Util.template(this.url, {
17+
num: Math.abs((coords.x + coords.y) % 8) + 1,
18+
x: coords.x,
19+
y: -coords.y - 1,
20+
z: this._getZoomForUrl()
21+
})
22+
}
23+
})
24+
L.supermap = L.supermap || {};
25+
L.supermap.baiduTileLayer = function (url, options) {
26+
return new BaiduTileLayer(url, options);
27+
};
28+
29+
module.exports = L.supermap.baiduTileLayer;

0 commit comments

Comments
 (0)