m4-w-fast 1.1.0 → 1.1.1

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 CHANGED
@@ -1,9 +1,15 @@
1
1
  # m4文件绘图程序
2
2
 
3
- ![img.png](img.png)
3
+ [![npm version](https://img.shields.io/npm/v/m4-w-fast.svg)](https://www.npmjs.com/package/m4-w-fast)
4
+ [![npm downloads (monthly)](https://img.shields.io/npm/dm/m4-w-fast.svg)](https://www.npmjs.com/package/m4-w-fast)
5
+
6
+ [在线 demo](https://priestqing.github.io/m4-w-fast/)
7
+ ---
4
8
  ![img_1.png](img_1.png)
5
9
 
6
10
  ### 更新说明
11
+ - v1.1.1
12
+ - 新增基于 `Leaflet` + `WebGPU` 的道路图层方案, 支持将 `LineString` / `MultiLineString` 道路 GeoJSON 按栅格值着色
7
13
  - v1.1.0
8
14
  - 正式启动主推 `leaflet canvas图层`方案
9
15
  - 现已支持`webgl2`, `webgpu`
@@ -64,8 +70,13 @@ npm i m4-w-fast
64
70
  # leaflet canvas图层
65
71
  - 理论上可以流畅的过滤数据或者放大不虚, 这可能是当前包体中显示最优的方案
66
72
  - 现已支持 webgl2, webgpu
73
+ - UMD 使用 `M4WRasterOverlay`
67
74
 
68
75
  ```ts
76
+ import { createRasterLeafletLayer, loadRasterGrid } from 'm4-w-fast/raster-overlay'
77
+
78
+ //...
79
+
69
80
  const grid = await loadRasterGrid({
70
81
  type: 'tif',
71
82
  url: 'xxx'
@@ -102,7 +113,8 @@ const layer = createRasterLeafletLayer({
102
113
  maxValue: Number(maxInput.value) // 过滤的最大值
103
114
  },
104
115
  opacity: 1,
105
- renderMode: 'step',
116
+ colorMode: 'step', // 'step' | 'smooth'
117
+ sampleMode: 'interpolate', // 'interpolate' | 'cell'
106
118
  pane: 'raster-pane',
107
119
  tooltip: {
108
120
  enabled: true,
@@ -124,9 +136,67 @@ layer.on('raster:click', event => {
124
136
 
125
137
  ```
126
138
 
139
+ # 道路 WebGPU 图层
140
+
141
+ - 用于把道路 GeoJSON 叠加到 Leaflet 地图上, 并根据栅格数据采样值给道路着色
142
+ - 当前道路示例建议使用 `rendererType: 'webgpu'`, 浏览器需要支持 `navigator.gpu`
143
+ - 道路数据支持 `LineString` / `MultiLineString`
144
+ - `grid` 和 `source` 二选一传入, `grid` 可以通过 `loadRasterGrid()` 预加载
145
+ - 如果道路和栅格是 WGS84, 底图使用高德 GCJ-02, 设置 `coordinateTransform: 'wgs84-to-gcj02'`
146
+ - UMD 使用 `M4WRoadOverlay`。
147
+
148
+ ```ts
149
+ import * as L from 'leaflet'
150
+ import { loadRasterGrid } from 'm4-w-fast/raster-overlay'
151
+ import { createRoadLeafletLayer } from 'm4-w-fast/road-overlay'
152
+ import type { RoadGeoJsonInput } from 'm4-w-fast/road-overlay'
153
+
154
+ const map = L.map('map', {
155
+ center: [35.97, 103.75],
156
+ zoom: 11
157
+ })
158
+
159
+ map.createPane('road-pane')
160
+
161
+ const roadPane = map.getPane('road-pane')
162
+
163
+ if (roadPane) {
164
+ roadPane.style.zIndex = '400'
165
+ }
166
+
167
+ // 这里是你的道路 GeoJSON, 只支持 LineString / MultiLineString
168
+ const roadsResponse = await fetch('/road.json')
169
+ const roads = await roadsResponse.json() as RoadGeoJsonInput
170
+
171
+ const grid = await loadRasterGrid({
172
+ type: 'micaps4',
173
+ url: '/2510270910.015'
174
+ })
175
+
176
+ const roadLayer = await createRoadLeafletLayer({
177
+ rendererType: 'webgpu',
178
+ coordinateTransform: 'wgs84-to-gcj02',
179
+ roads,
180
+ grid,
181
+ colorStops: legend,
182
+ colorRange: {
183
+ minValue: 0,
184
+ maxValue: 75
185
+ },
186
+ colorMode: 'step',
187
+ sampleMode: 'interpolate',
188
+ opacity: 1,
189
+ lineWidth: 8,
190
+ pane: 'road-pane'
191
+ })
192
+
193
+ roadLayer.addTo(map)
194
+ ```
195
+
127
196
  ---
128
197
 
129
198
  # geojson图层
199
+ - UMD 使用 `M4WFast`
130
200
 
131
201
  2. 使用示例
132
202
  ```vue
@@ -202,6 +272,54 @@ read.setParams({
202
272
  ```
203
273
 
204
274
  ### 类型参照
275
+
276
+ > RasterLeafletLayerCreateOptions
277
+
278
+ | 参数 | 说明 | 类型 | 默认值 |
279
+ |----|----|----|----|
280
+ | `rendererType` | 渲染方式 | `'cpu' \| 'webgl' \| 'webgl2' \| 'webgpu'` | 必填 |
281
+ | `grid` | 栅格数据, 可通过 `loadRasterGrid()` 获取 | `RasterGrid` | 必填 |
282
+ | `colorStops` | 色标配置 | `{ min: number, max: number, color: string }[]` | 必填 |
283
+ | `colorRange` | 当前显示的数据范围, 常用于滑块过滤 | `{ minValue: number, maxValue: number }` | 色标最小最大值 |
284
+ | `opacity` | 图层透明度 | `number` | 渲染器默认值 |
285
+ | `colorMode` | 颜色映射模式 | `'step' \| 'smooth'` | `'step'` |
286
+ | `sampleMode` | 栅格采样模式 | `'interpolate' \| 'cell'` | `'interpolate'` |
287
+ | `pane` | Leaflet pane 名称 | `string` | Leaflet 默认 overlayPane |
288
+ | `tooltip` | 内置 tooltip 配置 | `RasterTooltipOptions` | 不启用 |
289
+ | `onHover` | 鼠标移动查询回调 | `(result) => void` | 无 |
290
+ | `onClick` | 鼠标点击查询回调 | `(result) => void` | 无 |
291
+
292
+ > RasterLeafletLayer
293
+
294
+ | 方法 | 说明 |
295
+ |----|----|
296
+ | `setParams(params)` | 使用参数方式更新栅格数据 |
297
+ | `setSource(source)` | 使用 `tif` / `micaps4` / `params` 数据源更新栅格数据 |
298
+ | `setGrid(grid)` | 直接更新栅格数据并重新上传纹理 |
299
+ | `setColorStops(colorStops)` | 动态更新色标 |
300
+ | `setColorRange(range)` | 动态更新显示值范围 |
301
+ | `setColorMode(colorMode)` | 动态切换色标模式, 支持 `step` / `smooth` |
302
+ | `setSampleMode(sampleMode)` | 动态切换采样模式, 支持 `interpolate` / `cell` |
303
+ | `setOpacity(opacity)` | 动态设置图层透明度 |
304
+ | `redraw()` | 手动重绘当前视口 |
305
+ | `getCanvas()` | 获取当前图层 canvas, 可用于导出图片 |
306
+ | `queryValueAt(point)` | 按统一 `x/y` 坐标查询栅格值 |
307
+ | `queryValueAtLatLng(latLng)` | 按 Leaflet 经纬度查询栅格值 |
308
+
309
+ ---
310
+
311
+ > RoadLeafletLayer
312
+
313
+ | 方法 | 说明 |
314
+ |----|----|
315
+ | `redraw()` | 手动重绘道路图层 |
316
+ | `setOpacity(opacity)` | 动态设置道路透明度 |
317
+ | `setLineWidth(lineWidth)` | 动态设置道路线宽 |
318
+ | `setColorMode(colorMode)` | 动态切换色标模式, 支持 `step` / `smooth` |
319
+ | `setSampleMode(sampleMode)` | 动态切换采样模式, 支持 `interpolate` / `cell` |
320
+
321
+ ---
322
+
205
323
  > ReadConfig
206
324
 
207
325
  | 参数 | 说明 | 类型 | 默认值 |
@@ -0,0 +1 @@
1
+ export declare const wgs84ToGcj02: (lng: number, lat: number) => [number, number];
@@ -0,0 +1 @@
1
+ (function(_0x857358,_0x4c4cf8){const _0x292284=_0x3884,_0x13627e=_0x857358();while(!![]){try{const _0x481ae7=-parseInt(_0x292284(0x1dd))/0x1+parseInt(_0x292284(0x1e0))/0x2*(parseInt(_0x292284(0x1e8))/0x3)+-parseInt(_0x292284(0x1de))/0x4+-parseInt(_0x292284(0x1dc))/0x5+-parseInt(_0x292284(0x1e1))/0x6*(parseInt(_0x292284(0x1e5))/0x7)+-parseInt(_0x292284(0x1df))/0x8+-parseInt(_0x292284(0x1e6))/0x9*(-parseInt(_0x292284(0x1db))/0xa);if(_0x481ae7===_0x4c4cf8)break;else _0x13627e['push'](_0x13627e['shift']());}catch(_0x285f5c){_0x13627e['push'](_0x13627e['shift']());}}}(_0x54b8,0x97e29));function _0x3884(_0x2ee51b,_0x307973){const _0x54b83f=_0x54b8();return _0x3884=function(_0x388467,_0xab08c4){_0x388467=_0x388467-0x1db;let _0x5e2999=_0x54b83f[_0x388467];return _0x5e2999;},_0x3884(_0x2ee51b,_0x307973);}function _0x54b8(){const _0xa38149=['160yoDxjO','500946UwURys','cos','sin','abs','35pVKVHF','126yTLRZk','sqrt','18777kONwWb','1457230CGSOiK','1886325cmXfZi','410901GyTGAy','442168KMWNkR','4820464PYOLgs'];_0x54b8=function(){return _0xa38149;};return _0x54b8();}const PI=Math['PI'],AXIS=0x615305,OFFSET=0.006693421622965943,isOutsideChina=(_0x541120,_0x449bfa)=>{return _0x541120<72.004||_0x541120>137.8347||_0x449bfa<0.8293||_0x449bfa>55.8271;},transformLat=(_0x3edb63,_0x110c46)=>{const _0x58f593=_0x3884;let _0x5e8ee9=-0x64+0x2*_0x3edb63+0x3*_0x110c46+0.2*_0x110c46*_0x110c46+0.1*_0x3edb63*_0x110c46+0.2*Math[_0x58f593(0x1e7)](Math['abs'](_0x3edb63));return _0x5e8ee9+=(0x14*Math[_0x58f593(0x1e3)](0x6*_0x3edb63*PI)+0x14*Math[_0x58f593(0x1e3)](0x2*_0x3edb63*PI))*0x2/0x3,_0x5e8ee9+=(0x14*Math[_0x58f593(0x1e3)](_0x110c46*PI)+0x28*Math[_0x58f593(0x1e3)](_0x110c46/0x3*PI))*0x2/0x3,_0x5e8ee9+=(0xa0*Math['sin'](_0x110c46/0xc*PI)+0x140*Math[_0x58f593(0x1e3)](_0x110c46*PI/0x1e))*0x2/0x3,_0x5e8ee9;},transformLng=(_0x61cf1f,_0x15fc5d)=>{const _0x2d73f2=_0x3884;let _0x53ebe3=0x12c+_0x61cf1f+0x2*_0x15fc5d+0.1*_0x61cf1f*_0x61cf1f+0.1*_0x61cf1f*_0x15fc5d+0.1*Math[_0x2d73f2(0x1e7)](Math[_0x2d73f2(0x1e4)](_0x61cf1f));return _0x53ebe3+=(0x14*Math[_0x2d73f2(0x1e3)](0x6*_0x61cf1f*PI)+0x14*Math['sin'](0x2*_0x61cf1f*PI))*0x2/0x3,_0x53ebe3+=(0x14*Math[_0x2d73f2(0x1e3)](_0x61cf1f*PI)+0x28*Math['sin'](_0x61cf1f/0x3*PI))*0x2/0x3,_0x53ebe3+=(0x96*Math[_0x2d73f2(0x1e3)](_0x61cf1f/0xc*PI)+0x12c*Math['sin'](_0x61cf1f/0x1e*PI))*0x2/0x3,_0x53ebe3;};export const wgs84ToGcj02=(_0x32fc93,_0x2726ef)=>{const _0x3e286a=_0x3884;if(isOutsideChina(_0x32fc93,_0x2726ef))return[_0x32fc93,_0x2726ef];let _0x3bcdd6=transformLat(_0x32fc93-0x69,_0x2726ef-0x23),_0xdc4aa2=transformLng(_0x32fc93-0x69,_0x2726ef-0x23);const _0x4bf915=_0x2726ef/0xb4*PI;let _0x3e3689=Math[_0x3e286a(0x1e3)](_0x4bf915);_0x3e3689=0x1-OFFSET*_0x3e3689*_0x3e3689;const _0x4d7c2c=Math[_0x3e286a(0x1e7)](_0x3e3689);return _0x3bcdd6=_0x3bcdd6*0xb4/(AXIS*(0x1-OFFSET)/(_0x3e3689*_0x4d7c2c)*PI),_0xdc4aa2=_0xdc4aa2*0xb4/(AXIS/_0x4d7c2c*Math[_0x3e286a(0x1e2)](_0x4bf915)*PI),[_0x32fc93+_0xdc4aa2,_0x2726ef+_0x3bcdd6];};