@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.
@@ -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, enabled, forceUpdate }: UsePointermoveOptions<T>): {
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, enabled: c = !0, forceUpdate: l = !1 }) {
4
- let u = ref(!1), d = ref({
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
- }), f = ref(), p = ref(), m = ref({
7
+ }), d = ref(), f = ref(), p = ref({
8
8
  x: 0,
9
9
  y: 0
10
- }), h = ref(), g = ref(), _ = computed(() => ({
11
- x: d.value.x + m.value.x,
12
- y: d.value.y + m.value.y
13
- })), v = () => typeof c == "function" ? c() : c, y, b, x = "";
14
- function S(e) {
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 C(e) {
22
- if (!v()) {
23
- w();
24
- return;
25
- }
26
- if (!y || !b) return;
27
- let t = y.getEventCoordinate(e);
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 (!l && f.value && f.value.getId() === r.getId()) return;
35
- f.value = r;
36
- let o = {
37
- map: y,
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: e.clientX,
40
- y: e.clientY
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
- }, s = S(o);
46
- if (s) {
47
- let { content: e, cursor: t, visible: n, fixedFeatureCenter: r, offset: i, priority: a,...o } = s;
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 (!s) {
51
- w();
46
+ if (!b) {
47
+ C();
52
48
  return;
53
49
  }
54
- m.value = {
55
- x: s.offset?.x ?? 0,
56
- y: s.offset?.y ?? 0
50
+ p.value = {
51
+ x: b.offset?.x ?? 0,
52
+ y: b.offset?.y ?? 0
57
53
  };
58
- let c = l === !1 ? !0 : s.fixedFeatureCenter ?? !0, _ = r.getGeometry();
59
- if (c && _) {
60
- let e = getCenter(_.getExtent()), t = y.getPixelFromCoordinate(e), { top: n, left: r } = b.getBoundingClientRect();
61
- d.value.x = t[0] + r, d.value.y = t[1] + n;
62
- } else d.value = {
63
- x: e.clientX,
64
- y: e.clientY
65
- };
66
- let x = s.content;
67
- p.value = typeof x == "function" ? () => x(o) : x;
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 w() {
72
- u.value = !1, f.value = void 0, b && b.style.cursor !== x && (b.style.cursor = x);
65
+ function C() {
66
+ l.value = !1, d.value = void 0, y && y.style.cursor !== b && (y.style.cursor = b);
73
67
  }
74
- function T(e) {
75
- e.addEventListener("pointermove", C);
68
+ function w(e) {
69
+ e.on("pointermove", S);
76
70
  }
77
- function E(e) {
78
- e.removeEventListener("pointermove", C);
71
+ function T(e) {
72
+ e.un("pointermove", S);
79
73
  }
80
74
  return watch(() => toValue(o), (e, t) => {
81
- t !== e && (y = e, e && (b = e.getViewport(), E(b), T(b), x = b.style.cursor));
75
+ t && T(t), t !== e && (v = e, e && (y = e.getViewport(), w(e), b = y.style.cursor));
82
76
  }, { immediate: !0 }), onBeforeUnmount(() => {
83
- b && E(b);
77
+ v && T(v);
84
78
  }), {
85
- visible: computed(() => u.value),
79
+ visible: computed(() => l.value),
86
80
  position: computed(() => _.value),
87
- originalPosition: computed(() => d.value),
88
- feature: computed(() => f.value),
89
- content: computed(() => p.value),
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: w
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, enabled, forceUpdate }: UsePointermoveOptions<T>): {
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,enabled:i=!0,forceUpdate:a=!1}){let o=(0,t.ref)(!1),s=(0,t.ref)({x:0,y:0}),c=(0,t.ref)(),l=(0,t.ref)(),u=(0,t.ref)({x:0,y:0}),d=(0,t.ref)(),f=(0,t.ref)(),p=(0,t.computed)(()=>({x:s.value.x+u.value.x,y:s.value.y+u.value.y})),m=()=>typeof i==`function`?i():i,h,g,_=``;function v(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 y(e){if(!m()){b();return}if(!h||!g)return;let t=h.getEventCoordinate(e);d.value=t;let r=h.getEventPixel(e),i,p;if(h.forEachFeatureAtPixel(r,(e,t)=>(i=e,p=t,!0)),!i){b();return}if(!a&&c.value&&c.value.getId()===i.getId())return;c.value=i;let _={map:h,position:{x:e.clientX,y:e.clientY},coordinate:t,feature:i,layer:p},y=v(_);if(y){let{content:e,cursor:t,visible:n,fixedFeatureCenter:r,offset:i,priority:a,...o}=y;f.value={...o}}if(!y){b();return}u.value={x:y.offset?.x??0,y:y.offset?.y??0};let x=a===!1?!0:y.fixedFeatureCenter??!0,S=i.getGeometry();if(x&&S){let e=(0,n.getCenter)(S.getExtent()),t=h.getPixelFromCoordinate(e),{top:r,left:i}=g.getBoundingClientRect();s.value.x=t[0]+i,s.value.y=t[1]+r}else s.value={x:e.clientX,y:e.clientY};let C=y.content;l.value=typeof C==`function`?()=>C(_):C;let w=y.cursor,T=typeof w==`function`?w(_):w;T!==void 0&&T!==g.style.cursor&&(g.style.cursor=T),o.value=!0}function b(){o.value=!1,c.value=void 0,g&&g.style.cursor!==_&&(g.style.cursor=_)}function x(e){e.addEventListener(`pointermove`,y)}function S(e){e.removeEventListener(`pointermove`,y)}return(0,t.watch)(()=>(0,t.toValue)(e),(e,t)=>{t!==e&&(h=e,e&&(g=e.getViewport(),S(g),x(g),_=g.style.cursor))},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{g&&S(g)}),{visible:(0,t.computed)(()=>o.value),position:(0,t.computed)(()=>p.value),originalPosition:(0,t.computed)(()=>s.value),feature:(0,t.computed)(()=>c.value),content:(0,t.computed)(()=>l.value),coordinate:(0,t.computed)(()=>d.value),option:(0,t.computed)(()=>f.value),hide:b}}exports.usePointermove=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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@summeruse/ol",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.3.1",
5
5
  "description": "",
6
6
  "author": "finalsummer",
7
7
  "license": "ISC",