map.uvue 17.7 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>
Anne_LXM's avatar
Anne_LXM 已提交
22
      <button class="button" @click="addMarkersLabel">为标记点旁边增加标签</button>
Anne_LXM's avatar
Anne_LXM 已提交
23 24 25 26 27 28 29
      <button class="button" @click="deleteMarker">移除ID为4的标记点和标签</button>
      <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 已提交
30 31 32 33 34 35
      <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 已提交
36 37 38 39
      <button class="button" @click="handleTranslateMarker">平移marker</button>
      <button class="button" @click="handleMoveToLocation">将地图中心移动到当前定位点</button>
      <button class="button" @click="handleGetScale">获取当前地图的缩放级别</button>

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

Anne_LXM's avatar
Anne_LXM 已提交
44
<script setup lang="uts">
45
  type Anchor = {
Anne_LXM's avatar
Anne_LXM 已提交
46 47
    x : number,
    y : number
48 49 50
  }

  type Callout = {
Anne_LXM's avatar
Anne_LXM 已提交
51 52 53 54 55 56 57 58 59
    content : string,
    color : string,
    fontSize : number,
    borderRadius : number,
    borderWidth : number,
    borderColor : string,
    bgColor : string,
    padding : number,
    display : string
60 61
  }

Anne_LXM's avatar
Anne_LXM 已提交
62
  type Label = {
Anne_LXM's avatar
Anne_LXM 已提交
63 64 65 66 67 68 69 70 71 72
    content : string,
    color : string,
    fontSize : number,
    x : number,
    y : number,
    borderColor : string
    borderWidth : number,
    borderRadius : number,
    bgColor : string,
    padding : number
Anne_LXM's avatar
Anne_LXM 已提交
73 74
  }

75
  type Markers = {
Anne_LXM's avatar
Anne_LXM 已提交
76 77 78 79 80 81 82 83 84 85 86 87
    id : number,
    latitude : number,
    longitude : number,
    title ?: string,
    iconPath : string,
    zIndex ?: string,
    rotate ?: number,
    width ?: number,
    height ?: number,
    label ?: Label,
    anchor ?: Anchor,
    callout ?: Callout
88 89 90
  }

  type Points = {
Anne_LXM's avatar
Anne_LXM 已提交
91 92
    latitude : number,
    longitude : number
93 94 95
  }

  type Polyline = {
Anne_LXM's avatar
Anne_LXM 已提交
96 97 98 99 100 101 102
    points : Points[],
    color : string,
    width : number,
    dottedLine : boolean,
    arrowLine : boolean,
    borderColor : string,
    borderWidth : number
103 104 105
  }

  type Polygons = {
Anne_LXM's avatar
Anne_LXM 已提交
106 107 108 109 110
    points : Points[];
    fillColor : string;
    strokeWidth : number;
    strokeColor : string;
    zIndex : number;
111 112 113
  }

  type Circles = {
Anne_LXM's avatar
Anne_LXM 已提交
114 115 116 117 118 119
    latitude : number;
    longitude : number;
    radius : number;
    strokeWidth : number;
    color : string;
    fillColor : string;
120 121
  }

Anne_LXM's avatar
Anne_LXM 已提交
122
  type PositionType = {
Anne_LXM's avatar
Anne_LXM 已提交
123 124 125 126
    left : number,
    top : number,
    width : number,
    height : number
Anne_LXM's avatar
Anne_LXM 已提交
127 128 129
  }

  type ControlsType = {
Anne_LXM's avatar
Anne_LXM 已提交
130 131 132 133
    id ?: number;
    position : PositionType;
    iconPath : string;
    clickable ?: boolean;
Anne_LXM's avatar
Anne_LXM 已提交
134 135
  }

Anne_LXM's avatar
Anne_LXM 已提交
136
  type TypeJestResult = {
Anne_LXM's avatar
Anne_LXM 已提交
137 138 139 140 141 142 143
    translateMarkerMsg : string,
    animationEnd : boolean,
    centerPoints : Points,
    southwest : Points,
    northeast : Points,
    moveToLocationMsg : string,
    scale : number
Anne_LXM's avatar
Anne_LXM 已提交
144 145
  }

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
  const testMarkers = [{
    id: 0,
    latitude: 39.989631,
    longitude: 116.481018,
    title: '方恒国际 阜通东大街6号',
    zIndex: '1',
    iconPath: '../../../static/location.png',
    rotate: 0,
    width: 20,
    height: 20,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '方恒国际 阜通东大街6号',
      color: '#00BFFF',
      fontSize: 10,
      borderRadius: 4,
      borderWidth: 1,
      borderColor: '#333300',
      bgColor: '#CCFF99',
Anne_LXM's avatar
Anne_LXM 已提交
168
      padding: 5,
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
      display: 'ALWAYS'
    }
  },
  {
    id: 1,
    latitude: 39.9086920000,
    longitude: 116.3974770000,
    title: '天安门',
    zIndex: '1',
    iconPath: '../../../static/location.png',
    width: 40,
    height: 40,
    anchor: {
      x: 0.5,
      y: 1
    },
    callout: {
      content: '首都北京\n天安门',
      color: '#00BFFF',
      fontSize: 12,
189
      borderRadius: 10,
Anne_LXM's avatar
Anne_LXM 已提交
190
      borderWidth: 2,
191 192
      borderColor: '#333300',
      bgColor: '#CCFF11',
Anne_LXM's avatar
Anne_LXM 已提交
193
      padding: 5,
194 195
      display: 'ALWAYS'
    }
Anne_LXM's avatar
Anne_LXM 已提交
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
  },
  {
    id: 2,
    latitude: 39.894793,
    longitude: 116.321592,
    title: '北京西站',
    zIndex: '1',
    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'
    }
  },
  {
    id: 3,
    latitude: 39.902344,
    longitude: 116.484822,
    title: '北京东站',
    zIndex: '1',
    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'
    }
  },
  {
    id: 4,
    latitude: 39.865011,
    longitude: 116.379007,
    title: '北京南站',
    zIndex: '1',
    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'
    }
  },
272 273
  ];

Anne_LXM's avatar
Anne_LXM 已提交
274

275 276 277 278 279 280 281 282 283 284
  const testPolyline = [{
    points: [{
      latitude: 39.925539,
      longitude: 116.279037
    },
    {
      latitude: 39.925539,
      longitude: 116.520285
    }],
    color: '#FFCCFF',
285
    width: 7,
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
    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 已提交
314
    dottedLine: false,
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 403 404
    arrowLine: true,
    borderColor: '#CC0000',
    borderWidth: 3
  }
  ];

  const testPolygons = [{
    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
  }
  ];

  const testCircles = [{
    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'
  }
  ];

  const testIncludePoints = [{
    latitude: 39.989631,
    longitude: 116.481018,
  },
  {
    latitude: 39.9086920000,
    longitude: 116.3974770000,
  }
  ];


Anne_LXM's avatar
Anne_LXM 已提交
405
  const map = ref(null as MapContext | null);
Anne_LXM's avatar
Anne_LXM 已提交
406 407 408
  const location = ref({ longitude: 116.39742, latitude: 39.909 });
  const rotate = ref(0);
  const skew = ref(0);
Anne_LXM's avatar
Anne_LXM 已提交
409
  // 自动化测试
Anne_LXM's avatar
Anne_LXM 已提交
410
  const autoTest = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
411
  const updateAutoTest = (value : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
412 413 414 415 416
    autoTest.value = value
  }


  const jestResult = reactive({
417 418
    translateMarkerMsg: "",
    animationEnd: false,
Anne_LXM's avatar
Anne_LXM 已提交
419
    centerPoints: {
420 421
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
422 423
    },
    southwest: {
424 425
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
426 427
    },
    northeast: {
428 429
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
430
    },
431 432
    moveToLocationMsg: "",
    scale: 0,
Anne_LXM's avatar
Anne_LXM 已提交
433 434
  } as TypeJestResult);

435

Anne_LXM's avatar
Anne_LXM 已提交
436 437 438 439
  onReady(() => {
    map.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
  });

Anne_LXM's avatar
Anne_LXM 已提交
440
  const scale = ref(13);
Anne_LXM's avatar
Anne_LXM 已提交
441
  const confirm_scale_input = (value : number) => {
Anne_LXM's avatar
Anne_LXM 已提交
442 443 444
    scale.value = value
  };

445
  const controls = ref([] as ControlsType[]);
Anne_LXM's avatar
Anne_LXM 已提交
446
  const addControls = () => {
Anne_LXM's avatar
Anne_LXM 已提交
447
    controls.value.push({
Anne_LXM's avatar
Anne_LXM 已提交
448 449 450 451 452 453
      id: 1,
      position: {
        left: 5,
        top: 180,
        width: 30,
        height: 30
454
      },
Anne_LXM's avatar
Anne_LXM 已提交
455 456
      iconPath: '../../../static/uni.png',
      clickable: true
Anne_LXM's avatar
Anne_LXM 已提交
457
    })
458
  }
Anne_LXM's avatar
Anne_LXM 已提交
459

Anne_LXM's avatar
Anne_LXM 已提交
460
  const showLocation = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
461
  const change_show_location = (checked : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
462 463 464
    showLocation.value = checked
  }

Anne_LXM's avatar
Anne_LXM 已提交
465 466 467 468 469 470 471 472
  const includePoints = ref([] as Points[]);
  const includePoint = () => {
    includePoints.value = testIncludePoints;
  };


  const markers = reactive([] as Markers[]);
  const addMarkers = () => {
Anne_LXM's avatar
Anne_LXM 已提交
473
    scale.value = 11
Anne_LXM's avatar
Anne_LXM 已提交
474 475 476
    markers.push(...testMarkers);
  };

Anne_LXM's avatar
Anne_LXM 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489
  const removeMarker = () => {
    const index = markers.findIndex(marker => marker.id === 4);
    if (index !== -1) {
      delete markers[index].label;
      markers.splice(index, 1);
    }else{
      uni.showToast({
        title: '未找到该标记点',
        icon: 'none'
      });
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
490 491 492
  const addMarkersLabel = () => {
    markers.forEach((marker, index) => {
      marker.label = {
493
        content: 'Hello Label' + (index + 1),
Anne_LXM's avatar
Anne_LXM 已提交
494 495 496 497
        color: '#aa00ff',
        fontSize: 12,
        x: 5,
        y: 0,
498 499
        borderColor: '#333300',
        borderWidth: 2,
Anne_LXM's avatar
Anne_LXM 已提交
500 501 502 503 504 505 506 507 508 509
        borderRadius: 20,
        bgColor: '#aaffff',
        padding: 10
      };
    });
  };


  const polyline = ref([] as Polyline[]);
  const addPolyline = () => {
Anne_LXM's avatar
Anne_LXM 已提交
510
    scale.value = 11;
Anne_LXM's avatar
Anne_LXM 已提交
511 512
    polyline.value = testPolyline;
  };
Anne_LXM's avatar
Anne_LXM 已提交
513 514 515 516 517
  const removePolyline = () => {
    if (polyline.value.length > 1) {
      polyline.value.splice(0, 1);
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
518 519 520 521 522 523 524


  const polygons = ref([] as Polygons[]);
  const addPolygons = () => {
    scale.value = 10;
    polygons.value = testPolygons;
  };
Anne_LXM's avatar
Anne_LXM 已提交
525 526 527 528 529
  const removePolygon = () => {
    if (polygons.value.length > 1) {
      polygons.value.splice(0, 1);
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
530 531 532 533 534 535 536


  const circles = ref([] as Circles[]);
  const addCircles = () => {
    scale.value = 10;
    circles.value = testCircles;
  };
Anne_LXM's avatar
Anne_LXM 已提交
537 538 539 540 541 542
  const removeCircle = () => {
    if (circles.value.length > 1) {
      circles.value.splice(0, 1);
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
543 544 545 546 547 548 549 550 551 552

  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);

553
  const enableThreeD = (e) => {
Anne_LXM's avatar
Anne_LXM 已提交
554 555
    enable3D.value = e.detail.value;
  }
556
  const changeShowCompass = (e) => {
Anne_LXM's avatar
Anne_LXM 已提交
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
    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 = () => {
    if (map.value) {
      map.value.getCenterLocation({
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
588
          // console.log('getCenterLocation',ret);
Anne_LXM's avatar
Anne_LXM 已提交
589
          jestResult.centerPoints = ret;
590
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
591 592 593 594
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
595 596 597 598 599 600 601 602 603
        }
      });
    }
  };

  const handleGetRegion = () => {
    if (map.value) {
      map.value.getRegion({
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
604
          // console.log('getRegion',JSON.stringify(ret));
Anne_LXM's avatar
Anne_LXM 已提交
605 606
          jestResult.southwest = ret.southwest;
          jestResult.northeast = ret.northeast
607
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
608 609 610 611
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
612 613 614 615 616
        }
      });
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
617

Anne_LXM's avatar
Anne_LXM 已提交
618 619 620 621 622 623 624 625
  const handleTranslateMarker = () => {
    if (map.value) {
      map.value.translateMarker({
        markerId: 1,
        destination: {
          latitude: 39.989631,
          longitude: 116.481018
        },
626 627
        autoRotate: true,
        rotate: 10,
Anne_LXM's avatar
Anne_LXM 已提交
628 629
        duration: 2000,
        animationEnd: () => {
Anne_LXM's avatar
Anne_LXM 已提交
630 631
          // console.log('动画结束');
          jestResult.animationEnd = true;
Anne_LXM's avatar
Anne_LXM 已提交
632 633
        },
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
634 635
          // console.log('handleTranslateMarker',JSON.stringify(ret));
          jestResult.translateMarkerMsg = ret.errMsg;
Anne_LXM's avatar
Anne_LXM 已提交
636
        },
Anne_LXM's avatar
Anne_LXM 已提交
637 638
        fail: error => {
          console.log(error)
Anne_LXM's avatar
Anne_LXM 已提交
639 640
        }
      });
Anne_LXM's avatar
Anne_LXM 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
      map.value.translateMarker({
        markerId: 2,
        destination: {
          latitude: 39.902344,
          longitude: 116.484822,
        },
        autoRotate: true,
        rotate: 0,
        duration: 2000,
        success: ret => {
          console.log('handleTranslateMarker',JSON.stringify(ret));
        },
        fail: error => {
          console.log(error)
        }
      });
Anne_LXM's avatar
Anne_LXM 已提交
657 658 659
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
660 661 662 663 664

  const handleGetScale = () => {
    if (map.value) {
      map.value.getScale({
        success: res => {
665 666 667 668 669 670 671 672
          // 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 已提交
673 674
        },
        fail: error => {
675
          console.log(error)
Anne_LXM's avatar
Anne_LXM 已提交
676 677 678 679 680 681 682 683
        },
      });
    }
  };

  const handleMoveToLocation = () => {
    if (map.value) {
      map.value.moveToLocation({
684 685 686 687 688 689 690 691 692
        latitude: 39.909,
        longitude: 116.39742,
        success: res => {
          // console.log('moveToLocation',res);
          jestResult.moveToLocationMsg = res.errMsg;
          if (!autoTest.value) {
            uni.showModal({
              content: JSON.stringify(res)
            });
Anne_LXM's avatar
Anne_LXM 已提交
693
          }
694 695 696 697
        },
        fail: error => {
          console.log(error)
        }
Anne_LXM's avatar
Anne_LXM 已提交
698 699 700 701
      });
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
702
  const maptap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
703
    // console.log('点击地图时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
704 705 706 707 708
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
709
  const onmarkertap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
710
    // console.log('点击标记点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
711 712 713 714 715
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
716
  const oncontroltap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
717
    // console.log('点击控件时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
718 719 720 721 722
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
723
  const oncallouttap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
724
    // console.log('点击标记点对应的气泡时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
725 726 727 728 729
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
730
  const onupdated = (e : UniEvent) => {
731
    console.log('在地图渲染更新完成时触发', e)
Anne_LXM's avatar
Anne_LXM 已提交
732 733
  };

Anne_LXM's avatar
Anne_LXM 已提交
734
  const onregionchange = (e : UniEvent) => {
735
    console.log('视野发生变化时触发', e)
Anne_LXM's avatar
Anne_LXM 已提交
736 737
  };

Anne_LXM's avatar
Anne_LXM 已提交
738
  const onpoitap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
739
    // console.log('点击地图poi点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
740 741 742 743 744
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
745 746 747 748 749 750 751
  defineExpose({
    jestResult,
    autoTest,
    updateAutoTest,
    addControls,
    addMarkers,
    addMarkersLabel,
Anne_LXM's avatar
Anne_LXM 已提交
752
    removeMarker,
Anne_LXM's avatar
Anne_LXM 已提交
753
    addPolyline,
Anne_LXM's avatar
Anne_LXM 已提交
754
    removePolyline,
Anne_LXM's avatar
Anne_LXM 已提交
755
    addPolygons,
Anne_LXM's avatar
Anne_LXM 已提交
756
    removePolygon,
Anne_LXM's avatar
Anne_LXM 已提交
757
    addCircles,
Anne_LXM's avatar
Anne_LXM 已提交
758
    removeCircle,
Anne_LXM's avatar
Anne_LXM 已提交
759 760 761 762 763 764 765
    includePoint,
    handleGetCenterLocation,
    handleGetRegion,
    handleTranslateMarker,
    handleMoveToLocation,
    handleGetScale
  })
Anne_LXM's avatar
Anne_LXM 已提交
766
</script>
767

Anne_LXM's avatar
Anne_LXM 已提交
768
<style>
769 770 771 772 773 774
  .content {
    flex: 1;
  }

  .map {
    width: 100%;
Anne_LXM's avatar
Anne_LXM 已提交
775
    height: 300px;
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
    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;
  }
799 800 801 802 803 804

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