forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageTileLayer.js
More file actions
131 lines (119 loc) · 5.48 KB
/
ImageTileLayer.js
File metadata and controls
131 lines (119 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import L, { Util as LUtil } from 'leaflet';
import '../core/Base';
import { SecurityManager, CommonUtil } from '@supermap/iclient-common';
import Attributions from '../core/Attributions';
/**
* @class L.supermap.ImageTileLayer
* @version 10.2.0
* @classdesc iServer影像服务图层源。根据指定的请求参数,返回影像数据栅格瓦片并渲染。
* @category iServer Image
* @extends {L.TileLayer}
* @example
* L.supermap.ImageTileLayer(url,{collectionId:'xxx'}).addTo(map);
* @param {string} url - 地图服务地址,例如: http://{ip}:{port}/iserver/{imageservice-imageserviceName}/restjsr/
* @param {Object} options - 参数。
* @param {string} options.collectionId - 影像集合(Collection)的ID,在一个影像服务中唯一标识影像集合。
* @param {string} [options.sqlFilter] 对所显示影像的过滤条件。相当于sql查询中的where子句。支持st_geometry空间函数过滤。11.0版本暂不支持通过ECQL进行过滤。
* @param {SuperMap.ImageRenderingRule} [options.renderingRule] 指定影像显示的风格,包含拉伸显示方式、颜色表、波段组合以及应用栅格函数进行快速处理等。不指定时,使用发布服务时所配置的风格。
* @param {Array.<number>} [options.ids] 返回影像集合中指定ID的影像,该id为系统维护的一个自增id,为SuperMap SDX引擎的SmID字段内容。
* @param {Array.<string>} [options.names] 返回影像集合中指定名称影像的瓦片资源。影像名称包含文件后缀,如S-60-45.tif。
* @param {string} [options.format='png'] - 瓦片表述类型,瓦片格式目前支持png、jpg和webp三种格式。
* @param {boolean} [options.transparent=true] - 瓦片是否透明。默认透明。
* @param {boolean} [options.cacheEnabled=true] - 启用缓存。
* @param {string} [options.attribution='Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' title='SuperMap iServer' target='_blank'>SuperMap iServer</a></span>'] - 版权信息。
* @param {Array.<number>} [options.subdomains] - 子域名数组。
* @param {string} [options.tileProxy] - 代理地址。
*/
export var ImageTileLayer = L.TileLayer.extend({
options: {
collectionId: null,
sqlFilter: null,
ids: null,
names: null,
renderingRule: null,
format: 'png',
zoomOffset: 1,
transparent: true,
cacheEnabled: true,
tileProxy: null, //启用托管地址。
attribution: Attributions.Common.attribution,
subdomains: null
},
initialize: function (url, options) {
this._url = url;
L.TileLayer.prototype.initialize.apply(this, arguments);
L.setOptions(this, options);
L.stamp(this);
},
/**
* @private
* @function L.supermap.ImageTileLayer.prototype.onAdd
* @description 添加地图。
* @param {L.Map} map - 待添加的影像地图参数。
*/
onAdd: function (map) {
L.TileLayer.prototype.onAdd.call(this, map);
},
/**
* @function L.supermap.ImageTileLayer.prototype.getTileUrl
* @description 根据行列号获取瓦片地址。
* @param {Object} coords - 行列号。
* @returns {string} 瓦片地址。
*/
getTileUrl: function (coords) {
var layerUrl = this._getLayerUrl();
var tileUrl = layerUrl + '&z=' + this._getZoomForUrl() + '&x=' + coords.x + '&y=' + coords.y;
//支持代理
if (this.options.tileProxy) {
tileUrl = this.options.tileProxy + encodeURIComponent(tileUrl);
}
if (!this.options.cacheEnabled) {
tileUrl += '&_t=' + new Date().getTime();
}
if (this.options.subdomains) {
tileUrl = L.Util.template(tileUrl, { s: this._getSubdomain(coords) });
}
return tileUrl;
},
_getLayerUrl: function () {
return this._layerUrl || this._createLayerUrl();
},
_createLayerUrl: function () {
let layerUrl = CommonUtil.urlPathAppend(
this._url,
`/collections/${this.options.collectionId}/tile.${this.options.format}`
);
this.requestParams = this.requestParams || this._getAllRequestParams();
layerUrl = CommonUtil.urlAppend(layerUrl, LUtil.getParamString(this.requestParams));
layerUrl = SecurityManager.appendCredential(layerUrl);
this._layerUrl = layerUrl;
return layerUrl;
},
_getAllRequestParams: function () {
var me = this,
options = me.options || {},
params = {};
params['transparent'] = options.transparent === true;
params['cacheEnabled'] = !(options.cacheEnabled === false);
if (options.sqlFilter) {
params['sqlFilter'] = options.sqlFilter;
}
if (options.renderingRule) {
params['renderingRule'] = JSON.stringify(options.renderingRule);
}
if (options.ids) {
params['ids'] = options.ids.join(',');
}
if (options.names) {
params['names'] = options.names.join(',');
}
return params;
}
});
export var imageTileLayer = function (url, options) {
return new ImageTileLayer(url, options);
};
L.supermap.imageTileLayer = imageTileLayer;