Skip to content

Commit 9ea573e

Browse files
committed
【doc】增加modulecondition tag 用于jsdoc不同的module打出不同的类型
1 parent 7a1e618 commit 9ea573e

36 files changed

+198
-70
lines changed

build/jsdocs/leaflet/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"src/leaflet/core/CommontypesConversion"
8080
]
8181
},
82-
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories"],
82+
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories","../plugins/modulecondition"],
8383
"markdown": {
8484
"tags": ["usage"]
8585
},
@@ -89,6 +89,7 @@
8989
"default": {
9090
"outputSourceFiles": false
9191
},
92+
"moduleName":"leaflet",
9293
"namespace": "L.supermap",
9394
"npm":"@supermapgis/iclient-leaflet",
9495
"cdn":"https://iclient.supermap.io/dist/leaflet/iclient-leaflet.js"

build/jsdocs/mapboxgl/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"src/mapboxgl/overlay/L7/l7-render"
7878
]
7979
},
80-
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories"],
80+
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories","../plugins/modulecondition"],
8181
"markdown": {
8282
"tags": ["usage"]
8383
},
@@ -88,6 +88,7 @@
8888
"outputSourceFiles": false
8989
},
9090
"namespace": "mapboxgl.supermap",
91+
"moduleName":"mapboxgl",
9192
"npm":"@supermapgis/iclient-mapboxgl",
9293
"cdn":"https://iclient.supermap.io/dist/mapboxgl/iclient-mapboxgl.js"
9394
}

build/jsdocs/maplibregl/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"src/maplibregl/overlay/L7/l7-render"
7676
]
7777
},
78-
"plugins": ["plugins/markdown", "../plugins/usage", "../plugins/moduleCategories"],
78+
"plugins": ["plugins/markdown", "../plugins/usage", "../plugins/moduleCategories","../plugins/modulecondition"],
7979
"markdown": {
8080
"tags": ["usage"]
8181
},
@@ -86,6 +86,7 @@
8686
"outputSourceFiles": false
8787
},
8888
"namespace": "maplibregl.supermap",
89+
"moduleName":"maplibregl",
8990
"npm": "@supermapgis/iclient-maplibregl",
9091
"cdn": "https://iclient.supermap.io/dist/maplibregl/iclient-maplibregl.js"
9192
}

build/jsdocs/openlayers/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"src/common/mapping"
6868
]
6969
},
70-
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories"],
70+
"plugins": ["plugins/markdown","../plugins/usage", "../plugins/moduleCategories","../plugins/modulecondition"],
7171
"markdown": {
7272
"tags": ["usage"]
7373
},
@@ -78,6 +78,7 @@
7878
"outputSourceFiles": false
7979
},
8080
"namespace": "ol.supermap",
81+
"moduleName":"openlayers",
8182
"npm":"@supermapgis/iclient-ol",
8283
"cdn":"https://iclient.supermap.io/dist/openlayers/iclient-ol.js"
8384
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
const env = require('jsdoc/lib/jsdoc/env');
2+
3+
const globalParams = env.conf.templates;
4+
const moduleconditionNames = [];
5+
const moduleconditionMap = {};
6+
exports.defineTags = function (dictionary) {
7+
dictionary.defineTag('modulecondition', {
8+
mustHaveValue: false,
9+
mustNotHaveDescription: false,
10+
canHaveType: false,
11+
canHaveName: false,
12+
onTagged: function (doclet, tag) {
13+
if (tag.value) {
14+
const [modulecondition, value] = tag.value.split(':');
15+
if (modulecondition === globalParams.moduleName) {
16+
moduleconditionNames.push(doclet.name);
17+
moduleconditionMap[doclet.name] = value.split('|');
18+
}
19+
}
20+
doclet.undocumented = true;
21+
}
22+
});
23+
};
24+
25+
// 处理类型名称替换,支持普通类型和泛型类型(如 Array.<Name>)
26+
function replaceTypeName(name) {
27+
// 直接匹配
28+
if (moduleconditionNames.indexOf(name) >= 0) {
29+
return moduleconditionMap[name];
30+
}
31+
32+
// 检查是否包含泛型形式,如 Array.<Name> 或 Array.<Name|others>
33+
const genericMatch = name.match(/^(.+?)<(.+)>$/);
34+
if (genericMatch) {
35+
const [, prefix, inner] = genericMatch;
36+
37+
// 去除外层括号 (如果有)
38+
let cleanInner = inner.trim();
39+
let hasOuterParens = false;
40+
if (cleanInner.startsWith('(') && cleanInner.endsWith(')')) {
41+
cleanInner = cleanInner.substring(1, cleanInner.length - 1);
42+
hasOuterParens = true;
43+
}
44+
45+
const types = cleanInner.split('|').map((t) => t.trim());
46+
const newTypes = [];
47+
let hasReplacement = false;
48+
49+
types.forEach((type) => {
50+
const trimmedType = type.trim();
51+
if (moduleconditionNames.indexOf(trimmedType) >= 0) {
52+
const values = moduleconditionMap[trimmedType];
53+
if (values && values.length > 0) {
54+
hasReplacement = true;
55+
newTypes.push(...values);
56+
} else {
57+
newTypes.push(trimmedType);
58+
}
59+
} else {
60+
newTypes.push(trimmedType);
61+
}
62+
});
63+
64+
if (hasReplacement) {
65+
// 返回单个泛型类型,内部是联合类型,保留原有的括号
66+
const innerTypes = newTypes.join('|');
67+
const result = hasOuterParens ? `${prefix}<(${innerTypes})>` : `${prefix}<${innerTypes}>`;
68+
return [result];
69+
}
70+
}
71+
72+
return null;
73+
}
74+
75+
exports.handlers = {
76+
newDoclet: function (e) {
77+
if (moduleconditionNames.length === 0) {
78+
return;
79+
}
80+
// 处理成员类型
81+
if (e.doclet.kind === 'member') {
82+
if (!e.doclet.type || !e.doclet.type.names) {
83+
return;
84+
}
85+
// 从后向前遍历,避免在遍历时修改数组导致的问题
86+
for (let i = e.doclet.type.names.length - 1; i >= 0; i--) {
87+
const name = e.doclet.type.names[i];
88+
const replacedValues = replaceTypeName(name);
89+
if (replacedValues && replacedValues.length > 0) {
90+
e.doclet.type.names.splice(i, 1, ...replacedValues);
91+
}
92+
}
93+
return;
94+
}
95+
96+
// 处理function参数和返回值类型
97+
const parameters = e.doclet.params;
98+
if (!parameters) {
99+
return;
100+
}
101+
102+
parameters.forEach((element) => {
103+
if (!element.type || !element.type.names) {
104+
return;
105+
}
106+
// 从后向前遍历,避免在遍历时修改数组导致的问题
107+
for (let i = element.type.names.length - 1; i >= 0; i--) {
108+
const name = element.type.names[i];
109+
const replacedValues = replaceTypeName(name);
110+
if (replacedValues && replacedValues.length > 0) {
111+
element.type.names.splice(i, 1, ...replacedValues);
112+
}
113+
}
114+
});
115+
116+
const returns = e.doclet.returns;
117+
if (returns) {
118+
returns.forEach((element) => {
119+
if (!element.type || !element.type.names) {
120+
return;
121+
}
122+
// 从后向前遍历,避免在遍历时修改数组导致的问题
123+
for (let i = element.type.names.length - 1; i >= 0; i--) {
124+
const name = element.type.names[i];
125+
const replacedValues = replaceTypeName(name);
126+
if (replacedValues && replacedValues.length > 0) {
127+
element.type.names.splice(i, 1, ...replacedValues);
128+
}
129+
}
130+
});
131+
}
132+
}
133+
};

src/common/iServer/BuffersAnalystJobsParameter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { MappingParameters } from './MappingParameters';
1414
* 还可以对分析结果的输出参数、可视化参数进行一系列设置。
1515
* @param {Object} options - 参数。
1616
* @param {string} options.datasetName - 数据集名称。
17-
* @param {(SuperMap.Bounds|L.Bounds|L.LatLngBounds|ol.extent|mapboxgl.LngLatBounds|GeoJSONObject)} [options.bounds] - 缓冲区分析范围(默认为全图范围)。
17+
* @param {ModuleBounds} [options.bounds] - 缓冲区分析范围(默认为全图范围)。
1818
* @param {string} [options.distance='15'] - 缓冲距离,或缓冲区半径。
1919
* @param {string} [options.distanceField='pickup_latitude'] - 缓冲区分析距离字段。
2020
* @param {AnalystSizeUnit} [options.distanceUnit=AnalystSizeUnit.METER] - 缓冲距离单位。
@@ -31,7 +31,7 @@ export class BuffersAnalystJobsParameter {
3131
this.datasetName = '';
3232

3333
/**
34-
* @member {(SuperMap.Bounds|L.Bounds|L.LatLngBounds|ol.extent|mapboxgl.LngLatBounds|GeoJSONObject)} BuffersAnalystJobsParameter.prototype.bounds
34+
* @member {ModuleBounds} BuffersAnalystJobsParameter.prototype.bounds
3535
* @description 分析范围。
3636
*/
3737
this.bounds = '';

src/common/iServer/ChartQueryParameters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {ChartQueryFilterParameter} from './ChartQueryFilterParameter';
1414
* @param {string} options.queryMode - 海图查询模式类型,支持三种查询方式:海图属性查询("ChartAttributeQuery")和海图范围查询("ChartBoundsQuery")和海图要素范围查询("ChartFeatureBoundsQuery")。
1515
* @param {Array.<string>} options.chartLayerNames - 查询的海图图层的名称。
1616
* @param {Array.<ChartQueryFilterParameter>} options.chartQueryFilterParameters - 海图查询过滤参数。包括:物标代码、物标可应用对象的选择(是否查询点、线或面)、属性字段过滤条件。
17-
* @param {(SuperMap.Bounds|L.Bounds|L.LatLngBounds|ol.extent|mapboxgl.LngLatBounds|GeoJSONObject)} options.bounds - 海图查询范围。当进行海图范围查询和海图要素范围查询时,此为必选参数。
17+
* @param {ModuleBounds} options.bounds - 海图查询范围。当进行海图范围查询和海图要素范围查询时,此为必选参数。
1818
* @param {boolean} [options.returnContent=true] - 获取或设置是返回查询结果记录集 recordsets,还是返回查询结果的资源 resourceInfo。
1919
* @param {number} [options.startRecord=0] - 查询起始记录位置。
2020
* @param {number} [options.expectCount] - 期望查询结果返回的记录数,该值大于0。
@@ -31,7 +31,7 @@ export class ChartQueryParameters {
3131
this.queryMode = null;
3232

3333
/**
34-
* @member {(SuperMap.Bounds|L.Bounds|L.LatLngBounds|ol.extent|mapboxgl.LngLatBounds|GeoJSONObject)} ChartQueryParameters.prototype.bounds
34+
* @member {ModuleBounds} ChartQueryParameters.prototype.bounds
3535
* @description 海图查询范围。
3636
*/
3737
this.bounds = null;

src/common/iServer/ClipParameter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {ServerGeometry} from './ServerGeometry';
1212
* @param {Object} options - 可选参数。
1313
* @param {string} [options.clipDatasetName] - 裁剪的数据集名称。当不设置 clipRegion 时起作用。
1414
* @param {string} [options.clipDatasourceName] - 裁剪的数据集所在数据源的名称。
15-
* @param {GeometryPolygon|L.Polygon|L.GeoJSON|ol.geom.Polygon|ol.format.GeoJSON|GeoJSONObject} [options.clipRegion] - 用户指定的裁剪区域。
15+
* @param {ModulePolygon} [options.clipRegion] - 用户指定的裁剪区域。
1616
* @param {boolean} [options.isClipInRegion=true] - 是否对裁剪区内的数据集进行裁剪。若为 true,则对裁剪区域内的结果进行裁剪,若为 false,则对裁剪区域外的结果进行裁剪。
1717
* @param {boolean} [options.isExactClip=true] - 是否使用精确裁剪。若为 true,表示使用精确裁剪对栅格或影像数据集进行裁剪,false 表示使用显示裁剪。
1818
* @usage
@@ -34,7 +34,7 @@ export class ClipParameter {
3434
this.clipDatasourceName = null;
3535

3636
/**
37-
* @member {GeometryPolygon|L.Polygon|L.GeoJSON|ol.geom.Polygon|ol.format.GeoJSON|GeoJSONObject} ClipParameter.prototype.clipRegion
37+
* @member {ModulePolygon} ClipParameter.prototype.clipRegion
3838
* @description 用户指定的裁剪区域,当与 clipDatasetName 同时设置时,优先使用 clipRegion。不设置时则使用指定数据集的边界多边形进行裁剪。clipDatasetName 与 clipRegion 必须设置一个。
3939
*/
4040
this.clipRegion = null;

src/common/iServer/DatasetOverlayAnalystParameters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {ServerGeometry} from './ServerGeometry';
1919
* @param {string} options.sourceDataset - 源数据集名称。该名称用形如 "数据集名称@数据源别名" 形式来表示,例如:BaseMap_R@Jingjin。
2020
* @param {Array.<string>} [options.operateDatasetFields] - 叠加分析中操作数据集保留在结果数据集中的字段名列表。
2121
* @param {FilterParameter} [options.operateDatasetFilter] - 设置操作数据集中空间对象过滤条件。
22-
* @param {Array.<GeometryPolygon|L.Polygon|ol.geom.Polygon|GeoJSONObject>} [options.operateRegions] - 操作面对象集合,表示与这些面对象进行叠加分析。与 operateDataset 参数互斥,冲突时以 operateDataset 为准。
22+
* @param {Array.<ModulePolygon>} [options.operateRegions] - 操作面对象集合,表示与这些面对象进行叠加分析。与 operateDataset 参数互斥,冲突时以 operateDataset 为准。
2323
* @param {Array.<string>} [options.sourceDatasetFields] - 叠加分析中源数据集保留在结果数据集中的字段名列表。
2424
* @param {FilterParameter} [options.sourceDatasetFilter] - 设置源数据集中空间对象过滤条件。设置了过滤参数后,只有满足条件的对象参与叠加分析。
2525
* @param {number} [options.tolerance=0] - 容限。
@@ -52,7 +52,7 @@ export class DatasetOverlayAnalystParameters extends OverlayAnalystParameters {
5252
this.operateDatasetFilter = new FilterParameter();
5353

5454
/**
55-
* @member {Array.<GeometryPolygon|L.Polygon|ol.geom.Polygon|GeoJSONObject>} [DatasetOverlayAnalystParameters.prototype.operateRegions]
55+
* @member {Array.<ModulePolygon>} [DatasetOverlayAnalystParameters.prototype.operateRegions]
5656
* @description 操作面对象集合,表示与这些面对象进行叠加分析。与 operateDataset 参数互斥,冲突时以 operateDataset 为准。
5757
*/
5858
this.operateRegions = [];

src/common/iServer/DatasetThiessenAnalystParameters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ServerGeometry} from './ServerGeometry';
1111
* @category iServer SpatialAnalyst ThiessenAnalyst
1212
* @classdesc 数据集泰森多边形分析参数类。该类可以指定泰森多边形分析的数据集、返回数据集等参数。
1313
* @param {Object} options - 参数。
14-
* @param {(GeometryPolygon|L.Polygon|ol.geom.Polygon|GeoJSONObject)} [options.clipRegion] - 结果数据裁剪区域,可以为 null,表示不对结果进行裁剪。
14+
* @param {ModulePolygon} [options.clipRegion] - 结果数据裁剪区域,可以为 null,表示不对结果进行裁剪。
1515
* @param {boolean} [options.createResultDataset] - 是否返回结果数据集。如果为 true,则必须设置属性 resultDatasetName 和 resultDatasourceName。
1616
* @param {string} [options.dataset] - 数据集名称待分析的数据集名称,请使用 "datasetName@datasourceName" 格式来表示。
1717
* @param {FilterParameter} [options.filterQueryParameter] - 过滤参数类,即对数据集中的所有点进行分析。

0 commit comments

Comments
 (0)