@ywbgn/bgl-package 1.0.0 → 1.2.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 +660 -24
- package/dist/index.css +1 -0
- package/dist/index.d.ts +1091 -0
- package/dist/vue-arcgis-map.js +14989 -157
- package/dist/vue-arcgis-map.umd.cjs +131 -1
- package/package.json +56 -29
- package/dist/vue-arcgis-map.css +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# @ywbgn/bgl-package
|
|
2
2
|
|
|
3
|
-
基于 Vue 3 与 `@arcgis/core`
|
|
3
|
+
基于 Vue 3 与 `@arcgis/core` 的地图组件库:地图初始化、底图切换、底图卷帘、工具栏(全图、全屏、缩放、定位、测距、测面、图层管理、业务卷帘、地图标注、条件查询)、**空间分析面板**(`SpatialAnalysisPanel`),业务图层加载 / Portal Token 注册,以及平移边界约束(`panBounds` / `applyPanBoundsConstraint`)。
|
|
4
4
|
|
|
5
5
|
## 安装依赖
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @ywbgn/bgl-package vue @arcgis/core
|
|
8
|
+
npm install @ywbgn/bgl-package vue @arcgis/core@~4.34.8
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
**版本约定(作子系统模版时请对齐):**
|
|
12
|
+
|
|
13
|
+
- peer:`@arcgis/core@~4.34.8`(允许 `4.34.8`~`<4.35.0` 补丁,不自动升到 4.35)
|
|
14
|
+
- 业务项目建议同样使用 `"@arcgis/core": "~4.34.8"`
|
|
15
|
+
- 升级到 4.35+ 需先在本库回归验证,再同步改 peer 与各子系统依赖
|
|
16
|
+
|
|
11
17
|
## 引入依赖与注册
|
|
12
18
|
|
|
13
19
|
```js
|
|
@@ -21,47 +27,677 @@ app.use(VueArcgisMap)
|
|
|
21
27
|
app.mount('#app')
|
|
22
28
|
```
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
按需引入(不全局注册):
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import {
|
|
34
|
+
ArcgisMap,
|
|
35
|
+
BasemapSwitch,
|
|
36
|
+
SwipeCompare,
|
|
37
|
+
MapToolbar,
|
|
38
|
+
provideBasemapKeys,
|
|
39
|
+
loadBusinessLayers,
|
|
40
|
+
registerPortalToken,
|
|
41
|
+
startPortalTokenRenewal,
|
|
42
|
+
applyPanBoundsConstraint,
|
|
43
|
+
goToFullExtent
|
|
44
|
+
} from '@ywbgn/bgl-package'
|
|
45
|
+
import type {
|
|
46
|
+
BasemapKeys,
|
|
47
|
+
BusinessLayerConfig,
|
|
48
|
+
MapReadyPayload,
|
|
49
|
+
ToolbarToolId,
|
|
50
|
+
LonLatExtent,
|
|
51
|
+
PanConstraintHandle
|
|
52
|
+
} from '@ywbgn/bgl-package'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 快速接入
|
|
56
|
+
|
|
57
|
+
1. 先拿到底图密钥 / 系统参数(含 `minZoom` / `maxZoom` / 经纬度范围),再挂 `ArcgisMap`(密钥只在挂载时读一次,可用 `v-if` 等配置就绪后再渲染)。
|
|
58
|
+
2. `@ready` 里用 `shallowRef` 保存 `view` / `sketchLayer` / `map`。
|
|
59
|
+
3. 需要时再挂 `BasemapSwitch`、`SwipeCompare`、`MapLegend`、`MapScaleBar`、`MapToolbar`。
|
|
60
|
+
4. 有经纬度范围时:给 `ArcgisMap` 传 `:pan-bounds`(自动限制拖动),给 `MapToolbar` 传 `:home-extent`(全图回到范围中心 + minZoom)。
|
|
61
|
+
5. 在 `ready` 后 `startPortalTokenRenewal`(或 `registerPortalToken`)→ `loadBusinessLayers`;卸载时对续期调用 `stop()`。
|
|
62
|
+
6. 切底图前同时拆除**底图卷帘**与**工具栏业务卷帘**。
|
|
25
63
|
|
|
26
64
|
```vue
|
|
27
65
|
<template>
|
|
28
|
-
<div
|
|
29
|
-
<ArcgisMap
|
|
66
|
+
<div class="map-page">
|
|
67
|
+
<ArcgisMap
|
|
68
|
+
v-if="mapReady"
|
|
69
|
+
width="100%"
|
|
70
|
+
height="600px"
|
|
71
|
+
:zoom="zoom"
|
|
72
|
+
:center="center"
|
|
73
|
+
:min-zoom="minZoom"
|
|
74
|
+
:max-zoom="maxZoom"
|
|
75
|
+
:pan-bounds="extent"
|
|
76
|
+
@ready="onReady"
|
|
77
|
+
/>
|
|
30
78
|
<template v-if="view && sketchLayer">
|
|
31
|
-
<BasemapSwitch :view="view" />
|
|
32
|
-
<
|
|
79
|
+
<BasemapSwitch :view="view" @before-change="onBeforeBasemapChange" />
|
|
80
|
+
<SwipeCompare ref="swipeCompareRef" :view="view" />
|
|
81
|
+
<MapLegend :view="view" position="left" :offset-x="12" :offset-y="14" />
|
|
82
|
+
<MapScaleBar :view="view" position="left" :offset-x="170" :offset-y="14" />
|
|
83
|
+
<MapToolbar
|
|
84
|
+
ref="mapToolbarRef"
|
|
85
|
+
:view="view"
|
|
86
|
+
:sketch-layer="sketchLayer"
|
|
87
|
+
:home-extent="extent"
|
|
88
|
+
/>
|
|
33
89
|
</template>
|
|
34
90
|
</div>
|
|
35
91
|
</template>
|
|
36
92
|
|
|
37
|
-
<script setup>
|
|
38
|
-
import { ref, shallowRef } from 'vue'
|
|
93
|
+
<script setup lang="ts">
|
|
94
|
+
import { onMounted, ref, shallowRef } from 'vue'
|
|
95
|
+
import type MapView from '@arcgis/core/views/MapView.js'
|
|
96
|
+
import type GraphicsLayer from '@arcgis/core/layers/GraphicsLayer.js'
|
|
97
|
+
import {
|
|
98
|
+
ArcgisMap,
|
|
99
|
+
BasemapSwitch,
|
|
100
|
+
MapLegend,
|
|
101
|
+
MapScaleBar,
|
|
102
|
+
MapToolbar,
|
|
103
|
+
SwipeCompare,
|
|
104
|
+
loadBusinessLayers,
|
|
105
|
+
provideBasemapKeys,
|
|
106
|
+
registerPortalToken
|
|
107
|
+
} from '@ywbgn/bgl-package'
|
|
108
|
+
import type { BasemapKeys, BusinessLayerConfig, LonLatExtent, MapReadyPayload } from '@ywbgn/bgl-package'
|
|
109
|
+
|
|
110
|
+
const mapReady = ref(false)
|
|
111
|
+
const view = shallowRef<MapView | null>(null)
|
|
112
|
+
const sketchLayer = shallowRef<GraphicsLayer | null>(null)
|
|
113
|
+
const swipeCompareRef = ref<InstanceType<typeof SwipeCompare> | null>(null)
|
|
114
|
+
const mapToolbarRef = ref<InstanceType<typeof MapToolbar> | null>(null)
|
|
115
|
+
const zoom = ref(8)
|
|
116
|
+
const center = ref<[number, number]>([116.4, 39.9])
|
|
117
|
+
const minZoom = ref<number | null>(8)
|
|
118
|
+
const maxZoom = ref<number | null>(18)
|
|
119
|
+
const extent = ref<LonLatExtent | null>(null)
|
|
120
|
+
|
|
121
|
+
const basemapKeys = ref<BasemapKeys>({})
|
|
122
|
+
provideBasemapKeys(basemapKeys)
|
|
123
|
+
|
|
124
|
+
let businessLayers: BusinessLayerConfig[] = []
|
|
39
125
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
126
|
+
onMounted(async () => {
|
|
127
|
+
// 伪代码:从业务接口拉取密钥、缩放上下限、jw 范围、图层配置后再挂地图
|
|
128
|
+
// basemapKeys.value = ...
|
|
129
|
+
// minZoom.value = ...
|
|
130
|
+
// maxZoom.value = ...
|
|
131
|
+
// extent.value = { xmin, ymin, xmax, ymax }
|
|
132
|
+
// businessLayers = ...
|
|
133
|
+
mapReady.value = true
|
|
134
|
+
})
|
|
43
135
|
|
|
44
|
-
const onReady = (
|
|
45
|
-
view.value =
|
|
46
|
-
sketchLayer.value =
|
|
136
|
+
const onReady = async (payload: MapReadyPayload) => {
|
|
137
|
+
view.value = payload.view
|
|
138
|
+
sketchLayer.value = payload.sketchLayer
|
|
139
|
+
// minZoom / maxZoom / panBounds 已由 ArcgisMap 内部应用
|
|
140
|
+
|
|
141
|
+
// 如需 Portal 鉴权再注册 token(生产建议后端签发,勿长期在前端存密码)
|
|
142
|
+
// await registerPortalToken({ portalUrl, username, password, extraServers, tokenServiceUrl })
|
|
143
|
+
|
|
144
|
+
loadBusinessLayers({
|
|
145
|
+
map: payload.map,
|
|
146
|
+
layers: businessLayers,
|
|
147
|
+
reverse: true
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 切底图前拆除底图卷帘 + 业务图层卷帘 */
|
|
152
|
+
const onBeforeBasemapChange = () => {
|
|
153
|
+
swipeCompareRef.value?.destroySwipe()
|
|
154
|
+
mapToolbarRef.value?.destroySwipe()
|
|
47
155
|
}
|
|
48
156
|
</script>
|
|
157
|
+
|
|
158
|
+
<style scoped>
|
|
159
|
+
.map-page {
|
|
160
|
+
position: relative;
|
|
161
|
+
--bgl-toolbar-bottom: 14px;
|
|
162
|
+
}
|
|
163
|
+
</style>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 组件说明
|
|
167
|
+
|
|
168
|
+
### 通用输入组件
|
|
169
|
+
|
|
170
|
+
组件库提供统一深色主题样式的 `BglInput` 和 `BglSelect`,支持全局注册或按需引入。使用组件前请引入组件库样式:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import '@ywbgn/bgl-package/style.css'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
使用 `app.use(VueArcgisMap)` 全局注册后,可以直接在模板中使用:
|
|
177
|
+
|
|
178
|
+
```vue
|
|
179
|
+
<template>
|
|
180
|
+
<BglInput v-model="keyword" placeholder="请输入关键字" />
|
|
181
|
+
<BglSelect v-model="status" :options="statusOptions" placeholder="请选择状态" />
|
|
182
|
+
</template>
|
|
183
|
+
|
|
184
|
+
<script setup lang="ts">
|
|
185
|
+
import { ref } from 'vue'
|
|
186
|
+
|
|
187
|
+
const keyword = ref('')
|
|
188
|
+
const status = ref('')
|
|
189
|
+
const statusOptions = [
|
|
190
|
+
{ value: 'active', label: '有效' },
|
|
191
|
+
{ value: 'inactive', label: '无效' }
|
|
192
|
+
]
|
|
193
|
+
</script>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
按需引入时,在页面组件中直接导入:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { BglInput, BglSelect } from '@ywbgn/bgl-package'
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### BglInput
|
|
203
|
+
|
|
204
|
+
```vue
|
|
205
|
+
<BglInput
|
|
206
|
+
v-model="year"
|
|
207
|
+
type="number"
|
|
208
|
+
min="1900"
|
|
209
|
+
max="2200"
|
|
210
|
+
placeholder="请输入年份"
|
|
211
|
+
:disabled="loading"
|
|
212
|
+
/>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
216
|
+
| --- | --- | --- | --- |
|
|
217
|
+
| `modelValue` | `string \| number` | `''` | `v-model` 双向绑定值 |
|
|
218
|
+
| `type` | `string` | `'text'` | 原生输入类型,例如 `text`、`number` |
|
|
219
|
+
| `placeholder` | `string` | `''` | 占位文案 |
|
|
220
|
+
| `disabled` | `boolean` | `false` | 是否禁用输入框 |
|
|
221
|
+
| `min` / `max` | `string \| number` | 无 | 原生数值范围属性 |
|
|
222
|
+
|
|
223
|
+
输入内容变化时触发 `update:modelValue` 事件。即使 `type="number"`,组件发出的值仍是输入框产生的字符串,需要数值时请在业务侧自行转换。
|
|
224
|
+
|
|
225
|
+
#### BglSelect
|
|
226
|
+
|
|
227
|
+
选项值和当前绑定值均使用字符串:
|
|
228
|
+
|
|
229
|
+
```vue
|
|
230
|
+
<BglSelect
|
|
231
|
+
v-model="selectedStatus"
|
|
232
|
+
:options="statusOptions"
|
|
233
|
+
placeholder="请选择状态"
|
|
234
|
+
:disabled="loading"
|
|
235
|
+
/>
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
const selectedStatus = ref('')
|
|
240
|
+
const statusOptions = [
|
|
241
|
+
{ value: 'active', label: '有效' },
|
|
242
|
+
{ value: 'inactive', label: '无效', disabled: true }
|
|
243
|
+
]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
247
|
+
| --- | --- | --- | --- |
|
|
248
|
+
| `modelValue` | `string` | `''` | 当前选中值,支持 `v-model` |
|
|
249
|
+
| `options` | `{ value: string; label: string; disabled?: boolean }[]` | `[]` | 下拉选项 |
|
|
250
|
+
| `placeholder` | `string` | `'请选择'` | 没有匹配选中值时的占位文案 |
|
|
251
|
+
| `open` | `boolean` | `false` | 是否展开下拉框,可用于受控展开 |
|
|
252
|
+
| `disabled` | `boolean` | `false` | 是否禁用下拉框 |
|
|
253
|
+
|
|
254
|
+
组件事件:
|
|
255
|
+
|
|
256
|
+
- `update:modelValue(value)`:选中选项时触发,可通过 `v-model` 接收。
|
|
257
|
+
- `select(value)`:选中选项时触发,参数为选项的 `value`。
|
|
258
|
+
- `update:open(open)`:展开状态变化时触发。点击触发按钮、按 `Esc` 或点击组件外部时会更新为 `false`。
|
|
259
|
+
|
|
260
|
+
需要由业务侧控制展开状态时:
|
|
261
|
+
|
|
262
|
+
```vue
|
|
263
|
+
<BglSelect
|
|
264
|
+
:model-value="selectedStatus"
|
|
265
|
+
:options="statusOptions"
|
|
266
|
+
:open="selectOpen"
|
|
267
|
+
@select="selectedStatus = $event"
|
|
268
|
+
@update:open="selectOpen = $event"
|
|
269
|
+
/>
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### ArcgisMap
|
|
273
|
+
|
|
274
|
+
| Prop / 能力 | 说明 |
|
|
275
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
276
|
+
| `width` / `height` | 尺寸,支持数字(px)或 CSS 字符串 |
|
|
277
|
+
| `zoom` / `center` | 初始与可监听更新的缩放、中心`[经度, 纬度]` |
|
|
278
|
+
| `keys` | 底图密钥;也可上层`provideBasemapKeys` |
|
|
279
|
+
| `minZoom` / `maxZoom` | 写入`view.constraints` 的缩放上下限 |
|
|
280
|
+
| `panBounds` | 经纬度矩形`{ xmin, ymin, xmax, ymax }`;传入后自动限制拖动,并在程序化 `goTo` 期间临时放开约束 |
|
|
281
|
+
| 事件`ready` | 载荷`MapReadyPayload`(`map` / `view` / `sketchLayer`) |
|
|
282
|
+
|
|
283
|
+
- 默认底图优先级:天地图影像 → 星图 → 吉林一号 → ArcGIS 影像
|
|
284
|
+
- `panBounds` 在 view ready 后自动调用 `applyPanBoundsConstraint` + `wrapViewGoTo`;组件卸载时自动清理
|
|
285
|
+
- 有 `panBounds` 时,初始会定位到范围中心 + `minZoom`(与「全图」一致)
|
|
286
|
+
|
|
287
|
+
### BasemapSwitch(底图切换)
|
|
288
|
+
|
|
289
|
+
- 必填 `view`
|
|
290
|
+
- 可选 `keys`
|
|
291
|
+
- 事件 `before-change`:成功切换底图**前**触发(用于拆卷帘)
|
|
292
|
+
|
|
293
|
+
可选底图:天地图影像 / 矢量、星图地球、吉林一号、ArcGIS 影像。缺 Key 时可选中,切换时会提示。
|
|
294
|
+
|
|
295
|
+
### SwipeCompare(底图卷帘)
|
|
296
|
+
|
|
297
|
+
- 左下角入口,对比**底图影像**
|
|
298
|
+
- 方法 `destroySwipe()`:拆除 Swipe 并移除左侧对比层
|
|
299
|
+
|
|
300
|
+
### MapToolbar(工具栏)
|
|
301
|
+
|
|
302
|
+
内置工具:全图、全屏、放大、缩小、坐标定位、距离测量、面积测量、图层管理、业务图层卷帘、地图标注、条件查询。
|
|
303
|
+
|
|
304
|
+
| Prop / 能力 | 说明 |
|
|
305
|
+
| -------------------------- | ------------------------------------------------------------------------ |
|
|
306
|
+
| `view` / `sketchLayer` | 必填 |
|
|
307
|
+
| `layerIdPrefix` | 业务图层 id 前缀,默认`bgl-biz-`(需与 `loadBusinessLayers` 一致) |
|
|
308
|
+
| `tools` | 白名单;不传则全量 |
|
|
309
|
+
| `hiddenTools` | 黑名单;与`tools` 同传时以 `tools` 为准 |
|
|
310
|
+
| `showCoordinate` | 是否显示经纬度条,默认`true` |
|
|
311
|
+
| `homeExtent` | 全图经纬度范围;优先调用`goToFullExtent`(minZoom + 范围中心) |
|
|
312
|
+
| `homeCenter` | 无`homeExtent` 时回退:回到该中心 + `minZoom` |
|
|
313
|
+
| `delegateFullExtent` | 为`true` 时全图只抛 `fullExtent` 事件,由业务侧自行定位 |
|
|
314
|
+
| `coordinateSystemConfig` | 坐标定位面板动态坐标系配置;不传则使用内置默认 5 项 |
|
|
315
|
+
| `#extra` | 工具条末尾自定义按钮 |
|
|
316
|
+
| 事件 | `fullExtent` / `layerManage` / `swipeCompare` / `conditionQuery` |
|
|
317
|
+
| `destroySwipe()` | 拆除**业务图层**卷帘 |
|
|
318
|
+
|
|
319
|
+
工具 id(`ToolbarToolId`):
|
|
320
|
+
|
|
321
|
+
`fullExtent` | `fullscreen` | `zoomIn` | `zoomOut` | `coordinateLocate` | `distanceMeasure` | `areaMeasure` | `layerManage` | `layerSwipe` | `mapLabel` | `conditionQuery`
|
|
322
|
+
|
|
323
|
+
```vue
|
|
324
|
+
<MapToolbar
|
|
325
|
+
:view="view"
|
|
326
|
+
:sketch-layer="sketchLayer"
|
|
327
|
+
:home-extent="extent"
|
|
328
|
+
:coordinate-system-config="coordinateSystemConfig"
|
|
329
|
+
:tools="['fullExtent', 'fullscreen', 'zoomIn', 'zoomOut', 'distanceMeasure', 'areaMeasure', 'layerManage']"
|
|
330
|
+
:show-coordinate="true"
|
|
331
|
+
>
|
|
332
|
+
<template #extra>
|
|
333
|
+
<button type="button" data-tip="业务分析" aria-label="业务分析" @click="onBiz" />
|
|
334
|
+
</template>
|
|
335
|
+
</MapToolbar>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
```ts
|
|
339
|
+
const coordinateSystemConfig = {
|
|
340
|
+
defaultWkid: 4509,
|
|
341
|
+
options: [
|
|
342
|
+
{ wkid: 4490, label: '经纬度' },
|
|
343
|
+
{ wkid: 4548, label: '3度带-不带号' },
|
|
344
|
+
{ wkid: 4527, label: '3度带-带号' },
|
|
345
|
+
{ wkid: 4509, label: '6度带-不带号' },
|
|
346
|
+
{ wkid: 4498, label: '6度带-带号' }
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### 全图 / 全屏说明
|
|
352
|
+
|
|
353
|
+
| 工具 | 行为 |
|
|
354
|
+
| ---- | ------------------------------------------------------------------------------------------------- |
|
|
355
|
+
| 全图 | 有`homeExtent` 时:`goToFullExtent`(范围中心 + minZoom);否则用 `homeCenter` / 仅 minZoom |
|
|
356
|
+
| 全屏 | 对`document.documentElement` 请求整页全屏(接近 F11),再次点击或 Esc 退出 |
|
|
357
|
+
|
|
358
|
+
#### 内置面板说明
|
|
359
|
+
|
|
360
|
+
| 工具 | 作用 | 注意 |
|
|
361
|
+
| -------- | ---------------------------------------- | ---------------------------------------------------- |
|
|
362
|
+
| 图层管理 | 业务层显隐、透明度、排序、定位 | 仅识别`layerIdPrefix` 前缀图层;若加载时做过坐标系校验,不一致图层会标记「坐标系不一致」 |
|
|
363
|
+
| 卷帘对比 | 选左右**业务层**做 Swipe | 与底图卷帘互斥(应用时自动拆另一侧) |
|
|
364
|
+
| 坐标定位 | 按所选坐标系输入或拾取坐标后定位 | `coordinateSystemConfig` 可由业务系统动态下发默认坐标系与可选项 |
|
|
365
|
+
| 地图标注 | 按字段设置`labelingInfo` | 仅**FeatureLayer**;MapImageLayer 不出现在列表 |
|
|
366
|
+
| 条件查询 | 拼 WHERE →`queryFeatures` → 定位高亮 | 仅 FeatureLayer;字段值去重最多约 1000 条 |
|
|
367
|
+
|
|
368
|
+
### MapLegend(图例,独立常开)
|
|
369
|
+
|
|
370
|
+
与底图切换、卷帘一样单独挂载,**不在工具栏内**;默认常开,基于 ArcGIS `Legend` 微件。
|
|
371
|
+
|
|
372
|
+
- 只展示业务图层(`idPrefix` 前缀,默认 `bgl-biz-`)
|
|
373
|
+
- 排除 `listMode === 'hide'` 的图层(如绘制层)
|
|
374
|
+
- `map.layers` 变化时自动同步图例项
|
|
375
|
+
|
|
376
|
+
```vue
|
|
377
|
+
<MapLegend
|
|
378
|
+
:view="view"
|
|
379
|
+
position="left"
|
|
380
|
+
:offset-x="12"
|
|
381
|
+
:offset-y="14"
|
|
382
|
+
/>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
| Prop | 说明 |
|
|
386
|
+
| ------------ | ---------------------------------------------------------------- |
|
|
387
|
+
| `view` | 必填 |
|
|
388
|
+
| `idPrefix` | 业务层前缀,默认`bgl-biz-`(需与 `loadBusinessLayers` 一致) |
|
|
389
|
+
| `position` | `'left'` \| `'right'`,默认 `left`(右侧有业务抽屉时用左) |
|
|
390
|
+
| `offsetX` | 水平边距(px),默认`12` |
|
|
391
|
+
| `offsetY` | 相对地图底边抬高(px),默认`14` |
|
|
392
|
+
|
|
393
|
+
默认尺寸 **150×240px**(可用 CSS 变量 `--bgl-legend-width` / `--bgl-legend-height` 覆盖)。
|
|
394
|
+
层级默认约 `1050`,可用 `--bgl-legend-z` 覆盖。
|
|
395
|
+
|
|
396
|
+
与比例尺同侧时,建议比例尺加大 `offsetX`(例如图例 `12`、比例尺 `170`),避免重叠。
|
|
397
|
+
|
|
398
|
+
### MapScaleBar(比例尺,独立常开)
|
|
399
|
+
|
|
400
|
+
独立挂载,**不在工具栏内**;封装 ArcGIS `ScaleBar`,缩放时自动更新。定位 API 与 `MapLegend` 对齐。
|
|
401
|
+
|
|
402
|
+
```vue
|
|
403
|
+
<MapScaleBar
|
|
404
|
+
:view="view"
|
|
405
|
+
position="left"
|
|
406
|
+
:offset-x="170"
|
|
407
|
+
:offset-y="14"
|
|
408
|
+
unit="metric"
|
|
409
|
+
bar-style="line"
|
|
410
|
+
:show-numeric-scale="true"
|
|
411
|
+
:numeric-scale-use-grouping="true"
|
|
412
|
+
:numeric-scale-formatter="(scale) => `比例 1:${scale.toLocaleString()}`"
|
|
413
|
+
panel-background="rgba(24, 32, 42, 0.94)"
|
|
414
|
+
panel-border-color="rgba(255, 255, 255, 0.18)"
|
|
415
|
+
graphic-label-color="#ffffff"
|
|
416
|
+
numeric-label-color="rgba(255, 255, 255, 0.96)"
|
|
417
|
+
/>
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
| Prop | 说明 |
|
|
421
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
422
|
+
| `view` | 必填 |
|
|
423
|
+
| `position` | `'left'` \| `'right'`,默认 `left` |
|
|
424
|
+
| `offsetX` | 水平边距(px),默认`12` |
|
|
425
|
+
| `offsetY` | 相对地图底边抬高(px),默认`14` |
|
|
426
|
+
| `unit` | `'metric'`(公制)\| `'imperial'`(英制)\| `'dual'`(双单位),默认 `metric` |
|
|
427
|
+
| `barStyle` | `'line'`(线型)\| `'ruler'`(尺型),默认 `line` |
|
|
428
|
+
| `showNumericScale` | 是否显示实时数字比例尺(如 `1:40,000`),默认 `false` |
|
|
429
|
+
| `numericScaleUseGrouping` | 数字比例尺是否显示千分位,默认 `true` |
|
|
430
|
+
| `numericScaleFormatter` | 自定义数字比例尺格式化函数 `(scale: number) => string`;传入后优先级高于 `numericScaleUseGrouping` |
|
|
431
|
+
| `panelBackground` | 外层容器背景色;不传则用默认深色 |
|
|
432
|
+
| `panelBorderColor` | 外层容器边框色 |
|
|
433
|
+
| `graphicLabelColor` | 图形比例尺标题颜色 |
|
|
434
|
+
| `numericLabelColor` | 数字比例尺文字颜色 |
|
|
435
|
+
|
|
436
|
+
说明:
|
|
437
|
+
|
|
438
|
+
- 创建前会等待 `view.when()` 与一帧布局,避免容器宽高为 0 时算不出刻度长度
|
|
439
|
+
- `view` / `unit` / `barStyle` 变化会重建微件;卸载时自动 `destroy`
|
|
440
|
+
- 数字比例尺直接读取 ArcGIS `MapView.scale`,格式化为 `1:N` 文本,并随缩放、平移、全图、全屏和视口变化实时更新
|
|
441
|
+
- `numericScaleUseGrouping` 可关闭千分位;如需完全自定义文本,直接传 `numericScaleFormatter`
|
|
442
|
+
- `panelBackground` / `panelBorderColor` / `graphicLabelColor` / `numericLabelColor` 会以内联 CSS 变量方式写入,适合做轻量主题覆盖
|
|
443
|
+
- 组件会读取 ArcGIS 原生图形比例尺标题文案,并在容器上方自行居中渲染,避免默认标题在定制样式下偏移
|
|
444
|
+
- `showNumericScale` 开启后,会在图形比例尺下方追加一行数字比例尺文本;图形比例尺长度与刻度计算仍由 ArcGIS 原生 `ScaleBar` 负责
|
|
445
|
+
- 图形标题自绘依赖当前 ArcGIS `ScaleBar` 内部 `.esri-scale-bar__label` 文案;升级 `@arcgis/core` 时请回归检查比例尺标题是否仍可正常读取
|
|
446
|
+
- 容器 `pointer-events: none`,不挡地图拖拽
|
|
447
|
+
- 层级默认 `100`(与底图切换、图例、工具栏一致),可用 `--bgl-scalebar-z` 覆盖
|
|
448
|
+
|
|
449
|
+
## 平移边界约束
|
|
450
|
+
|
|
451
|
+
基于 ArcGIS `view.constraints.geometry`(只约束**视图中心点**):按当前可视范围反推中心点合法活动区域,效果上等价于「经纬度矩形始终不拖出屏幕」。所有缩放级别均生效;拖到边缘直接停住,不做回弹。
|
|
452
|
+
|
|
453
|
+
推荐优先用组件 props(见上 `ArcgisMap.panBounds` + `MapToolbar.homeExtent`)。也可直接调用工具函数:
|
|
454
|
+
|
|
455
|
+
```ts
|
|
456
|
+
import {
|
|
457
|
+
applyPanBoundsConstraint,
|
|
458
|
+
goToFullExtent
|
|
459
|
+
} from '@ywbgn/bgl-package'
|
|
460
|
+
import type { LonLatExtent, PanConstraintHandle } from '@ywbgn/bgl-package'
|
|
461
|
+
|
|
462
|
+
const extent: LonLatExtent = {
|
|
463
|
+
xmin: 116.3,
|
|
464
|
+
ymin: 43.8,
|
|
465
|
+
xmax: 119.4,
|
|
466
|
+
ymax: 45.4
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// 手动挂约束(组件卸载时务必 handle.remove())
|
|
470
|
+
const handle: PanConstraintHandle = await applyPanBoundsConstraint(view, extent)
|
|
471
|
+
handle.wrapViewGoTo(view) // 坐标定位等程序化 goTo 期间临时放开约束
|
|
472
|
+
|
|
473
|
+
await goToFullExtent(view, extent) // 回到范围中心 + minZoom
|
|
474
|
+
|
|
475
|
+
// 卸载
|
|
476
|
+
handle.remove()
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
| API | 说明 |
|
|
480
|
+
| ------------------------------------------ | ----------------------------------------------------------- |
|
|
481
|
+
| `LonLatExtent` | `{ xmin, ymin, xmax, ymax }`,WGS84 经纬度 |
|
|
482
|
+
| `applyPanBoundsConstraint(view, extent)` | 挂平移约束并初始定位到全图;返回`PanConstraintHandle` |
|
|
483
|
+
| `handle.wrapViewGoTo(view)` | 包装`view.goTo`,定位期间临时放开约束 |
|
|
484
|
+
| `handle.remove()` | 释放 watch,恢复原始`goTo`,清空 `constraints.geometry` |
|
|
485
|
+
| `goToFullExtent(view, extent)` | 定位到范围中心 +`constraints.minZoom` |
|
|
486
|
+
|
|
487
|
+
## 两套卷帘(务必区分)
|
|
488
|
+
|
|
489
|
+
| 组件 | 对比对象 | 入口 |
|
|
490
|
+
| ----------------------- | -------- | ---------- |
|
|
491
|
+
| `SwipeCompare` | 底图 | 地图左下角 |
|
|
492
|
+
| `MapToolbar` 卷帘对比 | 业务图层 | 底部工具栏 |
|
|
493
|
+
|
|
494
|
+
应用任一侧卷帘时,库内会通过 `swipe-registry` **自动拆除另一侧**。切底图时仍建议两边都 `destroySwipe()`,或调用导出的 `destroyAllSwipes()`。
|
|
495
|
+
|
|
496
|
+
## 业务图层与 Portal
|
|
497
|
+
|
|
498
|
+
### loadBusinessLayers
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
import { loadBusinessLayers, BUSINESS_LAYER_ID_PREFIX } from '@ywbgn/bgl-package'
|
|
502
|
+
import type { BusinessLayerConfig } from '@ywbgn/bgl-package'
|
|
503
|
+
|
|
504
|
+
const layers = loadBusinessLayers({
|
|
505
|
+
map,
|
|
506
|
+
layers: configs,
|
|
507
|
+
reverse: true,
|
|
508
|
+
idPrefix: BUSINESS_LAYER_ID_PREFIX,
|
|
509
|
+
// labelConfigs: [...] // 见下文「业务图层注记」
|
|
510
|
+
// expectedSpatialReferenceWkid: 8848, // 系统参数;8848=CGCS2000_Albers,其他为 WKID
|
|
511
|
+
})
|
|
49
512
|
```
|
|
50
513
|
|
|
51
|
-
`
|
|
514
|
+
`BusinessLayerConfig` 主要字段(对齐常见 `mapServiceSettings`):
|
|
515
|
+
|
|
516
|
+
- `id` / `mapServiceUrl` / `mapServiceName`
|
|
517
|
+
- `layerVisible` / `layerOrder`
|
|
518
|
+
- `mapServiceType`:`1`=MapServer,`2`=FeatureServer
|
|
519
|
+
- `scaleConfig` / `minScale` / `maxScale`:仅当 `scaleConfig` 为真时写入图层的 `minScale`/`maxScale`;为假时不写配置值(保留服务端自带比例尺)
|
|
520
|
+
|
|
521
|
+
加载规则简述:
|
|
522
|
+
|
|
523
|
+
- MapServer **根地址** → `MapImageLayer`
|
|
524
|
+
- FeatureServer 或 `MapServer/N` → `FeatureLayer`
|
|
525
|
+
- 同 id 重复加载会先 `remove` 并 `destroy` 旧层
|
|
526
|
+
- 可选传入 `expectedSpatialReferenceWkid`(通常来自系统参数 `systemCoordinate`):
|
|
527
|
+
- `8848` 为业务哨兵,按 `CGCS2000_Albers` WKT 作为期望坐标系(与参考项目一致,不是 EPSG:8848)
|
|
528
|
+
- 其他值按 WKID 比较
|
|
529
|
+
- 比较规则:优先 `wkid/latestWkid`,否则规范化后比 `wkt`
|
|
530
|
+
- 结果分 `match` / `mismatch` / `unreadable`:仅 `mismatch` 登记图层管理红标;`unreadable` 只回调/打日志
|
|
531
|
+
- 默认 `console.warn`,**不拦截上图**
|
|
532
|
+
- 不一致记录会登记到组件内,图层管理面板会显示「坐标系不一致」标记,并在顶部汇总数量
|
|
533
|
+
- 注意:`systemCoordinate` 表示业务图层期望坐标系;坐标定位面板默认输入坐标系仍优先使用 `latitudeLongitude`(经纬度)
|
|
534
|
+
|
|
535
|
+
### 业务图层注记(地图上显示属性字段)
|
|
52
536
|
|
|
53
|
-
|
|
54
|
-
|
|
537
|
+
对齐 forestpests:前端配置指定图层的 `labelingInfo`(Arcade + 描边样式),**不依赖**后端 mapServiceSettings。
|
|
538
|
+
|
|
539
|
+
```ts
|
|
540
|
+
import { loadBusinessLayers, applyBusinessLayerLabels } from '@ywbgn/bgl-package'
|
|
541
|
+
import type { BusinessLayerLabelConfig } from '@ywbgn/bgl-package'
|
|
542
|
+
|
|
543
|
+
const labelConfigs: BusinessLayerLabelConfig[] = [
|
|
544
|
+
{
|
|
545
|
+
title: '森林病虫害防治(亩)',
|
|
546
|
+
fields: ['fzmj', 'lycsh'],
|
|
547
|
+
fieldTemplate: '({0} 亩)({1})',
|
|
548
|
+
style: {
|
|
549
|
+
color: [26, 127, 55, 1],
|
|
550
|
+
fontSize: 11,
|
|
551
|
+
fontWeight: 'bold',
|
|
552
|
+
haloColor: [255, 255, 255, 1],
|
|
553
|
+
haloSize: 1.5,
|
|
554
|
+
labelPlacement: 'center-center'
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
// 也可按业务配置 id 匹配(自动加 bgl-biz- 前缀)
|
|
559
|
+
layerId: 12,
|
|
560
|
+
expression: '"(" + Text($feature["whmj"]) + " 亩)(" + Text($feature["hclx"]) + ")"',
|
|
561
|
+
style: { color: [207, 46, 6, 1], fontSize: 11, fontWeight: 'bold' }
|
|
562
|
+
}
|
|
563
|
+
]
|
|
564
|
+
|
|
565
|
+
loadBusinessLayers({
|
|
566
|
+
map,
|
|
567
|
+
layers: configs,
|
|
568
|
+
reverse: true,
|
|
569
|
+
labelConfigs
|
|
570
|
+
})
|
|
571
|
+
|
|
572
|
+
// 或图层已在图上时单独调用
|
|
573
|
+
// applyBusinessLayerLabels(map, labelConfigs)
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
注意:仅 **FeatureLayer** 生效;与工具栏「地图标注」可并存(手动标注会覆盖该层 `labelingInfo`)。
|
|
577
|
+
|
|
578
|
+
### registerPortalToken / startPortalTokenRenewal
|
|
579
|
+
|
|
580
|
+
单次注册:
|
|
581
|
+
|
|
582
|
+
```ts
|
|
583
|
+
await registerPortalToken({
|
|
584
|
+
portalUrl: 'https://example.com',
|
|
585
|
+
username: '...',
|
|
586
|
+
password: '...',
|
|
587
|
+
expirationMinutes: 120,
|
|
588
|
+
extraServers: ['https://gis.example.com/server'],
|
|
589
|
+
// 开发环境可走本地代理,避免 generateToken 跨域
|
|
590
|
+
tokenServiceUrl: import.meta.env.DEV
|
|
591
|
+
? '/gis-portal/portal/sharing/rest/generateToken'
|
|
592
|
+
: undefined
|
|
593
|
+
})
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
长会话建议用自动续期(默认在过期前约 1/6 有效期刷新;页面卸载时 `stop()`):
|
|
597
|
+
|
|
598
|
+
```ts
|
|
599
|
+
const renewal = await startPortalTokenRenewal({
|
|
600
|
+
portalUrl: 'https://example.com',
|
|
601
|
+
username: '...',
|
|
602
|
+
password: '...',
|
|
603
|
+
expirationMinutes: 120,
|
|
604
|
+
extraServers: ['https://gis.example.com/server'],
|
|
605
|
+
tokenServiceUrl: import.meta.env.DEV
|
|
606
|
+
? '/gis-portal/portal/sharing/rest/generateToken'
|
|
607
|
+
: undefined,
|
|
608
|
+
// renewBeforeMinutes: 20,
|
|
609
|
+
onRenewError: (err) => console.error(err)
|
|
610
|
+
})
|
|
611
|
+
|
|
612
|
+
// 组件卸载时
|
|
613
|
+
renewal.stop()
|
|
614
|
+
```
|
|
55
615
|
|
|
56
|
-
|
|
616
|
+
注意:前端持有账号密码仅适合内网联调;生产应由后端签发 token。
|
|
617
|
+
|
|
618
|
+
### 密钥怎么传
|
|
619
|
+
|
|
620
|
+
推荐页面级 `provide` 一次:
|
|
57
621
|
|
|
58
622
|
```js
|
|
59
|
-
import {
|
|
623
|
+
import { provideBasemapKeys } from '@ywbgn/bgl-package'
|
|
624
|
+
|
|
625
|
+
const basemapKeys = {
|
|
626
|
+
tiandituKey: '',
|
|
627
|
+
geovisToken: '',
|
|
628
|
+
jl1mallMk: '',
|
|
629
|
+
jl1mallToken: ''
|
|
630
|
+
}
|
|
631
|
+
provideBasemapKeys(basemapKeys)
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
也可给组件传 `:keys`(优先于 inject)。
|
|
635
|
+
|
|
636
|
+
导出:`BasemapKeys`、`BASEMAP_KEYS_KEY`、`provideBasemapKeys`、`useBasemapKeys`、`BASEMAP_OPTIONS`、`ToolbarToolId`、`DEFAULT_TOOLBAR_TOOLS`、`LonLatExtent`、`PanConstraintHandle`、`applyPanBoundsConstraint`、`goToFullExtent`。
|
|
637
|
+
|
|
638
|
+
## 样式定制
|
|
639
|
+
|
|
640
|
+
在地图、底图、卷帘、工具栏的**共同父节点**上设置 CSS 变量(父节点需 `position: relative`)。
|
|
641
|
+
|
|
642
|
+
**位置**
|
|
643
|
+
|
|
644
|
+
| 变量 | 作用对象 | 默认 |
|
|
645
|
+
| --------------------------- | ---------------------- | -------------------- |
|
|
646
|
+
| `--bgl-basemap-left` | 底图入口 | `16px` |
|
|
647
|
+
| `--bgl-basemap-bottom` | 底图入口 | `160px` |
|
|
648
|
+
| `--bgl-basemap-z` | 底图入口 | `1100` |
|
|
649
|
+
| `--bgl-swipe-left` | 底图卷帘入口 | `16px` |
|
|
650
|
+
| `--bgl-swipe-bottom` | 底图卷帘入口 | `100px` |
|
|
651
|
+
| `--bgl-swipe-z` | 底图卷帘入口 | `1100` |
|
|
652
|
+
| `--bgl-toolbar-left` | 工具栏整体(含经纬度) | `50%` |
|
|
653
|
+
| `--bgl-toolbar-bottom` | 工具栏整体 | `14px` |
|
|
654
|
+
| `--bgl-toolbar-transform` | 工具栏整体 | `translateX(-50%)` |
|
|
655
|
+
| `--bgl-toolbar-z` | 工具栏整体 | `1000` |
|
|
656
|
+
| `--bgl-legend-width` | 图例宽度 | `150px` |
|
|
657
|
+
| `--bgl-legend-height` | 图例高度 | `240px` |
|
|
658
|
+
| `--bgl-legend-z` | 图例层级 | `1050` |
|
|
659
|
+
| `--bgl-scalebar-z` | 比例尺层级 | `100` |
|
|
660
|
+
|
|
661
|
+
**背景与强调色**
|
|
662
|
+
|
|
663
|
+
| 变量 | 默认 |
|
|
664
|
+
| -------------------- | ------------------------- |
|
|
665
|
+
| `--bgl-trigger-bg` | `rgba(62, 68, 85, 0.9)` |
|
|
666
|
+
| `--bgl-panel-bg` | `rgba(62, 68, 85, 0.9)` |
|
|
667
|
+
| `--bgl-toolbar-bg` | `rgba(62, 68, 85, 0.9)` |
|
|
668
|
+
| `--bgl-coord-bg` | `rgba(40, 48, 58, 0.7)` |
|
|
669
|
+
| `--bgl-accent` | `#01b595` |
|
|
670
|
+
|
|
671
|
+
穿透补充(升级时 class 可能变化,优先用变量):
|
|
672
|
+
|
|
673
|
+
| class | 说明 |
|
|
674
|
+
| -------------------------------------------------------------- | ------------ |
|
|
675
|
+
| `.basemap-switch-wrap` / `.basemap-switch-trigger` | 底图 |
|
|
676
|
+
| `.swipe-compare-wrap` / `.swipe-compare-trigger` | 底图卷帘 |
|
|
677
|
+
| `.toolbar-wrap` / `.coordinate-display` / `.toolbar-box` | 工具栏 |
|
|
678
|
+
| `.map-tool-panel` | 通用浮层面板 |
|
|
679
|
+
| `.map-legend` / `.map-legend__body` | 图例 |
|
|
680
|
+
| `.map-scale-bar` / `.map-scale-bar__body` | 比例尺 |
|
|
681
|
+
|
|
682
|
+
## TypeScript
|
|
683
|
+
|
|
684
|
+
发布包提供 `dist/index.d.ts`。常用类型:
|
|
685
|
+
|
|
686
|
+
```ts
|
|
687
|
+
import type {
|
|
688
|
+
MapReadyPayload,
|
|
689
|
+
BasemapKeys,
|
|
690
|
+
BusinessLayerConfig,
|
|
691
|
+
ToolbarToolId,
|
|
692
|
+
LonLatExtent,
|
|
693
|
+
PanConstraintHandle,
|
|
694
|
+
SpatialReferenceMismatchInfo,
|
|
695
|
+
CoordinateSystemConfig
|
|
696
|
+
} from '@ywbgn/bgl-package'
|
|
60
697
|
```
|
|
61
698
|
|
|
62
699
|
## 说明
|
|
63
700
|
|
|
64
|
-
- **MapView、Layer
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
- 若使用 UMD 产物,请注意 Rollup 对 `default` + 具名导出同时存在时的用法;推荐 ESM 方式引用。
|
|
701
|
+
- **MapView、Layer 等不要用 `ref()` 做深度响应式**,请用 `shallowRef`(或 `markRaw`)。
|
|
702
|
+
- 本包 peer 依赖 `@arcgis/core@~4.34.8`,使用时需遵守 Esri 许可条款。
|
|
703
|
+
- 推荐 ESM 引用;UMD 场景请自行处理 `default` 与具名导出差异。
|