Skip to content

Commit 4331791

Browse files
committed
[update]海图S57和S101类型ChartSetting分开构造,水位查询改为查询最近的水位点,并新增时间过滤参数
1 parent e564a85 commit 4331791

File tree

23 files changed

+941
-1130
lines changed

23 files changed

+941
-1130
lines changed

examples/leaflet/01_chartService.html

Lines changed: 74 additions & 191 deletions
Large diffs are not rendered by default.

examples/mapboxgl/01_chartService.html

Lines changed: 89 additions & 206 deletions
Large diffs are not rendered by default.

examples/maplibregl/01_chartService.html

Lines changed: 89 additions & 206 deletions
Large diffs are not rendered by default.

examples/openlayers/01_chartService.html

Lines changed: 74 additions & 191 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"@supermapgis/iclient-common": "file:src/common",
146146
"@supermapgis/tile-decryptor": "^1.0.0",
147147
"@turf/center": "^7.2.0",
148+
"@turf/distance": "^7.2.0",
148149
"@turf/meta": "^7.2.0",
149150
"@turf/turf": "7.2.0",
150151
"canvg": "^4.0.3",

src/common/iServer/ChartService.js

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import { FeatureService } from './FeatureService';
1212
import { GetFeaturesBySQLParameters } from './GetFeaturesBySQLParameters';
1313
import { GetGridCellInfosParameters } from './GetGridCellInfosParameters';
14-
import { GetFeaturesByBoundsParameters } from './GetFeaturesByBoundsParameters';
14+
import { GetFeaturesByBufferParameters } from './GetFeaturesByBufferParameters';
15+
import { distance } from "@turf/distance";
16+
import { Point } from '../commontypes/geometry/Point';
1517

1618
/**
1719
* @class ChartService
@@ -196,20 +198,15 @@
196198
crossOrigin: me.options.crossOrigin,
197199
headers: me.options.headers
198200
});
199-
var { dataSource, dataset, waterLevelDataset, timeDataset, bounds, timeIdKey } = params;
200-
// 查询水位点
201-
var boundsParam = new GetFeaturesByBoundsParameters({
202-
...params,
203-
datasetNames: [dataSource + ':' + dataset],
204-
bounds: bounds
205-
});
206-
return featureService.getFeaturesByBounds(boundsParam, callback).then(function (boundsResult) {
207-
var stationFeature = boundsResult.result.features.features[0];
208-
if(!stationFeature) {
201+
var { dataSource, dataset, waterLevelDataset, timeDataset, coordinates, currentTime, startTime, endTime, timeIdKey } = params;
202+
// 查询最近的水位点
203+
var datasetNames = [dataSource + ':' + dataset];
204+
return this.findNearestPointNew(coordinates, datasetNames).then(function (closestFeature) {
205+
if (!closestFeature) {
209206
return null;
210207
}
211-
var stationId = stationFeature.properties.STATIONID;
212-
var cellId = stationFeature.properties.CELLID;
208+
var stationId = closestFeature.properties.STATIONID;
209+
var cellId = closestFeature.properties.CELLID;
213210
// 查询水位
214211
var waterLevelSqlParam = new GetFeaturesBySQLParameters({
215212
...params,
@@ -246,7 +243,19 @@
246243
feature.properties.TIMEPOINT = null;
247244
}
248245
});
249-
return { features: waterLevelResult.result.features, stationFeature };
246+
// 过滤时间范围,也可考虑用attributeFilter过滤
247+
if (currentTime || startTime || endTime) {
248+
features = features.filter(feature => {
249+
const timepoint = feature.properties.TIMEPOINT;
250+
if (currentTime) {
251+
return timepoint === currentTime;
252+
}
253+
const afterStart = !startTime || timepoint >= startTime;
254+
const beforeEnd = !endTime || timepoint <= endTime;
255+
return afterStart && beforeEnd;
256+
});
257+
}
258+
return { features, stationFeature: closestFeature };
250259
});
251260
});
252261
});
@@ -305,6 +314,35 @@
305314
});
306315
}
307316

317+
async findNearestPointNew(coordinates, datasetNames) {
318+
const [x, y] = coordinates
319+
if (x < -180.0 || x > 180.0 || y < -90 || y > 90){
320+
return
321+
}
322+
const point = new Point([x, y])
323+
const bufferParam = new GetFeaturesByBufferParameters({
324+
datasetNames: datasetNames,
325+
bufferDistance: 0.03,
326+
geometry: point
327+
})
328+
const serviceResult = await new FeatureService(this.dataUrl).getFeaturesByBuffer(bufferParam)
329+
if (serviceResult.result.features.features.length > 0) {
330+
// 变量用于保存最近的点
331+
let closestFeature = null
332+
let minDistance = Infinity // 初始设置为最大距离
333+
// 遍历所有的点数据,找出距离最近的点
334+
serviceResult.result.features.features.forEach((pointData) => {
335+
const dis = distance(coordinates, pointData.geometry.coordinates)
336+
// 更新最近点
337+
if (dis < minDistance) {
338+
minDistance = dis
339+
closestFeature = pointData
340+
}
341+
})
342+
return closestFeature
343+
}
344+
}
345+
308346
_processFormat(resultFormat) {
309347
return (resultFormat) ? resultFormat : DataFormat.GEOJSON;
310348
}

src/common/iServer/ChartSetting.js

Lines changed: 8 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
import {Util} from '../commontypes/Util';
5-
import {Unit, DisplayModeChart, ColourModeChart } from '../REST';
6-
75

86
/**
97
* @class ChartSetting
@@ -12,126 +10,27 @@
1210
* @classdesc 海图显示参数设置类,用于管理海图显示环境,包括海图的显示模式、显示类型名称、颜色模式、安全水深线等各种显示风格。更多内容介绍请参考[海图显示]{@link https://help.supermap.com/iDesktop/zh/tutorial/Chart/Visualization/ChartDisplaySetting}。
1311
* @version 11.2.0
1412
* @param {Object} options - 参数。
15-
* @param {DisplayModeChart} [options.displayModeChart=DisplayModeChart.STANDARD] - 海图显示模式。
16-
* @param {ColourModeChart} [options.colourModeChart=ColourModeChart.DAY_BRIGHT] - 海图显示的颜色模式。
17-
* @param {string} [options.displayTypeName="S52"] - 海图显示类型的名称,如 "S52"、"IENC"、"INT"。
18-
* @param {string} [options.fontName="Arial"] - 海图上显示文本的字体名称。
19-
* @param {boolean} [options.simplifiedMarker=true] - 是否使用简单海图符号。
20-
* @param {boolean} [options.symbolizedAreaBoundary=false] - 是否使用符号化的区域边界。
21-
* @param {boolean} [options.displayTextMessage=false] - 是否在海图上显示文本信息。
22-
* @param {boolean} [options.displaySounding=false] - 是否显示水深点。
23-
* @param {boolean} [options.minVisibleScaleEnabled=true] - 物标的最小可见比例尺是否有效。
24-
* @param {boolean} [options.localizationDisplayText=false] - 是否对文本进行本地化显示。
25-
* @param {boolean} [options.displayMetaObject=false] - 是否显示元物标。
26-
* @param {boolean} [options.displayCellName=false] - 是否显示图幅编号。
27-
* @param {boolean} [options.displaySafetyContourLabel=true] - 是否显示安全等深线标注。
28-
* @param {boolean} [options.displayBorder=false] - 是否显示图幅边框。
13+
* @param {string} [options.chartType] - 海图显示类型,S57、S100。
2914
* @param {number} [options.safetyContour=30.0] - 安全等深线。单位以 depthUnit 设置的水深单位为准。
3015
* @param {number} [options.shallowContour=2.0] - 浅水等深线。单位以 depthUnit 设置的水深单位为准。
3116
* @param {number} [options.deepContour=30.0] - 深水等深线。单位以 depthUnit 设置的水深单位为准。
3217
* @param {number} [options.safetyDepth=30.0] - 安全水深值。单位以 depthUnit 设置的水深单位为准。
33-
* @param {boolean} [options.displayOtherContourLabel=false] - 是否显示其他等深线标注,即安全水深线标注以外的标注。
34-
* @param {boolean} [options.displayTwoShades=false] - 是否以两色模式显示水深面。
35-
* @param {Unit} [options.depthUnit=Unit.METER] - 显示水深单位。目前仅支持DECIMETER、METER、FOOT。
36-
* @param {number} [options.fontSize=10.0] - 图上文本显示字体的字号。
37-
* @param {object} [options.displayableFeature] - 当前地图下所有物标类型是否可显示的对应关系。
38-
* @param {object} [options.selectableFeature] - 当前地图下所有物标类型是否可选择的对应关系。
39-
* @param {boolean} [options.textClipRegionEnabled=false] - 是否启用海图图层的文本显示裁剪区。
40-
* @param {boolean} [options.displayLowAccurateMarker=true] - 是否显示低精度符号。
41-
* @param {number} [options.displayScaleFactor] - 比例尺缩放。
42-
* @param {object} [options.displayableAcronymClassify] - 物标分组是否可显示的对应关系。
43-
* @param {boolean} [options.wlaEnable] - 设置是否开启WLA(Water Level Adjustment),既使用地图中的S104分组中的数据集设置给S102数据更正水深显示。
44-
* @param {boolean} [options.wlaDatetime] - 设置WLA(Water Level Adjustment)显示的时刻。时间格式为:yyyymmddThhmmssZ, 如20240224T000000Z,如果不符合格式则内部不解析
45-
* @param {boolean} [options.s98InteroperableEnable] - 是否开启S98互操作。
46-
* @param {number} [options.interoperabilityLevel=0] - 互操作级别,支持0,1。
4718
* @usage
4819
*/
4920
export class ChartSetting {
5021

5122
constructor(options) {
5223
/**
53-
* @member {DisplayModeChart} [options.displayModeChart]
54-
* @description 海图显示模式。
55-
*/
56-
this.displayModeChart = DisplayModeChart.STANDARD;
57-
58-
/**
59-
* @member {ColourModeChart} [options.colourModeChart]
60-
* @description 海图显示的颜色模式。
24+
* @member {string} [options.chartType]
25+
* @description 海图显示类型,S57、S100。
6126
*/
62-
this.colourModeChart = ColourModeChart.DAY_BRIGHT;
27+
this.chartType = null;
6328

6429
/**
65-
* @member {string} [options.displayTypeName]
66-
* @description 海图显示类型的名称,如 "S52"、"IENC"、"INT"。
67-
*/
68-
this.displayTypeName = "S52";
69-
70-
/**
71-
* @member {string} [options.fontName]
72-
* @description 海图上显示文本的字体名称。
73-
*/
74-
this.fontName = "Arial";
75-
76-
/**
77-
* @member {boolean} [options.simplifiedMarker]
78-
* @description 是否使用简单海图符号。
79-
*/
80-
this.simplifiedMarker = true;
81-
82-
/**
83-
* @member {boolean} [options.symbolizedAreaBoundary]
84-
* @description 是否使用简单海图符号。
85-
*/
86-
this.symbolizedAreaBoundary = false;
87-
88-
/**
89-
* @member {boolean} [options.displayTextMessage]
90-
* @description 是否在海图上显示文本信息。
91-
*/
92-
this.displayTextMessage = false;
93-
94-
/**
95-
* @member {boolean} [options.displaySounding]
96-
* @description 是否显示水深点。
97-
*/
98-
this.displaySounding = false;
99-
100-
/**
101-
* @member {boolean} [options.minVisibleScaleEnabled]
102-
* @description 物标的最小可见比例尺是否有效。
103-
*/
104-
this.minVisibleScaleEnabled = true;
105-
106-
/**
107-
* @member {boolean} [options.localizationDisplayText]
108-
* @description 是否对文本进行本地化显示。
109-
*/
110-
this.localizationDisplayText = false;
111-
112-
/**
113-
* @member {boolean} [options.displayMetaObject]
114-
* @description 是否显示元物标。
115-
*/
116-
this.displayMetaObject = false;
117-
118-
/**
119-
* @member {boolean} [options.displayCellName]
120-
* @description 是否显图幅编号。
121-
*/
122-
this.displayCellName = false;
123-
124-
/**
125-
* @member {boolean} [options.displaySafetyContourLabel]
126-
* @description 是否显示安全等深线标注。
127-
*/
128-
this.displaySafetyContourLabel = false;
129-
130-
/**
131-
* @member {boolean} [options.displayBorder]
132-
* @description 是否显示图幅边框
30+
* @member {number} [options.safetyContour]
31+
* @description 安全等深线。单位以 depthUnit 设置的水深单位为准。
13332
*/
134-
this.displayBorder = false;
33+
this.safetyContour = 30.0;
13534

13635
/**
13736
* @member {number} [options.safetyContour]
@@ -157,90 +56,6 @@
15756
*/
15857
this.safetyDepth = 30.0;
15958

160-
/**
161-
* @member {boolean} [options.displayOtherContourLabel]
162-
* @description 是否显示其他等深线标注,即安全水深线标注以外的标注。
163-
*/
164-
this.displayOtherContourLabel = false;
165-
166-
/**
167-
* @member {boolean} [options.displayTwoShades]
168-
* @description 是否以两色模式显示水深面。
169-
*/
170-
this.displayTwoShades = false;
171-
172-
/**
173-
* @member {Unit} [options.depthUnit]
174-
* @description 显示水深单位。
175-
*/
176-
this.depthUnit = Unit.METER;
177-
178-
/**
179-
* @member {number} [options.fontSize]
180-
* @description 图上文本显示字体的字号。
181-
*/
182-
this.fontSize = 10.0;
183-
184-
/**
185-
* @member {object} [options.displayableFeature]
186-
* @description 当前地图下所有物标类型是否可显示的对应关系。
187-
*/
188-
this.displayableFeature = null;
189-
190-
/**
191-
* @member {object} [options.selectableFeature]
192-
* @description 当前地图下所有物标类型是否可选择的对应关系。
193-
*/
194-
this.selectableFeature = null;
195-
196-
/**
197-
* @member {boolean} [options.textClipRegionEnabled]
198-
* @description 是否启用海图图层的文本显示裁剪区。
199-
*/
200-
this.textClipRegionEnabled = false;
201-
202-
/**
203-
* @member {boolean} [options.displayLowAccurateMarker=true]
204-
* @description 是否显示低精度符号。
205-
*/
206-
this.displayLowAccurateMarker = true;
207-
208-
/**
209-
* @member {boolean} [options.displayScaleFactor]
210-
* @description 比例尺缩放。
211-
*/
212-
this.displayScaleFactor = 0.05;
213-
214-
/**
215-
* @member {object} [options.displayableAcronymClassify]
216-
* @description 物标分组是否可显示的对应关系。
217-
*/
218-
this.displayableAcronymClassify = null;
219-
220-
/**
221-
* @member {boolean} [options.wlaEnable]
222-
* @description 是否开启WLA(Water Level Adjustment),既使用地图中的S104分组中的数据集设置给S102数据更正水深显示。
223-
*/
224-
this.wlaEnable = false;
225-
226-
/**
227-
* @member {string} [options.wlaDatetime]
228-
* @description 设置WLA(Water Level Adjustment)显示的时刻。时间格式为:yyyymmddThhmmssZ, 如20240224T000000Z,如果不符合格式则内部不解析。
229-
*/
230-
this.wlaDatetime = null;
231-
232-
/**
233-
* @member {boolean} [options.s98InteroperableEnable]
234-
* @description 是否开启S98互操作。
235-
*/
236-
this.s98InteroperableEnable = false;
237-
238-
/**
239-
* @member {number} [options.interoperabilityLevel]
240-
* @description 互操作等级。
241-
*/
242-
this.interoperabilityLevel = null;
243-
24459
if (options) {
24560
Util.extend(this, options);
24661
}
@@ -253,38 +68,11 @@
25368
* @description 释放资源,将引用资源的属性置空。
25469
*/
25570
destroy() {
256-
this.displayModeChart = null;
257-
this.colourModeChart = null;
258-
this.displayTypeName = null;
259-
this.fontName = null;
260-
this.simplifiedMarker = null;
261-
this.symbolizedAreaBoundary = null;
262-
this.displayTextMessage = null;
263-
this.displaySounding = null;
264-
this.minVisibleScaleEnabled = null;
265-
this.localizationDisplayText = null;
266-
this.displayMetaObject = null;
267-
this.displayCellName = null;
268-
this.displaySafetyContourLabel = null;
269-
this.displayBorder = null;
71+
this.chartType = null;
27072
this.safetyContour = null;
27173
this.shallowContour = null;
27274
this.deepContour = null;
27375
this.safetyDepth = null;
274-
this.displayOtherContourLabel = null;
275-
this.displayTwoShades = null;
276-
this.depthUnit = null;
277-
this.fontSize = null;
278-
this.displayableFeature = null;
279-
this.selectableFeature = null;
280-
this.textClipRegionEnabled = null;
281-
this.displayLowAccurateMarker = null;
282-
this.displayScaleFactor = null;
283-
this.displayableAcronymClassify = null;
284-
this.s98InteroperableEnable = null;
285-
this.interoperabilityLevel = null;
286-
this.wlaEnable = null;
287-
this.wlaDatetime = null;
28876
}
28977
}
29078

0 commit comments

Comments
 (0)