@ywbgn/bgl-package 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/README.md +67 -0
- package/dist/vue-arcgis-map.css +1 -0
- package/dist/vue-arcgis-map.js +192 -0
- package/dist/vue-arcgis-map.umd.cjs +1 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @ywbgn/bgl-package
|
|
2
|
+
|
|
3
|
+
基于 Vue 3 与 `@arcgis/core` 的地图组件库:地图初始化、底图切换(含自定义矢量示例)、工具栏(缩放、复位、测距、测面、绘图、清绘)。
|
|
4
|
+
|
|
5
|
+
## 安装依赖
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ywbgn/bgl-package vue @arcgis/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 引入依赖与注册
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { createApp } from 'vue'
|
|
15
|
+
import App from './App.vue'
|
|
16
|
+
import VueArcgisMap from '@ywbgn/bgl-package'
|
|
17
|
+
import '@arcgis/core/assets/esri/themes/light/main.css'
|
|
18
|
+
|
|
19
|
+
const app = createApp(App)
|
|
20
|
+
app.use(VueArcgisMap)
|
|
21
|
+
app.mount('#app')
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 使用示例
|
|
25
|
+
|
|
26
|
+
```vue
|
|
27
|
+
<template>
|
|
28
|
+
<div style="position: relative">
|
|
29
|
+
<ArcgisMap ref="mapRef" width="100%" height="600px" @ready="onReady" />
|
|
30
|
+
<template v-if="view && sketchLayer">
|
|
31
|
+
<BasemapSwitch :view="view" />
|
|
32
|
+
<MapToolbar :view="view" :sketch-layer="sketchLayer" />
|
|
33
|
+
</template>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script setup>
|
|
38
|
+
import { ref, shallowRef } from 'vue'
|
|
39
|
+
|
|
40
|
+
const mapRef = ref(null)
|
|
41
|
+
const view = shallowRef(null)
|
|
42
|
+
const sketchLayer = shallowRef(null)
|
|
43
|
+
|
|
44
|
+
const onReady = ({ view: v, sketchLayer: layer }) => {
|
|
45
|
+
view.value = v
|
|
46
|
+
sketchLayer.value = layer
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`ArcgisMap` 支持以下尺寸参数:
|
|
52
|
+
|
|
53
|
+
- `width`:默认 `100%`,支持 `String | Number`(`Number` 按 `px` 处理)
|
|
54
|
+
- `height`:默认 `70vh`,支持 `String | Number`(`Number` 按 `px` 处理)
|
|
55
|
+
|
|
56
|
+
### 按需引入(不全局注册)
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { ArcgisMap, BasemapSwitch, MapToolbar } from '@ywbgn/bgl-package'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 说明
|
|
63
|
+
|
|
64
|
+
- **MapView、Layer 等 ArcGIS 对象不要用 `ref()` 做深度响应式**,请用 `shallowRef`(或 `markRaw`),否则会出现 `__accessor__` 与 Vue Proxy 冲突。本库子组件内部已对 props 做了 `toRaw` 处理,但业务侧仍建议用 `shallowRef` 保存 `view`。
|
|
65
|
+
- 地图与测量能力依赖 Esri 服务与许可策略,部署与密钥请按官方文档配置。
|
|
66
|
+
- 本包依赖 `@arcgis/core`,使用时需遵守 Esri 官方许可条款。
|
|
67
|
+
- 若使用 UMD 产物,请注意 Rollup 对 `default` + 具名导出同时存在时的用法;推荐 ESM 方式引用。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.map-container[data-v-38c725b2]{position:relative}.basemap-box[data-v-98d50ba6]{position:absolute;top:15px;right:15px;background:#fff;padding:6px 10px;border-radius:6px;z-index:99;box-shadow:0 1px 4px #00000026}button[data-v-98d50ba6]{margin:0 4px;padding:4px 8px;cursor:pointer}.toolbar-box[data-v-37cacb1d]{position:absolute;top:70px;right:15px;background:#fff;padding:6px 10px;border-radius:6px;z-index:99;max-width:220px;box-shadow:0 1px 4px #00000026}button[data-v-37cacb1d]{margin:4px;padding:4px 8px;cursor:pointer}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { ref as C, shallowRef as d, computed as x, onMounted as S, onBeforeUnmount as k, openBlock as y, createElementBlock as f, normalizeStyle as $, createElementVNode as c, toRaw as w } from "vue";
|
|
2
|
+
import B from "@arcgis/core/Map.js";
|
|
3
|
+
import z from "@arcgis/core/views/MapView.js";
|
|
4
|
+
import L from "@arcgis/core/layers/GraphicsLayer.js";
|
|
5
|
+
import A from "@arcgis/core/Basemap.js";
|
|
6
|
+
import T from "@arcgis/core/layers/VectorTileLayer.js";
|
|
7
|
+
import V from "@arcgis/core/widgets/AreaMeasurement2D.js";
|
|
8
|
+
import D from "@arcgis/core/widgets/DistanceMeasurement2D.js";
|
|
9
|
+
import O from "@arcgis/core/widgets/Sketch.js";
|
|
10
|
+
const h = (a, p) => {
|
|
11
|
+
const n = a.__vccOpts || a;
|
|
12
|
+
for (const [i, r] of p)
|
|
13
|
+
n[i] = r;
|
|
14
|
+
return n;
|
|
15
|
+
}, I = {
|
|
16
|
+
__name: "ArcgisMap",
|
|
17
|
+
props: {
|
|
18
|
+
width: {
|
|
19
|
+
type: [String, Number],
|
|
20
|
+
default: "100%"
|
|
21
|
+
},
|
|
22
|
+
height: {
|
|
23
|
+
type: [String, Number],
|
|
24
|
+
default: "70vh"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
emits: ["ready"],
|
|
28
|
+
setup(a, { expose: p, emit: n }) {
|
|
29
|
+
const i = n, r = a, s = C(null), e = d(null), u = d(null), b = x(() => ({
|
|
30
|
+
width: typeof r.width == "number" ? `${r.width}px` : r.width,
|
|
31
|
+
height: typeof r.height == "number" ? `${r.height}px` : r.height
|
|
32
|
+
})), v = new L({ title: "绘制图层", listMode: "hide" });
|
|
33
|
+
return S(() => {
|
|
34
|
+
const l = new B({
|
|
35
|
+
basemap: "streets-vector",
|
|
36
|
+
layers: [v]
|
|
37
|
+
}), m = new z({
|
|
38
|
+
container: s.value,
|
|
39
|
+
map: l,
|
|
40
|
+
zoom: 12,
|
|
41
|
+
center: [116.3972, 39.9075]
|
|
42
|
+
});
|
|
43
|
+
e.value = l, u.value = m, m.when(() => {
|
|
44
|
+
i("ready", { map: l, view: m, sketchLayer: v });
|
|
45
|
+
});
|
|
46
|
+
}), k(() => {
|
|
47
|
+
var l;
|
|
48
|
+
(l = u.value) == null || l.destroy(), u.value = null, e.value = null;
|
|
49
|
+
}), p({ map: e, view: u, sketchLayer: v }), (l, m) => (y(), f("div", {
|
|
50
|
+
ref_key: "mapRef",
|
|
51
|
+
ref: s,
|
|
52
|
+
class: "map-container",
|
|
53
|
+
style: $(b.value)
|
|
54
|
+
}, null, 4));
|
|
55
|
+
}
|
|
56
|
+
}, R = /* @__PURE__ */ h(I, [["__scopeId", "data-v-38c725b2"]]), W = { class: "basemap-box" }, j = {
|
|
57
|
+
__name: "BasemapSwitch",
|
|
58
|
+
props: {
|
|
59
|
+
/** MapView 实例 */
|
|
60
|
+
view: { type: Object, required: !0 }
|
|
61
|
+
},
|
|
62
|
+
setup(a) {
|
|
63
|
+
const p = a, n = () => w(p.view), i = (s) => {
|
|
64
|
+
const e = n();
|
|
65
|
+
e != null && e.map && (e.map.basemap = s);
|
|
66
|
+
}, r = () => {
|
|
67
|
+
const s = n();
|
|
68
|
+
if (!(s != null && s.map)) return;
|
|
69
|
+
const e = new T({
|
|
70
|
+
url: "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer"
|
|
71
|
+
});
|
|
72
|
+
s.map.basemap = new A({
|
|
73
|
+
baseLayers: [e],
|
|
74
|
+
title: "自定义矢量",
|
|
75
|
+
id: "custom-vt"
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
return (s, e) => (y(), f("div", W, [
|
|
79
|
+
c("button", {
|
|
80
|
+
type: "button",
|
|
81
|
+
onClick: e[0] || (e[0] = (u) => i("streets-vector"))
|
|
82
|
+
}, "矢量"),
|
|
83
|
+
c("button", {
|
|
84
|
+
type: "button",
|
|
85
|
+
onClick: e[1] || (e[1] = (u) => i("satellite"))
|
|
86
|
+
}, "影像"),
|
|
87
|
+
c("button", {
|
|
88
|
+
type: "button",
|
|
89
|
+
onClick: e[2] || (e[2] = (u) => i("terrain"))
|
|
90
|
+
}, "地形"),
|
|
91
|
+
c("button", {
|
|
92
|
+
type: "button",
|
|
93
|
+
onClick: e[3] || (e[3] = (u) => i("topo-vector"))
|
|
94
|
+
}, "地形图"),
|
|
95
|
+
c("button", {
|
|
96
|
+
type: "button",
|
|
97
|
+
onClick: r
|
|
98
|
+
}, "自定义")
|
|
99
|
+
]));
|
|
100
|
+
}
|
|
101
|
+
}, q = /* @__PURE__ */ h(j, [["__scopeId", "data-v-98d50ba6"]]), N = { class: "toolbar-box" }, E = {
|
|
102
|
+
__name: "MapToolbar",
|
|
103
|
+
props: {
|
|
104
|
+
/** MapView 实例 */
|
|
105
|
+
view: { type: Object, required: !0 },
|
|
106
|
+
/** 绘图使用的 GraphicsLayer,由 ArcgisMap 注入 */
|
|
107
|
+
sketchLayer: { type: Object, required: !0 }
|
|
108
|
+
},
|
|
109
|
+
setup(a) {
|
|
110
|
+
const p = a, n = () => w(p.view), i = () => w(p.sketchLayer), r = d(null), s = d(null), e = () => {
|
|
111
|
+
const t = r.value, o = n();
|
|
112
|
+
t && o && (o.ui.remove(t), t.destroy()), r.value = null;
|
|
113
|
+
}, u = () => {
|
|
114
|
+
const t = n();
|
|
115
|
+
t && (t.zoom += 1);
|
|
116
|
+
}, b = () => {
|
|
117
|
+
const t = n();
|
|
118
|
+
t && (t.zoom -= 1);
|
|
119
|
+
}, v = () => {
|
|
120
|
+
const t = n();
|
|
121
|
+
t && t.goTo({ center: [116.3972, 39.9075], zoom: 12 });
|
|
122
|
+
}, l = () => {
|
|
123
|
+
const t = n();
|
|
124
|
+
if (!t) return;
|
|
125
|
+
e();
|
|
126
|
+
const o = new D({ view: t });
|
|
127
|
+
r.value = o, t.ui.add(o, "top-right"), o.viewModel.start();
|
|
128
|
+
}, m = () => {
|
|
129
|
+
const t = n();
|
|
130
|
+
if (!t) return;
|
|
131
|
+
e();
|
|
132
|
+
const o = new V({ view: t });
|
|
133
|
+
r.value = o, t.ui.add(o, "top-right"), o.viewModel.start();
|
|
134
|
+
}, g = () => {
|
|
135
|
+
const t = n(), o = i();
|
|
136
|
+
if (!(!t || !o) && (e(), !s.value)) {
|
|
137
|
+
const _ = new O({
|
|
138
|
+
view: t,
|
|
139
|
+
layer: o
|
|
140
|
+
});
|
|
141
|
+
s.value = _, t.ui.add(_, "bottom-right");
|
|
142
|
+
}
|
|
143
|
+
}, M = () => {
|
|
144
|
+
var t;
|
|
145
|
+
(t = i()) == null || t.removeAll();
|
|
146
|
+
};
|
|
147
|
+
return k(() => {
|
|
148
|
+
e();
|
|
149
|
+
const t = s.value, o = n();
|
|
150
|
+
t && o && (o.ui.remove(t), t.destroy()), s.value = null;
|
|
151
|
+
}), (t, o) => (y(), f("div", N, [
|
|
152
|
+
c("button", {
|
|
153
|
+
type: "button",
|
|
154
|
+
onClick: u
|
|
155
|
+
}, "放大"),
|
|
156
|
+
c("button", {
|
|
157
|
+
type: "button",
|
|
158
|
+
onClick: b
|
|
159
|
+
}, "缩小"),
|
|
160
|
+
c("button", {
|
|
161
|
+
type: "button",
|
|
162
|
+
onClick: v
|
|
163
|
+
}, "复位"),
|
|
164
|
+
c("button", {
|
|
165
|
+
type: "button",
|
|
166
|
+
onClick: l
|
|
167
|
+
}, "测距"),
|
|
168
|
+
c("button", {
|
|
169
|
+
type: "button",
|
|
170
|
+
onClick: m
|
|
171
|
+
}, "测面"),
|
|
172
|
+
c("button", {
|
|
173
|
+
type: "button",
|
|
174
|
+
onClick: g
|
|
175
|
+
}, "绘图"),
|
|
176
|
+
c("button", {
|
|
177
|
+
type: "button",
|
|
178
|
+
onClick: M
|
|
179
|
+
}, "清绘")
|
|
180
|
+
]));
|
|
181
|
+
}
|
|
182
|
+
}, G = /* @__PURE__ */ h(E, [["__scopeId", "data-v-37cacb1d"]]), Z = {
|
|
183
|
+
install(a) {
|
|
184
|
+
a.component("ArcgisMap", R), a.component("BasemapSwitch", q), a.component("MapToolbar", G);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
export {
|
|
188
|
+
R as ArcgisMap,
|
|
189
|
+
q as BasemapSwitch,
|
|
190
|
+
G as MapToolbar,
|
|
191
|
+
Z as default
|
|
192
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@arcgis/core/Map.js"),require("@arcgis/core/views/MapView.js"),require("@arcgis/core/layers/GraphicsLayer.js"),require("@arcgis/core/Basemap.js"),require("@arcgis/core/layers/VectorTileLayer.js"),require("@arcgis/core/widgets/AreaMeasurement2D.js"),require("@arcgis/core/widgets/DistanceMeasurement2D.js"),require("@arcgis/core/widgets/Sketch.js")):typeof define=="function"&&define.amd?define(["exports","vue","@arcgis/core/Map.js","@arcgis/core/views/MapView.js","@arcgis/core/layers/GraphicsLayer.js","@arcgis/core/Basemap.js","@arcgis/core/layers/VectorTileLayer.js","@arcgis/core/widgets/AreaMeasurement2D.js","@arcgis/core/widgets/DistanceMeasurement2D.js","@arcgis/core/widgets/Sketch.js"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.VueArcgisMap={},r.Vue,r.arcgis,r.arcgis,r.arcgis,r.arcgis,r.arcgis,r.arcgis,r.arcgis,r.arcgis))})(this,(function(r,e,v,k,M,j,V,B,E,S){"use strict";const y=(i,m)=>{const n=i.__vccOpts||i;for(const[l,c]of m)n[l]=c;return n},g=y({__name:"ArcgisMap",props:{width:{type:[String,Number],default:"100%"},height:{type:[String,Number],default:"70vh"}},emits:["ready"],setup(i,{expose:m,emit:n}){const l=n,c=i,a=e.ref(null),o=e.shallowRef(null),u=e.shallowRef(null),f=e.computed(()=>({width:typeof c.width=="number"?`${c.width}px`:c.width,height:typeof c.height=="number"?`${c.height}px`:c.height})),w=new M({title:"绘制图层",listMode:"hide"});return e.onMounted(()=>{const p=new v({basemap:"streets-vector",layers:[w]}),d=new k({container:a.value,map:p,zoom:12,center:[116.3972,39.9075]});o.value=p,u.value=d,d.when(()=>{l("ready",{map:p,view:d,sketchLayer:w})})}),e.onBeforeUnmount(()=>{var p;(p=u.value)==null||p.destroy(),u.value=null,o.value=null}),m({map:o,view:u,sketchLayer:w}),(p,d)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"mapRef",ref:a,class:"map-container",style:e.normalizeStyle(f.value)},null,4))}},[["__scopeId","data-v-38c725b2"]]),N={class:"basemap-box"},b=y({__name:"BasemapSwitch",props:{view:{type:Object,required:!0}},setup(i){const m=i,n=()=>e.toRaw(m.view),l=a=>{const o=n();o!=null&&o.map&&(o.map.basemap=a)},c=()=>{const a=n();if(!(a!=null&&a.map))return;const o=new V({url:"https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer"});a.map.basemap=new j({baseLayers:[o],title:"自定义矢量",id:"custom-vt"})};return(a,o)=>(e.openBlock(),e.createElementBlock("div",N,[e.createElementVNode("button",{type:"button",onClick:o[0]||(o[0]=u=>l("streets-vector"))},"矢量"),e.createElementVNode("button",{type:"button",onClick:o[1]||(o[1]=u=>l("satellite"))},"影像"),e.createElementVNode("button",{type:"button",onClick:o[2]||(o[2]=u=>l("terrain"))},"地形"),e.createElementVNode("button",{type:"button",onClick:o[3]||(o[3]=u=>l("topo-vector"))},"地形图"),e.createElementVNode("button",{type:"button",onClick:c},"自定义")]))}},[["__scopeId","data-v-98d50ba6"]]),C={class:"toolbar-box"},h=y({__name:"MapToolbar",props:{view:{type:Object,required:!0},sketchLayer:{type:Object,required:!0}},setup(i){const m=i,n=()=>e.toRaw(m.view),l=()=>e.toRaw(m.sketchLayer),c=e.shallowRef(null),a=e.shallowRef(null),o=()=>{const t=c.value,s=n();t&&s&&(s.ui.remove(t),t.destroy()),c.value=null},u=()=>{const t=n();t&&(t.zoom+=1)},f=()=>{const t=n();t&&(t.zoom-=1)},w=()=>{const t=n();t&&t.goTo({center:[116.3972,39.9075],zoom:12})},p=()=>{const t=n();if(!t)return;o();const s=new E({view:t});c.value=s,t.ui.add(s,"top-right"),s.viewModel.start()},d=()=>{const t=n();if(!t)return;o();const s=new B({view:t});c.value=s,t.ui.add(s,"top-right"),s.viewModel.start()},T=()=>{const t=n(),s=l();if(!(!t||!s)&&(o(),!a.value)){const _=new S({view:t,layer:s});a.value=_,t.ui.add(_,"bottom-right")}},$=()=>{var t;(t=l())==null||t.removeAll()};return e.onBeforeUnmount(()=>{o();const t=a.value,s=n();t&&s&&(s.ui.remove(t),t.destroy()),a.value=null}),(t,s)=>(e.openBlock(),e.createElementBlock("div",C,[e.createElementVNode("button",{type:"button",onClick:u},"放大"),e.createElementVNode("button",{type:"button",onClick:f},"缩小"),e.createElementVNode("button",{type:"button",onClick:w},"复位"),e.createElementVNode("button",{type:"button",onClick:p},"测距"),e.createElementVNode("button",{type:"button",onClick:d},"测面"),e.createElementVNode("button",{type:"button",onClick:T},"绘图"),e.createElementVNode("button",{type:"button",onClick:$},"清绘")]))}},[["__scopeId","data-v-37cacb1d"]]),q={install(i){i.component("ArcgisMap",g),i.component("BasemapSwitch",b),i.component("MapToolbar",h)}};r.ArcgisMap=g,r.BasemapSwitch=b,r.MapToolbar=h,r.default=q,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ywbgn/bgl-package",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/vue-arcgis-map.umd.cjs",
|
|
7
|
+
"module": "dist/vue-arcgis-map.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/vue-arcgis-map.js",
|
|
11
|
+
"require": "./dist/vue-arcgis-map.umd.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"build": "vite build"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@arcgis/core": "4.34.8",
|
|
21
|
+
"vue": "^3.5.13"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@arcgis/core": "4.34.8",
|
|
25
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
26
|
+
"vite": "^6.0.1",
|
|
27
|
+
"vue": "^3.5.13"
|
|
28
|
+
}
|
|
29
|
+
}
|