@supermapgis/iclient-ol 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/control/ChangeTileVersion.js +438 -0
- package/control/Logo.js +97 -0
- package/control/ScaleLine.js +164 -0
- package/control/index.js +6 -0
- package/core/MapExtend.js +49 -0
- package/core/StyleUtils.js +1253 -0
- package/core/Util.js +500 -0
- package/core/index.js +6 -0
- package/css/ChangeTileVersion.css +347 -0
- package/css/index.js +5 -0
- package/dist/iclient-openlayers-es6.js +124963 -0
- package/dist/iclient-openlayers-es6.min.js +8 -0
- package/dist/iclient-openlayers.css +668 -0
- package/dist/iclient-openlayers.js +142946 -0
- package/dist/iclient-openlayers.min.css +8 -0
- package/dist/iclient-openlayers.min.js +8 -0
- package/index.js +9 -0
- package/mapping/BaiduMap.js +121 -0
- package/mapping/ImageSuperMapRest.js +252 -0
- package/mapping/ImageTileSuperMapRest.js +99 -0
- package/mapping/InitMap.js +150 -0
- package/mapping/SuperMapCloud.js +56 -0
- package/mapping/Tianditu.js +152 -0
- package/mapping/TileSuperMapRest.js +374 -0
- package/mapping/WebMap.js +5485 -0
- package/mapping/index.js +11 -0
- package/mapping/webmap/Util.js +176 -0
- package/mapping/webmap/config/MunicipalCenter.json +1 -0
- package/mapping/webmap/config/ProvinceCenter.json +1 -0
- package/mapping/webmap/config/SampleDataInfo.json +55 -0
- package/namespace.js +150 -0
- package/overlay/DataFlow.js +114 -0
- package/overlay/FGB.js +100 -0
- package/overlay/Graph.js +439 -0
- package/overlay/GraphMap.js +140 -0
- package/overlay/Graphic.js +588 -0
- package/overlay/HeatMap.js +450 -0
- package/overlay/Label.js +966 -0
- package/overlay/Mapv.js +149 -0
- package/overlay/Range.js +129 -0
- package/overlay/RankSymbol.js +94 -0
- package/overlay/Turf.js +299 -0
- package/overlay/Unique.js +124 -0
- package/overlay/VectorTileSuperMapRest.js +501 -0
- package/overlay/graphic/CanvasRenderer.js +177 -0
- package/overlay/graphic/CloverShape.js +133 -0
- package/overlay/graphic/Graphic.js +174 -0
- package/overlay/graphic/HitCloverShape.js +64 -0
- package/overlay/graphic/WebGLRenderer.js +356 -0
- package/overlay/graphic/index.js +9 -0
- package/overlay/index.js +21 -0
- package/overlay/mapv/MapvCanvasLayer.js +104 -0
- package/overlay/mapv/MapvLayer.js +413 -0
- package/overlay/mapv/index.js +5 -0
- package/overlay/theme/GeoFeature.js +275 -0
- package/overlay/theme/Theme.js +587 -0
- package/overlay/theme/ThemeFeature.js +46 -0
- package/overlay/theme/index.js +6 -0
- package/overlay/vectortile/DeafultCanvasStyle.js +125 -0
- package/overlay/vectortile/MapboxStyles.js +377 -0
- package/overlay/vectortile/StyleMap.js +252 -0
- package/overlay/vectortile/VectorTileStyles.js +554 -0
- package/overlay/vectortile/index.js +7 -0
- package/overlay/vectortile/olExtends.js +382 -0
- package/package.json +30 -0
- package/services/AddressMatchService.js +60 -0
- package/services/ChartService.js +97 -0
- package/services/DataFlowService.js +119 -0
- package/services/DatasetService.js +104 -0
- package/services/DatasourceService.js +76 -0
- package/services/FeatureService.js +260 -0
- package/services/FieldService.js +53 -0
- package/services/GeoprocessingService.js +157 -0
- package/services/GridCellInfosService.js +53 -0
- package/services/ImageCollectionService.js +93 -0
- package/services/ImageService.js +70 -0
- package/services/KnowledgeGraphService.js +96 -0
- package/services/LayerInfoService.js +85 -0
- package/services/MapService.js +85 -0
- package/services/MeasureService.js +77 -0
- package/services/NetworkAnalyst3DService.js +93 -0
- package/services/NetworkAnalystService.js +268 -0
- package/services/ProcessingService.js +507 -0
- package/services/QueryService.js +116 -0
- package/services/ServiceBase.js +26 -0
- package/services/SpatialAnalystService.js +466 -0
- package/services/ThemeService.js +50 -0
- package/services/TrafficTransferAnalystService.js +93 -0
- package/services/WebPrintingJobService.js +112 -0
- package/services/index.js +27 -0
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
export * from '@supermapgis/iclient-common/index.common';
|
|
5
|
+
export * from './control';
|
|
6
|
+
export * from './core';
|
|
7
|
+
export * from './mapping';
|
|
8
|
+
export * from './overlay';
|
|
9
|
+
export * from './services';
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
import TileImage from 'ol/source/TileImage';
|
|
5
|
+
import * as asserts from 'ol/asserts';
|
|
6
|
+
import TileGrid from 'ol/tilegrid/TileGrid';
|
|
7
|
+
import { Util } from '../core/Util';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class BaiduMap
|
|
11
|
+
* @browsernamespace ol.source
|
|
12
|
+
* @category ThirdPartyMap
|
|
13
|
+
* @classdesc 百度地图图层源。
|
|
14
|
+
* @modulecategory Mapping
|
|
15
|
+
* @param {Object} opt_options - 参数。
|
|
16
|
+
* @param {string} [opt_options.url='https://maponline{num}.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={styles}&udt=20170408'] - 服务地址。
|
|
17
|
+
* @param {string} [opt_options.tileProxy] - 代理地址。
|
|
18
|
+
* @param {boolean} [hidpi = false] - 是否使用高分辨率地图。
|
|
19
|
+
* @extends {ol.source.TileImage}
|
|
20
|
+
* @usage
|
|
21
|
+
*/
|
|
22
|
+
export class BaiduMap extends TileImage {
|
|
23
|
+
constructor(opt_options) {
|
|
24
|
+
var options = opt_options || {};
|
|
25
|
+
var attributions =
|
|
26
|
+
options.attributions ||
|
|
27
|
+
"Map Data © 2018 Baidu - GS(2016)2089号 - Data © 长地万方 with <span>© SuperMap iClient</span>";
|
|
28
|
+
var tileGrid = BaiduMap.defaultTileGrid();
|
|
29
|
+
var crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
|
|
30
|
+
|
|
31
|
+
var url =
|
|
32
|
+
options.url !== undefined
|
|
33
|
+
? options.url
|
|
34
|
+
: 'https://maponline{num}.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles={styles}&udt=20170408';
|
|
35
|
+
var hidpi =
|
|
36
|
+
options.hidpi || (window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI) > 1;
|
|
37
|
+
url = url.replace('{styles}', hidpi ? 'ph' : 'pl');
|
|
38
|
+
super({
|
|
39
|
+
attributions: attributions,
|
|
40
|
+
cacheSize: options.cacheSize,
|
|
41
|
+
crossOrigin: crossOrigin,
|
|
42
|
+
opaque: options.opaque !== undefined ? options.opaque : true,
|
|
43
|
+
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 19,
|
|
44
|
+
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
|
45
|
+
tileLoadFunction: options.tileLoadFunction,
|
|
46
|
+
projection: 'EPSG:3857',
|
|
47
|
+
wrapX: options.wrapX,
|
|
48
|
+
tilePixelRatio: hidpi ? 2 : 1,
|
|
49
|
+
tileGrid: tileGrid,
|
|
50
|
+
tileUrlFunction: tileUrlFunction
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (options.tileProxy) {
|
|
54
|
+
this.tileProxy = options.tileProxy;
|
|
55
|
+
}
|
|
56
|
+
var me = this;
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line no-unused-vars
|
|
59
|
+
function tileUrlFunction(tileCoord, pixelRatio, projection) {
|
|
60
|
+
var tempUrl = url
|
|
61
|
+
.replace('{num}', Math.abs((tileCoord[1] + tileCoord[2]) % 4))
|
|
62
|
+
.replace('{z}', tileCoord[0].toString())
|
|
63
|
+
.replace('{x}', tileCoord[1].toString())
|
|
64
|
+
.replace('{y}', function() {
|
|
65
|
+
console.log(Util.getOlVersion());
|
|
66
|
+
var y = ['4', '5'].indexOf(Util.getOlVersion()) > -1 ? tileCoord[2] : -tileCoord[2] - 1;
|
|
67
|
+
return y.toString();
|
|
68
|
+
})
|
|
69
|
+
.replace('{-y}', function() {
|
|
70
|
+
var z = tileCoord[0];
|
|
71
|
+
var range = tileGrid.getFullTileRange(z);
|
|
72
|
+
asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
|
|
73
|
+
var y = range.getHeight() + tileCoord[2];
|
|
74
|
+
return y.toString();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
//支持代理
|
|
78
|
+
if (me.tileProxy) {
|
|
79
|
+
tempUrl = me.tileProxy + encodeURIComponent(tempUrl);
|
|
80
|
+
}
|
|
81
|
+
return tempUrl;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// TODO 确认这个方法是否要开出去
|
|
86
|
+
/**
|
|
87
|
+
* @function BaiduMap.defaultTileGrid
|
|
88
|
+
* @description 获取默认瓦片格网。
|
|
89
|
+
* @returns {ol.tilegrid.TileGrid} 返回瓦片格网对象。
|
|
90
|
+
*/
|
|
91
|
+
static defaultTileGrid() {
|
|
92
|
+
var tileGird = new TileGrid({
|
|
93
|
+
extent: [-33554432, -33554432, 33554432, 33554432],
|
|
94
|
+
resolutions: [
|
|
95
|
+
131072 * 2,
|
|
96
|
+
131072,
|
|
97
|
+
65536,
|
|
98
|
+
32768,
|
|
99
|
+
16284,
|
|
100
|
+
8192,
|
|
101
|
+
4096,
|
|
102
|
+
2048,
|
|
103
|
+
1024,
|
|
104
|
+
512,
|
|
105
|
+
256,
|
|
106
|
+
128,
|
|
107
|
+
64,
|
|
108
|
+
32,
|
|
109
|
+
16,
|
|
110
|
+
8,
|
|
111
|
+
4,
|
|
112
|
+
2,
|
|
113
|
+
1,
|
|
114
|
+
0.5
|
|
115
|
+
],
|
|
116
|
+
origin: [0, 0],
|
|
117
|
+
minZoom: 3
|
|
118
|
+
});
|
|
119
|
+
return tileGird;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
|
|
5
|
+
import { Unit } from '@supermapgis/iclient-common/REST';
|
|
6
|
+
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
7
|
+
import { ServerGeometry } from '@supermapgis/iclient-common/iServer/ServerGeometry';
|
|
8
|
+
import { Util } from '../core/Util';
|
|
9
|
+
import ImageSource, { defaultImageLoadFunction } from 'ol/source/Image';
|
|
10
|
+
import ImageWrapper from 'ol/Image';
|
|
11
|
+
import Geometry from 'ol/geom/Geometry';
|
|
12
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
13
|
+
import { containsExtent, getCenter, getHeight, getWidth, getForViewAndSize } from 'ol/extent';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @class ImageSuperMapRest
|
|
17
|
+
* @browsernamespace ol.source
|
|
18
|
+
* @category iServer Map Tile
|
|
19
|
+
* @classdesc SuperMap iServer Image 图层源。
|
|
20
|
+
* @modulecategory Mapping
|
|
21
|
+
* @param {Object} options - 参数。
|
|
22
|
+
* @param {string} options.url - 地图服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
|
|
23
|
+
* @param {ServerType} [options.serverType=SuperMap.ServerType.ISERVER] - 服务类型 ISERVER|IPORTAL|ONLINE。
|
|
24
|
+
* @param {boolean} [options.redirect=false] - 是否重定向。
|
|
25
|
+
* @param {boolean} [options.transparent=true] - 瓦片是否透明。
|
|
26
|
+
* @param {boolean} [options.antialias=false] - 是否反走样地图。
|
|
27
|
+
* @param {boolean} [options.cacheEnabled=true] - 是否使用服务端的缓存,true 表示使用服务端的缓存。
|
|
28
|
+
* @param {Object} [options.prjCoordSys] - 请求的地图的坐标参考系统。当此参数设置的坐标系统不同于地图的原有坐标系统时,系统会进行动态投影,并返回动态投影后的地图瓦片。例如:{"epsgCode":3857}。
|
|
29
|
+
* @param {string} [options.layersID] - 获取进行切片的地图图层 ID,即指定进行地图切片的图层,可以是临时图层集,也可以是当前地图中图层的组合。
|
|
30
|
+
* @param {boolean} [options.clipRegionEnabled = false] - 是否地图只显示该区域覆盖的部分。true 表示地图只显示该区域覆盖的部分。
|
|
31
|
+
* @param {ol.geom.Geometry} [options.clipRegion] - 地图显示裁剪的区域。是一个面对象,当 clipRegionEnabled = true 时有效,即地图只显示该区域覆盖的部分。
|
|
32
|
+
* @param {boolean} [options.overlapDisplayed=false] - 地图对象在同一范围内时,是否重叠显示。如果为 true,则同一范围内的对象会直接压盖;如果为 false 则通过 overlapDisplayedOptions 控制对象不压盖显示。
|
|
33
|
+
* @param {OverlapDisplayedOptions} [options.overlapDisplayedOptions] - 避免地图对象压盖显示的过滤选项,当 overlapDisplayed 为 false 时有效,用来增强对地图对象压盖时的处理。
|
|
34
|
+
* @param {boolean} [options.markerAngleFixed=false] - 指定点状符号的角度是否固定。
|
|
35
|
+
* @param {boolean} [options.textAngleFixed=false] - 文本角度是否固定。
|
|
36
|
+
* @param {boolean} [options.textOrientationFixed=false] - 文本朝向是否固定。
|
|
37
|
+
* @param {boolean} [options.paintBackground=false] - 是否绘制地图背景。
|
|
38
|
+
* @param {boolean} [options.maxVisibleTextSize] - 文本的最大可见尺寸,单位为像素。
|
|
39
|
+
* @param {boolean} [options.maxVisibleVertex] - 最大几何对象可见节点数。如果几何对象的节点数超过指定的个数,则超过的那部分节点不显示。
|
|
40
|
+
* @param {boolean} [options.minVisibleTextSize] - 文本的最小可见尺寸,单位为像素。
|
|
41
|
+
* @param {string} [options.tileversion] - 切片版本名称,_cache 为 true 时有效。
|
|
42
|
+
* @param {string} [options.tileProxy] - 代理地址。
|
|
43
|
+
* @param {NDVIParameter|HillshadeParameter} [options.rasterfunction] - 栅格分析参数。
|
|
44
|
+
* @param {string} [options.format = 'png'] - 瓦片表述类型,支持 "png" 、"webp"、"bmp" 、"jpg"、"gif" 等图片类型。
|
|
45
|
+
* @param {Function} [options.imageLoadFunction] - 加载图片的方法。默认为function(imageTile, src) {imageTile.getImage().src = src;};
|
|
46
|
+
* @param {string} [options.ratio=1.5] - 请求图片大小比例。 1 表示请求图片大小和地图视窗范围一致,2 表示请求图片大小是地图视窗范围的2倍,以此类推。
|
|
47
|
+
* @extends {ol.source.Image}
|
|
48
|
+
* @usage
|
|
49
|
+
*/
|
|
50
|
+
export class ImageSuperMapRest extends ImageSource {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
super({
|
|
53
|
+
attributions: options.attributions,
|
|
54
|
+
imageSmoothing: options.imageSmoothing,
|
|
55
|
+
projection: options.projection,
|
|
56
|
+
resolutions: options.resolutions
|
|
57
|
+
});
|
|
58
|
+
if (options.url === undefined) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.imageLoadFunction_ =
|
|
62
|
+
options.imageLoadFunction !== undefined ? options.imageLoadFunction : defaultImageLoadFunction;
|
|
63
|
+
this._image = null;
|
|
64
|
+
this.renderedRevision_ = 0;
|
|
65
|
+
this._crossOrigin = options.crossOrigin !== undefined ? options.crossOrigin : null;
|
|
66
|
+
this._url = options.url;
|
|
67
|
+
this.ratio_ = options.ratio !== undefined ? options.ratio : 1.5;
|
|
68
|
+
|
|
69
|
+
options.attributions =
|
|
70
|
+
options.attributions ||
|
|
71
|
+
"Map Data <span>© SuperMap iServer</span> with © SuperMap iClient";
|
|
72
|
+
|
|
73
|
+
options.format = options.format ? options.format : 'png';
|
|
74
|
+
this._layerUrl = CommonUtil.urlPathAppend(options.url, 'image.' + options.format);
|
|
75
|
+
//为url添加安全认证信息片段
|
|
76
|
+
this._layerUrl = SecurityManager.appendCredential(this._layerUrl);
|
|
77
|
+
|
|
78
|
+
const params = {};
|
|
79
|
+
//切片是否透明
|
|
80
|
+
const transparent = options.transparent !== undefined ? options.transparent : true;
|
|
81
|
+
params['transparent'] = transparent;
|
|
82
|
+
|
|
83
|
+
//是否使用缓存吗,默认为true
|
|
84
|
+
const cacheEnabled = options.cacheEnabled !== undefined ? options.cacheEnabled : true;
|
|
85
|
+
params['cacheEnabled'] = cacheEnabled;
|
|
86
|
+
|
|
87
|
+
//如果有layersID,则是在使用专题图
|
|
88
|
+
if (options.layersID !== undefined) {
|
|
89
|
+
params['layersID'] = options.layersID;
|
|
90
|
+
}
|
|
91
|
+
//是否重定向,默认为false
|
|
92
|
+
let redirect = false;
|
|
93
|
+
if (options.redirect !== undefined) {
|
|
94
|
+
redirect = options.redirect;
|
|
95
|
+
}
|
|
96
|
+
params['redirect'] = redirect;
|
|
97
|
+
|
|
98
|
+
if (options.prjCoordSys) {
|
|
99
|
+
params['prjCoordSys'] = JSON.stringify(options.prjCoordSys);
|
|
100
|
+
}
|
|
101
|
+
if (options.clipRegionEnabled && options.clipRegion instanceof Geometry) {
|
|
102
|
+
options.clipRegion = Util.toSuperMapGeometry(new GeoJSON().writeGeometryObject(options.clipRegion));
|
|
103
|
+
options.clipRegion = CommonUtil.toJSON(ServerGeometry.fromGeometry(options.clipRegion));
|
|
104
|
+
params['clipRegionEnabled'] = options.clipRegionEnabled;
|
|
105
|
+
params['clipRegion'] = JSON.stringify(options.clipRegion);
|
|
106
|
+
}
|
|
107
|
+
if (!!options.overlapDisplayed && options.overlapDisplayedOptions) {
|
|
108
|
+
// options.overlapDisplayedOptions = options.overlapDisplayedOptions;
|
|
109
|
+
params['overlapDisplayed'] = options.overlapDisplayed;
|
|
110
|
+
params['overlapDisplayedOptions'] = options.overlapDisplayedOptions.toString();
|
|
111
|
+
}
|
|
112
|
+
if (cacheEnabled === true && options.tileversion) {
|
|
113
|
+
params['tileversion'] = options.tileversion;
|
|
114
|
+
}
|
|
115
|
+
if (options.rasterfunction) {
|
|
116
|
+
params['rasterfunction'] = JSON.stringify(options.rasterfunction);
|
|
117
|
+
}
|
|
118
|
+
//是否反走样地图,默认为false
|
|
119
|
+
if (options.antialias !== undefined) {
|
|
120
|
+
params['antialias'] = options.antialias;
|
|
121
|
+
}
|
|
122
|
+
if (options.markerAngleFixed !== undefined) {
|
|
123
|
+
params['markerAngleFixed'] = options.markerAngleFixed;
|
|
124
|
+
}
|
|
125
|
+
if (options.textAngleFixed !== undefined) {
|
|
126
|
+
params['textAngleFixed'] = options.textAngleFixed;
|
|
127
|
+
}
|
|
128
|
+
if (options.textOrientationFixed !== undefined) {
|
|
129
|
+
params['textOrientationFixed'] = options.textOrientationFixed;
|
|
130
|
+
}
|
|
131
|
+
if (options.paintBackground !== undefined) {
|
|
132
|
+
params['paintBackground'] = options.paintBackground;
|
|
133
|
+
}
|
|
134
|
+
if (!isNaN(options.maxVisibleTextSize)) {
|
|
135
|
+
params['maxVisibleTextSize'] = +options.maxVisibleTextSize;
|
|
136
|
+
}
|
|
137
|
+
if (!isNaN(options.minVisibleTextSize)) {
|
|
138
|
+
params['maxVisibleTextSize'] = +options.minVisibleTextSize;
|
|
139
|
+
}
|
|
140
|
+
if (!isNaN(options.maxVisibleVertex)) {
|
|
141
|
+
params['maxVisibleVertex'] = Math.round(+options.maxVisibleVertex);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this._layerUrl = CommonUtil.urlAppend(this._layerUrl, CommonUtil.getParameterString(params));
|
|
145
|
+
|
|
146
|
+
//存储一个cacheEnabled
|
|
147
|
+
this.cacheEnabled = cacheEnabled;
|
|
148
|
+
|
|
149
|
+
if (options.tileProxy) {
|
|
150
|
+
this.tileProxy = options.tileProxy;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getImageInternal(extent, resolution, pixelRatio) {
|
|
154
|
+
resolution = this.findNearestResolution(resolution);
|
|
155
|
+
const imageResolution = resolution / pixelRatio;
|
|
156
|
+
const center = getCenter(extent);
|
|
157
|
+
const viewWidth = Math.ceil(getWidth(extent) / imageResolution);
|
|
158
|
+
const viewHeight = Math.ceil(getHeight(extent) / imageResolution);
|
|
159
|
+
const viewExtent = getForViewAndSize(center, imageResolution, 0, [viewWidth, viewHeight]);
|
|
160
|
+
const requestWidth = Math.ceil((this.ratio_ * getWidth(extent)) / imageResolution);
|
|
161
|
+
const requestHeight = Math.ceil((this.ratio_ * getHeight(extent)) / imageResolution);
|
|
162
|
+
const requestExtent = getForViewAndSize(center, imageResolution, 0, [requestWidth, requestHeight]);
|
|
163
|
+
const image = this._image;
|
|
164
|
+
if (
|
|
165
|
+
image &&
|
|
166
|
+
this.renderedRevision_ === this.getRevision() &&
|
|
167
|
+
image.getResolution() === resolution &&
|
|
168
|
+
image.getPixelRatio() === pixelRatio &&
|
|
169
|
+
containsExtent(image.getExtent(), viewExtent)
|
|
170
|
+
) {
|
|
171
|
+
return image;
|
|
172
|
+
}
|
|
173
|
+
const imageSize = [
|
|
174
|
+
Math.round(getWidth(requestExtent) / imageResolution),
|
|
175
|
+
Math.round(getHeight(requestExtent) / imageResolution)
|
|
176
|
+
];
|
|
177
|
+
const imageUrl = this._getRequestUrl(requestExtent, imageSize);
|
|
178
|
+
this._image = new ImageWrapper(
|
|
179
|
+
requestExtent,
|
|
180
|
+
resolution,
|
|
181
|
+
pixelRatio,
|
|
182
|
+
imageUrl,
|
|
183
|
+
this._crossOrigin,
|
|
184
|
+
this.imageLoadFunction_
|
|
185
|
+
);
|
|
186
|
+
this.renderedRevision_ = this.getRevision();
|
|
187
|
+
this._image.addEventListener('change', this.handleImageChange.bind(this));
|
|
188
|
+
return this._image;
|
|
189
|
+
}
|
|
190
|
+
_getRequestUrl(extent, imageSize) {
|
|
191
|
+
const params = {
|
|
192
|
+
width: imageSize[0],
|
|
193
|
+
height: imageSize[1],
|
|
194
|
+
viewBounds: { leftBottom: { x: extent[0], y: extent[1] }, rightTop: { x: extent[2], y: extent[3] } }
|
|
195
|
+
};
|
|
196
|
+
//不启用缓存时启用时间戳
|
|
197
|
+
if (!this.cacheEnabled) {
|
|
198
|
+
params['_t'] = new Date().getTime();
|
|
199
|
+
}
|
|
200
|
+
let imageUrl = CommonUtil.urlAppend(this._layerUrl, CommonUtil.getParameterString(params));
|
|
201
|
+
//支持代理
|
|
202
|
+
if (this.tileProxy) {
|
|
203
|
+
imageUrl = this.tileProxy + encodeURIComponent(imageUrl);
|
|
204
|
+
}
|
|
205
|
+
return imageUrl;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @function ImageSuperMapRest.optionsFromMapJSON
|
|
209
|
+
* @param {string} url - 地址。
|
|
210
|
+
* @param {Object} mapJSONObj - 地图 JSON。
|
|
211
|
+
* @description 获取地图 JSON 信息。
|
|
212
|
+
*/
|
|
213
|
+
static optionsFromMapJSON(url, mapJSONObj) {
|
|
214
|
+
var extent = [mapJSONObj.bounds.left, mapJSONObj.bounds.bottom, mapJSONObj.bounds.right, mapJSONObj.bounds.top];
|
|
215
|
+
var resolutions = getResolutions();
|
|
216
|
+
|
|
217
|
+
function getResolutions() {
|
|
218
|
+
var level = 28;
|
|
219
|
+
var dpi = 96;
|
|
220
|
+
var width = extent[2] - extent[0];
|
|
221
|
+
var height = extent[3] - extent[1];
|
|
222
|
+
var tileSize = width >= height ? width : height;
|
|
223
|
+
var maxReolution;
|
|
224
|
+
if (tileSize === width) {
|
|
225
|
+
maxReolution = tileSize / mapJSONObj.viewer.width;
|
|
226
|
+
} else {
|
|
227
|
+
maxReolution = tileSize / mapJSONObj.viewer.height;
|
|
228
|
+
}
|
|
229
|
+
var resolutions = [];
|
|
230
|
+
var unit = Unit.METER;
|
|
231
|
+
if (mapJSONObj.coordUnit === Unit.DEGREE) {
|
|
232
|
+
unit = Unit.DEGREE;
|
|
233
|
+
}
|
|
234
|
+
if (mapJSONObj.visibleScales.length > 0) {
|
|
235
|
+
for (let i = 0; i < mapJSONObj.visibleScales.length; i++) {
|
|
236
|
+
resolutions.push(Util.scaleToResolution(mapJSONObj.visibleScales[i], dpi, unit));
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
for (let i = 0; i < level; i++) {
|
|
240
|
+
resolutions.push(maxReolution / Math.pow(2, i));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function sortNumber(a, b) {
|
|
245
|
+
return b - a;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return resolutions.sort(sortNumber);
|
|
249
|
+
}
|
|
250
|
+
return { url,resolutions };
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* Copyright© 2000 - 2024 SuperMap Software Co.Ltd. All rights reserved.
|
|
2
|
+
* This program are made available under the terms of the Apache License, Version 2.0
|
|
3
|
+
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
|
|
4
|
+
|
|
5
|
+
import XYZ from 'ol/source/XYZ';
|
|
6
|
+
import { SecurityManager } from '@supermapgis/iclient-common/security/SecurityManager';
|
|
7
|
+
import { Util as CommonUtil } from '@supermapgis/iclient-common/commontypes/Util';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class ImageTileSuperMapRest
|
|
11
|
+
* @browsernamespace ol.source
|
|
12
|
+
* @version 10.2.0
|
|
13
|
+
* @category iServer Image
|
|
14
|
+
* @classdesc SuperMap iServer 影像服务图层源。根据指定的请求参数,返回影像数据栅格瓦片并渲染。
|
|
15
|
+
* @param {Object} options - 参数。
|
|
16
|
+
* @param {string} options.url - 服务地址。例如: http://{ip}:{port}/iserver/{imageservice-imageserviceName}/restjsr/
|
|
17
|
+
* @param {string} options.collectionId - 影像集合(Collection)的 ID,在一个影像服务中唯一标识影像集合。
|
|
18
|
+
* @param {string} [options.sqlFilter] 显示影像的过滤条件。相当于 SQL 查询中的 where 子句。支持 st_geometry 空间函数过滤。11.0 版本暂不支持通过 ECQL 进行过滤。
|
|
19
|
+
* @param {ImageRenderingRule} [options.renderingRule] 指定影像显示的风格,包含拉伸显示方式、颜色表、波段组合以及应用栅格函数进行快速处理等。不指定时,使用发布服务时所配置的风格。
|
|
20
|
+
* @param {Array.<number>} [options.ids] 返回影像集合中指定 ID 的影像,该 ID 为系统维护的一个自增 ID,为 SuperMap SDX 引擎的 SmID 字段内容。
|
|
21
|
+
* @param {Array.<string>} [options.names] 返回影像集合中指定名称影像的瓦片资源。影像名称包含文件后缀,如 S-60-45.tif。
|
|
22
|
+
* @param {string} [options.format='png'] - 瓦片表述类型,瓦片格式目前支持 png、jpg 和 webp 三种格式。
|
|
23
|
+
* @param {boolean} [options.transparent=true] - 瓦片是否透明。默认透明。
|
|
24
|
+
* @param {boolean} [options.cacheEnabled=true] - 是否启用缓存。
|
|
25
|
+
* @param {string} [options.tileProxy] - 代理地址。
|
|
26
|
+
* @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>'] - 版权描述信息。
|
|
27
|
+
* @extends {ol.source.XYZ}
|
|
28
|
+
* @usage
|
|
29
|
+
*/
|
|
30
|
+
export class ImageTileSuperMapRest extends XYZ {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
options = options || {};
|
|
33
|
+
options.format = options.format || 'png';
|
|
34
|
+
options.transparent = options.transparent === undefined ? true : options.transparent === true;
|
|
35
|
+
options.cacheEnabled = options.cacheEnabled === undefined ? true : options.cacheEnabled === true;
|
|
36
|
+
var attributions = options.attributions || "Map Data <span>© SuperMap iServer</span>";
|
|
37
|
+
var url = _createLayerUrl(options.url, options);
|
|
38
|
+
var superOptions = {
|
|
39
|
+
...options,
|
|
40
|
+
attributions: attributions,
|
|
41
|
+
url: url
|
|
42
|
+
};
|
|
43
|
+
// 需要代理时走自定义 tileLoadFunction,否则走默认的tileLoadFunction
|
|
44
|
+
if (!options.tileLoadFunction && options.tileProxy) {
|
|
45
|
+
superOptions.tileLoadFunction = tileLoadFunction;
|
|
46
|
+
}
|
|
47
|
+
super(superOptions);
|
|
48
|
+
var me = this;
|
|
49
|
+
this.options = options;
|
|
50
|
+
if (options.tileProxy) {
|
|
51
|
+
this.tileProxy = options.tileProxy;
|
|
52
|
+
}
|
|
53
|
+
function tileLoadFunction(imageTile, src) {
|
|
54
|
+
imageTile.getImage().src = me.tileProxy + encodeURIComponent(src);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _createLayerUrl(url, options) {
|
|
58
|
+
var layerUrl = CommonUtil.urlPathAppend(
|
|
59
|
+
url,
|
|
60
|
+
`/collections/${options.collectionId}/tile.${options.format}?x={x}&y={y}&z={z}`
|
|
61
|
+
);
|
|
62
|
+
var requestParams = _getAllRequestParams(options);
|
|
63
|
+
layerUrl = CommonUtil.urlAppend(layerUrl, _getParamString(requestParams));
|
|
64
|
+
layerUrl = SecurityManager.appendCredential(layerUrl);
|
|
65
|
+
|
|
66
|
+
if (!options.cacheEnabled) {
|
|
67
|
+
layerUrl += '&_t=' + new Date().getTime();
|
|
68
|
+
}
|
|
69
|
+
return layerUrl;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function _getAllRequestParams(options) {
|
|
73
|
+
var params = {};
|
|
74
|
+
params['transparent'] = options.transparent;
|
|
75
|
+
params['cacheEnabled'] = !(options.cacheEnabled === false);
|
|
76
|
+
if (options.sqlFilter) {
|
|
77
|
+
params['sqlFilter'] = options.sqlFilter;
|
|
78
|
+
}
|
|
79
|
+
if (options.renderingRule) {
|
|
80
|
+
params['renderingRule'] = JSON.stringify(options.renderingRule);
|
|
81
|
+
}
|
|
82
|
+
if (options.ids) {
|
|
83
|
+
params['ids'] = options.ids.join(',');
|
|
84
|
+
}
|
|
85
|
+
if (options.names) {
|
|
86
|
+
params['names'] = options.names.join(',');
|
|
87
|
+
}
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function _getParamString(obj) {
|
|
92
|
+
var params = [];
|
|
93
|
+
for (var i in obj) {
|
|
94
|
+
params.push(encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]));
|
|
95
|
+
}
|
|
96
|
+
return params.join('&');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { MapService } from '../services/MapService';
|
|
2
|
+
import { InitMapServiceBase, isPlaneProjection, getTileFormat, getTileset } from '@supermapgis/iclient-common/iServer/InitMapServiceBase';
|
|
3
|
+
import olMap from 'ol/Map';
|
|
4
|
+
import View from 'ol/View';
|
|
5
|
+
import Tile from 'ol/layer/Tile';
|
|
6
|
+
import { TileSuperMapRest } from './TileSuperMapRest';
|
|
7
|
+
import { Util } from '../core/Util';
|
|
8
|
+
import proj4 from 'proj4';
|
|
9
|
+
import * as olProj4 from 'ol/proj/proj4';
|
|
10
|
+
import { get } from 'ol/proj';
|
|
11
|
+
|
|
12
|
+
window.proj4 = proj4;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @function initMap
|
|
16
|
+
* @description 根据 SuperMap iServer 服务参数,创建地图与图层。目前仅支持 SuperMap iServer 地图服务,创建的图层为 ol.Tile。
|
|
17
|
+
* @category BaseTypes Util
|
|
18
|
+
* @version 11.0.1
|
|
19
|
+
* @param {number} url - 服务地址,例如: http://{ip}:{port}/iserver/services/map-world/rest/maps/World。
|
|
20
|
+
* @param {Object} options - 参数。
|
|
21
|
+
* @param {Object} [options.mapOptions] - 地图配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_Map-Map.html}。
|
|
22
|
+
* @param {Object} [options.viewOptions] - 视图配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_View-View.html} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
|
|
23
|
+
* @param {Object} [options.layerOptions] - 图层配置,参数设置参考 {@link https://openlayers.org/en/v6.15.1/apidoc/module-ol_layer_Tile-TileLayer.html} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
|
|
24
|
+
* @param {Object} [options.sourceOptions] - 数据源配置,参数设置参考 {@link TileSuperMapRest} ,未设置的情况下,默认使用 SuperMap iServer 服务参数进行设置。
|
|
25
|
+
* @param {string} [options.proxy] - 服务代理地址。
|
|
26
|
+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
|
|
27
|
+
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
|
|
28
|
+
* @param {Object} [options.headers] - 请求头。
|
|
29
|
+
* @returns {Object} 实例对象,对象包括地图实例,图层实例,数据源实例。
|
|
30
|
+
* @usage
|
|
31
|
+
* ```
|
|
32
|
+
* // 浏览器
|
|
33
|
+
* <script type="text/javascript" src="{cdn}"></script>
|
|
34
|
+
* <script>
|
|
35
|
+
* const initMap = {namespace}.initMap(url, { mapOptions, viewOptions, layerOptions, sourceOptions });
|
|
36
|
+
*
|
|
37
|
+
* </script>
|
|
38
|
+
* // ES6 Import
|
|
39
|
+
* import { initMap } from '{npm}';
|
|
40
|
+
*
|
|
41
|
+
* initMap(url, { mapOptions, viewOptions, layerOptions, sourceOptions })
|
|
42
|
+
* ```
|
|
43
|
+
* */
|
|
44
|
+
export async function initMap(url, options = {}) {
|
|
45
|
+
const { mapOptions, viewOptions, layerOptions, sourceOptions } = options;
|
|
46
|
+
const initMapService = new InitMapServiceBase(MapService, url, options);
|
|
47
|
+
const tilesets = await initMapService.getTilesets();
|
|
48
|
+
const result = await initMapService.getMapInfo();
|
|
49
|
+
if (!result || !result.result) {
|
|
50
|
+
return 'service is not work!';
|
|
51
|
+
}
|
|
52
|
+
const mapObject = result.result;
|
|
53
|
+
const { prjCoordSys, bounds, center, visibleScales, coordUnit, scale, dpi } = mapObject;
|
|
54
|
+
// tileset和地图不同投影,优先使用地图
|
|
55
|
+
const tileset = getTileset(tilesets.result, { prjCoordSys, tileType: 'Image' });
|
|
56
|
+
|
|
57
|
+
const config = {
|
|
58
|
+
center,
|
|
59
|
+
bounds,
|
|
60
|
+
dpi,
|
|
61
|
+
visibleScales,
|
|
62
|
+
scale,
|
|
63
|
+
prjCoordSys,
|
|
64
|
+
coordUnit,
|
|
65
|
+
tileFormat: 'webp',
|
|
66
|
+
tileSize: 256
|
|
67
|
+
};
|
|
68
|
+
if (tileset) {
|
|
69
|
+
config.tileFormat = getTileFormat(tileset);
|
|
70
|
+
config.tileSize = tileset.tileWidth || 256;
|
|
71
|
+
config.transparent = tileset.transparent || true;
|
|
72
|
+
config.origin = [tileset.originalPoint.x, tileset.originalPoint.y];
|
|
73
|
+
config.resolutions = tileset.resolutions;
|
|
74
|
+
config.scaleDenominators = tileset.scaleDenominators;
|
|
75
|
+
config.dpi = Util.getDpi(1.0 / tileset.scaleDenominators[0], tileset.resolutions[0], coordUnit);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!get(`EPSG:${prjCoordSys.epsgCode}`) && !isPlaneProjection(prjCoordSys.type)) {
|
|
79
|
+
const wkt = await initMapService.getWKT();
|
|
80
|
+
registerProj(prjCoordSys.epsgCode, wkt, bounds);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let map = createMap(config, mapOptions, viewOptions);
|
|
84
|
+
let { layer, source } = createLayer(url, config, sourceOptions, layerOptions);
|
|
85
|
+
map.addLayer(layer);
|
|
86
|
+
return {
|
|
87
|
+
map,
|
|
88
|
+
source,
|
|
89
|
+
layer
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @function viewOptionsFromMapJSON
|
|
95
|
+
* @category BaseTypes Util
|
|
96
|
+
* @version 11.0.1
|
|
97
|
+
* @description 通过 iServer REST 地图参数构造 ol 视图对象。
|
|
98
|
+
* @param {Object} mapJSONObj - 地图 JSON 对象。
|
|
99
|
+
* @param {number} [level=22] - 地图最大级别。
|
|
100
|
+
* @returns {Object} ol视图参数,包括中心点、投影、级别、分辨率数组。
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
export function viewOptionsFromMapJSON(mapJSONObj, level = 22) {
|
|
104
|
+
let { bounds, dpi, center, visibleScales, scale, coordUnit, prjCoordSys, scaleDenominators, resolutions } = mapJSONObj;
|
|
105
|
+
const mapCenter =
|
|
106
|
+
center.x && center.y ? [center.x, center.y] : [(bounds.left + bounds.right) / 2, (bounds.bottom + bounds.top) / 2];
|
|
107
|
+
const extent = [bounds.left, bounds.bottom, bounds.right, bounds.top];
|
|
108
|
+
let projection = Util.getProjection(prjCoordSys, extent);
|
|
109
|
+
resolutions = resolutions || Util.scalesToResolutions(visibleScales, bounds, dpi, coordUnit, level);
|
|
110
|
+
const resolution = scaleDenominators ? (1.0 / scale) : Util.scaleToResolution(scale, dpi, coordUnit);
|
|
111
|
+
const zoom = Util.getZoomByResolution(resolution, resolutions);
|
|
112
|
+
return {
|
|
113
|
+
center: mapCenter,
|
|
114
|
+
projection,
|
|
115
|
+
zoom,
|
|
116
|
+
resolutions
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function createMap(result, mapOptions, viewOptions) {
|
|
121
|
+
let view = viewOptionsFromMapJSON(result);
|
|
122
|
+
var map = new olMap({
|
|
123
|
+
target: 'map',
|
|
124
|
+
view: new View({ ...view, ...viewOptions }),
|
|
125
|
+
...mapOptions
|
|
126
|
+
});
|
|
127
|
+
return map;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function registerProj(epsgCode, wkt, bounds) {
|
|
131
|
+
const extent = [bounds.left, bounds.bottom, bounds.right, bounds.top];
|
|
132
|
+
let epsgCodeStr = `EPSG:${epsgCode}`;
|
|
133
|
+
!get(epsgCodeStr) && proj4.defs(epsgCodeStr, wkt);
|
|
134
|
+
if (olProj4 && olProj4.register) {
|
|
135
|
+
olProj4.register(proj4);
|
|
136
|
+
var prj = get(epsgCodeStr);
|
|
137
|
+
prj.setExtent(extent);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function createLayer(url, result, sourceOptions, layerOptions) {
|
|
142
|
+
let options = TileSuperMapRest.optionsFromMapJSON(url, result, true);
|
|
143
|
+
options = { ...options, ...sourceOptions };
|
|
144
|
+
var source = new TileSuperMapRest(options);
|
|
145
|
+
var layer = new Tile({
|
|
146
|
+
source,
|
|
147
|
+
...layerOptions
|
|
148
|
+
});
|
|
149
|
+
return { layer, source };
|
|
150
|
+
}
|