@summeruse/ol 0.1.6 → 0.2.0-alpha.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/index.js +564 -495
  3. package/es/components/index.d.ts +0 -2
  4. package/es/composables/index.d.ts +2 -0
  5. package/es/composables/useContextmenu/index.d.ts +71 -0
  6. package/es/composables/useContextmenu/index.mjs +77 -0
  7. package/es/composables/usePointermove/index.d.ts +57 -0
  8. package/es/composables/usePointermove/index.mjs +100 -0
  9. package/es/index.mjs +30 -30
  10. package/es/types/index.d.ts +2 -0
  11. package/es/utils/feature/index.mjs +49 -49
  12. package/lib/components/index.d.ts +0 -2
  13. package/lib/composables/index.d.ts +2 -0
  14. package/lib/composables/useContextmenu/index.d.ts +71 -0
  15. package/lib/composables/useContextmenu/index.js +1 -0
  16. package/lib/composables/usePointermove/index.d.ts +57 -0
  17. package/lib/composables/usePointermove/index.js +1 -0
  18. package/lib/index.js +1 -1
  19. package/lib/types/index.d.ts +2 -0
  20. package/lib/utils/feature/index.js +1 -1
  21. package/package.json +3 -5
  22. package/es/components/n-ol-contextmenu/index.d.ts +0 -3
  23. package/es/components/n-ol-contextmenu/index.vue.d.ts +0 -3
  24. package/es/components/n-ol-contextmenu/index.vue.mjs +0 -49
  25. package/es/components/n-ol-contextmenu/index.vue2.mjs +0 -4
  26. package/es/components/n-ol-contextmenu/props.d.ts +0 -17
  27. package/es/components/n-ol-pointermove/index.d.ts +0 -3
  28. package/es/components/n-ol-pointermove/index.vue.d.ts +0 -3
  29. package/es/components/n-ol-pointermove/index.vue.mjs +0 -62
  30. package/es/components/n-ol-pointermove/index.vue2.mjs +0 -4
  31. package/es/components/n-ol-pointermove/props.d.ts +0 -22
  32. package/lib/components/n-ol-contextmenu/index.d.ts +0 -3
  33. package/lib/components/n-ol-contextmenu/index.vue.d.ts +0 -3
  34. package/lib/components/n-ol-contextmenu/index.vue.js +0 -1
  35. package/lib/components/n-ol-contextmenu/index.vue2.js +0 -1
  36. package/lib/components/n-ol-contextmenu/props.d.ts +0 -17
  37. package/lib/components/n-ol-pointermove/index.d.ts +0 -3
  38. package/lib/components/n-ol-pointermove/index.vue.d.ts +0 -3
  39. package/lib/components/n-ol-pointermove/index.vue.js +0 -1
  40. package/lib/components/n-ol-pointermove/index.vue2.js +0 -1
  41. package/lib/components/n-ol-pointermove/props.d.ts +0 -22
@@ -1,3 +1 @@
1
- export * from './n-ol-contextmenu';
2
- export * from './n-ol-pointermove';
3
1
  export * from './ol-map';
@@ -1,4 +1,6 @@
1
+ export * from './useContextmenu';
1
2
  export * from './useDrawLineString';
2
3
  export * from './useDrawPolygon';
3
4
  export * from './useGraticule';
5
+ export * from './usePointermove';
4
6
  export * from './useSwitchBaseLayer';
@@ -0,0 +1,71 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { FeatureLike } from 'ol/Feature';
3
+ import { MaybeRefOrGetter, VNodeChild } from 'vue';
4
+ import { LayerLike, OLMap } from '../../types';
5
+ export interface ContextmenuPosition {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ interface ContextmenuItemParams {
10
+ map: OLMap;
11
+ coordinate: Coordinate;
12
+ position: ContextmenuPosition;
13
+ feature?: FeatureLike;
14
+ layer?: LayerLike;
15
+ }
16
+ export interface ContextmenuItemBase {
17
+ label: ((params: ContextmenuItemParams) => VNodeChild) | string;
18
+ visible?: ((params: ContextmenuItemParams) => boolean) | boolean;
19
+ disabled?: ((params: ContextmenuItemParams) => boolean) | boolean;
20
+ action?: (params: ContextmenuItemParams) => void;
21
+ divided?: boolean;
22
+ icon?: ((params: ContextmenuItemParams) => VNodeChild) | string;
23
+ order?: number;
24
+ key?: string | number;
25
+ [key: string]: any;
26
+ }
27
+ export interface ContextmenuItem extends ContextmenuItemBase {
28
+ children?: Array<ContextmenuItem>;
29
+ }
30
+ export type ContextmenuList = ContextmenuItem[];
31
+ export interface ContextmenuOptionBase {
32
+ label: string | (() => VNodeChild);
33
+ visible?: boolean;
34
+ disabled?: boolean;
35
+ action: () => void;
36
+ divided?: boolean;
37
+ icon?: string | (() => VNodeChild);
38
+ order?: number;
39
+ key?: string | number;
40
+ [key: string]: any;
41
+ }
42
+ export interface ContextmenuOption extends ContextmenuOptionBase {
43
+ children?: Array<ContextmenuOption>;
44
+ }
45
+ export type ContextmenuOptions = ContextmenuOption[];
46
+ export declare function useContextmenu(mapRef: MaybeRefOrGetter<OLMap | undefined>, items: MaybeRefOrGetter<ContextmenuList>): {
47
+ visible: import('vue').ComputedRef<boolean>;
48
+ position: import('vue').ComputedRef<{
49
+ x: number;
50
+ y: number;
51
+ }>;
52
+ feature: import('vue').ComputedRef<FeatureLike | undefined>;
53
+ options: import('vue').ComputedRef<{
54
+ [x: string]: any;
55
+ children?: /*elided*/ any[] | undefined;
56
+ label: string | (() => VNodeChild);
57
+ visible?: boolean | undefined;
58
+ disabled?: boolean | undefined;
59
+ action: () => void;
60
+ divided?: boolean | undefined;
61
+ icon?: string | (() => VNodeChild) | undefined;
62
+ order?: number | undefined;
63
+ key?: string | number | undefined;
64
+ }[]>;
65
+ coordinate: import('vue').ComputedRef<Coordinate | undefined>;
66
+ hide: () => void;
67
+ };
68
+ export type UseContextmenuReturn = ReturnType<typeof useContextmenu>;
69
+ export type UseContextmenuParams = Parameters<typeof useContextmenu>;
70
+ export type UseContextmenuFn = (...args: UseContextmenuParams) => UseContextmenuReturn;
71
+ export {};
@@ -0,0 +1,77 @@
1
+ import { ref as u, watch as A, toValue as y, onBeforeUnmount as C, computed as l } from "vue";
2
+ function P(g, L) {
3
+ const a = u(!1), d = u({ x: 0, y: 0 }), v = u(), b = u([]), h = u();
4
+ let i;
5
+ function p(t, n) {
6
+ const s = [];
7
+ return t.filter((e) => {
8
+ const o = e.visible;
9
+ return typeof o == "function" ? o(n) : o ?? !0;
10
+ }).filter((e) => !e.children || e.children.length > 0).sort((e, o) => (e.order ?? 0) - (o.order ?? 0)).forEach((e) => {
11
+ const o = e.icon, r = e.label;
12
+ s.push({
13
+ ...e,
14
+ children: e.children ? p(e.children, n) : void 0,
15
+ visible: !0,
16
+ action: () => {
17
+ var f;
18
+ (f = e.action) == null || f.call(e, n), c();
19
+ },
20
+ icon: typeof o == "function" ? () => o(n) : o,
21
+ label: typeof r == "function" ? () => r(n) : r,
22
+ disabled: typeof e.disabled == "function" ? e.disabled(n) : e.disabled ?? !1
23
+ });
24
+ }), s;
25
+ }
26
+ function E(t) {
27
+ if (t.preventDefault(), !i)
28
+ return;
29
+ const n = i.getEventCoordinate(t);
30
+ h.value = n;
31
+ const s = i.getEventPixel(t);
32
+ let e, o;
33
+ i.forEachFeatureAtPixel(s, (k, w) => (e = k, o = w, !0)), v.value = e;
34
+ const [r, f] = [t.clientX, t.clientY];
35
+ d.value = { x: r, y: f }, b.value = p(y(L), {
36
+ map: i,
37
+ position: { ...d.value },
38
+ coordinate: n,
39
+ feature: e,
40
+ layer: o
41
+ }), a.value = !0;
42
+ }
43
+ function c() {
44
+ a.value = !1;
45
+ }
46
+ function V(t) {
47
+ if (!t)
48
+ return;
49
+ const n = t.getViewport();
50
+ n.addEventListener("contextmenu", E), n.addEventListener("click", c);
51
+ }
52
+ function x(t) {
53
+ if (!t)
54
+ return;
55
+ const n = t.getViewport();
56
+ n.removeEventListener("contextmenu", E), n.removeEventListener("click", c);
57
+ }
58
+ return A(
59
+ () => y(g),
60
+ (t, n) => {
61
+ n !== t && (x(n), V(t), i = t);
62
+ },
63
+ { immediate: !0 }
64
+ ), C(() => {
65
+ x(i);
66
+ }), {
67
+ visible: l(() => a.value),
68
+ position: l(() => d.value),
69
+ feature: l(() => v.value),
70
+ options: l(() => b.value),
71
+ coordinate: l(() => h.value),
72
+ hide: c
73
+ };
74
+ }
75
+ export {
76
+ P as useContextmenu
77
+ };
@@ -0,0 +1,57 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { FeatureLike } from 'ol/Feature';
3
+ import { CSSProperties, MaybeRefOrGetter, VNodeChild } from 'vue';
4
+ import { LayerLike, OLMap } from '../../types';
5
+ export interface PointermovePosition {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ interface PointermoveContentParams {
10
+ map: OLMap;
11
+ coordinate: Coordinate;
12
+ position: PointermovePosition;
13
+ feature: FeatureLike;
14
+ layer?: LayerLike;
15
+ }
16
+ type Cursor = CSSProperties['cursor'];
17
+ export type PointermoveItem<T extends Option = Option> = {
18
+ /** 提示内容,支持函数动态生成 */
19
+ content: ((params: PointermoveContentParams) => VNodeChild) | string;
20
+ /** 是否显示提示,可根据 feature 动态判断 */
21
+ visible?: ((params: PointermoveContentParams) => boolean) | boolean;
22
+ /** 位置偏移 */
23
+ offset?: {
24
+ x?: number;
25
+ y?: number;
26
+ };
27
+ /** 优先级,数字越大优先级越高,当多个 tooltip 匹配时,显示优先级最高的 */
28
+ priority?: number;
29
+ /** 鼠标样式,如 'pointer', 'crosshair', 'move' 等 */
30
+ cursor?: Cursor | ((params: PointermoveContentParams) => Cursor);
31
+ /** 固定在feature center */
32
+ fixedFeatureCenter?: boolean;
33
+ } & T;
34
+ export type PointermoveList<T extends Option = Option> = PointermoveItem<T>[];
35
+ export interface Option {
36
+ [key: string]: any;
37
+ }
38
+ export declare function usePointermove<T extends Option>(mapRef: MaybeRefOrGetter<OLMap | undefined>, items: MaybeRefOrGetter<PointermoveList<T>>): {
39
+ visible: import('vue').ComputedRef<boolean>;
40
+ position: import('vue').ComputedRef<{
41
+ x: number;
42
+ y: number;
43
+ }>;
44
+ originalPosition: import('vue').ComputedRef<{
45
+ x: number;
46
+ y: number;
47
+ }>;
48
+ feature: import('vue').ComputedRef<FeatureLike | undefined>;
49
+ content: import('vue').ComputedRef<string | (() => VNodeChild) | undefined>;
50
+ coordinate: import('vue').ComputedRef<Coordinate | undefined>;
51
+ option: import('vue').ComputedRef<T | undefined>;
52
+ hide: () => void;
53
+ };
54
+ export type UsePointermoveReturn = ReturnType<typeof usePointermove>;
55
+ export type UsePointermoveParams<T extends Option> = Parameters<typeof usePointermove<T>>;
56
+ export type UsePointermoveFn<T extends Option> = (...args: UsePointermoveParams<T>) => UsePointermoveReturn;
57
+ export {};
@@ -0,0 +1,100 @@
1
+ import { getCenter as D } from "ol/extent";
2
+ import { ref as c, computed as s, watch as H, toValue as A, onBeforeUnmount as I } from "vue";
3
+ function O(G, M) {
4
+ const d = c(!1), l = c({ x: 0, y: 0 }), y = c(), h = c(), x = c({ x: 0, y: 0 }), w = c(), P = c(), R = s(() => ({
5
+ x: l.value.x + x.value.x,
6
+ y: l.value.y + x.value.y
7
+ }));
8
+ let t, f = "";
9
+ function U(e) {
10
+ const v = A(M).filter((n) => {
11
+ const r = n.visible;
12
+ return typeof r == "function" ? r(e) : r ?? !0;
13
+ });
14
+ return v.length === 0 ? null : v.sort((n, r) => (r.priority ?? 0) - (n.priority ?? 0))[0];
15
+ }
16
+ function b(e) {
17
+ var X, Y;
18
+ if (!t)
19
+ return;
20
+ const o = t.getEventCoordinate(e);
21
+ w.value = o;
22
+ const v = t.getEventPixel(e);
23
+ let n, r;
24
+ if (t.forEachFeatureAtPixel(v, (u, p) => (n = u, r = p, !0)), !n) {
25
+ a();
26
+ return;
27
+ }
28
+ y.value = n;
29
+ const g = {
30
+ map: t,
31
+ position: { x: e.clientX, y: e.clientY },
32
+ coordinate: o,
33
+ feature: n,
34
+ layer: r
35
+ }, i = U(g);
36
+ if (i) {
37
+ const { content: u, cursor: p, visible: E, fixedFeatureCenter: B, offset: S, priority: J, ...z } = i;
38
+ P.value = { ...z };
39
+ }
40
+ if (!i) {
41
+ a();
42
+ return;
43
+ }
44
+ const j = ((X = i.offset) == null ? void 0 : X.x) ?? 0, k = ((Y = i.offset) == null ? void 0 : Y.y) ?? 0;
45
+ x.value = { x: j, y: k };
46
+ const q = i.fixedFeatureCenter ?? !0, V = n.getGeometry();
47
+ if (q && V) {
48
+ const u = V.getExtent(), p = D(u), E = t.getPixelFromCoordinate(p), { top: B, left: S } = t.getViewport().getBoundingClientRect();
49
+ l.value.x = E[0] + S, l.value.y = E[1] + B;
50
+ } else
51
+ l.value = { x: e.clientX, y: e.clientY };
52
+ const m = i.content;
53
+ h.value = typeof m == "function" ? () => m(g) : m;
54
+ const C = i.cursor, L = typeof C == "function" ? C(g) : C;
55
+ if (L && t) {
56
+ const u = t.getViewport();
57
+ f || (f = u.style.cursor), u.style.cursor = L;
58
+ }
59
+ d.value = !0;
60
+ }
61
+ function a() {
62
+ if (d.value = !1, y.value = void 0, t && f !== void 0) {
63
+ const e = t.getViewport();
64
+ e.style.cursor = f, f = "";
65
+ }
66
+ }
67
+ function _(e) {
68
+ if (!e)
69
+ return;
70
+ const o = e.getViewport();
71
+ o.addEventListener("pointermove", b), o.addEventListener("pointerout", a);
72
+ }
73
+ function F(e) {
74
+ if (!e)
75
+ return;
76
+ const o = e.getViewport();
77
+ o.removeEventListener("pointermove", b), o.removeEventListener("pointerout", a);
78
+ }
79
+ return H(
80
+ () => A(G),
81
+ (e, o) => {
82
+ o !== e && (F(o), _(e), t = e);
83
+ },
84
+ { immediate: !0 }
85
+ ), I(() => {
86
+ F(t);
87
+ }), {
88
+ visible: s(() => d.value),
89
+ position: s(() => R.value),
90
+ originalPosition: s(() => l.value),
91
+ feature: s(() => y.value),
92
+ content: s(() => h.value),
93
+ coordinate: s(() => w.value),
94
+ option: s(() => P.value),
95
+ hide: a
96
+ };
97
+ }
98
+ export {
99
+ O as usePointermove
100
+ };
package/es/index.mjs CHANGED
@@ -1,32 +1,30 @@
1
- import { default as r } from "./components/n-ol-contextmenu/index.vue.mjs";
2
- import { default as a } from "./components/n-ol-pointermove/index.vue.mjs";
3
- import { default as i } from "./components/ol-map/index.vue.mjs";
4
- import { olMapInjectionKey as c, useOlMap as g } from "./components/ol-map/props.mjs";
5
- import { useDrawLineString as x } from "./composables/useDrawLineString/index.mjs";
6
- import { useDrawPolygon as P } from "./composables/useDrawPolygon/index.mjs";
7
- import { useGraticule as p } from "./composables/useGraticule/index.mjs";
1
+ import { default as r } from "./components/ol-map/index.vue.mjs";
2
+ import { olMapInjectionKey as a, useOlMap as n } from "./components/ol-map/props.mjs";
3
+ import { useContextmenu as c } from "./composables/useContextmenu/index.mjs";
4
+ import { useDrawLineString as g } from "./composables/useDrawLineString/index.mjs";
5
+ import { useDrawPolygon as x } from "./composables/useDrawPolygon/index.mjs";
6
+ import { useGraticule as P } from "./composables/useGraticule/index.mjs";
7
+ import { usePointermove as S } from "./composables/usePointermove/index.mjs";
8
8
  import { useSwitchBaseLayer as s } from "./composables/useSwitchBaseLayer/index.mjs";
9
9
  import { ONE_NM as M } from "./constants/distance.mjs";
10
10
  import { EPSG_3857 as y, EPSG_4326 as G, WGS84Projection as L, WebMercatorProjection as _ } from "./constants/projection.mjs";
11
- import { getAngle as F, getArea as O, getCenter as w, getDestinationPoint as D, getExtentCenter as N, getLineLength as d } from "./utils/calculate/index.mjs";
12
- import { kmToNauticalMiles as W, nauticalMilesToKm as j } from "./utils/distance/index.mjs";
11
+ import { getAngle as F, getArea as w, getCenter as D, getDestinationPoint as O, getExtentCenter as A, getLineLength as W } from "./utils/calculate/index.mjs";
12
+ import { kmToNauticalMiles as N, nauticalMilesToKm as d } from "./utils/distance/index.mjs";
13
13
  import { createCircle as B, createCircleFeature as K, createFeature as b, createLineString as k, createLineStringFeature as v, createMultiLineString as I, createMultiLineStringFeature as R, createMultiPoint as U, createMultiPointFeature as V, createMultiPolygon as q, createMultiPolygonFeature as z, createPoint as H, createPointFeature as J, createPolygon as Q, createPolygonFeature as X } from "./utils/feature/index.mjs";
14
14
  import { toOlAngle as Z, toTurfAngle as $ } from "./utils/format/index.mjs";
15
15
  import { createVectorLayer as te, getBingLayer as re, getOSMLayer as oe, getTianDiTuLayer as ae, getTianDiTuUrl as ne } from "./utils/layer/index.mjs";
16
- import { EPSG_3857ExtentToEPSG_4326 as le, EPSG_3857ToEPSG_4326 as ce, EPSG_4326ExtentToEPSG_3857 as ge, EPSG_4326ToEPSG_3857 as ue, mercatorExtentToWgs84 as xe, mercatorToWgs84 as me, wgs84ExtentToMercator as Pe, wgs84ToMercator as fe } from "./utils/projection/index.mjs";
17
- import { getRealCircleCoordinates as Se } from "./utils/realCircle/index.mjs";
16
+ import { EPSG_3857ExtentToEPSG_4326 as ce, EPSG_3857ToEPSG_4326 as le, EPSG_4326ExtentToEPSG_3857 as ge, EPSG_4326ToEPSG_3857 as ue, mercatorExtentToWgs84 as xe, mercatorToWgs84 as me, wgs84ExtentToMercator as Pe, wgs84ToMercator as pe } from "./utils/projection/index.mjs";
17
+ import { getRealCircleCoordinates as fe } from "./utils/realCircle/index.mjs";
18
18
  import { createCircleStyle as Ee, createStyle as Me, createTextStyle as Te } from "./utils/style/index.mjs";
19
19
  export {
20
20
  y as EPSG_3857,
21
- le as EPSG_3857ExtentToEPSG_4326,
22
- ce as EPSG_3857ToEPSG_4326,
21
+ ce as EPSG_3857ExtentToEPSG_4326,
22
+ le as EPSG_3857ToEPSG_4326,
23
23
  G as EPSG_4326,
24
24
  ge as EPSG_4326ExtentToEPSG_3857,
25
25
  ue as EPSG_4326ToEPSG_3857,
26
- r as NOlContextmenu,
27
- a as NOlPointermove,
28
26
  M as ONE_NM,
29
- i as OlMap,
27
+ r as OlMap,
30
28
  L as WGS84Projection,
31
29
  _ as WebMercatorProjection,
32
30
  B as createCircle,
@@ -49,28 +47,30 @@ export {
49
47
  Te as createTextStyle,
50
48
  te as createVectorLayer,
51
49
  F as getAngle,
52
- O as getArea,
50
+ w as getArea,
53
51
  re as getBingLayer,
54
- w as getCenter,
55
- D as getDestinationPoint,
56
- N as getExtentCenter,
57
- d as getLineLength,
52
+ D as getCenter,
53
+ O as getDestinationPoint,
54
+ A as getExtentCenter,
55
+ W as getLineLength,
58
56
  oe as getOSMLayer,
59
- Se as getRealCircleCoordinates,
57
+ fe as getRealCircleCoordinates,
60
58
  ae as getTianDiTuLayer,
61
59
  ne as getTianDiTuUrl,
62
- W as kmToNauticalMiles,
60
+ N as kmToNauticalMiles,
63
61
  xe as mercatorExtentToWgs84,
64
62
  me as mercatorToWgs84,
65
- j as nauticalMilesToKm,
66
- c as olMapInjectionKey,
63
+ d as nauticalMilesToKm,
64
+ a as olMapInjectionKey,
67
65
  Z as toOlAngle,
68
66
  $ as toTurfAngle,
69
- x as useDrawLineString,
70
- P as useDrawPolygon,
71
- p as useGraticule,
72
- g as useOlMap,
67
+ c as useContextmenu,
68
+ g as useDrawLineString,
69
+ x as useDrawPolygon,
70
+ P as useGraticule,
71
+ n as useOlMap,
72
+ S as usePointermove,
73
73
  s as useSwitchBaseLayer,
74
74
  Pe as wgs84ExtentToMercator,
75
- fe as wgs84ToMercator
75
+ pe as wgs84ToMercator
76
76
  };
@@ -1,2 +1,4 @@
1
1
  import { Map as OLMap } from 'ol';
2
2
  export type { OLMap };
3
+ export type ForEachFeatureAtPixelCallbackOptions = Parameters<Parameters<OLMap['forEachFeatureAtPixel']>[1]>;
4
+ export type LayerLike = ForEachFeatureAtPixelCallbackOptions[1];
@@ -1,97 +1,97 @@
1
- import { Feature as i } from "ol";
2
- import { Point as u, LineString as c, Polygon as a, Circle as l, MultiPoint as f, MultiLineString as g, MultiPolygon as y } from "ol/geom";
3
- import { createStyle as s } from "../style/index.mjs";
4
- function m(e) {
5
- return new u(e);
1
+ import { Feature as a } from "ol";
2
+ import { Point as l, LineString as g, Polygon as f, Circle as y, MultiPoint as s, MultiLineString as m, MultiPolygon as P } from "ol/geom";
3
+ import { createStyle as F } from "../style/index.mjs";
4
+ function M(e) {
5
+ return new l(e);
6
6
  }
7
- function P(e) {
8
- return new c(e);
7
+ function w(e) {
8
+ return new g(e);
9
9
  }
10
- function F(e) {
11
- return new a(e);
10
+ function S(e) {
11
+ return new f(e);
12
12
  }
13
- function M(e, t) {
14
- return new l(e, t);
13
+ function p(e, t) {
14
+ return new y(e, t);
15
15
  }
16
- function w(e) {
17
- return new f(e);
16
+ function L(e) {
17
+ return new s(e);
18
18
  }
19
- function S(e) {
20
- return new g(e);
19
+ function C(e) {
20
+ return new m(e);
21
21
  }
22
- function p(e) {
23
- return new y(e);
22
+ function O(e) {
23
+ return new P(e);
24
24
  }
25
25
  function r(e) {
26
- const { styleOptions: t, ...n } = e ?? {}, o = t ? s(t) : n.style;
27
- return new i({
28
- ...n,
29
- style: o
26
+ const { styleOptions: t, style: n, geometry: o, ...u } = e ?? {}, c = t ? F(t) : n, i = new a({
27
+ geometry: o,
28
+ ...u
30
29
  });
30
+ return i.setStyle(c), i;
31
31
  }
32
- function b(e, t) {
33
- const n = m(e);
32
+ function d(e, t) {
33
+ const n = M(e);
34
34
  return r({
35
35
  ...t,
36
36
  geometry: n
37
37
  });
38
38
  }
39
- function d(e, t) {
40
- const n = P(e);
39
+ function h(e, t) {
40
+ const n = w(e);
41
41
  return r({
42
42
  ...t,
43
43
  geometry: n
44
44
  });
45
45
  }
46
- function h(e, t) {
47
- const n = F(e);
46
+ function j(e, t) {
47
+ const n = S(e);
48
48
  return r({
49
49
  ...t,
50
50
  geometry: n
51
51
  });
52
52
  }
53
- function j(e, t, n) {
54
- const o = M(e, t);
53
+ function k(e, t, n) {
54
+ const o = p(e, t);
55
55
  return r({
56
56
  ...n,
57
57
  geometry: o
58
58
  });
59
59
  }
60
- function k(e, t) {
61
- const n = w(e);
60
+ function q(e, t) {
61
+ const n = L(e);
62
62
  return r({
63
63
  ...t,
64
64
  geometry: n
65
65
  });
66
66
  }
67
- function q(e, t) {
68
- const n = S(e);
67
+ function v(e, t) {
68
+ const n = C(e);
69
69
  return r({
70
70
  ...t,
71
71
  geometry: n
72
72
  });
73
73
  }
74
- function v(e, t) {
75
- const n = p(e);
74
+ function z(e, t) {
75
+ const n = O(e);
76
76
  return r({
77
77
  ...t,
78
78
  geometry: n
79
79
  });
80
80
  }
81
81
  export {
82
- M as createCircle,
83
- j as createCircleFeature,
82
+ p as createCircle,
83
+ k as createCircleFeature,
84
84
  r as createFeature,
85
- P as createLineString,
86
- d as createLineStringFeature,
87
- S as createMultiLineString,
88
- q as createMultiLineStringFeature,
89
- w as createMultiPoint,
90
- k as createMultiPointFeature,
91
- p as createMultiPolygon,
92
- v as createMultiPolygonFeature,
93
- m as createPoint,
94
- b as createPointFeature,
95
- F as createPolygon,
96
- h as createPolygonFeature
85
+ w as createLineString,
86
+ h as createLineStringFeature,
87
+ C as createMultiLineString,
88
+ v as createMultiLineStringFeature,
89
+ L as createMultiPoint,
90
+ q as createMultiPointFeature,
91
+ O as createMultiPolygon,
92
+ z as createMultiPolygonFeature,
93
+ M as createPoint,
94
+ d as createPointFeature,
95
+ S as createPolygon,
96
+ j as createPolygonFeature
97
97
  };
@@ -1,3 +1 @@
1
- export * from './n-ol-contextmenu';
2
- export * from './n-ol-pointermove';
3
1
  export * from './ol-map';
@@ -1,4 +1,6 @@
1
+ export * from './useContextmenu';
1
2
  export * from './useDrawLineString';
2
3
  export * from './useDrawPolygon';
3
4
  export * from './useGraticule';
5
+ export * from './usePointermove';
4
6
  export * from './useSwitchBaseLayer';
@@ -0,0 +1,71 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { FeatureLike } from 'ol/Feature';
3
+ import { MaybeRefOrGetter, VNodeChild } from 'vue';
4
+ import { LayerLike, OLMap } from '../../types';
5
+ export interface ContextmenuPosition {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ interface ContextmenuItemParams {
10
+ map: OLMap;
11
+ coordinate: Coordinate;
12
+ position: ContextmenuPosition;
13
+ feature?: FeatureLike;
14
+ layer?: LayerLike;
15
+ }
16
+ export interface ContextmenuItemBase {
17
+ label: ((params: ContextmenuItemParams) => VNodeChild) | string;
18
+ visible?: ((params: ContextmenuItemParams) => boolean) | boolean;
19
+ disabled?: ((params: ContextmenuItemParams) => boolean) | boolean;
20
+ action?: (params: ContextmenuItemParams) => void;
21
+ divided?: boolean;
22
+ icon?: ((params: ContextmenuItemParams) => VNodeChild) | string;
23
+ order?: number;
24
+ key?: string | number;
25
+ [key: string]: any;
26
+ }
27
+ export interface ContextmenuItem extends ContextmenuItemBase {
28
+ children?: Array<ContextmenuItem>;
29
+ }
30
+ export type ContextmenuList = ContextmenuItem[];
31
+ export interface ContextmenuOptionBase {
32
+ label: string | (() => VNodeChild);
33
+ visible?: boolean;
34
+ disabled?: boolean;
35
+ action: () => void;
36
+ divided?: boolean;
37
+ icon?: string | (() => VNodeChild);
38
+ order?: number;
39
+ key?: string | number;
40
+ [key: string]: any;
41
+ }
42
+ export interface ContextmenuOption extends ContextmenuOptionBase {
43
+ children?: Array<ContextmenuOption>;
44
+ }
45
+ export type ContextmenuOptions = ContextmenuOption[];
46
+ export declare function useContextmenu(mapRef: MaybeRefOrGetter<OLMap | undefined>, items: MaybeRefOrGetter<ContextmenuList>): {
47
+ visible: import('vue').ComputedRef<boolean>;
48
+ position: import('vue').ComputedRef<{
49
+ x: number;
50
+ y: number;
51
+ }>;
52
+ feature: import('vue').ComputedRef<FeatureLike | undefined>;
53
+ options: import('vue').ComputedRef<{
54
+ [x: string]: any;
55
+ children?: /*elided*/ any[] | undefined;
56
+ label: string | (() => VNodeChild);
57
+ visible?: boolean | undefined;
58
+ disabled?: boolean | undefined;
59
+ action: () => void;
60
+ divided?: boolean | undefined;
61
+ icon?: string | (() => VNodeChild) | undefined;
62
+ order?: number | undefined;
63
+ key?: string | number | undefined;
64
+ }[]>;
65
+ coordinate: import('vue').ComputedRef<Coordinate | undefined>;
66
+ hide: () => void;
67
+ };
68
+ export type UseContextmenuReturn = ReturnType<typeof useContextmenu>;
69
+ export type UseContextmenuParams = Parameters<typeof useContextmenu>;
70
+ export type UseContextmenuFn = (...args: UseContextmenuParams) => UseContextmenuReturn;
71
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue");function C(E,x){const f=o.ref(!1),d=o.ref({x:0,y:0}),a=o.ref(),v=o.ref([]),b=o.ref();let i;function p(n,t){const l=[];return n.filter(e=>{const r=e.visible;return typeof r=="function"?r(t):r??!0}).filter(e=>!e.children||e.children.length>0).sort((e,r)=>(e.order??0)-(r.order??0)).forEach(e=>{const r=e.icon,u=e.label;l.push({...e,children:e.children?p(e.children,t):void 0,visible:!0,action:()=>{var s;(s=e.action)==null||s.call(e,t),c()},icon:typeof r=="function"?()=>r(t):r,label:typeof u=="function"?()=>u(t):u,disabled:typeof e.disabled=="function"?e.disabled(t):e.disabled??!1})}),l}function h(n){if(n.preventDefault(),!i)return;const t=i.getEventCoordinate(n);b.value=t;const l=i.getEventPixel(n);let e,r;i.forEachFeatureAtPixel(l,(L,V)=>(e=L,r=V,!0)),a.value=e;const[u,s]=[n.clientX,n.clientY];d.value={x:u,y:s},v.value=p(o.toValue(x),{map:i,position:{...d.value},coordinate:t,feature:e,layer:r}),f.value=!0}function c(){f.value=!1}function g(n){if(!n)return;const t=n.getViewport();t.addEventListener("contextmenu",h),t.addEventListener("click",c)}function y(n){if(!n)return;const t=n.getViewport();t.removeEventListener("contextmenu",h),t.removeEventListener("click",c)}return o.watch(()=>o.toValue(E),(n,t)=>{t!==n&&(y(t),g(n),i=n)},{immediate:!0}),o.onBeforeUnmount(()=>{y(i)}),{visible:o.computed(()=>f.value),position:o.computed(()=>d.value),feature:o.computed(()=>a.value),options:o.computed(()=>v.value),coordinate:o.computed(()=>b.value),hide:c}}exports.useContextmenu=C;