@summeruse/ol 0.2.0-alpha.3 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @summeruse/ol
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 95fc65d: refactor(usePointermove): 重构指针移动事件处理逻辑
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - c2ad696: 将 n-ol-pointermove 组件重构为 usePointermove 组合式函数
14
+ - 6fbc681: 重构右键菜单功能为组合式 API
15
+ - f605ee4: 移除对 naive-ui 的依赖并调整相关配置
16
+
17
+ ### Patch Changes
18
+
19
+ - fd8d77c: 修复 createFeature 中样式不生效
20
+ - 9275a0b: refactor(utils): 移除计算和格式化工具模块
21
+ - 66a195e: refactor(utils/layer): 移除 T_MAP_TYPE 的外部依赖并内联定义
22
+ - 93d2746: refactor(usePointermove): 重构指针移动逻辑并添加新配置选项
23
+ - 3317ecf: feat(utils): 添加角度和旋转格式化函数
24
+ - c466dde: build(ol): 清理 package.json 中未使用的依赖项
25
+ - 03fc086: feat(ol-map): 添加地图事件监听和 emit 功能
26
+ - ba32d77: refactor(utils/layer): 重构地图图层工具函数,优化类型定义和参数结构
27
+
3
28
  ## 0.2.0-alpha.3
4
29
 
5
30
  ### Patch Changes
package/dist/index.js CHANGED
@@ -619,96 +619,90 @@ function useGraticule(a) {
619
619
  deep: !0
620
620
  }), { showGraticule: u };
621
621
  }
622
- function usePointermove({ mapRef: u, items: d, enabled: f = !0, forceUpdate: m = !1 }) {
623
- let h = ref(!1), g = ref({
622
+ function usePointermove({ mapRef: u, items: d, forceUpdate: f = !1 }) {
623
+ let m = ref(!1), h = ref({
624
624
  x: 0,
625
625
  y: 0
626
- }), _ = ref(), y = ref(), b = ref({
626
+ }), g = ref(), _ = ref(), y = ref({
627
627
  x: 0,
628
628
  y: 0
629
- }), S = ref(), w = ref(), T = computed(() => ({
630
- x: g.value.x + b.value.x,
631
- y: g.value.y + b.value.y
632
- })), E = () => typeof f == "function" ? f() : f, D, O, k = "";
633
- function A(a) {
629
+ }), b = ref(), S = ref(), w = computed(() => ({
630
+ x: h.value.x + y.value.x,
631
+ y: h.value.y + y.value.y
632
+ })), T, E, D = "";
633
+ function O(a) {
634
634
  let u = toValue(d);
635
635
  return u.sort((a, u) => (u.priority ?? 0) - (a.priority ?? 0)), u.find((u) => {
636
636
  let d = u.visible;
637
637
  return typeof d == "function" ? d(a) : d ?? !0;
638
638
  });
639
639
  }
640
- function j(a) {
641
- if (!E()) {
642
- M();
643
- return;
644
- }
645
- if (!D || !O) return;
646
- let u = D.getEventCoordinate(a);
647
- S.value = u;
648
- let d = D.getEventPixel(a), f, p;
649
- if (D.forEachFeatureAtPixel(d, (a, u) => (f = a, p = u, !0)), !f) {
650
- M();
640
+ function k(a) {
641
+ if (a.dragging || !T || !E) return;
642
+ let u = a.coordinate;
643
+ b.value = u;
644
+ let d = a.pixel, p, v;
645
+ if (T.forEachFeatureAtPixel(d, (a, u) => (p = a, v = u, !0)), !p) {
646
+ A();
651
647
  return;
652
648
  }
653
- if (!m && _.value && _.value.getId() === f.getId()) return;
654
- _.value = f;
655
- let v = {
656
- map: D,
649
+ if (!f && g.value && g.value.getId() === p.getId()) return;
650
+ g.value = p;
651
+ let { top: x, left: C } = E.getBoundingClientRect(), w = {
652
+ map: T,
657
653
  position: {
658
- x: a.clientX,
659
- y: a.clientY
654
+ x: d[0] + C,
655
+ y: d[1] + x
660
656
  },
661
657
  coordinate: u,
662
- feature: f,
663
- layer: p
664
- }, x = A(v);
665
- if (x) {
666
- let { content: a, cursor: u, visible: d, fixedFeatureCenter: f, offset: p, priority: m,...h } = x;
667
- w.value = { ...h };
658
+ feature: p,
659
+ layer: v
660
+ }, D = O(w);
661
+ if (D) {
662
+ let { content: a, cursor: u, visible: d, fixedFeatureCenter: f, offset: p, priority: m,...h } = D;
663
+ S.value = { ...h };
668
664
  }
669
- if (!x) {
670
- M();
665
+ if (!D) {
666
+ A();
671
667
  return;
672
668
  }
673
- b.value = {
674
- x: x.offset?.x ?? 0,
675
- y: x.offset?.y ?? 0
669
+ y.value = {
670
+ x: D.offset?.x ?? 0,
671
+ y: D.offset?.y ?? 0
676
672
  };
677
- let C = m === !1 ? !0 : x.fixedFeatureCenter ?? !0, T = f.getGeometry();
678
- if (C && T) {
679
- let a = getCenter(T.getExtent()), u = D.getPixelFromCoordinate(a), { top: d, left: f } = O.getBoundingClientRect();
680
- g.value.x = u[0] + f, g.value.y = u[1] + d;
681
- } else g.value = {
682
- x: a.clientX,
683
- y: a.clientY
684
- };
685
- let k = x.content;
686
- y.value = typeof k == "function" ? () => k(v) : k;
687
- let j = x.cursor, N = typeof j == "function" ? j(v) : j;
688
- N !== void 0 && N !== O.style.cursor && (O.style.cursor = N), h.value = !0;
673
+ let k = f === !1 ? !0 : D.fixedFeatureCenter ?? !0, j = p.getGeometry();
674
+ if (k && j) {
675
+ let a = getCenter(j.getExtent());
676
+ d = T.getPixelFromCoordinate(a);
677
+ }
678
+ h.value.x = d[0] + C, h.value.y = d[1] + x;
679
+ let M = D.content;
680
+ _.value = typeof M == "function" ? () => M(w) : M;
681
+ let N = D.cursor, P = typeof N == "function" ? N(w) : N;
682
+ P !== void 0 && P !== E.style.cursor && (E.style.cursor = P), m.value = !0;
689
683
  }
690
- function M() {
691
- h.value = !1, _.value = void 0, O && O.style.cursor !== k && (O.style.cursor = k);
684
+ function A() {
685
+ m.value = !1, g.value = void 0, E && E.style.cursor !== D && (E.style.cursor = D);
692
686
  }
693
- function N(a) {
694
- a.addEventListener("pointermove", j);
687
+ function j(a) {
688
+ a.on("pointermove", k);
695
689
  }
696
- function P(a) {
697
- a.removeEventListener("pointermove", j);
690
+ function M(a) {
691
+ a.un("pointermove", k);
698
692
  }
699
693
  return watch(() => toValue(u), (a, u) => {
700
- u !== a && (D = a, a && (O = a.getViewport(), P(O), N(O), k = O.style.cursor));
694
+ u && M(u), u !== a && (T = a, a && (E = a.getViewport(), j(a), D = E.style.cursor));
701
695
  }, { immediate: !0 }), onBeforeUnmount(() => {
702
- O && P(O);
696
+ T && M(T);
703
697
  }), {
704
- visible: computed(() => h.value),
705
- position: computed(() => T.value),
706
- originalPosition: computed(() => g.value),
707
- feature: computed(() => _.value),
708
- content: computed(() => y.value),
709
- coordinate: computed(() => S.value),
710
- option: computed(() => w.value),
711
- hide: M
698
+ visible: computed(() => m.value),
699
+ position: computed(() => w.value),
700
+ originalPosition: computed(() => h.value),
701
+ feature: computed(() => g.value),
702
+ content: computed(() => _.value),
703
+ coordinate: computed(() => b.value),
704
+ option: computed(() => S.value),
705
+ hide: A
712
706
  };
713
707
  }
714
708
  function useSwitchBaseLayer(a) {
@@ -40,12 +40,10 @@ 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;
@@ -1,95 +1,89 @@
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 = computed(() => ({
11
+ x: u.value.x + p.value.x,
12
+ y: u.value.y + p.value.y
13
+ })), _, v, y = "";
14
+ function b(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 x(e) {
22
+ if (e.dragging || !_ || !v) return;
23
+ let t = e.coordinate;
24
+ m.value = t;
25
+ let n = e.pixel, r, i;
26
+ if (_.forEachFeatureAtPixel(n, (e, t) => (r = e, i = t, !0)), !r) {
27
+ S();
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 } = v.getBoundingClientRect(), g = {
33
+ map: _,
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;
48
- g.value = { ...o };
41
+ }, y = b(g);
42
+ if (y) {
43
+ let { content: e, cursor: t, visible: n, fixedFeatureCenter: r, offset: i, priority: a,...o } = y;
44
+ h.value = { ...o };
49
45
  }
50
- if (!s) {
51
- w();
46
+ if (!y) {
47
+ S();
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: y.offset?.x ?? 0,
52
+ y: y.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 x = c === !1 ? !0 : y.fixedFeatureCenter ?? !0, C = r.getGeometry();
55
+ if (x && C) {
56
+ let e = getCenter(C.getExtent());
57
+ n = _.getPixelFromCoordinate(e);
58
+ }
59
+ u.value.x = n[0] + s, u.value.y = n[1] + o;
60
+ let w = y.content;
61
+ f.value = typeof w == "function" ? () => w(g) : w;
62
+ let T = y.cursor, E = typeof T == "function" ? T(g) : T;
63
+ E !== void 0 && E !== v.style.cursor && (v.style.cursor = E), 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 S() {
66
+ l.value = !1, d.value = void 0, v && v.style.cursor !== y && (v.style.cursor = y);
73
67
  }
74
- function T(e) {
75
- e.addEventListener("pointermove", C);
68
+ function C(e) {
69
+ e.on("pointermove", x);
76
70
  }
77
- function E(e) {
78
- e.removeEventListener("pointermove", C);
71
+ function w(e) {
72
+ e.un("pointermove", x);
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 && w(t), t !== e && (_ = e, e && (v = e.getViewport(), C(e), y = v.style.cursor));
82
76
  }, { immediate: !0 }), onBeforeUnmount(() => {
83
- b && E(b);
77
+ _ && w(_);
84
78
  }), {
85
- visible: computed(() => u.value),
86
- position: computed(() => _.value),
87
- originalPosition: computed(() => d.value),
88
- feature: computed(() => f.value),
89
- content: computed(() => p.value),
90
- coordinate: computed(() => h.value),
91
- option: computed(() => g.value),
92
- hide: w
79
+ visible: computed(() => l.value),
80
+ position: computed(() => g.value),
81
+ originalPosition: computed(() => u.value),
82
+ feature: computed(() => d.value),
83
+ content: computed(() => f.value),
84
+ coordinate: computed(() => m.value),
85
+ option: computed(() => h.value),
86
+ hide: S
93
87
  };
94
88
  }
95
89
  export { usePointermove };
@@ -40,12 +40,10 @@ 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;
@@ -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.computed)(()=>({x:o.value.x+l.value.x,y:o.value.y+l.value.y})),p,m,h=``;function g(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 _(e){if(e.dragging||!p||!m)return;let t=e.coordinate;u.value=t;let r=e.pixel,f,h;if(p.forEachFeatureAtPixel(r,(e,t)=>(f=e,h=t,!0)),!f){v();return}if(!i&&s.value&&s.value.getId()===f.getId())return;s.value=f;let{top:_,left:y}=m.getBoundingClientRect(),b={map:p,position:{x:r[0]+y,y:r[1]+_},coordinate:t,feature:f,layer:h},x=g(b);if(x){let{content:e,cursor:t,visible:n,fixedFeatureCenter:r,offset:i,priority:a,...o}=x;d.value={...o}}if(!x){v();return}l.value={x:x.offset?.x??0,y:x.offset?.y??0};let S=i===!1?!0:x.fixedFeatureCenter??!0,C=f.getGeometry();if(S&&C){let e=(0,n.getCenter)(C.getExtent());r=p.getPixelFromCoordinate(e)}o.value.x=r[0]+y,o.value.y=r[1]+_;let w=x.content;c.value=typeof w==`function`?()=>w(b):w;let T=x.cursor,E=typeof T==`function`?T(b):T;E!==void 0&&E!==m.style.cursor&&(m.style.cursor=E),a.value=!0}function v(){a.value=!1,s.value=void 0,m&&m.style.cursor!==h&&(m.style.cursor=h)}function y(e){e.on(`pointermove`,_)}function b(e){e.un(`pointermove`,_)}return(0,t.watch)(()=>(0,t.toValue)(e),(e,t)=>{t&&b(t),t!==e&&(p=e,e&&(m=e.getViewport(),y(e),h=m.style.cursor))},{immediate:!0}),(0,t.onBeforeUnmount)(()=>{p&&b(p)}),{visible:(0,t.computed)(()=>a.value),position:(0,t.computed)(()=>f.value),originalPosition:(0,t.computed)(()=>o.value),feature:(0,t.computed)(()=>s.value),content:(0,t.computed)(()=>c.value),coordinate:(0,t.computed)(()=>u.value),option:(0,t.computed)(()=>d.value),hide:v}}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-alpha.3",
4
+ "version": "0.3.0",
5
5
  "description": "",
6
6
  "author": "finalsummer",
7
7
  "license": "ISC",