@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/overlay/FGB.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
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 VectorSource from 'ol/source/Vector';
|
|
5
|
+
import { deserialize } from 'flatgeobuf/lib/mjs/geojson';
|
|
6
|
+
import { FetchRequest } from '@supermapgis/iclient-common/util/FetchRequest';
|
|
7
|
+
import { all, bbox } from 'ol/loadingstrategy';
|
|
8
|
+
import { getIntersection } from '@supermapgis/iclient-common/util/MapCalculateUtil';
|
|
9
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
10
|
+
/**
|
|
11
|
+
* @class FGB
|
|
12
|
+
* @browsernamespace ol.source
|
|
13
|
+
* @category Visualization FGB
|
|
14
|
+
* @classdesc FGB 图层源,该图层源把 {@link FlatGeobuf} 格式解析为点线面要素。
|
|
15
|
+
* FlatGeobuf(FGB)是一种用于存储地理要素的坐标、类型的二进制编码格式。
|
|
16
|
+
* FGB 格式与传统的 Shapefile、GeoJSON 等文件格式类似,支持地理空间矢量数据的存储,但 FGB 格式具有更高的存储效率和更快的读写速度,
|
|
17
|
+
* 适用于大量静态数据的编码与传输。
|
|
18
|
+
* @modulecategory Overlay
|
|
19
|
+
* @version 11.1.0
|
|
20
|
+
* @param {Object} opt_options - 参数。
|
|
21
|
+
* @param {string} opt_options.url - FGB 地址,例如:http://localhost:8090/iserver/services/xxx/rest/data/featureResults/newResourceId.fgb。
|
|
22
|
+
* @param {ol.loadingstrategy} [opt_options.strategy= ol.loadingstrategy.bbox] - ol.loadingstrategy.all 为全量加载,要素会以流的方式渲染到地图。ol.loadingstrategy.bbox 为当前可见范围加载,当地图范围改变时会重新加载要素,此时可以通过 idField 参数来标识已被加载过的要素,被标识的要素无需再次加载。idField 参数无效时会清空要素,重新加载。
|
|
23
|
+
* @param {Array} [opt_options.extent] - 加载范围,参数规范为: [minX, minY, maxX, maxY],传递此参数后,图层将使用局部加载。
|
|
24
|
+
* @param {function} [opt_options.featureLoader] - 要素加载回调函数。
|
|
25
|
+
* @param {boolean} [opt_options.overlaps] - 是否优化重叠要素的填充与描边操作。
|
|
26
|
+
* @param {boolean} [opt_options.useSpatialIndex] - 是否启用要素空间索引。
|
|
27
|
+
* @param {boolean} [opt_options.wrapX] - 是否平铺地图。
|
|
28
|
+
* @param {boolean} [opt_options.idField='SmID'] - 要素属性中表示唯一标识的字段,当 strategy 为 ol.loadingstrategy.bbox 时生效。
|
|
29
|
+
* @extends {ol.source.Vector}
|
|
30
|
+
* @usage
|
|
31
|
+
*/
|
|
32
|
+
export class FGB extends VectorSource {
|
|
33
|
+
constructor(options) {
|
|
34
|
+
const baseOptions = Object.assign({ strategy: bbox }, options);
|
|
35
|
+
delete baseOptions.url;
|
|
36
|
+
delete baseOptions.extent;
|
|
37
|
+
delete baseOptions.idField;
|
|
38
|
+
super(baseOptions);
|
|
39
|
+
this.options = options || {};
|
|
40
|
+
this.strategy = baseOptions.strategy;
|
|
41
|
+
this.url = this.options.url;
|
|
42
|
+
this.extent = this.options.extent;
|
|
43
|
+
this._idField = this.options.idField || 'SmID';
|
|
44
|
+
this._validatedId = false;
|
|
45
|
+
this._checked = false;
|
|
46
|
+
this.setLoader(async function (extent) {
|
|
47
|
+
if (this.strategy === bbox) {
|
|
48
|
+
if (!this._validatedId) {
|
|
49
|
+
this.clear();
|
|
50
|
+
}
|
|
51
|
+
if (this.extent) {
|
|
52
|
+
const intersectExtent = getIntersection(this.extent, extent);
|
|
53
|
+
extent = (intersectExtent && intersectExtent.length) ? intersectExtent : this.extent;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!this.extent && (this.strategy === all || !isFinite(extent[0]))) {
|
|
57
|
+
extent = [];
|
|
58
|
+
}
|
|
59
|
+
let fgbStream;
|
|
60
|
+
if (!Object.keys(extent).length) {
|
|
61
|
+
fgbStream = await this._getStream(this.url);
|
|
62
|
+
}
|
|
63
|
+
this._handleFeatures((fgbStream && fgbStream.body) || this.url, extent);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async _handleFeatures(url, extent) {
|
|
68
|
+
let rect = {};
|
|
69
|
+
if (extent && extent.length) {
|
|
70
|
+
rect = {
|
|
71
|
+
minX: extent[0],
|
|
72
|
+
minY: extent[1],
|
|
73
|
+
maxX: extent[2],
|
|
74
|
+
maxY: extent[3]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const fgb = deserialize(url, rect);
|
|
78
|
+
for await (let feature of fgb) {
|
|
79
|
+
let id = feature.properties[this._idField];
|
|
80
|
+
if (id && !this._validatedId) {
|
|
81
|
+
this._validatedId = true;
|
|
82
|
+
this._checked = true;
|
|
83
|
+
}
|
|
84
|
+
feature = new GeoJSON().readFeature(feature);
|
|
85
|
+
if (id && this._checked) {
|
|
86
|
+
feature.setId(id);
|
|
87
|
+
}
|
|
88
|
+
if (this.options.featureLoader && typeof this.options.featureLoader === 'function') {
|
|
89
|
+
feature = this.options.featureLoader(feature);
|
|
90
|
+
}
|
|
91
|
+
this.addFeature(feature);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async _getStream(url) {
|
|
96
|
+
return await FetchRequest.get(url, {}, { withoutFormatSuffix: true }).then(function (response) {
|
|
97
|
+
return response;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
package/overlay/Graph.js
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
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 { Util as CommonUtil} from '@supermapgis/iclient-common/commontypes/Util';
|
|
5
|
+
import { Theme as FeatureTheme } from "@supermapgis/iclient-common/overlay/feature/Theme";
|
|
6
|
+
import { LonLat } from '@supermapgis/iclient-common/commontypes/LonLat';
|
|
7
|
+
import { Bounds } from '@supermapgis/iclient-common/commontypes/Bounds';
|
|
8
|
+
import {
|
|
9
|
+
Theme
|
|
10
|
+
} from './theme/Theme';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @class Graph
|
|
14
|
+
* @browsernamespace ol.source
|
|
15
|
+
* @category Visualization Theme
|
|
16
|
+
* @classdesc 统计专题图图层基类。统计专题图是通过为每个要素或记录绘制统计图来反映其对应的专题值的大小。
|
|
17
|
+
* 统计专题图可以基于多个变量,反映多种属性,即可以将多个专题值绘制在一个统计图上,并且每个区域都会有一幅表示该区域各专题值的统计图。
|
|
18
|
+
* 通过统计专题图可以在区域本身与各区域之间形成横向和纵向的对比。多用于具有相关数量特征的地图上,比如表示不同地区多年的粮食产量、GDP、人口等,
|
|
19
|
+
* 不同时段客运量、地铁流量等。
|
|
20
|
+
* @modulecategory Overlay
|
|
21
|
+
* @param {string} chartsType - 图表类别。
|
|
22
|
+
* @param {string} name - 图层名称。
|
|
23
|
+
* @param {Object} opt_options - 参数。
|
|
24
|
+
* @param {ol.Map} opt_options.map - 当前 OpenLayers 地图对象。
|
|
25
|
+
* @param {string} opt_options.chartsType - 图表类型。目前可用:"Bar","Bar3D","Line","Point","Pie","Ring"。
|
|
26
|
+
* @param {Object} opt_options.chartsSetting - 各类型图表的 chartsSetting 对象可设属性请参考具体图表模型类的注释中对 chartsSetting 对象可设属性的描述。chartsSetting 对象通常都具有以下几个基础可设属性。
|
|
27
|
+
* @param {number} opt_options.chartsSetting.width - 专题要素(图表)宽度,单位为像素。
|
|
28
|
+
* @param {number} opt_options.chartsSetting.height - 专题要素(图表)高度,单位为像素。
|
|
29
|
+
* @param {Array.<number>} opt_options.chartsSetting.codomain - 值域,长度为 2 的一维数组,第一个元素表示值域下限,第二个元素表示值域上限。
|
|
30
|
+
* @param {number} [opt_options.chartsSetting.XOffset] - 专题要素(图表)在 X 方向上的偏移值,单位为像素。
|
|
31
|
+
* @param {number} [opt_options.chartsSetting.YOffset] - 专题要素(图表)在 Y 方向上的偏移值,单位为像素。
|
|
32
|
+
* @param {Array.<number>} [opt_options.chartsSetting.dataViewBoxParameter] - 数据视图框 dataViewBox 参数,它是指图表框 chartBox(由图表位置、图表宽度、图表高度构成的图表范围框)在左、下,右,上四个方向上的内偏距值,长度为 4 的一维数组。
|
|
33
|
+
* @param {number} [opt_options.chartsSetting.decimalNumber] - 数据值数组 dataValues 元素值小数位数,数据的小数位处理参数,取值范围:[0, 16]。如果不设置此参数,在取数据值时不对数据做小数位处理。
|
|
34
|
+
* @param {string} opt_options.themeFields - 指定创建专题图字段。
|
|
35
|
+
* @param {string} [opt_options.id] - 专题图层 ID。默认使用 CommonUtil.createUniqueID("themeLayer_") 创建专题图层 ID。
|
|
36
|
+
* @param {number} [opt_options.opacity = 1] - 图层不透明度。
|
|
37
|
+
* @param {string} [opt_options.logo] - Logo(OpenLayers 5.0.0 及更高版本不再支持此参数)。
|
|
38
|
+
* @param {ol.proj.Projection} [opt_options.projection] - {@link ol.proj.Projection} 投影信息。
|
|
39
|
+
* @param {number} [opt_options.ratio=1.5] - 视图比,1 表示画布是地图视口的大小,2 表示地图视口的宽度和高度的两倍,依此类推。必须是 1 或更高。
|
|
40
|
+
* @param {Array.<number>} [opt_options.resolutions] - 分辨率数组。
|
|
41
|
+
* @param {boolean} [opt_options.isOverLay=true] - 是否进行压盖处理,如果设为 true,图表绘制过程中将隐藏对已在图层中绘制的图表产生压盖的图表。
|
|
42
|
+
* @param {ol.source.State} [opt_options.state] - 资源状态。
|
|
43
|
+
* @param {(string|Object)} [opt_options.attributions='Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权描述信息。
|
|
44
|
+
* @extends {Theme}
|
|
45
|
+
* @usage
|
|
46
|
+
*/
|
|
47
|
+
export class Graph extends Theme {
|
|
48
|
+
|
|
49
|
+
constructor(name, chartsType, opt_options) {
|
|
50
|
+
super(name, opt_options);
|
|
51
|
+
this.chartsSetting = opt_options.chartsSetting || {};
|
|
52
|
+
this.themeFields = opt_options.themeFields || null;
|
|
53
|
+
this.overlayWeightField = opt_options.overlayWeightField || null;
|
|
54
|
+
this.isOverLay = opt_options.isOverLay === undefined ? true : opt_options.isOverLay;
|
|
55
|
+
this.charts = opt_options.charts || [];
|
|
56
|
+
this.cache = opt_options.cache || {};
|
|
57
|
+
this.chartsType = chartsType;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @function Graph.prototype.destroy
|
|
62
|
+
* @description 释放资源,将引用资源的属性置空。
|
|
63
|
+
*/
|
|
64
|
+
destroy() {
|
|
65
|
+
this.chartsType = null;
|
|
66
|
+
this.chartsSetting = null;
|
|
67
|
+
this.themeFields = null;
|
|
68
|
+
this.overlayWeightField = null;
|
|
69
|
+
this.isOverLay = null;
|
|
70
|
+
Theme.prototype.destroy.apply(this, arguments);
|
|
71
|
+
// charts cache 为缓存,需要在父类destory后置为null(父类destory中有方法会初始化缓存参数)
|
|
72
|
+
this.charts = null;
|
|
73
|
+
this.cache = null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @function Graph.prototype.setChartsType
|
|
78
|
+
* @description 设置图表类型,此函数可动态改变图表类型。在调用此函数前请通过 chartsSetting 为新类型的图表做相关配置。
|
|
79
|
+
* @param {string} chartsType - 图表类型。目前可用:"Bar","Bar3D","Line","Point","Pie","Ring"。
|
|
80
|
+
*/
|
|
81
|
+
setChartsType(chartsType) {
|
|
82
|
+
this.chartsType = chartsType;
|
|
83
|
+
this.redraw();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @function Graph.prototype.addFeatures
|
|
88
|
+
* @description 向专题图图层中添加数据。
|
|
89
|
+
* @param {(ServerFeature|ThemeFeature)} features - 待添加的要素。
|
|
90
|
+
*/
|
|
91
|
+
addFeatures(features) {
|
|
92
|
+
var ret = this.dispatchEvent({
|
|
93
|
+
type: 'beforefeaturesadded',
|
|
94
|
+
value: {
|
|
95
|
+
features: features
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
if (ret === false) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
//转换 features 形式
|
|
102
|
+
this.features = this.toiClientFeature(features);
|
|
103
|
+
//绘制专题要素
|
|
104
|
+
if (this.renderer) {
|
|
105
|
+
this.changed();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @function Graph.prototype.redrawThematicFeatures
|
|
111
|
+
* @description 重绘所有专题要素。
|
|
112
|
+
* 此方法包含绘制专题要素的所有步骤,包含用户数据到专题要素的转换,抽稀,缓存等步骤。
|
|
113
|
+
* 地图漫游时调用此方法进行图层刷新。
|
|
114
|
+
* @param {Object} extent - 重绘的范围。
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
redrawThematicFeatures(extent) {
|
|
118
|
+
//清除当前所有可视元素
|
|
119
|
+
this.renderer.clearAll();
|
|
120
|
+
var features = this.features;
|
|
121
|
+
for (var i = 0, len = features.length; i < len; i++) {
|
|
122
|
+
var feature = features[i];
|
|
123
|
+
// 要素范围判断
|
|
124
|
+
var feaBounds = feature.geometry.getBounds();
|
|
125
|
+
//剔除当前视图(地理)范围以外的数据
|
|
126
|
+
if (extent) {
|
|
127
|
+
var bounds = new Bounds(extent[0], extent[1], extent[2], extent[3]);
|
|
128
|
+
if (!bounds.intersectsBounds(feaBounds)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
var cache = this.cache;
|
|
133
|
+
// 用 feature id 做缓存标识
|
|
134
|
+
var cacheField = feature.id;
|
|
135
|
+
// 数据对应的图表是否已缓存,没缓存则重新创建图表
|
|
136
|
+
if (cache[cacheField]) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
cache[cacheField] = cacheField;
|
|
140
|
+
var chart = this.createThematicFeature(feature);
|
|
141
|
+
// 压盖处理权重值
|
|
142
|
+
if (chart && this.overlayWeightField) {
|
|
143
|
+
if (feature.attributes[this.overlayWeightField] && !isNaN(feature.attributes[this.overlayWeightField])) {
|
|
144
|
+
chart["__overlayWeight"] = feature.attributes[this.overlayWeightField];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (chart) {
|
|
148
|
+
this.charts.push(chart);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.drawCharts();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @function Graph.prototype.createThematicFeature
|
|
156
|
+
* @description 向专题图图层中添加数据,支持的 feature 类型为:SuperMap iServer 返回的 feature JSON 对象。
|
|
157
|
+
* @param {ServerFeature} feature - 待添加的要素。
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
createThematicFeature(feature) {
|
|
161
|
+
var thematicFeature;
|
|
162
|
+
// 检查图表创建条件并创建图形
|
|
163
|
+
if (FeatureTheme[this.chartsType] && this.themeFields && this.chartsSetting) {
|
|
164
|
+
thematicFeature = new FeatureTheme[this.chartsType](feature, this, this.themeFields, this.chartsSetting);
|
|
165
|
+
}
|
|
166
|
+
// thematicFeature 是否创建成功
|
|
167
|
+
if (!thematicFeature) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
// 对专题要素执行图形装载
|
|
171
|
+
thematicFeature.assembleShapes();
|
|
172
|
+
return thematicFeature;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @function Graph.prototype.drawCharts
|
|
177
|
+
* @description 绘制图表。包含压盖处理。
|
|
178
|
+
*
|
|
179
|
+
*/
|
|
180
|
+
drawCharts() {
|
|
181
|
+
// 判断 rendere r就绪
|
|
182
|
+
if (!this.renderer) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
var charts = this.charts;
|
|
186
|
+
// 图表权重值处理
|
|
187
|
+
if (this.overlayWeightField) {
|
|
188
|
+
charts.sort(function (cs, ce) {
|
|
189
|
+
if (typeof (cs["__overlayWeight"]) == "undefined" && typeof (ce["__overlayWeight"]) == "undefined") {
|
|
190
|
+
return 0;
|
|
191
|
+
} else if (typeof (cs["__overlayWeight"]) != "undefined" && typeof (ce["__overlayWeight"]) == "undefined") {
|
|
192
|
+
return -1;
|
|
193
|
+
} else if (typeof (cs["__overlayWeight"]) == "undefined" && typeof (ce["__overlayWeight"]) != "undefined") {
|
|
194
|
+
return 1;
|
|
195
|
+
} else if (typeof (cs["__overlayWeight"]) != "undefined" && typeof (ce["__overlayWeight"]) != "undefined") {
|
|
196
|
+
if (parseFloat(cs["__overlayWeight"]) < parseFloat(ce["__overlayWeight"])) {
|
|
197
|
+
return 1;
|
|
198
|
+
} else {
|
|
199
|
+
return -1;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return 0;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// 不进行避让
|
|
206
|
+
if (!this.isOverLay) {
|
|
207
|
+
for (var m = 0, len_m = charts.length; m < len_m; m++) {
|
|
208
|
+
var chart_m = charts[m];
|
|
209
|
+
// 图形参考位置 (reSetLocation 会更新 chartBounds)
|
|
210
|
+
var shapeROP_m = chart_m.resetLocation();
|
|
211
|
+
// 添加图形
|
|
212
|
+
var shapes_m = chart_m.shapes;
|
|
213
|
+
for (var n = 0, slen_n = shapes_m.length; n < slen_n; n++) {
|
|
214
|
+
shapes_m[n].refOriginalPosition = shapeROP_m;
|
|
215
|
+
this.renderer.addShape(shapes_m[n]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
// 压盖判断所需 chartsBounds 集合
|
|
220
|
+
var chartsBounds = [];
|
|
221
|
+
var extent = this.map.getView().calculateExtent();
|
|
222
|
+
var mapBounds = new Bounds(extent[0], extent[1], extent[2], extent[3]);
|
|
223
|
+
// 获取地图像素 bounds
|
|
224
|
+
var mapPxLT = this.getLocalXY(new LonLat(mapBounds.left, mapBounds.top));
|
|
225
|
+
var mapPxRB = this.getLocalXY(new LonLat(mapBounds.right, mapBounds.bottom));
|
|
226
|
+
var mBounds = new Bounds(mapPxLT[0], mapPxRB[1], mapPxRB[0], mapPxLT[1]);
|
|
227
|
+
// 压盖处理 & 添加图形
|
|
228
|
+
for (var i = 0, len = charts.length; i < len; i++) {
|
|
229
|
+
var chart = charts[i];
|
|
230
|
+
// 图形参考位置 (reSetLocation 会更新 chartBounds)
|
|
231
|
+
var shapeROP = chart.resetLocation();
|
|
232
|
+
// 图表框
|
|
233
|
+
var cbs = chart.chartBounds;
|
|
234
|
+
var cBounds = [{
|
|
235
|
+
"x": cbs.left,
|
|
236
|
+
"y": cbs.top
|
|
237
|
+
}, {
|
|
238
|
+
"x": cbs.left,
|
|
239
|
+
"y": cbs.bottom
|
|
240
|
+
}, {
|
|
241
|
+
"x": cbs.right,
|
|
242
|
+
"y": cbs.bottom
|
|
243
|
+
}, {
|
|
244
|
+
"x": cbs.right,
|
|
245
|
+
"y": cbs.top
|
|
246
|
+
}, {
|
|
247
|
+
"x": cbs.left,
|
|
248
|
+
"y": cbs.top
|
|
249
|
+
}];
|
|
250
|
+
// 地图范围外不绘制
|
|
251
|
+
if (mBounds) {
|
|
252
|
+
if (!this.isChartInMap(mBounds, cBounds)) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// 是否压盖
|
|
257
|
+
var isOL = false;
|
|
258
|
+
if (i !== 0) {
|
|
259
|
+
for (let j = 0; j < chartsBounds.length; j++) {
|
|
260
|
+
//压盖判断
|
|
261
|
+
if (this.isQuadrilateralOverLap(cBounds, chartsBounds[j])) {
|
|
262
|
+
isOL = true;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (isOL) {
|
|
268
|
+
continue;
|
|
269
|
+
} else {
|
|
270
|
+
chartsBounds.push(cBounds);
|
|
271
|
+
}
|
|
272
|
+
// 添加图形
|
|
273
|
+
var shapes = chart.shapes;
|
|
274
|
+
for (let j = 0, slen = shapes.length; j < slen; j++) {
|
|
275
|
+
shapes[j].refOriginalPosition = shapeROP;
|
|
276
|
+
this.renderer.addShape(shapes[j]);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 绘制图形
|
|
281
|
+
this.renderer.render();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @function Graph.prototype.getShapesByFeatureID
|
|
286
|
+
* @description 通过要素 ID 获取要素关联的所有图形。如果不传入此参数,函数将返回所有图形。
|
|
287
|
+
* @param {number} featureID - 要素 ID。
|
|
288
|
+
*/
|
|
289
|
+
getShapesByFeatureID(featureID) {
|
|
290
|
+
var list = [];
|
|
291
|
+
var shapeList = this.renderer.getAllShapes();
|
|
292
|
+
if (!featureID) {
|
|
293
|
+
return shapeList
|
|
294
|
+
}
|
|
295
|
+
for (var i = 0, len = shapeList.length; i < len; i++) {
|
|
296
|
+
var si = shapeList[i];
|
|
297
|
+
if (si.refDataID && featureID === si.refDataID) {
|
|
298
|
+
list.push(si);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return list;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @function Graph.prototype.isQuadrilateralOverLap
|
|
306
|
+
* @description 判断两个四边形是否有压盖。
|
|
307
|
+
* @param {Array.<Object>} quadrilateral - 四边形节点数组。
|
|
308
|
+
* @param {Array.<Object>} quadrilateral2 - 第二个四边形节点数组。
|
|
309
|
+
*/
|
|
310
|
+
isQuadrilateralOverLap(quadrilateral, quadrilateral2) {
|
|
311
|
+
var quadLen = quadrilateral.length,
|
|
312
|
+
quad2Len = quadrilateral2.length;
|
|
313
|
+
if (quadLen !== 5 || quad2Len !== 5) {
|
|
314
|
+
return null;
|
|
315
|
+
} //不是四边形
|
|
316
|
+
|
|
317
|
+
var OverLap = false;
|
|
318
|
+
//如果两四边形互不包含对方的节点,则两个四边形不相交
|
|
319
|
+
for (let i = 0; i < quadLen; i++) {
|
|
320
|
+
if (this.isPointInPoly(quadrilateral[i], quadrilateral2)) {
|
|
321
|
+
OverLap = true;
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (let i = 0; i < quad2Len; i++) {
|
|
326
|
+
if (this.isPointInPoly(quadrilateral2[i], quadrilateral)) {
|
|
327
|
+
OverLap = true;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
//加上两矩形十字相交的情况
|
|
332
|
+
for (let i = 0; i < quadLen - 1; i++) {
|
|
333
|
+
if (OverLap) {
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
for (let j = 0; j < quad2Len - 1; j++) {
|
|
337
|
+
var isLineIn = CommonUtil.lineIntersection(quadrilateral[i], quadrilateral[i + 1], quadrilateral2[j], quadrilateral2[j + 1]);
|
|
338
|
+
if (isLineIn.CLASS_NAME === "SuperMap.Geometry.Point") {
|
|
339
|
+
OverLap = true;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return OverLap;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @function Graph.prototype.isPointInPoly
|
|
349
|
+
* @description 判断一个点是否在多边形里面(射线法)。
|
|
350
|
+
* @param {Object} pt - 需要判定的点对象,该对象含有属性 x(横坐标),属性 y(纵坐标)。
|
|
351
|
+
* @param {Array.<Object>} poly - 多边形节点数组。
|
|
352
|
+
*/
|
|
353
|
+
isPointInPoly(pt, poly) {
|
|
354
|
+
for (var isIn = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
|
|
355
|
+
((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) &&
|
|
356
|
+
(pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x) &&
|
|
357
|
+
(isIn = !isIn);
|
|
358
|
+
}
|
|
359
|
+
return isIn;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @function Graph.prototype.isChartInMap
|
|
364
|
+
* @description 判断图表是否在地图里。
|
|
365
|
+
* @param {Bounds} mapPxBounds - 地图像素范围。
|
|
366
|
+
* @param {Array.<Object>} chartPxBounds - 图表范围的四边形节点数组。
|
|
367
|
+
*/
|
|
368
|
+
isChartInMap(mapPxBounds, chartPxBounds) {
|
|
369
|
+
var mb = mapPxBounds;
|
|
370
|
+
var isIn = false;
|
|
371
|
+
for (var i = 0, len = chartPxBounds.length; i < len; i++) {
|
|
372
|
+
var cb = chartPxBounds[i];
|
|
373
|
+
|
|
374
|
+
if (cb.x >= mb.left && cb.x <= mb.right && cb.y >= mb.top && cb.y <= mb.bottom) {
|
|
375
|
+
isIn = true;
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return isIn;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* @function Graph.prototype.clearCache
|
|
384
|
+
* @description 清除缓存。
|
|
385
|
+
*/
|
|
386
|
+
clearCache() {
|
|
387
|
+
this.cache = {};
|
|
388
|
+
this.charts = [];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @function Graph.prototype.removeFeatures
|
|
393
|
+
* @description 从专题图中删除要素。这个函数删除所有传递进来的矢量要素。参数中的要素数组中的每一项,必须是已经添加到当前图层中的 feature。
|
|
394
|
+
* @param {Array.<FeatureVector>|FeatureVector|Function} features - 要删除的要素。
|
|
395
|
+
*/
|
|
396
|
+
removeFeatures(features) {
|
|
397
|
+
this.clearCache();
|
|
398
|
+
super.removeFeatures(features);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* @function Graph.prototype.removeAllFeatures
|
|
403
|
+
* @description 移除所有的要素。
|
|
404
|
+
*/
|
|
405
|
+
removeAllFeatures() {
|
|
406
|
+
this.clearCache();
|
|
407
|
+
super.removeAllFeatures();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @function Graph.prototype.redraw
|
|
412
|
+
* @description 重绘该图层。
|
|
413
|
+
*/
|
|
414
|
+
redraw() {
|
|
415
|
+
this.clearCache();
|
|
416
|
+
if (this.renderer) {
|
|
417
|
+
this.redrawThematicFeatures(this.map.getView().calculateExtent());
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
return false
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* @function Graph.prototype.clear
|
|
425
|
+
* @description 清除的内容包括数据(features)、专题要素、缓存。
|
|
426
|
+
*/
|
|
427
|
+
clear() {
|
|
428
|
+
if (this.renderer) {
|
|
429
|
+
this.renderer.clearAll();
|
|
430
|
+
this.renderer.refresh();
|
|
431
|
+
}
|
|
432
|
+
this.removeAllFeatures();
|
|
433
|
+
this.clearCache();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
canvasFunctionInternal_(extent, resolution, pixelRatio, size, projection) { // eslint-disable-line no-unused-vars
|
|
437
|
+
return Theme.prototype.canvasFunctionInternal_.apply(this, arguments);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 Observable from 'ol/Observable';
|
|
5
|
+
import { KnowledgeGraphService } from '../services/KnowledgeGraphService';
|
|
6
|
+
import { KnowledgeGraph } from '@supermapgis/iclient-common/overlay/KnowledgeGraph';
|
|
7
|
+
import { transformExpandCollapseHiddenData } from '@supermapgis/iclient-common/overlay/knowledge-graph/format';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class GraphMap
|
|
11
|
+
* @classdesc 对接 SuperMap iServer GraphMap,即 SuperMap iServer 中的知识图谱图文档,此类提供了知识图谱的服务地址、配置项等参数。
|
|
12
|
+
* 配置项包括:知识图谱的尺寸、中心点、缩放比例、布局、节点配置、边配置、高亮样式、拖拽设置等参数。
|
|
13
|
+
* @category iServer KnowledgeGraph
|
|
14
|
+
* @version 11.1.0
|
|
15
|
+
* @param {string} serviceUrl - GraphMap 服务地址, 例如:http://{iserver}/services/{knowledgeGraph-provider}/restjsr/graph/graphmaps/{graphmap}。
|
|
16
|
+
* @param {Object} [options] - 参数。
|
|
17
|
+
* @param {KnowledgeGraph.Config} [options.config] - KnowledgeGraph 的配置项。
|
|
18
|
+
* @param {string} [options.proxy] - 服务代理地址。
|
|
19
|
+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
|
|
20
|
+
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
|
|
21
|
+
* @param {Object} [options.headers] - 请求头。
|
|
22
|
+
* @fires GraphMap#loaded
|
|
23
|
+
* @extends {ol.Observable}
|
|
24
|
+
* @usage
|
|
25
|
+
*/
|
|
26
|
+
export class GraphMap extends Observable {
|
|
27
|
+
constructor(serviceUrl, options) {
|
|
28
|
+
super();
|
|
29
|
+
/**
|
|
30
|
+
* @member GraphMap.prototype.graph
|
|
31
|
+
* @description KnowledgeGraph 的实例。
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
this.graph = null;
|
|
35
|
+
/**
|
|
36
|
+
* @member GraphMap.prototype.EVENT_TYPES
|
|
37
|
+
* @description 监听一个自定义事件可用如下方式:
|
|
38
|
+
*
|
|
39
|
+
* 支持的事件如下:
|
|
40
|
+
* loaded - 渲染完成时触发。
|
|
41
|
+
*/
|
|
42
|
+
this.EVENT_TYPES = ['loaded'];
|
|
43
|
+
this.url = serviceUrl;
|
|
44
|
+
this.options = options;
|
|
45
|
+
const graphMapName = serviceUrl.split('/').pop();
|
|
46
|
+
this.url = serviceUrl.replace(`/graphmaps/${graphMapName}`, '');
|
|
47
|
+
this.createGraphMap(graphMapName, options);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @private
|
|
52
|
+
* @function GraphMap.prototype.createGraphMap
|
|
53
|
+
* @description 创建图谱。
|
|
54
|
+
* @param {string} graphMapName - 图谱名称。
|
|
55
|
+
* @param {Object} options - 参数。
|
|
56
|
+
* @param {string} [options.proxy] - 服务代理地址。
|
|
57
|
+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
|
|
58
|
+
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
|
|
59
|
+
* @param {Object} [options.headers] - 请求头。
|
|
60
|
+
* @param {KnowledgeGraph.Config} [options.config] - knowledgegraph 配置项。
|
|
61
|
+
*/
|
|
62
|
+
async createGraphMap(graphMapName, options) {
|
|
63
|
+
this.knowledgeGraphService = this.createKnowledgeGraphService(this.url, options);
|
|
64
|
+
const res = await this.knowledgeGraphService.getGraphMapData(graphMapName);
|
|
65
|
+
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap);
|
|
66
|
+
this.graph = new KnowledgeGraph(options && options.config);
|
|
67
|
+
this.graph.on('afterlayout', () => {
|
|
68
|
+
/**
|
|
69
|
+
* @event GraphMap#loaded
|
|
70
|
+
* @description 渲染完成时触发。
|
|
71
|
+
*/
|
|
72
|
+
this.dispatchEvent(this.EVENT_TYPES[0]);
|
|
73
|
+
});
|
|
74
|
+
this.graph.setData(result);
|
|
75
|
+
this.graph.handleNodeStatus(transformExpandCollapseHiddenData(res.graphMap));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
* @function GraphMap.prototype.createKnowledgeGraphService
|
|
81
|
+
* @description 创建 KnowledgeGraphService 实例。
|
|
82
|
+
* @param {string} serviceUrl - GraphMap 服务地址,例如:http://{iserver}/services/knowledgeGraph-test/restjsr/graph
|
|
83
|
+
* @param {Object} options - 参数。
|
|
84
|
+
* @param {string} [options.proxy] - 服务代理地址。
|
|
85
|
+
* @param {boolean} [options.withCredentials=false] - 请求是否携带 cookie。
|
|
86
|
+
* @param {boolean} [options.crossOrigin] - 是否允许跨域请求。
|
|
87
|
+
* @param {Object} [options.headers] - 请求头。
|
|
88
|
+
*/
|
|
89
|
+
createKnowledgeGraphService(serviceUrl, options) {
|
|
90
|
+
return new KnowledgeGraphService(serviceUrl, options);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @function GraphMap.prototype.findShortestPath
|
|
95
|
+
* @version 11.2.0
|
|
96
|
+
* @description 获取开始节点和结束节点之间的最短路径。(在渲染完成后调用)
|
|
97
|
+
* @param {GraphMap.findShortestPathParams} params - 参数。
|
|
98
|
+
* @param {RequestCallback} [callback] - 回调函数,该参数未传时可通过返回的 promise 获取结果。
|
|
99
|
+
* @returns {Promise} Promise 对象。
|
|
100
|
+
*/
|
|
101
|
+
findShortestPath(params, callback) {
|
|
102
|
+
const { startID, endID, isHighlight = true, highlightStateStyles = {} } = params;
|
|
103
|
+
return this.knowledgeGraphService.findShortestPath({ startID, endID }, (res) => {
|
|
104
|
+
callback && callback(res);
|
|
105
|
+
if (isHighlight) {
|
|
106
|
+
if (res.type === 'processCompleted' && res.result.succeed) {
|
|
107
|
+
const { nodeIDs, edgeIDs } = res.result;
|
|
108
|
+
this.highlight({ nodeIDs, edgeIDs, ...highlightStateStyles });
|
|
109
|
+
} else {
|
|
110
|
+
alert(res.error.errorMsg, false);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @function GraphMap.prototype.highlight
|
|
118
|
+
* @version 11.2.0
|
|
119
|
+
* @description 高亮节点和边。(在渲染完成后调用)
|
|
120
|
+
* @param {KnowledgeGraph.highlightParams} params - 高亮参数。
|
|
121
|
+
*/
|
|
122
|
+
highlight(params) {
|
|
123
|
+
if (!this.graph) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.graph.highlight(params);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @function GraphMap.prototype.clearHighlight
|
|
130
|
+
* @version 11.2.0
|
|
131
|
+
* @description 取消高亮节点和边。(在渲染完成后调用)
|
|
132
|
+
* @param {KnowledgeGraph.clearHighlightParams} [params] - 取消高亮节点id数组和边id数组, 不传默认取消所有激活状态的高亮。
|
|
133
|
+
*/
|
|
134
|
+
clearHighlight(params) {
|
|
135
|
+
if (!this.graph) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.graph.clearHighlight(params);
|
|
139
|
+
}
|
|
140
|
+
}
|