UNPKG

16.5 kBTypeScriptView Raw
1import { ComponentType } from 'react'
2import { StandardProps, CommonEventFunction } from './common'
3interface MapProps extends StandardProps {
4 /** 中心经度
5 * @supported weapp, alipay, swan, tt, qq, jd
6 */
7 longitude: number
8
9 /** 中心纬度
10 * @supported weapp, alipay, swan, tt, qq, jd
11 */
12 latitude: number
13
14 /** 缩放级别,取值范围为 3-20
15 * @default 16
16 * @supported weapp, alipay, swan, tt, qq, jd
17 * @swan 取值范围为4-21
18 * @alipay 取值范围为5-18
19 */
20 scale?: number
21
22 /** 最小缩放级别 3-20
23 * @default 3
24 * @supported weapp, tt
25 */
26 minScale?: number
27
28 /** 最大缩放级别 3-20
29 * @default 20
30 * @supported weapp, tt
31 */
32 maxScale?: number
33
34 /** 标记点
35 * @supported weapp, alipay, swan, tt, qq, jd
36 */
37 markers?: MapProps.marker[]
38
39 /** 标记点
40 * @supported weapp
41 */
42 covers?: any[]
43
44 /** 路线
45 * @supported weapp, alipay, swan, tt, qq, jd
46 */
47 polyline?: MapProps.polyline[]
48
49 /** 圆
50 * @supported weapp, alipay, swan, tt, qq, jd
51 */
52 circles?: MapProps.circle[]
53
54 /** 控件(即将废弃,建议使用 cover-view 代替)
55 * @deprecated
56 * @supported weapp, alipay, swan, jd
57 */
58 controls?: MapProps.control[]
59
60 /** 缩放视野以包含所有给定的坐标点
61 * @supported weapp, alipay, swan, tt, qq, jd
62 */
63 includePoints?: MapProps.point[]
64
65 /** 显示带有方向的当前定位点
66 * @default false
67 * @supported weapp, alipay, swan, tt, qq, jd
68 */
69 showLocation?: boolean
70
71 /** 多边形
72 * @supported weapp, swan, tt, qq
73 */
74 polygons?: MapProps.polygon[]
75
76 /** 个性化地图使用的 key
77 * @supported weapp, qq
78 */
79 subkey?: string
80
81 /** 个性化地图配置的 style,不支持动态修改
82 * @default 1
83 * @supported weapp, qq
84 */
85 layerStyle?: number
86
87 /** 旋转角度,范围 0 ~ 360, 地图正北和设备 y 轴角度的夹角
88 * @default 0
89 * @supported weapp, alipay, tt, qq
90 */
91 rotate?: number
92
93 /** 倾斜角度,范围 0 ~ 40 , 关于 z 轴的倾角
94 * @default 0
95 * @supported weapp, alipay, tt, qq
96 */
97 skew?: number
98
99 /** 显示指南针
100 * @default false
101 * @supported weapp, alipay, swan, tt, qq
102 */
103 showCompass?: boolean
104
105 /** 显示比例尺
106 * @default false
107 * @supported weapp, alipay, tt, qq
108 */
109 showScale?: boolean
110
111 /** 开启俯视
112 * @default false
113 * @supported weapp, alipay, swan, tt, qq
114 */
115 enableOverlooking?: boolean
116
117 /** 是否支持缩放
118 * @default true
119 * @supported weapp, alipay, swan, tt, qq
120 */
121 enableZoom?: boolean
122
123 /** 是否支持拖动
124 * @default true
125 * @supported weapp, alipay, swan, tt, qq
126 */
127 enableScroll?: boolean
128
129 /** 是否支持旋转
130 * @default false
131 * @supported weapp, alipay, swan, tt, qq
132 */
133 enableRotate?: boolean
134
135 /** 是否开启卫星图
136 * @default false
137 * @supported weapp, alipay, tt, qq
138 */
139 enableSatellite?: boolean
140
141 /** 是否开启实时路况
142 * @default false
143 * @supported weapp, alipay, tt, qq
144 */
145 enableTraffic?: boolean
146
147 /** 配置项
148 *
149 * 提供 setting 对象统一设置地图配置。同时对于一些动画属性如 rotate 和 skew,通过 setData 分开设置时无法同时生效,需通过 settting 统一修改。
150 * @supported weapp, alipay, qq
151 */
152 setting?:
153 | MapProps
154 | {
155 [key: string]: number | string | any
156 }
157
158 /** 视野在地图 padding 范围内展示
159 * @supported alipay
160 */
161 includePadding?: { [key in 'left' | 'right' | 'top' | 'bottom']: number | string }
162
163 /** 覆盖物,自定义贴图
164 * @supported alipay
165 */
166 groundOverlays?: any[]
167
168 /** 覆盖物,网格贴图
169 * @supported alipay
170 */
171 tileOverlay?: any[]
172
173 /** 是否展示 POI 点
174 * @supported weapp, alipay, tt
175 */
176 enablePoi?: string
177
178 /** 是否展示建筑物
179 * @supported weapp, alipay, tt
180 */
181 enableBuilding?: string
182
183 /** 覆盖物,多边形。
184 * @supported alipay
185 */
186 polygon?: string
187
188 /** 设置地图样式。
189 *
190 * default:默认样式
191 * light:精简样式
192 * @supported alipay
193 */
194 customMapStyle?: string
195
196 /** 基于 map 高级定制渲染,设置覆盖在地图上的 view。
197 * @supported alipay
198 */
199 panels?: string
200
201 /** 否
202 * @supported jd
203 */
204 theme?: string
205
206 /** 内联样式。
207 * @supported alipay
208 */
209 optimize?: string
210
211 /** 展示3D楼块
212 * @supported weapp, swan, tt, qq
213 * @default false
214 */
215 enable3D?: boolean
216
217 /** 点击地图时触发
218 * @supported weapp, alipay, swan, tt, qq, jd
219 */
220 onTap?: CommonEventFunction
221
222 /** 点击标记点时触发,e.detail = {markerId}
223 * @supported weapp, alipay, swan, tt, qq, jd
224 */
225 onMarkerTap?: CommonEventFunction<MapProps.onMarkerTapEventDetail>
226
227 /** 点击label时触发,e.detail = {markerId}
228 * @supported weapp, tt
229 */
230 onLabelTap?: CommonEventFunction<MapProps.onLabelTapEventDetail>
231
232 /** 点击控件时触发,e.detail = {controlId}
233 * @supported weapp, alipay, swan, jd
234 */
235 onControlTap?: CommonEventFunction<MapProps.onControlTapEventDetail>
236
237 /** 点击标记点对应的气泡时触发,e.detail = {markerId}
238 * @supported alipay
239 */
240 onCalloutTap?: CommonEventFunction<MapProps.onCalloutTapEventDetail>
241
242 /** 在地图渲染更新完成时触发
243 * @supported weapp, swan, tt, qq
244 */
245 onUpdated?: CommonEventFunction
246
247 /** 视野发生变化时触发
248 * @supported weapp, alipay, swan, tt, qq, jd
249 */
250 onRegionChange?: CommonEventFunction<MapProps.onRegionEventDetail<'begin'> | MapProps.onRegionEventDetail<'end'>>
251
252 /** 点击地图poi点时触发,e.detail = {name, longitude, latitude}
253 * @supported weapp, swan, qq
254 */
255 onPoiTap?: CommonEventFunction<MapProps.onPoiTapEventDetail>
256
257 /** 点击标记点对应的气泡时触发e.detail = {markerId}
258 * @supported weapp, swan, tt, jd
259 */
260 onCallOutTap?: CommonEventFunction
261
262 /** 点击定位标时触发,e.detail = {longitude, latitude}
263 * @supported weapp, tt
264 */
265 onAnchorPointTap?: CommonEventFunction
266
267 /** 点击 panel 时触发。
268 * @supported alipay
269 */
270 onPanelTap?: CommonEventFunction<{
271 panelId
272 layoutId
273 }>
274
275 /** 地图初始化完成即将开始渲染第一帧时触发。
276 * @supported alipay
277 */
278 onInitComplete?: CommonEventFunction
279}
280declare namespace MapProps {
281 /** 标记点用于在地图上显示标记的位置 */
282 interface marker {
283 /** 标记点id
284 * @remarks marker 点击事件回调会返回此id。建议为每个 marker 设置上 Number 类型 id,保证更新 marker 时有更好的性能。
285 */
286 id?: number
287
288 /** 纬度
289 * @remarks 浮点数,范围 -90 ~ 90
290 */
291 latitude: number
292
293 /** 经度
294 * @remarks 浮点数,范围 -180 ~ 180
295 */
296 longitude: number
297
298 /** 标注点名
299 * @remarks 点击时显示,callout 存在时将被忽略
300 */
301 title?: string
302
303 /** 显示层级
304 */
305 zIndex?: number
306
307 /** 显示的图标
308 * @remarks 项目目录下的图片路径,支持相对路径写法,以'/'开头则表示相对小程序根目录;也支持临时路径和网络图片
309 */
310 iconPath: string
311
312 /** 旋转角度
313 * @remarks 顺时针旋转的角度,范围 0 ~ 360,默认为 0
314 */
315 rotate?: number
316
317 /** 标注的透明度
318 * @remarks 默认1,无透明,范围 0 ~ 1
319 */
320 alpha?: number
321
322 /** 标注图标宽度
323 * @remarks 默认为图片实际宽度
324 */
325 width?: number | string
326
327 /** 标注图标高度
328 * @remarks 默认为图片实际高度
329 */
330 height?: number | string
331
332 /** 标记点上方的气泡窗口
333 * @remarks 支持的属性见下表,可识别换行符。
334 */
335 callout?: callout
336
337 /** 自定义气泡窗口
338 * @remarks 支持的属性见下表,可识别换行符。
339 */
340 customCallout?: customCallout
341
342 /** 为标记点旁边增加标签
343 * @remarks 支持的属性见下表
344 */
345 label?: label
346
347 /** 经纬度在标注图标的锚点,默认底边中点
348 * @remarks {x, y},x表示横向(0-1),y表示竖向(0-1)。{x: .5, y: 1} 表示底边中点
349 */
350 anchor?: {
351 x: number
352 y: number
353 }
354
355 /** 无障碍访问,(属性)元素的额外描述 */
356 ariaLabel?: string
357 }
358
359 /** marker 上的气泡 callout */
360 interface callout {
361 /** 文本 */
362 content: string
363
364 /** 文本颜色 */
365 color: string
366
367 /** 文字大小 */
368 fontSize: number
369
370 /** 横向偏移量,向右为正数 */
371 anchorX: number
372
373 /** 纵向偏移量,向下为正数 */
374 anchorY: number
375
376 /** 边框圆角 */
377 borderRadius: number
378
379 /** 边框宽度 */
380 borderWidth: number
381
382 /** 边框颜色 */
383 borderColor: string
384
385 /** 背景色 */
386 bgColor: string
387
388 /** 文本边缘留白 */
389 padding: number
390
391 /** 'BYCLICK':点击显示; 'ALWAYS':常显 */
392 display: 'BYCLICK' | 'ALWAYS'
393
394 /** 文本对齐方式。有效值: left, right, center */
395 textAlign: 'left' | 'right' | 'center'
396 }
397
398 /** marker 上的自定义气泡 customCallout
399 *
400 * `customCallout` 存在时将忽略 `callout` 与 `title` 属性。自定义气泡采用采用 `cover-view` 定制,灵活度更高。
401 */
402 interface customCallout {
403 /** 'BYCLICK':点击显示; 'ALWAYS':常显 */
404 display: 'BYCLICK' | 'ALWAYS' | string
405
406 /** 横向偏移量,向右为正数 */
407 anchorX: number
408
409 /** 纵向偏移量,向下为正数 */
410 anchorY: number
411 }
412
413 /** marker 上的气泡 label */
414 interface label {
415 /** 文本 */
416 content: string
417
418 /** 文本颜色 */
419 color: string
420
421 /** 文字大小 */
422 fontSize: number
423
424 /** label的坐标,原点是 marker 对应的经纬度 */
425 anchorX: number
426
427 /** label的坐标,原点是 marker 对应的经纬度 */
428 anchorY: number
429
430 /** 边框宽度 */
431 borderWidth: number
432
433 /** 边框颜色 */
434 borderColor: string
435
436 /** 边框圆角 */
437 borderRadius: number
438
439 /** 背景色 */
440 bgColor: string
441
442 /** 文本边缘留白 */
443 padding: number
444
445 /** 文本对齐方式。有效值: left, right, center */
446 textAlign: 'left' | 'right' | 'center'
447 }
448
449 /** 指定一系列坐标点,从数组第一项连线至最后一项 */
450 interface polyline {
451 /** 经纬度数组
452 * @remarks [{latitude: 0, longitude: 0}]
453 */
454 points: point[]
455
456 /** 线的颜色
457 * @remarks 十六进制
458 */
459 color?: string
460
461 /** 线的宽度 */
462 width?: number
463
464 /** 是否虚线
465 * @remarks 默认 false
466 */
467 dottedLine?: boolean
468
469 /** 带箭头的线
470 * @remarks 默认 false,开发者工具暂不支持该属性
471 */
472 arrowLine?: boolean
473
474 /** 更换箭头图标
475 * @remarks 在 arrowLine 为 true 时生效
476 */
477 arrowIconPath?: string
478
479 /** 线的边框颜色 */
480 borderColor?: string
481
482 /** 线的厚度 */
483 borderWidth?: number
484 }
485
486 /** 指定一系列坐标点,根据 points 坐标数据生成闭合多边形 */
487 interface polygon {
488 /** 经纬度数组
489 * @remarks [{latitude: 0, longitude: 0}]
490 */
491 points: point[]
492
493 /** 描边的宽度 */
494 strokeWidth?: number
495
496 /** 描边的颜色
497 * @remarks 十六进制
498 */
499 strokeColor?: string
500
501 /** 填充颜色
502 * @remarks 十六进制
503 */
504 fillColor?: string
505
506 /** 设置多边形Z轴数值 */
507 zIndex?: number
508 }
509
510 /** 在地图上显示圆 */
511 interface circle {
512 /** 纬度
513 * @remarks 浮点数,范围 -90 ~ 90
514 */
515 latitude: number
516
517 /** 经度
518 * @remarks 浮点数,范围 -180 ~ 180
519 */
520 longitude?: number
521
522 /** 描边的颜色
523 * @remarks 十六进制
524 */
525 color?: string
526
527 /** 填充颜色
528 * @remarks 十六进制
529 */
530 fillColor?: string
531
532 /** 半径 */
533 radius: number
534
535 /** 描边的宽度 */
536 strokeWidth?: number
537 }
538
539 /** 在地图上显示控件,控件不随着地图移动。即将废弃,请使用 cover-view
540 * @deprecated
541 */
542 interface control {
543 /** 控件id
544 * @remarks 在控件点击事件回调会返回此id
545 */
546 id?: number
547
548 /** 控件在地图的位置
549 * @remarks 控件相对地图位置
550 */
551 position: position
552
553 /** 显示的图标
554 * @remarks 项目目录下的图片路径,支持本地路径、代码包路径
555 */
556 iconPath: string
557
558 /** 是否可点击
559 * @remarks 默认不可点击
560 */
561 clickable?: boolean
562 }
563 interface point {
564 /** 经度 */
565 longitude: number
566
567 /** 纬度 */
568 latitude: number
569 }
570 interface position {
571 /** 距离地图的左边界多远
572 * @default 0
573 */
574 left: number
575
576 /** 距离地图的上边界多远
577 * @default 0
578 */
579 top: number
580
581 /** 控件宽度
582 * @default 图片宽度
583 */
584 width: number
585
586 /** 控件高度
587 * @default 图片宽度
588 */
589 height: number
590 }
591 interface onMarkerTapEventDetail {
592 markerId: number | string
593 }
594 interface onLabelTapEventDetail {
595 markerId: number | string
596 }
597 interface onControlTapEventDetail {
598 controlId: number | string
599 }
600 interface onCalloutTapEventDetail {
601 markerId: number | string
602 }
603 namespace RegionChangeDetail {
604 interface type {
605 begin
606 end
607 }
608 interface CausedByBegin {
609 /** 手势触发 */
610 gesture
611
612 /** 接口触发 */
613 update
614 }
615 interface CausedByEnd {
616 /** 拖动导致 */
617 drag
618
619 /** 缩放导致 */
620 scale
621
622 /** 调用更新接口导致 */
623 update
624 }
625 }
626 interface onRegionEventDetail<T = keyof RegionChangeDetail.type> {
627 /** 视野变化开始、结束时触发
628 * @remarks 视野变化开始为begin,结束为end
629 */
630 type: T
631
632 /** 导致视野变化的原因
633 * @remarks 有效值为 gesture(手势触发)、update(接口触发或调用更新接口导致)、drag(拖动导致)、scale(缩放导致)
634 */
635 causedBy: keyof (T extends 'begin' ? RegionChangeDetail.CausedByBegin : RegionChangeDetail.CausedByEnd)
636
637 /** 视野改变详情 */
638 detail: regionChangeDetail<RegionChangeDetail.type>
639 }
640 interface regionChangeDetail<T = keyof RegionChangeDetail.type> {
641 /** 旋转角度 */
642 rotate: number
643
644 /** 倾斜角度 */
645 skew: number
646 causedBy: keyof (T extends 'begin' ? RegionChangeDetail.CausedByBegin : RegionChangeDetail.CausedByEnd)
647 type: T | string
648 scale: number
649 centerLocation: point
650 region: {
651 northeast: point
652 southeast: point
653 }
654 }
655 interface onPoiTapEventDetail {
656 name: string
657 longitude: number
658 latitude: number
659 }
660}
661
662/** 地图。相关api Taro.createMapContext。
663 * @classification maps
664 * @supported weapp, alipay, swan, tt, qq, jd
665 * @example_react
666 * ```tsx
667 * class App extends Component {
668 * onTap () {}
669 * render () {
670 * return (
671 * <Map onClick={this.onTap} />
672 * )
673 * }
674 * }
675 * ```
676 * @example_vue
677 * ```html
678 * <template>
679 * <map
680 * id="map"
681 * style="width: 100%; height: 300px;"
682 * longitude="113.324520"
683 * latitude="23.099994"
684 * scale="14"
685 * :markers="markers"
686 * :polyline="polyline"
687 * :show-location="true"
688 * `@regionchange="regionchange"
689 * `@markertap="markertap"
690 * />
691 * </template>
692 *
693 * <script>
694 * export default {
695 * data() {
696 * return {
697 * markers: [{
698 * iconPath: "https://avatars2.githubusercontent.com/u/1782542?s=460&u=d20514a52100ed1f82282bcfca6f49052793c889&v=4",
699 * id: 0,
700 * latitude: 23.099994,
701 * longitude: 113.324520,
702 * width: 50,
703 * height: 50
704 * }],
705 * polyline: [{
706 * points: [{
707 * longitude: 113.3245211,
708 * latitude: 23.10229
709 * }, {
710 * longitude: 113.324520,
711 * latitude: 23.21229
712 * }],
713 * color:"#FF0000DD",
714 * width: 2,
715 * dottedLine: true
716 * }]
717 * }
718 * },
719 * methods: {
720 * regionchange(e) {
721 * console.log(e.type)
722 * },
723 * markertap(e) {
724 * console.log("markertap:", e.detail.markerId)
725 * }
726 * }
727 * }
728 * </script>
729 * ```
730 * @see https://developers.weixin.qq.com/miniprogram/dev/component/map.html#map
731 */
732declare const Map: ComponentType<MapProps>
733export { Map, MapProps }