Skip to content

Commit 0de6c37

Browse files
author
潘卓然-中地数码台式机
committed
补充leaflet自定义图层错级显示示例及其说明
1 parent 8aaf86b commit 0de6c37

4 files changed

Lines changed: 140 additions & 1 deletion

File tree

config/config-leaflet.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ var config = {
303303
folder: "mapdisplay",
304304
leaffolder: true,
305305
childs: [
306+
{
307+
name: "瓦片错级显示",
308+
file: "customlayer",
309+
diffcult: "1",
310+
detail:"针对自定义的瓦片裁图方式,进行个性化配置。",
311+
icon: "customlayer.png",
312+
update: "最后更新时间:2018-12-27",
313+
person: "基础平台/创新中心-潘卓然"
314+
},
306315
{
307316
name: "百度炫彩地图-3857",
308317
file: "baidumap",
@@ -321,7 +330,7 @@ var config = {
321330
update: "最后更新时间:2018-05-23"
322331
},
323332
{
324-
name: "瓦片地图显示-4326-BUG",
333+
name: "瓦片地图显示-4326",
325334
file: "tilemapdisplay",
326335
diffcult: "3",
327336
detail: "瓦片地图显示",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
4+
<head>
5+
<title>瓦片错级显示</title>
6+
<script src="../../libs/zondyclient/include-leaflet-local.js"></script>
7+
<script type="text/javascript">
8+
/**
9+
* @description 自定义瓦片图层,这里仅作示例参考,请根据自己的错级逻辑修改
10+
* @see Zondy.Map.MapTileLayer
11+
*/
12+
var CustomTileLayer = L.TileLayer.extend({
13+
/**
14+
* @description 根据行列号获取瓦片地址
15+
* @param coords - {Object} 行列号 x,y,z
16+
* @return {string} 瓦片地址
17+
*/
18+
getTileUrl: function (coords) {
19+
var tileUrl = 'http://localhost:6163/igs/rest/mrms/tile/株洲市/{z}/{y}/{x}';
20+
//如果下面需要错一级则 coords.z = coords.z +1
21+
tileUrl = tileUrl.replace('{x}', coords.x.toString()).replace('{y}', coords.y.toString()).replace(
22+
'{z}', coords.z.toString());
23+
return tileUrl;
24+
}
25+
});
26+
27+
//显示地图
28+
function init() {
29+
var map = L.map('leaf_map', {
30+
//参考坐标系,默认是墨卡托坐标系(EPSG3857),EPSG4326为经纬度坐标系
31+
crs: L.CRS.EPSG4326,
32+
center: [0, 0],
33+
minZoom: 1,
34+
maxZoom: 5,
35+
zoom: 2,
36+
//限制显示地理范围
37+
maxBounds: L.latLngBounds(L.latLng(-180, -180), L.latLng(180, 180))
38+
});
39+
40+
//添加自定义瓦片图层,这里我直接使用公司内部封装好的的天地图的类
41+
//var layer = new CustomTileLayer().addTo(map);
42+
var layer = new Zondy.Map.TDTLayer({
43+
layerType: 'vec',
44+
minZoom: 0,
45+
maxZoom: 5
46+
}).addTo(map);
47+
}
48+
</script>
49+
</head>
50+
51+
<body onload="init()">
52+
<div id="leaf_map" style="width: 100%; height:700px;">
53+
</div>
54+
</body>
55+
56+
</html>
49 KB
Loading
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
### 情况说明
2+
由于各个事业单位对天地图,或者其他世界地图的标准不一致,导致自己裁剪的级别可能与标准的差一级或者错位一级
3+
4+
### 解决方案
5+
自定义图层 拓展一个TileLayer, `并重写 getTileUrl函数`
6+
7+
``` js
8+
var TianDiTuLayer = window.L.TileLayer.extend({
9+
layerLabelMap: {
10+
"vec": "cva",
11+
"ter": "cta",
12+
"img": "cia"
13+
},
14+
layerZoomMap: {
15+
"vec": 18,
16+
"ter": 14,
17+
"img": 18
18+
},
19+
options: {
20+
layerType: "vec", //(vec:矢量图层,vec:矢量标签图层,img:影像图层,cia:影像标签图层,ter:地形,cta:地形标签图层)
21+
isLabel: false,
22+
url: "http://t{s}.tianditu.com/{layer}_{proj}/wmts?",
23+
zoomOffset: 1,
24+
dpi: 96,
25+
style: "default",
26+
format: "tiles",
27+
subdomains: [0, 1, 2, 3, 4, 5, 6, 7],
28+
version: '1.0.0',
29+
tilematrixSet: '',
30+
tileSize: 256,
31+
matrixIds: null,
32+
layer: '',
33+
attribution: "天地图"
34+
},
35+
36+
initialize: function (options) {
37+
options = options || {};
38+
window.L.setOptions(this, options);
39+
this.options.layer = this.options.isLabel ? this.layerLabelMap[this.options.layerType] : this.options.layerType;
40+
this.options.maxZoom = this.layerZoomMap[this.options.layerType];
41+
42+
this._url = this.options.url;
43+
window.L.setOptions(this, this.options);
44+
window.L.stamp(this);
45+
},
46+
onAdd: function (map) {
47+
this._crs = this.options.crs || map.options.crs;
48+
this.options.tilematrixSet = this._crs.code === "EPSG:4326" ? "c" : "w";
49+
this._url = this._url.replace("{layer}", this.options.layer).replace("{proj}", this.options.tilematrixSet);
50+
window.L.TileLayer.prototype.onAdd.call(this, map);
51+
},
52+
getTileUrl: function (coords) { // (Point, Number) -> String
53+
var zoom = this._getZoomForUrl();
54+
var ident = this.options.matrixIds ? this.options.matrixIds[zoom].identifier : zoom;
55+
var url = window.L.Util.template(this._url, {s: this._getSubdomain(coords)});
56+
var obj = {
57+
service: 'WMTS',
58+
request: 'GetTile',
59+
version: this.options.version,
60+
style: this.options.style,
61+
tilematrixSet: this.options.tilematrixSet,
62+
format: this.options.format,
63+
width: this.options.tileSize,
64+
height: this.options.tileSize,
65+
layer: this.options.layer,
66+
tilematrix: ident,
67+
tilerow: coords.y,
68+
tilecol: coords.x
69+
};
70+
return url + window.L.Util.getParamString(obj, url);
71+
}
72+
73+
});
74+
```

0 commit comments

Comments
 (0)