grid-webgl-openlayers 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # grid-webgl-openlayers
2
+
3
+ > OpenLayers + WebGL 网格色斑图与格点数值标注。图层叠加在外部 `ol/Map` 上,不创建 Map、不管理底图。
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6
+ ![peer ol](https://img.shields.io/badge/peer-ol%20%5E9%20%7C%20%5E10-blue)
7
+ ![vue optional](<https://img.shields.io/badge/vue-%5E3.3%20(optional)-4FC08D>)
8
+
9
+ ## 在线演示
10
+
11
+ GitHub Actions 构建并部署后,Demo 地址为(**必须带仓库名路径**):
12
+
13
+ **https://openlayer-computer.github.io/grid-webgl-openlayers/**
14
+
15
+ > 不要访问 `https://openlayer-computer.github.io/` 根路径,那里没有构建产物。
16
+ > 若 Network 里出现 `404 /src/main.ts`,说明 Pages 仍在发布源码而非 Actions 构建结果,见 [docs/github-pages.md](docs/github-pages.md#出现-404-srcmaints)。
17
+
18
+ [![Live Demo](https://img.shields.io/badge/demo-live-blue)](https://openlayer-computer.github.io/grid-webgl-openlayers/)
19
+
20
+ 部署说明见 [docs/github-pages.md](docs/github-pages.md)。
21
+
22
+ ## 特性
23
+
24
+ - **外部 Map 叠加** — 底图、投影、控件由业务方管理
25
+ - **WebGL 色斑图** — LOD 降采样,支持不规则色带
26
+ - **Canvas2D 格点标注** — 按像素间距自动稀疏
27
+ - **图例双滑块** — 过滤显示数值区间(`blocks` / `gradient`)
28
+ - **鼠标拾取** — 悬停返回当前格点值
29
+ - **Vue 3 组件** — `GredGridMap`、`GredLegendPanel`(renderless 叠加层)
30
+
31
+ ## 架构
32
+
33
+ ```mermaid
34
+ flowchart TB
35
+ Map["外部 ol/Map\n底图 + View + 控件"]
36
+ Overlay["GridMapView / GredGridMap"]
37
+ Choropleth["ChoroplethLayer\nWebGL 色斑"]
38
+ Labels["GridValueLayer\n格点数值"]
39
+ Legend["LegendPanel / GredLegendPanel\n可选"]
40
+
41
+ Map --> Overlay
42
+ Overlay --> Choropleth
43
+ Overlay --> Labels
44
+ Overlay -.-> Legend
45
+ ```
46
+
47
+ ## 安装
48
+
49
+ ```bash
50
+ npm install grid-webgl-openlayers ol
51
+ npm install vue # 仅 Vue 项目需要
52
+ ```
53
+
54
+ ```ts
55
+ import 'ol/ol.css';
56
+ import 'grid-webgl-openlayers/style.css'; // 使用图例面板时建议引入
57
+ ```
58
+
59
+ ## 快速开始
60
+
61
+ ### 命令式
62
+
63
+ ```ts
64
+ import Map from 'ol/Map';
65
+ import View from 'ol/View';
66
+ import { GridMapView } from 'grid-webgl-openlayers';
67
+
68
+ const map = new Map({
69
+ target: 'map',
70
+ view: new View({ projection: 'EPSG:4326', center: [105, 30], zoom: 6 }),
71
+ layers: [
72
+ /* 你的底图 */
73
+ ],
74
+ });
75
+
76
+ const overlay = await GridMapView.create({
77
+ map,
78
+ dataUrl: '/data/arrayData.json',
79
+ });
80
+
81
+ overlay.onPointerMove(({ value }) => {
82
+ if (value != null) console.log(value);
83
+ });
84
+ ```
85
+
86
+ ### Vue 3
87
+
88
+ ```vue
89
+ <GredGridMap v-if="map" :map="map" data-url="/data/arrayData.json" @pointermove="onHover" />
90
+ ```
91
+
92
+ ```ts
93
+ import { GredGridMap, GredLegendPanel } from 'grid-webgl-openlayers/vue';
94
+ ```
95
+
96
+ ## 📖 文档
97
+
98
+ 完整操作手册见 **[docs/](./docs/README.md)**:
99
+
100
+ | 文档 | 说明 |
101
+ | --------------------------------------------- | --------------------------------- |
102
+ | [快速上手](docs/getting-started.md) | 使用前提、安装、功能一览 |
103
+ | [数据格式](docs/data-format.md) | `arrayData.json` 结构 |
104
+ | [命令式 API](docs/api-grid-map.md) | `GridMapView` 参数与方法 |
105
+ | [Vue 组件](docs/vue-components.md) | `GredGridMap` / `GredLegendPanel` |
106
+ | [图例与图层控制](docs/legend-and-controls.md) | 图例面板、双滑块、开关按钮 |
107
+ | [鼠标拾取](docs/pointer-pick.md) | 悬停返回值 |
108
+ | [投影切换](docs/projection.md) | EPSG:4326 ↔ 3857 |
109
+ | [色带配置](docs/color-ramp.md) | 不规则色带 |
110
+ | [示例合集](docs/examples.md) | 完整 Demo 代码 |
111
+ | [平台支持](docs/platform.md) | 浏览器 / 移动端 / Flutter |
112
+ | [构建发布](docs/build.md) | npm 打包与类型导出 |
113
+ | [npm 发布](docs/npm-publish.md) | 发布到 npm 完整步骤 |
114
+ | [GitHub Pages 部署](docs/github-pages.md) | 在线 Demo 自动发布 |
115
+
116
+ ## 本地预览
117
+
118
+ ```bash
119
+ npm install
120
+ npm run dev # http://localhost:5173 — 见 src/main.ts
121
+ ```
122
+
123
+ Vue 示例:[`examples/vue-demo/App.vue`](examples/vue-demo/App.vue)
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,2 @@
1
+ (function(){"use strict";function G(a){return 2**Math.max(0,Math.min(3,Math.floor((11-a)/2)))}function B(a,t,o,e){const r=(a.startLat+a.endLat)*.5,s=a.lonStep*t;if(e==="EPSG:3857"){const l=111320*Math.cos(r*Math.PI/180);return s*l/Math.max(o,1e-12)}return s/Math.max(o,1e-12)}function F(a,t,o,e,r="EPSG:4326"){const s=G(t),l=B(a,s,o,r),p=Math.max(1,Math.round(e/Math.max(l,1)));return s*p}function O(a,t,o,e,r){let s=0,l=0;const{latCount:p,lonCount:i}=t;for(let c=0;c<r;c++)for(let d=0;d<r;d++){const f=o+c,S=e+d;if(f>=p||S>=i)continue;const L=a[f*i+S];L==null||Number.isNaN(L)||(s+=L,l++)}return l>0?s/l:-9999}function j(a,t,o,e){const r=[t.startLon,t.startLat,t.endLon,t.endLat],[s,l,p,i]=o,[c,d,f,S]=r,L=Math.max(s,c),g=Math.max(l,d),u=Math.min(p,f),A=Math.min(i,S);if(L>=u||g>=A)return null;const{startLon:k,startLat:C,lonStep:w,latStep:x,lonCount:E,latCount:D}=t,n=G(e),b=Math.max(0,Math.floor((L-k)/w/n)*n),M=Math.min(E,Math.ceil((u-k)/w)),h=Math.max(0,Math.floor((g-C)/x/n)*n),m=Math.min(D,Math.ceil((A-C)/x));if(b>=M||h>=m)return null;const v=Math.ceil((M-b)/n),N=Math.ceil((m-h)/n),T=new Float32Array(v*N);let q=0;for(let W=m-n;W>=h;W-=n)for(let z=b;z<M;z+=n)T[q++]=O(a,t,W,z,n);return{data:T,width:v,height:N,bbox:[k+b*w,C+h*x,k+M*w,C+m*x],resolution:[w*n,x*n],lodLevel:Math.log2(n),lodStep:n}}function I(a,t,o,e,r,s,l,p="EPSG:4326"){const{startLon:i,startLat:c,lonStep:d,latStep:f,lonCount:S,latCount:L}=t,g=G(e),u=F(t,e,r,s,p),[A,k,C,w]=o,x=Math.max(0,Math.floor((A-i)/d/u)*u),E=Math.min(S,Math.ceil((C-i)/d)),D=Math.max(0,Math.floor((k-c)/f/u)*u),n=Math.min(L,Math.ceil((w-c)/f));if(x>=E||D>=n)return[];const b=[];for(let M=D;M<n;M+=u)for(let h=x;h<E;h+=u){const m=O(a,t,M,h,g);if(m===-9999||Number.isNaN(m))continue;const v=i+(h+g*.5)*d,N=c+(M+g*.5)*f;v<i||v>=t.endLon||N<c||N>=t.endLat||b.push({lon:v,lat:N,text:m.toFixed(l)})}return b}let P=null,y=null;self.onmessage=a=>{const t=a.data;try{switch(t.type){case"init":{P=t.meta,y=t.flat;const o={id:t.id,ok:!0,type:"init"};self.postMessage(o);break}case"readWindow":{if(!P||!y)throw new Error("worker not initialized");const o=j(y,P,t.extent4326,t.zoom);if(!o){self.postMessage({id:t.id,ok:!1,error:"empty window"});break}const e={id:t.id,ok:!0,type:"readWindow",tile:o};self.postMessage(e);break}case"computeLabels":{if(!P||!y)throw new Error("worker not initialized");const o=I(y,P,t.extent4326,t.zoom,t.resolution,t.distancePx,t.precision,t.projCode??"EPSG:4326"),e={id:t.id,ok:!0,type:"computeLabels",labels:o};self.postMessage(e);break}}}catch(o){const e={id:t.id,ok:!1,error:String(o)};self.postMessage(e)}}})();
2
+ //# sourceMappingURL=gridData.worker-z5TRvtQ2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gridData.worker-z5TRvtQ2.js","sources":["../src/data/gridDataCore.ts","../src/worker/gridData.worker.ts"],"sourcesContent":["/** 纯函数:Worker 与主线程共享的网格数据处理 */\r\n\r\nexport interface ArrayDataMeta {\r\n startLat: number\r\n endLat: number\r\n startLon: number\r\n endLon: number\r\n latStep: number\r\n lonStep: number\r\n latCount: number\r\n lonCount: number\r\n}\r\n\r\nexport interface GridTile {\r\n data: Float32Array\r\n width: number\r\n height: number\r\n bbox: [number, number, number, number]\r\n resolution: [number, number]\r\n lodLevel: number\r\n lodStep: number\r\n}\r\n\r\nexport interface GridLabel {\r\n lon: number\r\n lat: number\r\n text: string\r\n}\r\n\r\nexport type ColorRampItem = [number, [number, number, number, number]]\r\n\r\n/** 与 arrayData.json 一致的网格数据格式 */\r\nexport interface ArrayDataJson {\r\n startLat: number\r\n endLat: number\r\n startLon: number\r\n endLon: number\r\n latStep: number\r\n lonStep: number\r\n latCount: number\r\n lonCount: number\r\n ds: number[][]\r\n}\r\n\r\nconst NODATA = -9999\r\n\r\nexport function getLodStep(zoom: number): number {\r\n const level = Math.max(0, Math.min(3, Math.floor((11 - zoom) / 2)))\r\n return 2 ** level\r\n}\r\n\r\n/** LOD 块在屏幕上的宽度(像素),兼容 4326(度/px)与 3857(米/px) */\r\nfunction lodCellPixelWidth(\r\n meta: ArrayDataMeta,\r\n lodStep: number,\r\n mapResolution: number,\r\n projCode: string,\r\n): number {\r\n const latMid = (meta.startLat + meta.endLat) * 0.5\r\n const lodCellLonDeg = meta.lonStep * lodStep\r\n if (projCode === \"EPSG:3857\") {\r\n const metersPerDegLon = 111320 * Math.cos((latMid * Math.PI) / 180)\r\n return (lodCellLonDeg * metersPerDegLon) / Math.max(mapResolution, 1e-12)\r\n }\r\n return lodCellLonDeg / Math.max(mapResolution, 1e-12)\r\n}\r\n\r\n/** 标注步长(原生格索引),与色斑图 LOD 对齐:lodStep × 像素稀疏倍数 */\r\nexport function getLabelStep(\r\n meta: ArrayDataMeta,\r\n zoom: number,\r\n mapResolution: number,\r\n distancePx: number,\r\n projCode = \"EPSG:4326\",\r\n): number {\r\n const lodStep = getLodStep(zoom)\r\n const lodCellPx = lodCellPixelWidth(meta, lodStep, mapResolution, projCode)\r\n const blockSkip = Math.max(1, Math.round(distancePx / Math.max(lodCellPx, 1)))\r\n return lodStep * blockSkip\r\n}\r\n\r\nfunction sampleBlock(\r\n flat: Float32Array,\r\n meta: ArrayDataMeta,\r\n row0: number,\r\n col0: number,\r\n step: number,\r\n): number {\r\n let sum = 0\r\n let count = 0\r\n const { latCount, lonCount } = meta\r\n for (let dr = 0; dr < step; dr++) {\r\n for (let dc = 0; dc < step; dc++) {\r\n const r = row0 + dr\r\n const c = col0 + dc\r\n if (r >= latCount || c >= lonCount) continue\r\n const v = flat[r * lonCount + c]\r\n if (v == null || Number.isNaN(v)) continue\r\n sum += v\r\n count++\r\n }\r\n }\r\n return count > 0 ? sum / count : NODATA\r\n}\r\n\r\nexport function readWindow(\r\n flat: Float32Array,\r\n meta: ArrayDataMeta,\r\n extent4326: number[],\r\n zoom: number,\r\n): GridTile | null {\r\n const dataBbox: [number, number, number, number] = [\r\n meta.startLon,\r\n meta.startLat,\r\n meta.endLon,\r\n meta.endLat,\r\n ]\r\n const [vMinLon, vMinLat, vMaxLon, vMaxLat] = extent4326\r\n const [dMinLon, dMinLat, dMaxLon, dMaxLat] = dataBbox\r\n\r\n const minLon = Math.max(vMinLon, dMinLon)\r\n const minLat = Math.max(vMinLat, dMinLat)\r\n const maxLon = Math.min(vMaxLon, dMaxLon)\r\n const maxLat = Math.min(vMaxLat, dMaxLat)\r\n\r\n if (minLon >= maxLon || minLat >= maxLat) return null\r\n\r\n const { startLon, startLat, lonStep, latStep, lonCount, latCount } = meta\r\n const lodStep = getLodStep(zoom)\r\n\r\n const col0 = Math.max(0, Math.floor((minLon - startLon) / lonStep / lodStep) * lodStep)\r\n const col1 = Math.min(lonCount, Math.ceil((maxLon - startLon) / lonStep))\r\n const row0 = Math.max(0, Math.floor((minLat - startLat) / latStep / lodStep) * lodStep)\r\n const row1 = Math.min(latCount, Math.ceil((maxLat - startLat) / latStep))\r\n\r\n if (col0 >= col1 || row0 >= row1) return null\r\n\r\n const outCols = Math.ceil((col1 - col0) / lodStep)\r\n const outRows = Math.ceil((row1 - row0) / lodStep)\r\n const data = new Float32Array(outCols * outRows)\r\n\r\n let idx = 0\r\n for (let r = row1 - lodStep; r >= row0; r -= lodStep) {\r\n for (let c = col0; c < col1; c += lodStep) {\r\n data[idx++] = sampleBlock(flat, meta, r, c, lodStep)\r\n }\r\n }\r\n\r\n return {\r\n data,\r\n width: outCols,\r\n height: outRows,\r\n bbox: [startLon + col0 * lonStep, startLat + row0 * latStep, startLon + col1 * lonStep, startLat + row1 * latStep],\r\n resolution: [lonStep * lodStep, latStep * lodStep],\r\n lodLevel: Math.log2(lodStep),\r\n lodStep,\r\n }\r\n}\r\n\r\n/**\r\n * 与 readWindow 相同 LOD 聚合 + 相同格网原点对齐;\r\n * 位置取 LOD 块中心,数值取 sampleBlock(与色斑图一致)。\r\n */\r\nexport function computeLabels(\r\n flat: Float32Array,\r\n meta: ArrayDataMeta,\r\n extent4326: number[],\r\n zoom: number,\r\n resolution: number,\r\n distancePx: number,\r\n precision: number,\r\n projCode = \"EPSG:4326\",\r\n): GridLabel[] {\r\n const { startLon, startLat, lonStep, latStep, lonCount, latCount } = meta\r\n const lodStep = getLodStep(zoom)\r\n const labelStep = getLabelStep(meta, zoom, resolution, distancePx, projCode)\r\n\r\n const [minLon, minLat, maxLon, maxLat] = extent4326\r\n const col0 = Math.max(0, Math.floor((minLon - startLon) / lonStep / labelStep) * labelStep)\r\n const col1 = Math.min(lonCount, Math.ceil((maxLon - startLon) / lonStep))\r\n const row0 = Math.max(0, Math.floor((minLat - startLat) / latStep / labelStep) * labelStep)\r\n const row1 = Math.min(latCount, Math.ceil((maxLat - startLat) / latStep))\r\n\r\n if (col0 >= col1 || row0 >= row1) return []\r\n\r\n const labels: GridLabel[] = []\r\n for (let row = row0; row < row1; row += labelStep) {\r\n for (let col = col0; col < col1; col += labelStep) {\r\n const v = sampleBlock(flat, meta, row, col, lodStep)\r\n if (v === NODATA || Number.isNaN(v)) continue\r\n const lon = startLon + (col + lodStep * 0.5) * lonStep\r\n const lat = startLat + (row + lodStep * 0.5) * latStep\r\n if (lon < startLon || lon >= meta.endLon || lat < startLat || lat >= meta.endLat) continue\r\n labels.push({ lon, lat, text: v.toFixed(precision) })\r\n }\r\n }\r\n return labels\r\n}\r\n\r\nexport function flattenGrid(ds: number[][], latCount: number, lonCount: number): Float32Array {\r\n const flat = new Float32Array(latCount * lonCount)\r\n for (let r = 0; r < latCount; r++) {\r\n for (let c = 0; c < lonCount; c++) {\r\n flat[r * lonCount + c] = ds[r][c]\r\n }\r\n }\r\n return flat\r\n}\r\n\r\nexport function computeStats(flat: Float32Array): { min: number; max: number } {\r\n let min = Infinity\r\n let max = -Infinity\r\n for (const v of flat) {\r\n if (v == null || Number.isNaN(v)) continue\r\n if (v < min) min = v\r\n if (v > max) max = v\r\n }\r\n return { min, max }\r\n}\r\n\r\nexport function getNativeValue(\r\n flat: Float32Array,\r\n meta: ArrayDataMeta,\r\n lon: number,\r\n lat: number,\r\n): number | null {\r\n const { startLon, startLat, lonStep, latStep, lonCount, latCount } = meta\r\n const col = Math.floor((lon - startLon) / lonStep)\r\n const row = Math.floor((lat - startLat) / latStep)\r\n if (col < 0 || row < 0 || col >= lonCount || row >= latCount) return null\r\n const v = flat[row * lonCount + col]\r\n if (v == null || Number.isNaN(v)) return null\r\n return v\r\n}\r\n\r\nexport { NODATA }\r\n","import {\r\n type ArrayDataMeta,\r\n type GridLabel,\r\n type GridTile,\r\n computeLabels,\r\n readWindow,\r\n} from \"../data/gridDataCore\"\r\nimport type { WorkerRequest, WorkerResponse } from \"./gridDataWorkerTypes\"\r\n\r\nlet meta: ArrayDataMeta | null = null\r\nlet flat: Float32Array | null = null\r\n\r\nself.onmessage = (ev: MessageEvent<WorkerRequest>) => {\r\n const msg = ev.data\r\n try {\r\n switch (msg.type) {\r\n case \"init\": {\r\n meta = msg.meta\r\n flat = msg.flat\r\n const res: WorkerResponse = { id: msg.id, ok: true, type: \"init\" }\r\n self.postMessage(res)\r\n break\r\n }\r\n case \"readWindow\": {\r\n if (!meta || !flat) throw new Error(\"worker not initialized\")\r\n const tile = readWindow(flat, meta, msg.extent4326, msg.zoom)\r\n if (!tile) {\r\n self.postMessage({ id: msg.id, ok: false, error: \"empty window\" } satisfies WorkerResponse)\r\n break\r\n }\r\n const res: WorkerResponse = { id: msg.id, ok: true, type: \"readWindow\", tile }\r\n self.postMessage(res)\r\n break\r\n }\r\n case \"computeLabels\": {\r\n if (!meta || !flat) throw new Error(\"worker not initialized\")\r\n const labels = computeLabels(\r\n flat,\r\n meta,\r\n msg.extent4326,\r\n msg.zoom,\r\n msg.resolution,\r\n msg.distancePx,\r\n msg.precision,\r\n msg.projCode ?? \"EPSG:4326\",\r\n )\r\n const res: WorkerResponse = { id: msg.id, ok: true, type: \"computeLabels\", labels }\r\n self.postMessage(res)\r\n break\r\n }\r\n }\r\n } catch (e) {\r\n const res: WorkerResponse = { id: msg.id, ok: false, error: String(e) }\r\n self.postMessage(res)\r\n }\r\n}\r\n"],"names":["getLodStep","zoom","lodCellPixelWidth","meta","lodStep","mapResolution","projCode","latMid","lodCellLonDeg","metersPerDegLon","getLabelStep","distancePx","lodCellPx","blockSkip","sampleBlock","flat","row0","col0","step","sum","count","latCount","lonCount","dr","dc","r","c","v","readWindow","extent4326","dataBbox","vMinLon","vMinLat","vMaxLon","vMaxLat","dMinLon","dMinLat","dMaxLon","dMaxLat","minLon","minLat","maxLon","maxLat","startLon","startLat","lonStep","latStep","col1","row1","outCols","outRows","data","idx","computeLabels","resolution","precision","labelStep","labels","row","col","lon","lat","ev","msg","res","tile","e"],"mappings":"yBA8CO,SAASA,EAAWC,EAAsB,CAE/C,MAAO,IADO,KAAK,IAAI,EAAG,KAAK,IAAI,EAAG,KAAK,OAAO,GAAKA,GAAQ,CAAC,CAAC,CAAC,CAEpE,CAGA,SAASC,EACPC,EACAC,EACAC,EACAC,EACQ,CACR,MAAMC,GAAUJ,EAAK,SAAWA,EAAK,QAAU,GACzCK,EAAgBL,EAAK,QAAUC,EACrC,GAAIE,IAAa,YAAa,CAC5B,MAAMG,EAAkB,OAAS,KAAK,IAAKF,EAAS,KAAK,GAAM,GAAG,EAClE,OAAQC,EAAgBC,EAAmB,KAAK,IAAIJ,EAAe,KAAK,CAC1E,CACA,OAAOG,EAAgB,KAAK,IAAIH,EAAe,KAAK,CACtD,CAGO,SAASK,EACdP,EACAF,EACAI,EACAM,EACAL,EAAW,YACH,CACR,MAAMF,EAAUJ,EAAWC,CAAI,EACzBW,EAAYV,EAAkBC,EAAMC,EAASC,EAAeC,CAAQ,EACpEO,EAAY,KAAK,IAAI,EAAG,KAAK,MAAMF,EAAa,KAAK,IAAIC,EAAW,CAAC,CAAC,CAAC,EAC7E,OAAOR,EAAUS,CACnB,CAEA,SAASC,EACPC,EACAZ,EACAa,EACAC,EACAC,EACQ,CACR,IAAIC,EAAM,EACNC,EAAQ,EACZ,KAAM,CAAE,SAAAC,EAAU,SAAAC,CAAA,EAAanB,EAC/B,QAASoB,EAAK,EAAGA,EAAKL,EAAMK,IAC1B,QAASC,EAAK,EAAGA,EAAKN,EAAMM,IAAM,CAChC,MAAMC,EAAIT,EAAOO,EACXG,EAAIT,EAAOO,EACjB,GAAIC,GAAKJ,GAAYK,GAAKJ,EAAU,SACpC,MAAMK,EAAIZ,EAAKU,EAAIH,EAAWI,CAAC,EAC3BC,GAAK,MAAQ,OAAO,MAAMA,CAA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JA,EAAI,WACJA,EAAI,WACJA,EAAI,UACJA,EAAI,UAAY,WAAA,EAEZC,EAAsB,CAAE,GAAID,EAAI,GAAI,GAAI,GAAM,KAAM,gBAAiB,OAAAN,CAAA,EAC3E,KAAK,YAAYO,CAAG,EACpB,KACF,CAAA,CAEJ,OAASE,EAAG,CACV,MAAMF,EAAsB,CAAE,GAAID,EAAI,GAAI,GAAI,GAAO,MAAO,OAAOG,CAAC,CAAA,EACpE,KAAK,YAAYF,CAAG,CACtB,CACF"}
@@ -0,0 +1 @@
1
+ .gred-legend-panel__title[data-v-ce6d21e6]{margin-bottom:6px;color:#333;font-size:12px}.gred-legend-panel__controls[data-v-ce6d21e6]{margin-top:8px;display:flex;flex-wrap:wrap;gap:6px}.gred-legend-slider-host[data-v-d893e60a]{min-width:220px}