map.uvue 17.0 KB
Newer Older
Anne_LXM's avatar
Anne_LXM 已提交
1
<template>
2
  <view class="content">
3 4 5
    <map class="map" id="map1" ref="map1" :longitude="location.longitude" :latitude="location.latitude" :scale="scale"
      :markers="markers" :include-points="includePoints" :polyline="polyline" :polygons="polygons" :circles="circles"
      :controls="controls" :show-location="showLocation" :enable-3D="enable3D" :rotate="rotate" :skew="skew"
6 7
      :show-compass="showCompass" :enable-overlooking="enableOverlooking" :enable-zoom="enableZoom"
      :enable-scroll="enableScroll" :enable-rotate="enableRotate" :enable-satellite="enableSatellite"
8 9
      :enable-traffic="enableTraffic" @markertap="onmarkertap" @callouttap="oncallouttap" @controltap="oncontroltap"
      @regionchange="onregionchange" @tap="maptap" @updated="onupdated" @poitap="onpoitap"></map>
10
    <scroll-view class="scrollview" scroll-y="true">
11
      <view class="tips">注意:需要正确配置地图服务商的Key才能正常显示地图组件</view>
Anne_LXM's avatar
Anne_LXM 已提交
12 13 14
      <view class="uni-title">
        <text class="uni-title-text">属性示例</text>
      </View>
15 16
      <input-data defaultValue="13" title="scale: 缩放级别,取值范围为5-18" type="number"
        @confirm="confirm_scale_input"></input-data>
Anne_LXM's avatar
Anne_LXM 已提交
17
      <boolean-data :defaultValue="showLocation" title="开启显示带有方向的当前定位点" @change="change_show_location"></boolean-data>
18

Anne_LXM's avatar
Anne_LXM 已提交
19

Anne_LXM's avatar
Anne_LXM 已提交
20
      <button class="button" @click="addControls">控件</button>
Anne_LXM's avatar
Anne_LXM 已提交
21
      <button class="button" @click="addMarkers">添加标记点</button>
22
      <!-- #ifdef WEB -->
Anne_LXM's avatar
Anne_LXM 已提交
23
      <button class="button" @click="addMarkersLabel">为标记点旁边增加标签</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25
      <!-- #endif -->
      <button class="button" @click="removeMarker">移除ID为4的标记点和标签</button>
Anne_LXM's avatar
Anne_LXM 已提交
26 27 28 29 30 31
      <button class="button" @click="addPolyline">添加路线</button>
      <button class="button" @click="removePolyline">移除一条路线</button>
      <button class="button" @click="addPolygons">添加多边形</button>
      <button class="button" @click="removePolygon">移除一个多边形</button>
      <button class="button" @click="addCircles">添加圆</button>
      <button class="button" @click="removeCircle">移除一个圆</button>
Anne_LXM's avatar
Anne_LXM 已提交
32 33 34 35 36 37
      <button class="button" @click="includePoint">缩放视野以包含所有给定的坐标点</button>
      <view class="uni-title">
        <text class="uni-title-text">方法示例</text>
      </View>
      <button class="button" @click="handleGetCenterLocation">获取当前地图中心的经纬度</button>
      <button class="button" @click="handleGetRegion">获取当前地图的视野范围</button>
Anne_LXM's avatar
Anne_LXM 已提交
38
      <button class="button" @click="handleTranslateMarker">平移marker</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
39
      <button class="button" @click="handleMoveToLocation">将地图中心移动到指定坐标</button>
Anne_LXM's avatar
Anne_LXM 已提交
40 41
      <button class="button" @click="handleGetScale">获取当前地图的缩放级别</button>

42 43
    </scroll-view>
  </view>
Anne_LXM's avatar
Anne_LXM 已提交
44
</template>
45

Anne_LXM's avatar
Anne_LXM 已提交
46
<script setup lang="uts">
Anne_LXM's avatar
Anne_LXM 已提交
47
  type TypeJestResult = {
Anne_LXM's avatar
Anne_LXM 已提交
48 49
    translateMarkerMsg : string,
    animationEnd : boolean,
DCloud-WZF's avatar
DCloud-WZF 已提交
50 51 52
    centerPoints : LocationObject,
    southwest : LocationObject,
    northeast : LocationObject,
Anne_LXM's avatar
Anne_LXM 已提交
53 54
    moveToLocationMsg : string,
    scale : number
Anne_LXM's avatar
Anne_LXM 已提交
55 56
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
57
  const testMarkers :Marker[]= [{
58 59 60 61 62 63 64 65 66 67 68
    id: 0,
    latitude: 39.989631,
    longitude: 116.481018,
    title: '方恒国际 阜通东大街6号',
    iconPath: '../../../static/location.png',
    rotate: 0,
    width: 20,
    height: 20,
    anchor: {
      x: 0.5,
      y: 1
DCloud-WZF's avatar
DCloud-WZF 已提交
69
    } ,
70 71 72 73 74 75 76 77
    callout: {
      content: '方恒国际 阜通东大街6号',
      color: '#00BFFF',
      fontSize: 10,
      borderRadius: 4,
      borderWidth: 1,
      borderColor: '#333300',
      bgColor: '#CCFF99',
Anne_LXM's avatar
Anne_LXM 已提交
78
      padding: 5,
79
      display: 'ALWAYS'
DCloud-WZF's avatar
DCloud-WZF 已提交
80
    } as MapMarkerCallout
81 82 83 84 85 86
  },
  {
    id: 1,
    latitude: 39.9086920000,
    longitude: 116.3974770000,
    title: '天安门',
DCloud-WZF's avatar
DCloud-WZF 已提交
87
    // zIndex: '1',
88 89 90 91 92 93 94 95 96 97 98
    iconPath: '../../../static/location.png',
    width: 40,
    height: 40,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '首都北京\n天安门',
      color: '#00BFFF',
      fontSize: 12,
99
      borderRadius: 10,
Anne_LXM's avatar
Anne_LXM 已提交
100
      borderWidth: 2,
101 102
      borderColor: '#333300',
      bgColor: '#CCFF11',
Anne_LXM's avatar
Anne_LXM 已提交
103
      padding: 5,
104
      display: 'ALWAYS'
DCloud-WZF's avatar
DCloud-WZF 已提交
105
    } as MapMarkerCallout
Anne_LXM's avatar
Anne_LXM 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  },
  {
    id: 2,
    latitude: 39.894793,
    longitude: 116.321592,
    title: '北京西站',
    iconPath: '../../../static/location.png',
    width: 40,
    height: 40,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '北京西站',
      color: '#ffffff',
      fontSize: 12,
      borderRadius: 10,
      borderWidth: 2,
      borderColor: '#333300',
      bgColor: '#ff5500',
      padding: 5,
      display: 'ALWAYS'
DCloud-WZF's avatar
DCloud-WZF 已提交
129
    } as MapMarkerCallout
Anne_LXM's avatar
Anne_LXM 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  },
  {
    id: 3,
    latitude: 39.902344,
    longitude: 116.484822,
    title: '北京东站',
    iconPath: '../../../static/location.png',
    width: 20,
    height: 20,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '北京东站',
      color: '#ffffff',
      fontSize: 12,
      borderRadius: 10,
      borderWidth: 2,
      borderColor: '#333300',
      bgColor: '#ff5500',
      padding: 5,
      display: 'ALWAYS'
DCloud-WZF's avatar
DCloud-WZF 已提交
153
    } as MapMarkerCallout
Anne_LXM's avatar
Anne_LXM 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  },
  {
    id: 4,
    latitude: 39.865011,
    longitude: 116.379007,
    title: '北京南站',
    iconPath: '../../../static/location.png',
    width: 40,
    height: 40,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '北京南站',
      color: '#ffffff',
      fontSize: 12,
      borderRadius: 10,
      borderWidth: 2,
      borderColor: '#333300',
      bgColor: '#00aa00',
      padding: 5,
      display: 'ALWAYS'
DCloud-WZF's avatar
DCloud-WZF 已提交
177
    } as MapMarkerCallout
Anne_LXM's avatar
Anne_LXM 已提交
178
  },
179 180
  ];

Anne_LXM's avatar
Anne_LXM 已提交
181

DCloud-WZF's avatar
DCloud-WZF 已提交
182
  const testPolyline: Polyline[] = [{
183 184 185 186 187 188 189 190 191
    points: [{
      latitude: 39.925539,
      longitude: 116.279037
    },
    {
      latitude: 39.925539,
      longitude: 116.520285
    }],
    color: '#FFCCFF',
192
    width: 7,
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
    dottedLine: true,
    arrowLine: true,
    borderColor: '#000000',
    borderWidth: 2
  },
  {
    points: [{
      latitude: 39.938698,
      longitude: 116.275177
    },
    {
      latitude: 39.966069,
      longitude: 116.289253
    },
    {
      latitude: 39.944226,
      longitude: 116.306076
    },
    {
      latitude: 39.966069,
      longitude: 116.322899
    },
    {
      latitude: 39.938698,
      longitude: 116.336975
    }],
    color: '#CCFFFF',
    width: 5,
Anne_LXM's avatar
Anne_LXM 已提交
221
    dottedLine: false,
222 223 224 225 226 227
    arrowLine: true,
    borderColor: '#CC0000',
    borderWidth: 3
  }
  ];

DCloud-WZF's avatar
DCloud-WZF 已提交
228
  const testPolygons : Polygon[] = [{
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
    points: [{
      latitude: 39.781892,
      longitude: 116.293413
    },
    {
      latitude: 39.787600,
      longitude: 116.391842
    },
    {
      latitude: 39.733187,
      longitude: 116.417932
    },
    {
      latitude: 39.704653,
      longitude: 116.338255
    }],
    fillColor: '#FFCCFF',
    strokeWidth: 3,
    strokeColor: '#CC99CC',
    zIndex: 11
  },
  {
    points: [{
      latitude: 39.887600,
      longitude: 116.518932
    },
    {
      latitude: 39.781892,
      longitude: 116.518932
    },
    {
      latitude: 39.781892,
      longitude: 116.428932
    },
    {
      latitude: 39.887600,
      longitude: 116.428932
    }
    ],
    fillColor: '#CCFFFF',
    strokeWidth: 5,
    strokeColor: '#CC0000',
    zIndex: 3
  }
  ];

DCloud-WZF's avatar
DCloud-WZF 已提交
275
  const testCircles: Circle[] = [{
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
    latitude: 39.996441,
    longitude: 116.411146,
    radius: 15000,
    strokeWidth: 5,
    color: '#CCFFFF',
    fillColor: '#CC0000'
  },
  {
    latitude: 40.096441,
    longitude: 116.511146,
    radius: 12000,
    strokeWidth: 3,
    color: '#CCFFFF',
    fillColor: '#FFCCFF'
  },
  {
    latitude: 39.896441,
    longitude: 116.311146,
    radius: 9000,
    strokeWidth: 1,
    color: '#CCFFFF',
    fillColor: '#CC0000'
  }
  ];

DCloud-WZF's avatar
DCloud-WZF 已提交
301
  const testIncludePoints :LocationObject[] = [{
302 303 304 305 306 307 308 309 310 311
    latitude: 39.989631,
    longitude: 116.481018,
  },
  {
    latitude: 39.9086920000,
    longitude: 116.3974770000,
  }
  ];


DCloud-WZF's avatar
DCloud-WZF 已提交
312 313
  const mapContext = ref(null as MapContext | null);
  const location = ref({ longitude: 116.39742, latitude: 39.909 } as LocationObject);
Anne_LXM's avatar
Anne_LXM 已提交
314 315
  const rotate = ref(0);
  const skew = ref(0);
Anne_LXM's avatar
Anne_LXM 已提交
316
  // 自动化测试
Anne_LXM's avatar
Anne_LXM 已提交
317
  const autoTest = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
318
  const updateAutoTest = (value : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
319 320 321 322 323
    autoTest.value = value
  }


  const jestResult = reactive({
324 325
    translateMarkerMsg: "",
    animationEnd: false,
Anne_LXM's avatar
Anne_LXM 已提交
326
    centerPoints: {
327 328
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
329 330
    },
    southwest: {
331 332
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
333 334
    },
    northeast: {
335 336
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
337
    },
338 339
    moveToLocationMsg: "",
    scale: 0,
Anne_LXM's avatar
Anne_LXM 已提交
340 341
  } as TypeJestResult);

342

Anne_LXM's avatar
Anne_LXM 已提交
343
  onReady(() => {
DCloud-WZF's avatar
DCloud-WZF 已提交
344
    mapContext.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
Anne_LXM's avatar
Anne_LXM 已提交
345 346
  });

Anne_LXM's avatar
Anne_LXM 已提交
347
  const scale = ref(13);
Anne_LXM's avatar
Anne_LXM 已提交
348
  const confirm_scale_input = (value : number) => {
Anne_LXM's avatar
Anne_LXM 已提交
349 350 351
    scale.value = value
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
352
  const controls = ref([] as Control[]);
Anne_LXM's avatar
Anne_LXM 已提交
353
  const addControls = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
354
    controls.value = [{
Anne_LXM's avatar
Anne_LXM 已提交
355 356 357 358 359 360
      id: 1,
      position: {
        left: 5,
        top: 180,
        width: 30,
        height: 30
DCloud-WZF's avatar
DCloud-WZF 已提交
361
      } as ControlPosition,
Anne_LXM's avatar
Anne_LXM 已提交
362 363
      iconPath: '../../../static/uni.png',
      clickable: true
364
    } as Control]
365
  }
Anne_LXM's avatar
Anne_LXM 已提交
366

Anne_LXM's avatar
Anne_LXM 已提交
367
  const showLocation = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
368
  const change_show_location = (checked : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
369 370 371
    showLocation.value = checked
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
372
  const includePoints = ref([] as LocationObject[]);
Anne_LXM's avatar
Anne_LXM 已提交
373 374 375 376 377
  const includePoint = () => {
    includePoints.value = testIncludePoints;
  };


DCloud-WZF's avatar
DCloud-WZF 已提交
378
  let markers = ref([] as Marker[]);
Anne_LXM's avatar
Anne_LXM 已提交
379
  const addMarkers = () => {
Anne_LXM's avatar
Anne_LXM 已提交
380
    scale.value = 11
DCloud-WZF's avatar
DCloud-WZF 已提交
381 382
    const temp = JSON.parse<Marker[]>(JSON.stringify(testMarkers))!
    markers.value = temp
Anne_LXM's avatar
Anne_LXM 已提交
383 384
  };

Anne_LXM's avatar
Anne_LXM 已提交
385
  const removeMarker = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
386 387 388 389 390 391 392 393 394 395 396
    // #ifdef APP
    mapContext.value?.removeMarkers({markerIds:[4]})
    // #endif
    // #ifdef WEB
    const index = markers.value.findIndex((marker: Marker):boolean=>{
       return marker.id == 4
    });
    if (index != -1) {
      delete markers.value[index].label;
      markers.value.splice(index, 1);
    } else {
Anne_LXM's avatar
Anne_LXM 已提交
397 398 399 400 401
      uni.showToast({
        title: '未找到该标记点',
        icon: 'none'
      });
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
402
    // #endif
Anne_LXM's avatar
Anne_LXM 已提交
403 404
  };

405
  // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
406
  const addMarkersLabel = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
407
    markers.value.forEach((marker, index) => {
Anne_LXM's avatar
Anne_LXM 已提交
408
      marker.label = {
409
        content: 'Hello Label' + (index + 1),
Anne_LXM's avatar
Anne_LXM 已提交
410 411 412 413
        color: '#aa00ff',
        fontSize: 12,
        x: 5,
        y: 0,
414 415
        borderColor: '#333300',
        borderWidth: 2,
Anne_LXM's avatar
Anne_LXM 已提交
416 417 418 419 420 421
        borderRadius: 20,
        bgColor: '#aaffff',
        padding: 10
      };
    });
  };
DCloud-WZF's avatar
DCloud-WZF 已提交
422
  // #endif
Anne_LXM's avatar
Anne_LXM 已提交
423 424 425 426


  const polyline = ref([] as Polyline[]);
  const addPolyline = () => {
Anne_LXM's avatar
Anne_LXM 已提交
427
    scale.value = 11;
DCloud-WZF's avatar
DCloud-WZF 已提交
428
    polyline.value = JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!;
Anne_LXM's avatar
Anne_LXM 已提交
429
  };
Anne_LXM's avatar
Anne_LXM 已提交
430 431
  const removePolyline = () => {
    if (polyline.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
432
      polyline.value = JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!.splice(0, 1);
Anne_LXM's avatar
Anne_LXM 已提交
433 434
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
435 436


DCloud-WZF's avatar
DCloud-WZF 已提交
437
  const polygons = ref([] as Polygon[]);
Anne_LXM's avatar
Anne_LXM 已提交
438 439
  const addPolygons = () => {
    scale.value = 10;
DCloud-WZF's avatar
DCloud-WZF 已提交
440
    polygons.value = JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!;
Anne_LXM's avatar
Anne_LXM 已提交
441
  };
Anne_LXM's avatar
Anne_LXM 已提交
442 443
  const removePolygon = () => {
    if (polygons.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
444
      polygons.value = JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!.splice(0, 1);
Anne_LXM's avatar
Anne_LXM 已提交
445 446
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
447 448


DCloud-WZF's avatar
DCloud-WZF 已提交
449
  const circles = ref([] as Circle[]);
Anne_LXM's avatar
Anne_LXM 已提交
450 451
  const addCircles = () => {
    scale.value = 10;
DCloud-WZF's avatar
DCloud-WZF 已提交
452
    circles.value = JSON.parse<Circle[]>(JSON.stringify(testCircles))!;
Anne_LXM's avatar
Anne_LXM 已提交
453
  };
Anne_LXM's avatar
Anne_LXM 已提交
454 455
  const removeCircle = () => {
    if (circles.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
456
      circles.value = JSON.parse<Circle[]>(JSON.stringify(testCircles))!.slice(1);
Anne_LXM's avatar
Anne_LXM 已提交
457 458 459
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
460 461 462 463 464 465 466 467 468 469

  const showCompass = ref(true);
  const enable3D = ref(true);
  const enableOverlooking = ref(true);
  const enableZoom = ref(true);
  const enableScroll = ref(true);
  const enableRotate = ref(true);
  const enableSatellite = ref(false);
  const enableTraffic = ref(false);

470
  const enableThreeD = (e) => {
Anne_LXM's avatar
Anne_LXM 已提交
471 472
    enable3D.value = e.detail.value;
  }
473
  const changeShowCompass = (e) => {
Anne_LXM's avatar
Anne_LXM 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
    showCompass.value = e.detail.value;
  }
  const changeEnableOverlooking = (e) => {
    enableOverlooking.value = e.detail.value;
  };

  const changeEnableZoom = (e) => {
    enableZoom.value = e.detail.value;
  };

  const changeEnableScroll = (e) => {
    enableScroll.value = e.detail.value;
  };

  const changeEnableRotate = (e) => {
    enableRotate.value = e.detail.value;
  };

  const changeEnableSatellite = (e) => {
    enableSatellite.value = e.detail.value;
  };

  const changeEnableTraffic = (e) => {
    enableTraffic.value = e.detail.value;
  };


  const handleGetCenterLocation = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
502
      mapContext.value?.getCenterLocation({
Anne_LXM's avatar
Anne_LXM 已提交
503
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
504
          // console.log('getCenterLocation',ret);
Anne_LXM's avatar
Anne_LXM 已提交
505
          jestResult.centerPoints = ret;
506
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
507 508 509 510
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
511 512 513 514 515
        }
      });
  };

  const handleGetRegion = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
516
      mapContext.value?.getRegion({
Anne_LXM's avatar
Anne_LXM 已提交
517
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
518
          // console.log('getRegion',JSON.stringify(ret));
Anne_LXM's avatar
Anne_LXM 已提交
519 520
          jestResult.southwest = ret.southwest;
          jestResult.northeast = ret.northeast
521
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
522 523 524 525
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
526 527 528 529
        }
      });
  };

Anne_LXM's avatar
Anne_LXM 已提交
530

Anne_LXM's avatar
Anne_LXM 已提交
531
  const handleTranslateMarker = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
532
      mapContext.value?.translateMarker({
Anne_LXM's avatar
Anne_LXM 已提交
533 534 535 536 537
        markerId: 1,
        destination: {
          latitude: 39.989631,
          longitude: 116.481018
        },
538 539
        autoRotate: true,
        rotate: 10,
Anne_LXM's avatar
Anne_LXM 已提交
540
        duration: 2000,
DCloud-WZF's avatar
DCloud-WZF 已提交
541 542
        moveWithRotate: true,
        // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
543
        animationEnd: () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
544
          console.log('动画结束');
Anne_LXM's avatar
Anne_LXM 已提交
545
          jestResult.animationEnd = true;
Anne_LXM's avatar
Anne_LXM 已提交
546
        },
DCloud-WZF's avatar
DCloud-WZF 已提交
547
        // #endif
Anne_LXM's avatar
Anne_LXM 已提交
548
        success: ret => {
549
          console.log('handleTranslateMarker',JSON.stringify(ret));
DCloud-WZF's avatar
DCloud-WZF 已提交
550 551
          const result = ret as UTSJSONObject
          jestResult.translateMarkerMsg = result["errMsg"] as string;
Anne_LXM's avatar
Anne_LXM 已提交
552
        },
Anne_LXM's avatar
Anne_LXM 已提交
553 554
        fail: error => {
          console.log(error)
Anne_LXM's avatar
Anne_LXM 已提交
555 556
        }
      });
DCloud-WZF's avatar
DCloud-WZF 已提交
557
      mapContext.value?.translateMarker({
Anne_LXM's avatar
Anne_LXM 已提交
558 559 560 561 562 563 564 565 566
        markerId: 2,
        destination: {
          latitude: 39.902344,
          longitude: 116.484822,
        },
        autoRotate: true,
        rotate: 0,
        duration: 2000,
        success: ret => {
DCloud-WZF's avatar
DCloud-WZF 已提交
567
          console.log('handleTranslateMarker', JSON.stringify(ret));
Anne_LXM's avatar
Anne_LXM 已提交
568 569 570 571 572
        },
        fail: error => {
          console.log(error)
        }
      });
Anne_LXM's avatar
Anne_LXM 已提交
573 574
  };

Anne_LXM's avatar
Anne_LXM 已提交
575 576

  const handleGetScale = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
577
      mapContext.value?.getScale({
Anne_LXM's avatar
Anne_LXM 已提交
578
        success: res => {
579 580 581 582 583 584 585 586
          // console.log('getScale',res);
          scale.value = res.scale
          jestResult.scale = res.scale
          if (!autoTest.value) {
            uni.showModal({
              content: '当前地图的缩放级别为:' + res.scale
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
587 588
        },
        fail: error => {
589
          console.log(error)
Anne_LXM's avatar
Anne_LXM 已提交
590 591 592 593 594
        },
      });
  };

  const handleMoveToLocation = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
595
      mapContext.value?.moveToLocation({
596 597 598
        latitude: 39.909,
        longitude: 116.39742,
        success: res => {
599
          console.log('moveToLocation',res);
DCloud-WZF's avatar
DCloud-WZF 已提交
600
          const result = res as UTSJSONObject
601
          jestResult.moveToLocationMsg = result["errMsg"] as string;
DCloud-WZF's avatar
DCloud-WZF 已提交
602

603 604 605 606
          if (!autoTest.value) {
            uni.showModal({
              content: JSON.stringify(res)
            });
Anne_LXM's avatar
Anne_LXM 已提交
607
          }
608 609 610 611
        },
        fail: error => {
          console.log(error)
        }
Anne_LXM's avatar
Anne_LXM 已提交
612 613 614
      });
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
615
  const maptap = (e : UniMapUpdatedEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
616
    // console.log('点击地图时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
617 618 619 620 621
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
622
  const onmarkertap = (e : UniMapMarkerTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
623
    // console.log('点击标记点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
624 625 626 627 628
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
629
  const oncontroltap = (e : UniMapControlTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
630
    // console.log('点击控件时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
631 632 633 634 635
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
636
  const oncallouttap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
637
    // console.log('点击标记点对应的气泡时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
638 639 640 641 642
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
643
  const onupdated = (e : UniMapUpdatedEvent) => {
644
    console.log('在地图渲染更新完成时触发', e)
Anne_LXM's avatar
Anne_LXM 已提交
645 646
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
647
  const onregionchange = (e : UniMapRegionChangeEvent) => {
648
    console.log('视野发生变化时触发', e)
Anne_LXM's avatar
Anne_LXM 已提交
649 650
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
651
  const onpoitap = (e : UniMapPoiTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
652
    // console.log('点击地图poi点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
653 654 655 656 657
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
658 659 660 661 662 663
  defineExpose({
    jestResult,
    autoTest,
    updateAutoTest,
    addControls,
    addMarkers,
664
    // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
665
    addMarkersLabel,
DCloud-WZF's avatar
DCloud-WZF 已提交
666
    // #endif
Anne_LXM's avatar
Anne_LXM 已提交
667
    removeMarker,
Anne_LXM's avatar
Anne_LXM 已提交
668
    addPolyline,
Anne_LXM's avatar
Anne_LXM 已提交
669
    removePolyline,
Anne_LXM's avatar
Anne_LXM 已提交
670
    addPolygons,
Anne_LXM's avatar
Anne_LXM 已提交
671
    removePolygon,
Anne_LXM's avatar
Anne_LXM 已提交
672
    addCircles,
Anne_LXM's avatar
Anne_LXM 已提交
673
    removeCircle,
Anne_LXM's avatar
Anne_LXM 已提交
674 675 676 677 678 679 680
    includePoint,
    handleGetCenterLocation,
    handleGetRegion,
    handleTranslateMarker,
    handleMoveToLocation,
    handleGetScale
  })
Anne_LXM's avatar
Anne_LXM 已提交
681
</script>
682

Anne_LXM's avatar
Anne_LXM 已提交
683
<style>
684 685 686 687 688 689
  .content {
    flex: 1;
  }

  .map {
    width: 100%;
Anne_LXM's avatar
Anne_LXM 已提交
690
    height: 300px;
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
    background-color: #f0f0f0;
  }

  .scrollview {
    flex: 1;
    padding: 10px;
  }

  .list-item {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    padding: 5px 0px;
  }

  .list-text {
    flex: 1;
  }

  .button {
    margin-top: 5px;
    margin-bottom: 5px;
  }
714 715 716 717 718 719

  .tips {
    font-size: 12px;
    margin-top: 15px;
    opacity: .8;
  }
Anne_LXM's avatar
Anne_LXM 已提交
720
</style>