iServer s3m 静态化 ----
npm install @msign/s3ticiServer s3m 静态化
----
本工具的功能是将超图s3m三维缓存场景包静态化生成为iServer风格的路径文件, 提供可脱离iServer独立分发的资源目录.
全局安装
``sh`
npm i -g @msign/s3tic
`
➜ ~ s3tic -h
Usage: s3tic [options]
Options:
-i, --input [string] SXWU文件路径.
-o, --output [string] 静态化场景包输出路径(/path_to/output/)
-h, --help output usage information
`
自行编译
`sh`
yarn build
yarn release
``
➜ s3tic git:(master) ✗ yarn build
yarn run v1.19.1
$ tsc
✨ Done in 2.96s.
➜ s3tic git:(master) ✗ yarn release
yarn run v1.19.1
$ pkg . --out-path ./release
> pkg@4.4.0
> Targets not specified. Assuming:
node10-linux-x64, node10-macos-x64, node10-win-x64
✨ Done in 16.80s.
可执行文件在./release/
`sh`
./s3tic-win.exe -i ./sample/scene_pack/1.sxwu -o ./sample/output
`sh`
./s3tic-macos -i ./sample/scene_pack/1.sxwu -o ./sample/output
`sh`
./s3tic-linux -i ./sample/scene_pack/1.sxwu -o ./sample/output
``
➜ sample tree .
.
└── scene_pack
...
├── WS_NAME.sxwu
└── SCENE_NAME
└── DATA_DIR
├── DATASET@DATASOURCE
│ ├── Tile_X_Y_Z
│ │ ├── Tile_XX_YY_ZZ.s3m
...
│ └── DATASET@DATASOURCE.scp
...
``
➜ s3tic ./release/s3tic-macos -i ./sample/scene_pack/1.sxwu -o ./sample/output
ℹ { input: './sample/scene_pack/1.sxwu',
output: './sample/output' }
[场景-0]: SCENE_NAME
[图层-0]: DATASET@DATASOURCE
...
``
➜ output tree .
.
├── datas
│ ├── DATASET@DATASOURCE
│ │ ├── config
│ │ └── data
│ │ └── path
│ │ ├── Tile_X_Y_Z
│ │ │ ├── Tile_XX_YY_ZZ.s3m
...
│ │ └── DATASET@DATASOURCE.scp
...
├── login
├── login.json
├── scenes
│ ├── SCENE_NAME
│ │ ├── layers
│ │ │ ├── DATASET@DATASOURCE
│ │ │ │ └── extendxml.xml
│ │ └── layers.json
│ └── SCENE_NAME.json
└── scenes.json
可以直接采用 Nginx 分发, 有三个要点需要注意
生成好的文件如下
`json`
[
{
"resourceConfigID": "scene",
"supportedMediaTypes": [
"application/xml",
"text/xml",
"application/json",
"application/fastjson",
"application/rjson",
"text/html",
"application/jsonp",
"application/x-java-serialized-object",
"application/realspace",
"application/openrealspace",
"application/scenezip"
],
"path": "/scenes/scene_cache",
"name": "scene_cache",
"resourceType": "ArithmeticResource"
}
]
假设我们发布的网络路径是https://YOUR_STATIC_SERVER/SOME_PATH/rest/realspace, 将scenes.json修改至如下
`json`
[
{
"resourceConfigID": "scene",
"supportedMediaTypes": [
"application/xml",
"text/xml",
"application/json",
"application/fastjson",
"application/rjson",
"text/html",
"application/jsonp",
"application/x-java-serialized-object",
"application/realspace",
"application/openrealspace",
"application/scenezip"
],
"path": "https://YOUR_STATIC_SERVER/SOME_PATH/rest/realspace/scenes/scene_cache",
"name": "scene_cache",
"resourceType": "ArithmeticResource"
}
]
Supermap-Cesium 是依赖于这个 path 值去加载场景实例的, 理论上这个 scenes.json 也可以从业务系统动态生成. path 指向 CDN 即可.
Supermap-Cesium中写死了一行字符串匹配, 用于定位login.json的网络路径.
``
e.indexOf("rest/realspace") + 14
Supermap-Cesium会在场景载入过程中向iServer提交会话请求
1. GET PATH_TO_STATIC/rest/realspace/login.json
2. POST PATH_TO_STATIC/rest/realspace/login
这两个请求的返回值已在静态包中生成静态文件. 前者是个普通 json
`json`
{"random":"1","jsessionID":"1"}
后者由于是POST请求, Nginx 默认不会返回路径文件(405), 需要修改 Nginx 配置
`
server {
...
#屏蔽405, 使前端可对静态文件POST
error_page 405 =200 $request_uri;
#顺便加上这个, 以便于方便查看 sample/output/datas/xxx/config 文件. 不影响使用
default_type text/html;
}
`
修改Nginx配置后POST PATH_TO_STATIC/rest/realspace/login即可返回
`text``
isSucceed : true
注意 __这不是JSON__.
武运昌隆.