xwt
2 天以前 0d3eadb50310ca60b8871e967e64da01aa25a9ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
import { AsyncOptions } from './Utils';
 
declare global {
  namespace UniNamespace {
    interface MapContext {
      /**
       * 获取当前地图中心的经纬度,返回的是 gcj02 坐标系,可以用于 uni.openLocation
       */
      getCenterLocation(options: MapContextGetCenterLocationOptions): void;
      /**
       * 将地图中心移动到当前定位点,需要配合map组件的show-location使用
       */
      moveToLocation(options: MapContextMoveToLocationOptions): void;
      /**
       * 平移marker,带动画
       */
      translateMarker(options: MapContextTranslateMarkerOptions): void;
      /**
       * 缩放视野展示所有经纬度
       */
      includePoints(options: MapContextIncludePointsOptions): void;
      /**
       * 获取当前地图的视野范围
       */
      getRegion(options: MapContextGetRegionOptions): void;
      /**
       * 获取当前地图的缩放级别
       */
      getScale(options: MapContextGetScaleOptions): void;
      /**
       * 添加个性化图层
       */
      addCustomLayer?: (options: MapContextAddCustomLayerOptions) => void;
      /**
       * 创建自定义图片图层,图片会随着地图缩放而缩放
       */
      addGroundOverlay(options: MapContextAddGroundOverlayOptions): void;
      /**
       * 添加 marker
       */
      addMarkers(options: MapContextAddMarkersOptions): void;
      /**
       * 获取屏幕上的点对应的经纬度,坐标原点为地图左上角
       */
      fromScreenLocation?: (options: MapContextFromScreenLocationOptions) => void;
      /**
       * 初始化点聚合的配置,未调用时采用默认配置
       */
      initMarkerCluster(options: MapContextInitMarkerClusterOptions): void;
      /**
       * 沿指定路径移动 marker,用于轨迹回放等场景。动画完成时触发回调事件,若动画进行中,对同一 marker 再次调用 moveAlong 方法,前一次的动画将被打断。
       */
      moveAlong(options: MapContextMoveAlongOptions): void;
      /**
       * 拉起地图APP选择导航。
       */
      openMapApp(options: MapContextOpenMapAppOptions): void;
      /**
       * 移除个性化图层
       */
      removeCustomLayer(options: MapContextRemoveCustomLayerOptions): void;
      /**
       * 移除自定义图片图层
       */
      removeGroundOverlay(options: MapContextRemoveGroundOverlayOptions): void;
      /**
       * 移除 marker
       */
      removeMarkers(options: MapContextRemoveMarkersOptions): void;
      /**
       * 设置地图中心点偏移,向后向下为增长,屏幕比例范围(0.25~0.75),默认偏移为[0.5, 0.5]
       */
      setCenterOffset?: (options: MapContextSetCenterOffsetOptions) => void;
      /**
       * 获取经纬度对应的屏幕坐标,坐标原点为地图左上角。
       */
      toScreenLocation?: (options: MapContextToScreenLocationOptions) => void;
      /**
       * 更新自定义图片图层。
       */
      updateGroundOverlay(options: MapContextUpdateGroundOverlayOptions): void;
      /**
       * 监听地图事件。
       */
      on(event: 'markerClusterCreate' | 'markerClusterClick', callback: (...args: any[]) => any): void;
      /**
       * 获取原生地图对象 plus.maps.Map
       */
      $getAppMap(): any;
    }
 
    interface MapContextGetCenterLocationOptions extends AsyncOptions {
      /**
       * 接口调用成功的回调函数 ,res = { longitude: "经度", latitude: "纬度"}
       */
      success?: (result: LocationObject) => void;
    }
 
    interface MapContextMoveToLocationOptions extends AsyncOptions {
      /**
       * 纬度,浮点数,范围为-90~90,负数表示南纬
       */
      latitude?: number;
      /**
       * 经度,范围为-180~180,负数表示西经
       */
      longitude?: number;
    }
 
    interface LocationObject {
      /**
       * 纬度,浮点数,范围为-90~90,负数表示南纬
       */
      latitude: number;
      /**
       * 经度,范围为-180~180,负数表示西经
       */
      longitude: number;
    }
 
    interface MapContextTranslateMarkerOptions extends AsyncOptions {
      /**
       * 指定marker
       */
      markerId: number;
      /**
       * 指定marker移动到的目标点
       */
      destination: LocationObject;
      /**
       * 移动过程中是否自动旋转marker
       */
      autoRotate: boolean;
      /**
       * marker的旋转角度
       */
      rotate: number;
      /**
       * 平移和旋转同时进行,默认值false(仅微信小程序2.13.0支持)
       */
      moveWithRotate?: boolean;
      /**
       * 动画持续时长,默认值1000ms,平移与旋转分别计算
       */
      duration?: number;
      /**
       * 动画结束回调函数
       */
      animationEnd?: (result: any) => void;
    }
 
    interface MapContextIncludePointsOptions extends AsyncOptions {
      /**
       * 要显示在可视区域内的坐标点列表,[{latitude, longitude}]
       */
      points: LocationObject[];
      /**
       * 坐标点形成的矩形边缘到地图边缘的距离,单位像素。格式为[上,右,下,左],安卓上只能识别数组第一项,上下左右的padding一致。开发者工具暂不支持padding参数。
       */
      padding?: number[];
    }
 
    interface MapContextGetRegionOptions extends AsyncOptions {
      /**
       * 接口调用成功的回调函数,res = {southwest, northeast},西南角与东北角的经纬度
       */
      success?: (result: MapContextGetRegionResult) => void;
    }
 
    interface MapContextGetRegionResult {
      /**
       * 西南角的经纬度
       */
      southwest: LocationObject;
      /**
       * 东北角的经纬度
       */
      northeast: LocationObject;
    }
 
    interface MapContextGetScaleOptions extends AsyncOptions {
      /**
       * 接口调用成功的回调函数,res = {scale}
       */
      success?: (result: MapContextGetScaleResult) => void;
    }
 
    interface MapContextGetScaleResult {
      /**
       * 地图缩放级别
       */
      scale: number;
    }
 
    interface MapContextAddCustomLayerOptions extends AsyncOptions {
      /**
       * 个性化图层id
       */
      layerId: string;
    }
 
    interface MapContextAddGroundOverlayOptions extends AsyncOptions {
      /**
       * 图片图层 id
       */
      id: string;
      /**
       * 图片路径,支持网络图片、临时路径、代码包路径
       */
      src: string;
      /**
       * 图片覆盖的经纬度范围
       */
      bounds: Bounds;
      /**
       * 是否可见
       */
      visible?: boolean;
      /**
       * 图层绘制顺序
       */
      zIndex?: number;
      /**
       * 图层透明度
       */
      opacity?: number;
    }
 
    interface Bounds {
      /**
       * 西南角的经纬度
       */
      southwest: LocationObject;
      /**
       * 东北角的经纬度
       */
      northeast: LocationObject;
    }
 
    interface MapContextAddMarkersOptions extends AsyncOptions {
      /**
       * 同传入 map 组件的 marker 属性
       */
      markers: any[];
      /**
       * 是否先清空地图上所有 marker
       */
      clear: boolean;
    }
 
    interface MapContextFromScreenLocationOptions extends AsyncOptions {
      /**
       * x 坐标值
       */
      x: number;
      /**
       * y 坐标值
       */
      y: number;
      /**
       * 接口调用成功的回调函数
       */
      success?: (result: LocationObject) => void;
    }
 
    interface MapContextInitMarkerClusterOptions extends AsyncOptions {
      /**
       * 启用默认的聚合样式
       */
      enableDefaultStyle: boolean;
      /**
       * 点击已经聚合的标记点时是否实现聚合分离
       */
      zoomOnClick: boolean;
      /**
       * 聚合算法的可聚合距离,即距离小于该值的点会聚合至一起,以像素为单位
       */
      gridSize: number;
    }
 
    interface MapContextMoveAlongOptions extends AsyncOptions {
      /**
       * 指定 marker
       */
      markerId: number;
      /**
       * 移动路径的坐标串,坐标点格式 {longitude, latitude}
       */
      path: LocationObject[];
      /**
       * 根据路径方向自动改变 marker 的旋转角度
       */
      autoRotate?: boolean;
      /**
       * 平滑移动的时间
       */
      duration: number;
    }
 
    interface MapContextOpenMapAppOptions extends AsyncOptions {
      /**
       * 目的地名称
       */
      destination: string;
      /**
       * 目的地纬度
       */
      latitude: number;
      /**
       * 目的地经度
       */
      longitude: number;
    }
 
    interface MapContextRemoveCustomLayerOptions extends AsyncOptions {
      /**
       * 个性化图层id
       */
      layerId: string;
    }
 
    interface MapContextRemoveGroundOverlayOptions extends AsyncOptions {
      /**
       * 图片图层 id
       */
      id: string;
    }
 
    interface MapContextRemoveMarkersOptions extends AsyncOptions {
      /**
       * 要被删除的marker的id属性组成的数组
       */
      markerIds: any[];
    }
 
    interface MapContextSetCenterOffsetOptions {
      /**
       * 偏移量,两位数组
       */
      offset: number[];
      /**
       * 接口调用成功的回调函数
       */
      success?: (result: any) => void;
      /**
       * 接口调用失败的回调函数
       */
      fail?: (result: any) => void;
      /**
       * 接口调用结束的回调函数(调用成功、失败都会执行)
       */
      complete?: (result: any) => void;
    }
 
    interface MapContextToScreenLocationOptions extends AsyncOptions {
      /**
       * 纬度
       */
      latitude: number;
      /**
       * 经度
       */
      longitude: number;
    }
 
    interface MapContextUpdateGroundOverlayOptions extends AsyncOptions {
      /**
       * 图片图层 id
       */
      id: string;
      /**
       * 图片路径,支持网络图片、临时路径、代码包路径
       */
      src: string;
      /**
       * 图片路径,支持网络图片、临时路径、代码包路径
       */
      bounds: Bounds;
      /**
       * 是否可见
       */
      visible?: boolean;
      /**
       * 图层绘制顺序
       */
      zIndex?: number;
      /**
       * 图层透明度
       */
      opacity?: number;
    }
  }
 
  interface Uni {
    /**
     * 创建并返回 map 上下文 mapContext 对象
     *
     * 文档: [http://uniapp.dcloud.io/api/location/map?id=createmapcontext](http://uniapp.dcloud.io/api/location/map?id=createmapcontext)
     */
    createMapContext(mapId: string, currentComponent?: any): UniNamespace.MapContext;
  }
}