@summeruse/ol 0.2.0 → 0.3.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/CHANGELOG.md +12 -0
- package/dist/index.js +453 -457
- package/es/composables/usePointermove/index.d.ts +6 -3
- package/es/composables/usePointermove/index.mjs +54 -58
- package/lib/composables/usePointermove/index.d.ts +6 -3
- package/lib/composables/usePointermove/index.js +1 -1
- package/package.json +1 -1
|
@@ -40,23 +40,26 @@ export interface UsePointermoveOptions<T extends Option = Option> {
|
|
|
40
40
|
mapRef: MaybeRefOrGetter<OLMap | undefined>;
|
|
41
41
|
/** 提示配置列表 */
|
|
42
42
|
items: MaybeRefOrGetter<PointermoveList<T>>;
|
|
43
|
-
/** 前置判断条件 */
|
|
44
|
-
enabled?: boolean | (() => boolean | undefined | void);
|
|
45
43
|
/** 强制更新 (开启后,无论 feature 是否变化,都强制更新提示) */
|
|
46
44
|
forceUpdate?: boolean;
|
|
47
45
|
}
|
|
48
|
-
export declare function usePointermove<T extends Option>({ mapRef, items,
|
|
46
|
+
export declare function usePointermove<T extends Option>({ mapRef, items, forceUpdate }: UsePointermoveOptions<T>): {
|
|
49
47
|
visible: import('vue').ComputedRef<boolean>;
|
|
50
48
|
position: import('vue').ComputedRef<{
|
|
51
49
|
x: number;
|
|
52
50
|
y: number;
|
|
53
51
|
}>;
|
|
52
|
+
offset: import('vue').ComputedRef<{
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
}>;
|
|
54
56
|
originalPosition: import('vue').ComputedRef<{
|
|
55
57
|
x: number;
|
|
56
58
|
y: number;
|
|
57
59
|
}>;
|
|
58
60
|
feature: import('vue').ComputedRef<FeatureLike | undefined>;
|
|
59
61
|
content: import('vue').ComputedRef<string | (() => VNodeChild) | undefined>;
|
|
62
|
+
originalCoordinate: import('vue').ComputedRef<Coordinate | undefined>;
|
|
60
63
|
coordinate: import('vue').ComputedRef<Coordinate | undefined>;
|
|
61
64
|
option: import('vue').ComputedRef<T | undefined>;
|
|
62
65
|
hide: () => void;
|
|
@@ -1,95 +1,91 @@
|
|
|
1
1
|
import { computed, onBeforeUnmount, ref, toValue, watch } from "vue";
|
|
2
2
|
import { getCenter } from "ol/extent";
|
|
3
|
-
function usePointermove({ mapRef: o, items: s,
|
|
4
|
-
let
|
|
3
|
+
function usePointermove({ mapRef: o, items: s, forceUpdate: c = !1 }) {
|
|
4
|
+
let l = ref(!1), u = ref({
|
|
5
5
|
x: 0,
|
|
6
6
|
y: 0
|
|
7
|
-
}),
|
|
7
|
+
}), d = ref(), f = ref(), p = ref({
|
|
8
8
|
x: 0,
|
|
9
9
|
y: 0
|
|
10
|
-
}), h = ref(), g = ref(), _ = computed(() => ({
|
|
11
|
-
x:
|
|
12
|
-
y:
|
|
13
|
-
})), v
|
|
14
|
-
function
|
|
10
|
+
}), m = ref(), h = ref(), g = ref(), _ = computed(() => ({
|
|
11
|
+
x: u.value.x + p.value.x,
|
|
12
|
+
y: u.value.y + p.value.y
|
|
13
|
+
})), v, y, b = "";
|
|
14
|
+
function x(e) {
|
|
15
15
|
let t = toValue(s);
|
|
16
16
|
return t.sort((e, t) => (t.priority ?? 0) - (e.priority ?? 0)), t.find((t) => {
|
|
17
17
|
let n = t.visible;
|
|
18
18
|
return typeof n == "function" ? n(e) : n ?? !0;
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
if (!v
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
h.value = t;
|
|
29
|
-
let n = y.getEventPixel(e), r, i;
|
|
30
|
-
if (y.forEachFeatureAtPixel(n, (e, t) => (r = e, i = t, !0)), !r) {
|
|
31
|
-
w();
|
|
21
|
+
function S(e) {
|
|
22
|
+
if (e.dragging || !v || !y) return;
|
|
23
|
+
let t = e.coordinate;
|
|
24
|
+
m.value = t, h.value = t;
|
|
25
|
+
let n = e.pixel, r, i;
|
|
26
|
+
if (v.forEachFeatureAtPixel(n, (e, t) => (r = e, i = t, !0)), !r) {
|
|
27
|
+
C();
|
|
32
28
|
return;
|
|
33
29
|
}
|
|
34
|
-
if (!
|
|
35
|
-
|
|
36
|
-
let o = {
|
|
37
|
-
map:
|
|
30
|
+
if (!c && d.value && d.value.getId() === r.getId()) return;
|
|
31
|
+
d.value = r;
|
|
32
|
+
let { top: o, left: s } = y.getBoundingClientRect(), _ = {
|
|
33
|
+
map: v,
|
|
38
34
|
position: {
|
|
39
|
-
x:
|
|
40
|
-
y:
|
|
35
|
+
x: n[0] + s,
|
|
36
|
+
y: n[1] + o
|
|
41
37
|
},
|
|
42
38
|
coordinate: t,
|
|
43
39
|
feature: r,
|
|
44
40
|
layer: i
|
|
45
|
-
},
|
|
46
|
-
if (
|
|
47
|
-
let { content: e, cursor: t, visible: n, fixedFeatureCenter: r, offset: i, priority: a,...o } =
|
|
41
|
+
}, b = x(_);
|
|
42
|
+
if (b) {
|
|
43
|
+
let { content: e, cursor: t, visible: n, fixedFeatureCenter: r, offset: i, priority: a,...o } = b;
|
|
48
44
|
g.value = { ...o };
|
|
49
45
|
}
|
|
50
|
-
if (!
|
|
51
|
-
|
|
46
|
+
if (!b) {
|
|
47
|
+
C();
|
|
52
48
|
return;
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
x:
|
|
56
|
-
y:
|
|
50
|
+
p.value = {
|
|
51
|
+
x: b.offset?.x ?? 0,
|
|
52
|
+
y: b.offset?.y ?? 0
|
|
57
53
|
};
|
|
58
|
-
let
|
|
59
|
-
if (
|
|
60
|
-
let e = getCenter(
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
let C = s.cursor, T = typeof C == "function" ? C(o) : C;
|
|
69
|
-
T !== void 0 && T !== b.style.cursor && (b.style.cursor = T), u.value = !0;
|
|
54
|
+
let S = c === !1 ? !0 : b.fixedFeatureCenter ?? !0, w = r.getGeometry();
|
|
55
|
+
if (S && w) {
|
|
56
|
+
let e = getCenter(w.getExtent());
|
|
57
|
+
h.value = e, n = v.getPixelFromCoordinate(e);
|
|
58
|
+
}
|
|
59
|
+
u.value.x = n[0] + s, u.value.y = n[1] + o;
|
|
60
|
+
let T = b.content;
|
|
61
|
+
f.value = typeof T == "function" ? () => T(_) : T;
|
|
62
|
+
let E = b.cursor, D = typeof E == "function" ? E(_) : E;
|
|
63
|
+
D !== void 0 && D !== y.style.cursor && (y.style.cursor = D), l.value = !0;
|
|
70
64
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
65
|
+
function C() {
|
|
66
|
+
l.value = !1, d.value = void 0, y && y.style.cursor !== b && (y.style.cursor = b);
|
|
73
67
|
}
|
|
74
|
-
function
|
|
75
|
-
e.
|
|
68
|
+
function w(e) {
|
|
69
|
+
e.on("pointermove", S);
|
|
76
70
|
}
|
|
77
|
-
function
|
|
78
|
-
e.
|
|
71
|
+
function T(e) {
|
|
72
|
+
e.un("pointermove", S);
|
|
79
73
|
}
|
|
80
74
|
return watch(() => toValue(o), (e, t) => {
|
|
81
|
-
t !== e && (
|
|
75
|
+
t && T(t), t !== e && (v = e, e && (y = e.getViewport(), w(e), b = y.style.cursor));
|
|
82
76
|
}, { immediate: !0 }), onBeforeUnmount(() => {
|
|
83
|
-
|
|
77
|
+
v && T(v);
|
|
84
78
|
}), {
|
|
85
|
-
visible: computed(() =>
|
|
79
|
+
visible: computed(() => l.value),
|
|
86
80
|
position: computed(() => _.value),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
81
|
+
offset: computed(() => p.value),
|
|
82
|
+
originalPosition: computed(() => u.value),
|
|
83
|
+
feature: computed(() => d.value),
|
|
84
|
+
content: computed(() => f.value),
|
|
85
|
+
originalCoordinate: computed(() => m.value),
|
|
90
86
|
coordinate: computed(() => h.value),
|
|
91
87
|
option: computed(() => g.value),
|
|
92
|
-
hide:
|
|
88
|
+
hide: C
|
|
93
89
|
};
|
|
94
90
|
}
|
|
95
91
|
export { usePointermove };
|
|
@@ -40,23 +40,26 @@ export interface UsePointermoveOptions<T extends Option = Option> {
|
|
|
40
40
|
mapRef: MaybeRefOrGetter<OLMap | undefined>;
|
|
41
41
|
/** 提示配置列表 */
|
|
42
42
|
items: MaybeRefOrGetter<PointermoveList<T>>;
|
|
43
|
-
/** 前置判断条件 */
|
|
44
|
-
enabled?: boolean | (() => boolean | undefined | void);
|
|
45
43
|
/** 强制更新 (开启后,无论 feature 是否变化,都强制更新提示) */
|
|
46
44
|
forceUpdate?: boolean;
|
|
47
45
|
}
|
|
48
|
-
export declare function usePointermove<T extends Option>({ mapRef, items,
|
|
46
|
+
export declare function usePointermove<T extends Option>({ mapRef, items, forceUpdate }: UsePointermoveOptions<T>): {
|
|
49
47
|
visible: import('vue').ComputedRef<boolean>;
|
|
50
48
|
position: import('vue').ComputedRef<{
|
|
51
49
|
x: number;
|
|
52
50
|
y: number;
|
|
53
51
|
}>;
|
|
52
|
+
offset: import('vue').ComputedRef<{
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
}>;
|
|
54
56
|
originalPosition: import('vue').ComputedRef<{
|
|
55
57
|
x: number;
|
|
56
58
|
y: number;
|
|
57
59
|
}>;
|
|
58
60
|
feature: import('vue').ComputedRef<FeatureLike | undefined>;
|
|
59
61
|
content: import('vue').ComputedRef<string | (() => VNodeChild) | undefined>;
|
|
62
|
+
originalCoordinate: import('vue').ComputedRef<Coordinate | undefined>;
|
|
60
63
|
coordinate: import('vue').ComputedRef<Coordinate | undefined>;
|
|
61
64
|
option: import('vue').ComputedRef<T | undefined>;
|
|
62
65
|
hide: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../_virtual/rolldown_runtime.js`);let t=require(`vue`);t=e.__toESM(t);let n=require(`ol/extent`);n=e.__toESM(n);function r({mapRef:e,items:r,
|
|
1
|
+
const e=require(`../../_virtual/rolldown_runtime.js`);let t=require(`vue`);t=e.__toESM(t);let n=require(`ol/extent`);n=e.__toESM(n);function r({mapRef:e,items:r,forceUpdate:i=!1}){let a=(0,t.ref)(!1),o=(0,t.ref)({x:0,y:0}),s=(0,t.ref)(),c=(0,t.ref)(),l=(0,t.ref)({x:0,y:0}),u=(0,t.ref)(),d=(0,t.ref)(),f=(0,t.ref)(),p=(0,t.computed)(()=>({x:o.value.x+l.value.x,y:o.value.y+l.value.y})),m,h,g=``;function _(e){let n=(0,t.toValue)(r);return n.sort((e,t)=>(t.priority??0)-(e.priority??0)),n.find(t=>{let n=t.visible;return typeof n==`function`?n(e):n??!0})}function v(e){if(e.dragging||!m||!h)return;let t=e.coordinate;u.value=t,d.value=t;let r=e.pixel,p,g;if(m.forEachFeatureAtPixel(r,(e,t)=>(p=e,g=t,!0)),!p){y();return}if(!i&&s.value&&s.value.getId()===p.getId())return;s.value=p;let{top:v,left:b}=h.getBoundingClientRect(),x={map:m,position:{x:r[0]+b,y:r[1]+v},coordinate:t,feature:p,layer:g},S=_(x);if(S){let{content:e,cursor:t,visible:n,fixedFeatureCenter:r,offset:i,priority:a,...o}=S;f.value={...o}}if(!S){y();return}l.value={x:S.offset?.x??0,y:S.offset?.y??0};let C=i===!1?!0:S.fixedFeatureCenter??!0,w=p.getGeometry();if(C&&w){let e=(0,n.getCenter)(w.getExtent());d.value=e,r=m.getPixelFromCoordinate(e)}o.value.x=r[0]+b,o.value.y=r[1]+v;let T=S.content;c.value=typeof T==`function`?()=>T(x):T;let E=S.cursor,D=typeof E==`function`?E(x):E;D!==void 0&&D!==h.style.cursor&&(h.style.cursor=D),a.value=!0}function y(){a.value=!1,s.value=void 0,h&&h.style.cursor!==g&&(h.style.cursor=g)}function b(e){e.on(`pointermove`,v)}function x(e){e.un(`pointermove`,v)}return(0,t.watch)(()=>(0,t.toValue)(e),(e,t)=>{t&&x(t),t!==e&&(m=e,e&&(h=e.getViewport(),b(e),g=h.style.cursor))},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{m&&x(m)}),{visible:(0,t.computed)(()=>a.value),position:(0,t.computed)(()=>p.value),offset:(0,t.computed)(()=>l.value),originalPosition:(0,t.computed)(()=>o.value),feature:(0,t.computed)(()=>s.value),content:(0,t.computed)(()=>c.value),originalCoordinate:(0,t.computed)(()=>u.value),coordinate:(0,t.computed)(()=>d.value),option:(0,t.computed)(()=>f.value),hide:y}}exports.usePointermove=r;
|