@tarojs/components-react 4.1.12-beta.5 → 4.1.12-beta.51

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 (70) hide show
  1. package/dist/components/image/index.js +5 -3
  2. package/dist/components/image/index.js.map +1 -1
  3. package/dist/components/map/MapContext.js +628 -0
  4. package/dist/components/map/MapContext.js.map +1 -0
  5. package/dist/components/map/MapCustomCallout.js +91 -0
  6. package/dist/components/map/MapCustomCallout.js.map +1 -0
  7. package/dist/components/map/common.js +4 -0
  8. package/dist/components/map/common.js.map +1 -0
  9. package/dist/components/map/createMapContext.js +34 -0
  10. package/dist/components/map/createMapContext.js.map +1 -0
  11. package/dist/components/map/handler.js +50 -0
  12. package/dist/components/map/handler.js.map +1 -0
  13. package/dist/components/map/index.js +329 -0
  14. package/dist/components/map/index.js.map +1 -0
  15. package/dist/components/picker/index.js +110 -38
  16. package/dist/components/picker/index.js.map +1 -1
  17. package/dist/components/picker/picker-group.js +400 -111
  18. package/dist/components/picker/picker-group.js.map +1 -1
  19. package/dist/components/scroll-view/index.js +80 -36
  20. package/dist/components/scroll-view/index.js.map +1 -1
  21. package/dist/components/switch/index.js +125 -0
  22. package/dist/components/switch/index.js.map +1 -0
  23. package/dist/components/switch/style/index.scss.js +4 -0
  24. package/dist/components/switch/style/index.scss.js.map +1 -0
  25. package/dist/contexts/ScrollElementContext.js +6 -0
  26. package/dist/contexts/ScrollElementContext.js.map +1 -0
  27. package/dist/index.css +1 -1
  28. package/dist/index.js +5 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/original/components/image/index.js +5 -3
  31. package/dist/original/components/image/index.js.map +1 -1
  32. package/dist/original/components/image/style/index.scss +5 -1
  33. package/dist/original/components/map/MapContext.js +628 -0
  34. package/dist/original/components/map/MapContext.js.map +1 -0
  35. package/dist/original/components/map/MapCustomCallout.js +91 -0
  36. package/dist/original/components/map/MapCustomCallout.js.map +1 -0
  37. package/dist/original/components/map/common.js +4 -0
  38. package/dist/original/components/map/common.js.map +1 -0
  39. package/dist/original/components/map/createMapContext.js +34 -0
  40. package/dist/original/components/map/createMapContext.js.map +1 -0
  41. package/dist/original/components/map/handler.js +50 -0
  42. package/dist/original/components/map/handler.js.map +1 -0
  43. package/dist/original/components/map/index.js +329 -0
  44. package/dist/original/components/map/index.js.map +1 -0
  45. package/dist/original/components/picker/index.js +110 -38
  46. package/dist/original/components/picker/index.js.map +1 -1
  47. package/dist/original/components/picker/picker-group.js +400 -111
  48. package/dist/original/components/picker/picker-group.js.map +1 -1
  49. package/dist/original/components/picker/style/index.scss +9 -8
  50. package/dist/original/components/scroll-view/index.js +80 -36
  51. package/dist/original/components/scroll-view/index.js.map +1 -1
  52. package/dist/original/components/switch/index.js +125 -0
  53. package/dist/original/components/switch/index.js.map +1 -0
  54. package/dist/original/components/switch/style/index.scss +35 -0
  55. package/dist/original/contexts/ScrollElementContext.js +6 -0
  56. package/dist/original/contexts/ScrollElementContext.js.map +1 -0
  57. package/dist/original/index.js +5 -1
  58. package/dist/original/index.js.map +1 -1
  59. package/dist/solid/components/image/index.js +5 -3
  60. package/dist/solid/components/image/index.js.map +1 -1
  61. package/dist/solid/components/picker/index.js +121 -45
  62. package/dist/solid/components/picker/index.js.map +1 -1
  63. package/dist/solid/components/picker/picker-group.js +423 -135
  64. package/dist/solid/components/picker/picker-group.js.map +1 -1
  65. package/dist/solid/components/scroll-view/index.js +84 -40
  66. package/dist/solid/components/scroll-view/index.js.map +1 -1
  67. package/dist/solid/contexts/ScrollElementContext.js +6 -0
  68. package/dist/solid/contexts/ScrollElementContext.js.map +1 -0
  69. package/dist/solid/index.css +1 -1
  70. package/package.json +8 -6
@@ -11,16 +11,18 @@ function Image(props) {
11
11
  const [, setIsLoaded] = useState(false);
12
12
  const {
13
13
  className,
14
- style = {},
14
+ style,
15
15
  src,
16
16
  mode,
17
17
  onError,
18
18
  lazyLoad,
19
19
  imgProps,
20
- forwardedRef
20
+ forwardedRef,
21
+ disableDefaultSize = false
21
22
  } = props,
22
- reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef"]);
23
+ reset = __rest(props, ["className", "style", "src", "mode", "onError", "lazyLoad", "imgProps", "forwardedRef", "disableDefaultSize"]);
23
24
  const cls = classNames('taro-img', {
25
+ 'taro-img--with-default-host-size': !disableDefaultSize,
24
26
  'taro-img__widthfix': mode === 'widthFix'
25
27
  }, className);
26
28
  const imgCls = classNames('taro-img__mode-' + (mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style = {},\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n ...reset\n } = props\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAmBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,CAAC;AACpD,EAAA,MAAMC,QAAQ,GAAGD,MAAM,CAAgC,EAAE,CAAC;AAC1D,EAAA,MAAM,GAAGE,WAAW,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM;MACJC,SAAS;MACTC,KAAK,GAAG,EAAE;MACVC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;AACRC,MAAAA;AAAY,KAAA,GAEVb,KAAK;IADJc,KAAK,GAAAC,MAAA,CACNf,KAAK,EAVH,CAUL,WAAA,EAAA,OAAA,EAAA,KAAA,EAAA,MAAA,EAAA,SAAA,EAAA,UAAA,EAAA,U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":["../../../src/components/image/index.tsx"],"sourcesContent":["import './style/index.scss'\n\nimport classNames from 'classnames'\n\nimport { createForwardRefComponent } from '../../utils'\nimport { useCallback, useEffect, useRef, useState } from '../../utils/hooks'\n\nimport type React from 'react'\n\ninterface IProps extends React.HTMLAttributes<HTMLDivElement> {\n src: string\n mode: string\n onError: () => void\n onLoad: (e) => void\n lazyLoad?: boolean\n imgProps?: Record<string, any>\n forwardedRef?: React.MutableRefObject<HTMLDivElement>\n /** 为 true 时不挂载默认占位尺寸(320×240),由业务 style/class 决定容器大小 */\n disableDefaultSize?: boolean\n}\n\nfunction Image (props: IProps) {\n const imgRef = useRef<HTMLImageElement | null>(null)\n const observer = useRef<Partial<IntersectionObserver>>({})\n const [, setIsLoaded] = useState(false)\n const {\n className,\n style,\n src,\n mode,\n onError,\n lazyLoad,\n imgProps,\n forwardedRef,\n disableDefaultSize = false,\n ...reset\n } = props\n\n const cls = classNames(\n 'taro-img',\n {\n 'taro-img--with-default-host-size': !disableDefaultSize,\n 'taro-img__widthfix': mode === 'widthFix'\n },\n className\n )\n const imgCls = classNames(\n 'taro-img__mode-' +\n (mode || 'scaleToFill').toLowerCase().replace(/\\s/g, '')\n )\n\n const imageOnLoad = useCallback((e) => {\n const { onLoad } = props\n Object.defineProperty(e, 'detail', {\n enumerable: true,\n writable: true,\n value: {\n width: e.target.width,\n height: e.target.height\n }\n })\n\n onLoad && onLoad(e)\n }, [props])\n\n useEffect(() => {\n if (lazyLoad) {\n observer.current = new IntersectionObserver(\n entries => {\n // 异步 api 关系\n if (entries[entries.length - 1].isIntersecting) {\n setIsLoaded(true)\n // findDOMNode(this).children[0].src = src\n imgRef.current!.src = src\n }\n },\n {\n rootMargin: '300px 0px'\n }\n )\n observer.current.observe?.(imgRef.current!)\n }\n\n return () => {\n observer.current?.disconnect?.()\n }\n }, [lazyLoad, src])\n\n return (\n <div className={cls} style={style} ref={forwardedRef} {...reset}>\n {lazyLoad ? (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n data-src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n ) : (\n <img\n ref={img => (imgRef.current = img)}\n className={imgCls}\n src={src}\n onLoad={imageOnLoad}\n onError={onError}\n {...imgProps}\n />\n )}\n </div>\n )\n}\n\nexport default createForwardRefComponent(Image)\n"],"names":["Image","props","imgRef","useRef","observer","setIsLoaded","useState","className","style","src","mode","onError","lazyLoad","imgProps","forwardedRef","disableDefaultSize","reset","__rest","cls","classNames","imgCls","toLowerCase","replace","imageOnLoad","useCallback","e","onLoad","Object","defineProperty","enumerable","writable","value","width","target","height","useEffect","current","IntersectionObserver","entries","length","isIntersecting","rootMargin","_b","_a","observe","call","disconnect","_jsx","ref","children","img","createForwardRefComponent"],"mappings":";;;;;;;AAqBA,SAASA,KAAKA,CAAEC,KAAa,EAAA;AAC3B,EAAA,MAAMC,MAAM,GAAGC,MAAM,CAA0B,IAAI,CAAC;AACpD,EAAA,MAAMC,QAAQ,GAAGD,MAAM,CAAgC,EAAE,CAAC;AAC1D,EAAA,MAAM,GAAGE,WAAW,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACvC,MAAM;MACJC,SAAS;MACTC,KAAK;MACLC,GAAG;MACHC,IAAI;MACJC,OAAO;MACPC,QAAQ;MACRC,QAAQ;MACRC,YAAY;AACZC,MAAAA,kBAAkB,GAAG;AAEnB,KAAA,GAAAd,KAAK;IADJe,KAAK,GACNC,MAAA,CAAAhB,KAAK,EAXH,CAAA,WAAA,EAAA,OAAA,EAAA,KAAA,EAAA,MAAA,EAAA,SAAA,EAAA,UAAA,EAAA,UAAA,EAAA,cAAA,EAAA,oBAAA,CAWL,CAAQ;AAET,EAAA,MAAMiB,GAAG,GAAGC,UAAU,CACpB,UAAU,EACV;IACE,kCAAkC,EAAE,CAACJ,kBAAkB;IACvD,oBAAoB,EAAEL,IAAI,KAAK;GAChC,EACDH,SAAS,CACV;EACD,MAAMa,MAAM,GAAGD,UAAU,CACvB,iBAAiB,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AK;;AACV,MAAA,CAAAM,EAAA,GAAA,MAAAtC,QAAQ,CAACgC,OAAO,MAAE,IAAA,IAAAO,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAAA,EAAA,CAAAG,UAAU,kDAAI;KACjC;AACH,GAAC,EAAE,CAAClC,QAAQ,EAAEH,GAAG,CAAC,CAAC;AAEnB,EAAA,oBACEsC,GAAA,CAAA,KAAA,EAAA;AAAKxC,IAAAA,SAAS,EAAEW,GAAI;AAACV,IAAAA,KAAK,EAAEA,KAAM;AAACwC,IAAAA,GAAG,EAAElC,YAAa;AAAA,IAAA,GAAKE,KAAK;IAAAiC,QAAA,EAC5DrC,QAAQ,gBACPmC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAKhD,MAAM,CAACkC,OAAO,GAAGc,GAAK;AACnC3C,MAAAA,SAAS,EAAEa,MAAO;AAClB,MAAA,UAAA,EAAUX,GAAI;AACdiB,MAAAA,MAAM,EAAEH,WAAY;AACpBZ,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KAAS,CACb,gBAEFkC,GAAA,CAAA,KAAA,EAAA;AACEC,MAAAA,GAAG,EAAEE,GAAG,IAAKhD,MAAM,CAACkC,OAAO,GAAGc,GAAK;AACnC3C,MAAAA,SAAS,EAAEa,MAAO;AAClBX,MAAAA,GAAG,EAAEA,GAAI;AACTiB,MAAAA,MAAM,EAAEH,WAAY;AACpBZ,MAAAA,OAAO,EAAEA,OAAQ;MAAA,GACbE;KACJ;AACH,GACE,CAAC;AAEV;AAEA,YAAesC,yBAAyB,CAACnD,KAAK,CAAC;;;;"}
@@ -0,0 +1,628 @@
1
+ import { logPrefix } from './common.js';
2
+ import { MethodHandler } from './handler.js';
3
+
4
+ /* eslint-disable no-console */
5
+ /**
6
+ * 全局地图实例存储
7
+ * key: Map 组件的 id
8
+ * value: TMap.Map 实例
9
+ */
10
+ const mapInstances = new Map();
11
+ /**
12
+ * 注册地图实例(同时创建 MapContextImpl 并挂载到 window)
13
+ * @param id Map 组件的 id
14
+ * @param instance 地图实例
15
+ */
16
+ function registerMapInstance(id, instance) {
17
+ mapInstances.set(id, instance);
18
+ console.log(logPrefix, '[MapContext] 注册地图实例:', id, instance);
19
+ // ✅ 方案 F:创建 MapContextImpl 并挂载到 window
20
+ if (typeof window !== 'undefined') {
21
+ // 确保 window 对象存在
22
+ if (!window.__TARO_MAP_CONTEXTS__) {
23
+ window.__TARO_MAP_CONTEXTS__ = new Map();
24
+ }
25
+ // ✅ 在这里 new MapContextImpl(有 TMap 类型)
26
+ const contextImpl = new MapContextImpl(instance);
27
+ window.__TARO_MAP_CONTEXTS__.set(id, contextImpl);
28
+ console.log(logPrefix, '[MapContext] 挂载 MapContextImpl 到 window:', id);
29
+ }
30
+ }
31
+ /**
32
+ * 注销地图实例(同时清理 window)
33
+ * @param id Map 组件的 id
34
+ */
35
+ function unregisterMapInstance(id) {
36
+ var _a;
37
+ mapInstances.delete(id);
38
+ console.log(logPrefix, '[MapContext] 注销地图实例:', id);
39
+ // ✅ 从 window 清理 MapContextImpl
40
+ if (typeof window !== 'undefined') {
41
+ (_a = window.__TARO_MAP_CONTEXTS__) === null || _a === void 0 ? void 0 : _a.delete(id);
42
+ console.log(logPrefix, '[MapContext] 从 window 清理 MapContextImpl:', id);
43
+ }
44
+ }
45
+ /**
46
+ * 获取地图实例
47
+ * @param id Map 组件的 id
48
+ * @returns 地图实例,如果不存在则返回 undefined
49
+ */
50
+ function getMapInstance(id) {
51
+ return mapInstances.get(id);
52
+ }
53
+ /**
54
+ * MapContext 实现类
55
+ * 将腾讯地图 API 适配到 Taro MapContext 接口
56
+ */
57
+ class MapContextImpl {
58
+ constructor(map) {
59
+ this.map = map;
60
+ if (!map) {
61
+ console.warn(logPrefix, '[MapContext] 地图实例为空,部分方法将不可用');
62
+ }
63
+ }
64
+ /**
65
+ * 缩放视野包含所有经纬度
66
+ * @supported weapp, tt
67
+ */
68
+ includePoints(option) {
69
+ const handle = new MethodHandler({
70
+ name: 'includePoints',
71
+ success: option === null || option === void 0 ? void 0 : option.success,
72
+ fail: option === null || option === void 0 ? void 0 : option.fail,
73
+ complete: option === null || option === void 0 ? void 0 : option.complete
74
+ });
75
+ if (!this.map) {
76
+ return handle.fail({
77
+ errMsg: '地图实例不存在'
78
+ });
79
+ }
80
+ try {
81
+ const {
82
+ points,
83
+ padding
84
+ } = option;
85
+ console.log(logPrefix, '[MapContext.includePoints] 开始执行:', {
86
+ points,
87
+ padding
88
+ });
89
+ // 创建空的 LatLngBounds
90
+ const bounds = new TMap.LatLngBounds();
91
+ // 转换坐标格式: {latitude, longitude} -> TMap.LatLng 并扩展边界
92
+ points.forEach(p => {
93
+ const latLng = new TMap.LatLng(p.latitude, p.longitude);
94
+ bounds.extend(latLng);
95
+ });
96
+ console.log(logPrefix, '[MapContext.includePoints] LatLngBounds:', bounds, 'padding:', padding);
97
+ // 转换 padding 格式: Taro [top, right, bottom, left] -> TMap {top, right, bottom, left}
98
+ let paddingOption;
99
+ if (padding) {
100
+ if (Array.isArray(padding)) {
101
+ // padding 是数组格式 [top, right, bottom, left]
102
+ paddingOption = {
103
+ top: padding[0],
104
+ right: padding[1],
105
+ bottom: padding[2],
106
+ left: padding[3]
107
+ };
108
+ } else {
109
+ // padding 是数字格式,直接使用
110
+ paddingOption = padding;
111
+ }
112
+ }
113
+ // 调用地图的 fitBounds 方法
114
+ this.map.fitBounds(bounds, {
115
+ padding: paddingOption
116
+ });
117
+ console.log(logPrefix, '[MapContext.includePoints] 执行成功');
118
+ return handle.success({});
119
+ } catch (error) {
120
+ console.error(logPrefix, '[MapContext.includePoints] 执行失败:', error);
121
+ return handle.fail({
122
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
123
+ });
124
+ }
125
+ }
126
+ /**
127
+ * 获取当前地图中心的经纬度
128
+ * @supported weapp, tt
129
+ */
130
+ getCenterLocation(option) {
131
+ const handle = new MethodHandler({
132
+ name: 'getCenterLocation',
133
+ success: option === null || option === void 0 ? void 0 : option.success,
134
+ fail: option === null || option === void 0 ? void 0 : option.fail,
135
+ complete: option === null || option === void 0 ? void 0 : option.complete
136
+ });
137
+ if (!this.map) {
138
+ return handle.fail({
139
+ errMsg: '地图实例不存在'
140
+ });
141
+ }
142
+ try {
143
+ // 调用腾讯地图 API: map.getCenter()
144
+ const center = this.map.getCenter();
145
+ console.log(logPrefix, '[MapContext.getCenterLocation] 执行成功:', center);
146
+ return handle.success({
147
+ latitude: center.lat,
148
+ longitude: center.lng
149
+ });
150
+ } catch (error) {
151
+ console.error(logPrefix, '[MapContext.getCenterLocation] 执行失败:', error);
152
+ return handle.fail({
153
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
154
+ });
155
+ }
156
+ }
157
+ /**
158
+ * 设置定位点图标
159
+ * @supported weapp, tt
160
+ */
161
+ setLocMarkerIcon(_option) {
162
+ console.warn(logPrefix, '[MapContext.setLocMarkerIcon] 暂未实现');
163
+ return Promise.reject(new Error('setLocMarkerIcon: 暂未实现'));
164
+ }
165
+ /**
166
+ * 将地图中心移置当前定位点
167
+ * @supported weapp, tt
168
+ */
169
+ moveToLocation(option) {
170
+ const handle = new MethodHandler({
171
+ name: 'moveToLocation',
172
+ success: option === null || option === void 0 ? void 0 : option.success,
173
+ fail: option === null || option === void 0 ? void 0 : option.fail,
174
+ complete: option === null || option === void 0 ? void 0 : option.complete
175
+ });
176
+ if (!this.map) {
177
+ return handle.fail({
178
+ errMsg: '地图实例不存在'
179
+ });
180
+ }
181
+ try {
182
+ const {
183
+ latitude,
184
+ longitude
185
+ } = option;
186
+ console.log(logPrefix, '[MapContext.moveToLocation] 开始执行:', {
187
+ latitude,
188
+ longitude
189
+ });
190
+ // 参数校验
191
+ if (latitude === undefined || longitude === undefined) {
192
+ return handle.fail({
193
+ errMsg: 'latitude 和 longitude 参数必须提供'
194
+ });
195
+ }
196
+ // 调用腾讯地图 API: map.panTo()
197
+ const latLng = new TMap.LatLng(latitude, longitude);
198
+ this.map.panTo(latLng, {});
199
+ console.log(logPrefix, '[MapContext.moveToLocation] 执行成功');
200
+ return handle.success({});
201
+ } catch (error) {
202
+ console.error(logPrefix, '[MapContext.moveToLocation] 执行失败:', error);
203
+ return handle.fail({
204
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
205
+ });
206
+ }
207
+ }
208
+ /**
209
+ * 平移marker,带动画
210
+ * @supported weapp, tt
211
+ */
212
+ translateMarker(_option) {
213
+ console.warn(logPrefix, '[MapContext.translateMarker] 暂未实现');
214
+ return Promise.reject(new Error('translateMarker: 暂未实现'));
215
+ }
216
+ /**
217
+ * 沿指定路径移动 marker
218
+ */
219
+ moveAlong(_object) {
220
+ console.warn(logPrefix, '[MapContext.moveAlong] 暂未实现');
221
+ throw new Error('moveAlong: 暂未实现');
222
+ }
223
+ /**
224
+ * 获取当前地图的视野范围
225
+ * @supported weapp, tt
226
+ */
227
+ getRegion(option) {
228
+ const handle = new MethodHandler({
229
+ name: 'getRegion',
230
+ success: option === null || option === void 0 ? void 0 : option.success,
231
+ fail: option === null || option === void 0 ? void 0 : option.fail,
232
+ complete: option === null || option === void 0 ? void 0 : option.complete
233
+ });
234
+ if (!this.map) {
235
+ return handle.fail({
236
+ errMsg: '地图实例不存在'
237
+ });
238
+ }
239
+ try {
240
+ // 调用腾讯地图 API: map.getBounds()
241
+ const bounds = this.map.getBounds();
242
+ console.log(logPrefix, '[MapContext.getRegion] 执行成功:', bounds);
243
+ const sw = bounds.getSouthWest();
244
+ const ne = bounds.getNorthEast();
245
+ return handle.success({
246
+ southwest: {
247
+ latitude: sw.lat,
248
+ longitude: sw.lng
249
+ },
250
+ northeast: {
251
+ latitude: ne.lat,
252
+ longitude: ne.lng
253
+ }
254
+ });
255
+ } catch (error) {
256
+ console.error(logPrefix, '[MapContext.getRegion] 执行失败:', error);
257
+ return handle.fail({
258
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
259
+ });
260
+ }
261
+ }
262
+ /**
263
+ * 获取当前地图的旋转角
264
+ * @supported weapp, tt
265
+ */
266
+ getRotate(option) {
267
+ const handle = new MethodHandler({
268
+ name: 'getRotate',
269
+ success: option === null || option === void 0 ? void 0 : option.success,
270
+ fail: option === null || option === void 0 ? void 0 : option.fail,
271
+ complete: option === null || option === void 0 ? void 0 : option.complete
272
+ });
273
+ if (!this.map) {
274
+ return handle.fail({
275
+ errMsg: '地图实例不存在'
276
+ });
277
+ }
278
+ try {
279
+ // 调用腾讯地图 API: map.getRotation()
280
+ const rotate = this.map.getRotation();
281
+ console.log(logPrefix, '[MapContext.getRotate] 执行成功:', rotate);
282
+ return handle.success({
283
+ rotate: rotate
284
+ });
285
+ } catch (error) {
286
+ console.error(logPrefix, '[MapContext.getRotate] 执行失败:', error);
287
+ return handle.fail({
288
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
289
+ });
290
+ }
291
+ }
292
+ /**
293
+ * 获取当前地图的倾斜角
294
+ * @supported weapp, tt
295
+ */
296
+ getSkew(option) {
297
+ const handle = new MethodHandler({
298
+ name: 'getSkew',
299
+ success: option === null || option === void 0 ? void 0 : option.success,
300
+ fail: option === null || option === void 0 ? void 0 : option.fail,
301
+ complete: option === null || option === void 0 ? void 0 : option.complete
302
+ });
303
+ if (!this.map) {
304
+ return handle.fail({
305
+ errMsg: '地图实例不存在'
306
+ });
307
+ }
308
+ try {
309
+ // 调用腾讯地图 API: map.getPitch()
310
+ const skew = this.map.getPitch();
311
+ console.log(logPrefix, '[MapContext.getSkew] 执行成功:', skew);
312
+ return handle.success({
313
+ skew: skew
314
+ });
315
+ } catch (error) {
316
+ console.error(logPrefix, '[MapContext.getSkew] 执行失败:', error);
317
+ return handle.fail({
318
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
319
+ });
320
+ }
321
+ }
322
+ /**
323
+ * 获取当前地图的缩放级别
324
+ * @supported weapp, tt
325
+ */
326
+ getScale(option) {
327
+ const handle = new MethodHandler({
328
+ name: 'getScale',
329
+ success: option === null || option === void 0 ? void 0 : option.success,
330
+ fail: option === null || option === void 0 ? void 0 : option.fail,
331
+ complete: option === null || option === void 0 ? void 0 : option.complete
332
+ });
333
+ if (!this.map) {
334
+ return handle.fail({
335
+ errMsg: '地图实例不存在'
336
+ });
337
+ }
338
+ try {
339
+ // 调用腾讯地图 API: map.getZoom()
340
+ const scale = this.map.getZoom();
341
+ console.log(logPrefix, '[MapContext.getScale] 执行成功:', scale);
342
+ return handle.success({
343
+ scale: scale
344
+ });
345
+ } catch (error) {
346
+ console.error(logPrefix, '[MapContext.getScale] 执行失败:', error);
347
+ return handle.fail({
348
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
349
+ });
350
+ }
351
+ }
352
+ /**
353
+ * 设置地图中心点偏移
354
+ * @supported weapp, tt
355
+ */
356
+ setCenterOffset(option) {
357
+ const handle = new MethodHandler({
358
+ name: 'setCenterOffset',
359
+ success: option === null || option === void 0 ? void 0 : option.success,
360
+ fail: option === null || option === void 0 ? void 0 : option.fail,
361
+ complete: option === null || option === void 0 ? void 0 : option.complete
362
+ });
363
+ if (!this.map) {
364
+ return handle.fail({
365
+ errMsg: '地图实例不存在'
366
+ });
367
+ }
368
+ try {
369
+ const {
370
+ offset
371
+ } = option;
372
+ console.log(logPrefix, '[MapContext.setCenterOffset] 开始执行:', {
373
+ offset
374
+ });
375
+ // 转换 offset 格式: Taro [x, y] -> TMap {x, y}
376
+ const offsetOption = {
377
+ x: offset[0],
378
+ y: offset[1]
379
+ };
380
+ // 调用腾讯地图 API: map.setOffset()
381
+ this.map.setOffset(offsetOption);
382
+ console.log(logPrefix, '[MapContext.setCenterOffset] 执行成功');
383
+ return handle.success({});
384
+ } catch (error) {
385
+ console.error(logPrefix, '[MapContext.setCenterOffset] 执行失败:', error);
386
+ return handle.fail({
387
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
388
+ });
389
+ }
390
+ }
391
+ /**
392
+ * 移除个性化图层
393
+ * @supported weapp
394
+ */
395
+ removeCustomLayer(option) {
396
+ console.warn(logPrefix, '[MapContext.removeCustomLayer] 暂未实现', option);
397
+ return Promise.reject(new Error('removeCustomLayer: 暂未实现'));
398
+ }
399
+ /**
400
+ * 添加个性化图层
401
+ * @supported weapp
402
+ */
403
+ addCustomLayer(option) {
404
+ console.warn(logPrefix, '[MapContext.addCustomLayer] 暂未实现', option);
405
+ return Promise.reject(new Error('addCustomLayer: 暂未实现'));
406
+ }
407
+ /**
408
+ * 创建自定义图片图层
409
+ * @supported weapp, tt
410
+ */
411
+ addGroundOverlay(option) {
412
+ console.warn(logPrefix, '[MapContext.addGroundOverlay] 暂未实现', option);
413
+ return Promise.reject(new Error('addGroundOverlay: 暂未实现'));
414
+ }
415
+ /**
416
+ * 添加可视化图层
417
+ * @supported weapp
418
+ */
419
+ addVisualLayer(option) {
420
+ console.warn(logPrefix, '[MapContext.addVisualLayer] 暂未实现', option);
421
+ return Promise.reject(new Error('addVisualLayer: 暂未实现'));
422
+ }
423
+ /**
424
+ * 移除可视化图层
425
+ * @supported weapp
426
+ */
427
+ removeVisualLayer(option) {
428
+ console.warn(logPrefix, '[MapContext.removeVisualLayer] 暂未实现', option);
429
+ return Promise.reject(new Error('removeVisualLayer: 暂未实现'));
430
+ }
431
+ /**
432
+ * 添加弧线
433
+ * @supported weapp
434
+ */
435
+ addArc(option) {
436
+ console.warn(logPrefix, '[MapContext.addArc] 暂未实现', option);
437
+ return Promise.reject(new Error('addArc: 暂未实现'));
438
+ }
439
+ /**
440
+ * 删除弧线
441
+ * @supported weapp
442
+ */
443
+ removeArc(option) {
444
+ console.warn(logPrefix, '[MapContext.removeArc] 暂未实现', option);
445
+ return Promise.reject(new Error('removeArc: 暂未实现'));
446
+ }
447
+ /**
448
+ * 限制地图的显示范围
449
+ * @supported weapp
450
+ */
451
+ setBoundary(option) {
452
+ const handle = new MethodHandler({
453
+ name: 'setBoundary',
454
+ success: option === null || option === void 0 ? void 0 : option.success,
455
+ fail: option === null || option === void 0 ? void 0 : option.fail,
456
+ complete: option === null || option === void 0 ? void 0 : option.complete
457
+ });
458
+ if (!this.map) {
459
+ return handle.fail({
460
+ errMsg: '地图实例不存在'
461
+ });
462
+ }
463
+ try {
464
+ const {
465
+ southwest,
466
+ northeast
467
+ } = option;
468
+ console.log(logPrefix, '[MapContext.setBoundary] 开始执行:', {
469
+ southwest,
470
+ northeast
471
+ });
472
+ // 转换坐标格式: {latitude, longitude} -> TMap.LatLng
473
+ const sw = new TMap.LatLng(southwest.latitude, southwest.longitude);
474
+ const ne = new TMap.LatLng(northeast.latitude, northeast.longitude);
475
+ const bounds = new TMap.LatLngBounds(sw, ne);
476
+ // 调用腾讯地图 API: map.setBoundary()
477
+ this.map.setBoundary(bounds);
478
+ console.log(logPrefix, '[MapContext.setBoundary] 执行成功');
479
+ return handle.success({});
480
+ } catch (error) {
481
+ console.error(logPrefix, '[MapContext.setBoundary] 执行失败:', error);
482
+ return handle.fail({
483
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
484
+ });
485
+ }
486
+ }
487
+ /**
488
+ * 更新自定义图片图层
489
+ * @supported weapp, tt
490
+ */
491
+ updateGroundOverlay(option) {
492
+ console.warn(logPrefix, '[MapContext.updateGroundOverlay] 暂未实现', option);
493
+ return Promise.reject(new Error('updateGroundOverlay: 暂未实现'));
494
+ }
495
+ /**
496
+ * 移除自定义图片图层
497
+ * @supported weapp, tt
498
+ */
499
+ removeGroundOverlay(option) {
500
+ console.warn(logPrefix, '[MapContext.removeGroundOverlay] 暂未实现', option);
501
+ return Promise.reject(new Error('removeGroundOverlay: 暂未实现'));
502
+ }
503
+ /**
504
+ * 获取经纬度对应的屏幕坐标
505
+ * @supported weapp
506
+ */
507
+ toScreenLocation(option) {
508
+ const handle = new MethodHandler({
509
+ name: 'toScreenLocation',
510
+ success: option === null || option === void 0 ? void 0 : option.success,
511
+ fail: option === null || option === void 0 ? void 0 : option.fail,
512
+ complete: option === null || option === void 0 ? void 0 : option.complete
513
+ });
514
+ if (!this.map) {
515
+ return handle.fail({
516
+ errMsg: '地图实例不存在'
517
+ });
518
+ }
519
+ try {
520
+ const {
521
+ latitude,
522
+ longitude
523
+ } = option;
524
+ console.log(logPrefix, '[MapContext.toScreenLocation] 开始执行:', {
525
+ latitude,
526
+ longitude
527
+ });
528
+ // 转换坐标格式: {latitude, longitude} -> TMap.LatLng
529
+ const latLng = new TMap.LatLng(latitude, longitude);
530
+ // 调用腾讯地图 API: map.projectToContainer()
531
+ const point = this.map.projectToContainer(latLng);
532
+ console.log(logPrefix, '[MapContext.toScreenLocation] 执行成功:', point);
533
+ return handle.success({
534
+ x: point.x,
535
+ y: point.y
536
+ });
537
+ } catch (error) {
538
+ console.error(logPrefix, '[MapContext.toScreenLocation] 执行失败:', error);
539
+ return handle.fail({
540
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
541
+ });
542
+ }
543
+ }
544
+ /**
545
+ * 获取屏幕上的点对应的经纬度
546
+ * @supported weapp
547
+ */
548
+ fromScreenLocation(option) {
549
+ const handle = new MethodHandler({
550
+ name: 'fromScreenLocation',
551
+ success: option === null || option === void 0 ? void 0 : option.success,
552
+ fail: option === null || option === void 0 ? void 0 : option.fail,
553
+ complete: option === null || option === void 0 ? void 0 : option.complete
554
+ });
555
+ if (!this.map) {
556
+ return handle.fail({
557
+ errMsg: '地图实例不存在'
558
+ });
559
+ }
560
+ try {
561
+ const {
562
+ x,
563
+ y
564
+ } = option;
565
+ console.log(logPrefix, '[MapContext.fromScreenLocation] 开始执行:', {
566
+ x,
567
+ y
568
+ });
569
+ // 转换坐标格式: {x, y} -> TMap.Point
570
+ const point = new TMap.Point(x, y);
571
+ // 调用腾讯地图 API: map.unprojectFromContainer()
572
+ const latLng = this.map.unprojectFromContainer(point);
573
+ console.log(logPrefix, '[MapContext.fromScreenLocation] 执行成功:', latLng);
574
+ return handle.success({
575
+ latitude: latLng.lat,
576
+ longitude: latLng.lng
577
+ });
578
+ } catch (error) {
579
+ console.error(logPrefix, '[MapContext.fromScreenLocation] 执行失败:', error);
580
+ return handle.fail({
581
+ errMsg: (error === null || error === void 0 ? void 0 : error.message) || String(error)
582
+ });
583
+ }
584
+ }
585
+ /**
586
+ * 拉起地图APP选择导航
587
+ * @supported weapp
588
+ */
589
+ openMapApp(option) {
590
+ console.warn(logPrefix, '[MapContext.openMapApp] 暂未实现', option);
591
+ return Promise.reject(new Error('openMapApp: 暂未实现'));
592
+ }
593
+ /**
594
+ * 添加 marker
595
+ * @supported weapp
596
+ */
597
+ addMarkers(option) {
598
+ console.warn(logPrefix, '[MapContext.addMarkers] 暂未实现', option);
599
+ return Promise.reject(new Error('addMarkers: 暂未实现'));
600
+ }
601
+ /**
602
+ * 移除 marker
603
+ * @supported weapp
604
+ */
605
+ removeMarkers(option) {
606
+ console.warn(logPrefix, '[MapContext.removeMarkers] 暂未实现', option);
607
+ return Promise.reject(new Error('removeMarkers: 暂未实现'));
608
+ }
609
+ /**
610
+ * 初始化点聚合的配置
611
+ * @supported weapp
612
+ */
613
+ initMarkerCluster(option) {
614
+ console.warn(logPrefix, '[MapContext.initMarkerCluster] 暂未实现', option);
615
+ return Promise.reject(new Error('initMarkerCluster: 暂未实现'));
616
+ }
617
+ /**
618
+ * 监听地图事件
619
+ * @supported weapp
620
+ */
621
+ on(event, callback) {
622
+ console.warn(logPrefix, '[MapContext.on] 暂未实现', event, callback);
623
+ throw new Error('on: 暂未实现');
624
+ }
625
+ }
626
+
627
+ export { MapContextImpl as MapContext, MapContextImpl, getMapInstance, registerMapInstance, unregisterMapInstance };
628
+ //# sourceMappingURL=MapContext.js.map