cd-mapgis 1.0.3 → 1.0.5
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/package.json +2 -1
- package/src/LayerUtil.js +34 -33
- package/src/OM.js +16 -12
- package/src/index.js +5 -3
- package/test-om.js +11 -0
package/package.json
CHANGED
package/src/LayerUtil.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
// 使用 CommonJS 模块系统
|
|
2
|
+
import XYZ from 'ol/source/XYZ.js';
|
|
3
|
+
import Tile from 'ol/layer/Tile.js';
|
|
4
|
+
import Image from 'ol/layer/Image.js';
|
|
5
|
+
import ImageWMS from 'ol/source/ImageWMS.js';
|
|
6
|
+
import WMTS from 'ol/source/WMTS.js';
|
|
7
|
+
import TilegridWMTS from 'ol/tilegrid/WMTS.js';
|
|
8
|
+
import * as proj from 'ol/proj.js';
|
|
9
|
+
import * as extent from 'ol/extent.js';
|
|
10
|
+
import WMTSCapabilities from 'ol/format/WMTSCapabilities.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* 图层工具
|
|
@@ -32,7 +33,7 @@ export default class LayerUtil {
|
|
|
32
33
|
url: p.url,
|
|
33
34
|
wrapX: false
|
|
34
35
|
})
|
|
35
|
-
};
|
|
36
|
+
};
|
|
36
37
|
return new Tile(param);
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
@@ -113,8 +114,8 @@ export default class LayerUtil {
|
|
|
113
114
|
const projectionCode = supportedCRS.includes('4490') ? 'EPSG:4326' :
|
|
114
115
|
supportedCRS.replace('urn:ogc:def:crs:', '').replace('::', ':');
|
|
115
116
|
// 创建投影对象
|
|
116
|
-
const
|
|
117
|
-
const projExtent =
|
|
117
|
+
const projObj = proj.get(projectionCode) || proj.get('EPSG:4326');
|
|
118
|
+
const projExtent = projObj.getExtent();
|
|
118
119
|
// 获取支持的格式
|
|
119
120
|
const format = layer.Format && layer.Format.length > 0 ? layer.Format[0] : 'tiles';
|
|
120
121
|
// 获取样式
|
|
@@ -131,7 +132,7 @@ export default class LayerUtil {
|
|
|
131
132
|
const sortedMatrices = tileMatrixSet.TileMatrix.sort((a, b) => {
|
|
132
133
|
return parseInt(a.Identifier) - parseInt(b.Identifier);
|
|
133
134
|
});
|
|
134
|
-
const size = getWidth(projExtent) / 256;
|
|
135
|
+
const size = extent.getWidth(projExtent) / 256;
|
|
135
136
|
sortedMatrices.forEach(matrix => {
|
|
136
137
|
matrixIds.push(matrix.Identifier);
|
|
137
138
|
// 根据坐标系类型自动选择分辨率计算方式
|
|
@@ -157,28 +158,28 @@ export default class LayerUtil {
|
|
|
157
158
|
origin.push(matrix.TopLeftCorner[1]);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
161
|
+
})
|
|
162
|
+
// 创建瓦片网格配置
|
|
163
|
+
const tileGridConfig = new TilegridWMTS({
|
|
164
|
+
origin: origin.length > 0 ? origin : (isGeographic ? [-180, 90] : [-20037508.342789244, 20037508.342789244]),
|
|
165
|
+
resolutions: resolutions,
|
|
166
|
+
matrixIds: matrixIds
|
|
160
167
|
});
|
|
168
|
+
// 创建 WMTS 图层
|
|
169
|
+
const wmtsLayer = new Tile({
|
|
170
|
+
source: new WMTS({
|
|
171
|
+
url: wmtsUrl,
|
|
172
|
+
layer: layerName,
|
|
173
|
+
matrixSet: matrixSetName,
|
|
174
|
+
format: format,
|
|
175
|
+
projection: projObj,
|
|
176
|
+
tileGrid: tileGridConfig,
|
|
177
|
+
style: style,
|
|
178
|
+
wrapX: true
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
return wmtsLayer;
|
|
161
182
|
}
|
|
162
|
-
// 创建瓦片网格配置
|
|
163
|
-
const tileGridConfig = new TilegridWMTS({
|
|
164
|
-
origin: origin.length > 0 ? origin : (isGeographic ? [-180, 90] : [-20037508.342789244, 20037508.342789244]),
|
|
165
|
-
resolutions: resolutions,
|
|
166
|
-
matrixIds: matrixIds
|
|
167
|
-
});
|
|
168
|
-
// 创建 WMTS 图层
|
|
169
|
-
const wmtsLayer = new Tile({
|
|
170
|
-
source: new WMTS({
|
|
171
|
-
url: wmtsUrl,
|
|
172
|
-
layer: layerName,
|
|
173
|
-
matrixSet: matrixSetName,
|
|
174
|
-
format: format,
|
|
175
|
-
projection: proj,
|
|
176
|
-
tileGrid: tileGridConfig,
|
|
177
|
-
style: style,
|
|
178
|
-
wrapX: true
|
|
179
|
-
})
|
|
180
|
-
});
|
|
181
|
-
return wmtsLayer;
|
|
182
183
|
} catch (e) {
|
|
183
184
|
console.error("加载wmts图层失败:" + JSON.stringify(node), e);
|
|
184
185
|
}
|
package/src/OM.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
1
|
+
// 使用 ES 模块系统
|
|
2
|
+
import GeoJSON from 'ol/format/GeoJSON.js';
|
|
3
|
+
import Feature from 'ol/Feature.js';
|
|
4
|
+
import VectorSource from 'ol/source/Vector.js';
|
|
5
|
+
import Style from 'ol/style/Style.js';
|
|
6
|
+
import Stroke from 'ol/style/Stroke.js';
|
|
7
|
+
import Fill from 'ol/style/Fill.js';
|
|
8
|
+
import VectorLayer from 'ol/layer/Vector.js';
|
|
9
|
+
import View from 'ol/View.js';
|
|
10
|
+
import Map from 'ol/Map.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* OM
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
class OM {
|
|
15
16
|
static map = null;//openlayer map对象
|
|
16
17
|
static view = null;
|
|
17
18
|
/**
|
|
@@ -23,7 +24,7 @@ export default class OM {
|
|
|
23
24
|
let zoom = p.zoom ? p.zoom : 16; //地图初始显示级数
|
|
24
25
|
let projection = p.projection ? p.projection : 'EPSG:4326';
|
|
25
26
|
let layers = p.layers ? p.layers : [];
|
|
26
|
-
OM.view = new View({
|
|
27
|
+
let view = OM.view = new View({
|
|
27
28
|
center: center,
|
|
28
29
|
zoom: zoom,
|
|
29
30
|
projection: projection
|
|
@@ -103,4 +104,7 @@ export default class OM {
|
|
|
103
104
|
var newMaxY = centerY + newHeight / 2;
|
|
104
105
|
return [newMinX, newMinY, newMaxX, newMaxY];
|
|
105
106
|
}
|
|
106
|
-
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 导出模块
|
|
110
|
+
export default OM;
|
package/src/index.js
CHANGED
package/test-om.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// 导入 OM 类
|
|
2
|
+
import { OM } from './src/index.js';
|
|
3
|
+
|
|
4
|
+
// 打印 OM 类,检查是否为类而不是字符串
|
|
5
|
+
console.log('OM 类型:', typeof OM);
|
|
6
|
+
console.log('OM 类定义:', OM);
|
|
7
|
+
|
|
8
|
+
// 测试调用静态方法(不执行实际初始化,只检查方法是否存在)
|
|
9
|
+
console.log('OM.initMap 存在:', typeof OM.initMap === 'function');
|
|
10
|
+
|
|
11
|
+
console.log('测试完成,请检查输出结果。');
|