map.uvue 18.6 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>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
18
      <boolean-data :default-value="enable3D" :disabled="enableSatellite" title="3D效果(放大缩放级别才能看到建筑物3D效果)" @change="change_enable_3d"></boolean-data>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
19 20 21 22 23 24 25
      <boolean-data :default-value="showCompass" title="显示指南针" @change="change_show_campass"></boolean-data>
      <boolean-data :default-value="enableOverlooking" title="俯视支持" @change="change_enable_overlooking"></boolean-data>
      <boolean-data :default-value="enableRotate" title="旋转支持" @change="change_enable_rotate"></boolean-data>
      <boolean-data :default-value="enableZoom" title="缩放支持" @change="change_enable_zoom"></boolean-data>
      <boolean-data :default-value="enableScroll" title="拖动支持" @change="change_enable_scroll"></boolean-data>
      <boolean-data :default-value="enableSatellite" title="卫星图" @change="change_enable_satellite"></boolean-data>
      <boolean-data :default-value="enableTraffic" title="实时路况" @change="change_enable_traffic"></boolean-data>
Anne_LXM's avatar
Anne_LXM 已提交
26

Anne_LXM's avatar
Anne_LXM 已提交
27
      <button class="button" @click="addControls">控件</button>
Anne_LXM's avatar
Anne_LXM 已提交
28
      <button class="button" @click="addMarkers">添加标记点</button>
29
      <!-- #ifdef WEB -->
Anne_LXM's avatar
Anne_LXM 已提交
30
      <button class="button" @click="addMarkersLabel">为标记点旁边增加标签</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32
      <!-- #endif -->
      <button class="button" @click="removeMarker">移除ID为4的标记点和标签</button>
Anne_LXM's avatar
Anne_LXM 已提交
33 34 35 36 37 38
      <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 已提交
39 40 41 42 43 44
      <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 已提交
45
      <button class="button" @click="handleTranslateMarker">平移marker</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
46
      <button class="button" @click="handleMoveToLocation">将地图中心移动到指定坐标</button>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
47
      <button class="button" @click="handleMoveToMyLocation">将地图中心移动到当前位置</button>
Anne_LXM's avatar
Anne_LXM 已提交
48 49
      <button class="button" @click="handleGetScale">获取当前地图的缩放级别</button>

50 51
    </scroll-view>
  </view>
Anne_LXM's avatar
Anne_LXM 已提交
52
</template>
53

Anne_LXM's avatar
Anne_LXM 已提交
54
<script setup lang="uts">
Anne_LXM's avatar
Anne_LXM 已提交
55
  type TypeJestResult = {
Anne_LXM's avatar
Anne_LXM 已提交
56 57
    translateMarkerMsg : string,
    animationEnd : boolean,
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60
    centerPoints : LocationObject,
    southwest : LocationObject,
    northeast : LocationObject,
Anne_LXM's avatar
Anne_LXM 已提交
61
    moveToLocationMsg : string,
62 63
    scale : number,
    eventDetailJsonStringify: string,
Anne_LXM's avatar
Anne_LXM 已提交
64 65
  }

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

Anne_LXM's avatar
Anne_LXM 已提交
190

DCloud-WZF's avatar
DCloud-WZF 已提交
191
  const testPolyline: Polyline[] = [{
192 193 194 195 196 197 198 199 200
    points: [{
      latitude: 39.925539,
      longitude: 116.279037
    },
    {
      latitude: 39.925539,
      longitude: 116.520285
    }],
    color: '#FFCCFF',
201
    width: 7,
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
    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 已提交
230
    dottedLine: false,
231 232 233 234 235 236
    arrowLine: true,
    borderColor: '#CC0000',
    borderWidth: 3
  }
  ];

DCloud-WZF's avatar
DCloud-WZF 已提交
237
  const testPolygons : Polygon[] = [{
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
    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 已提交
284
  const testCircles: Circle[] = [{
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
    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 已提交
310
  const testIncludePoints :LocationObject[] = [{
311 312 313 314 315 316 317 318 319 320
    latitude: 39.989631,
    longitude: 116.481018,
  },
  {
    latitude: 39.9086920000,
    longitude: 116.3974770000,
  }
  ];


DCloud-WZF's avatar
DCloud-WZF 已提交
321 322
  const mapContext = ref(null as MapContext | null);
  const location = ref({ longitude: 116.39742, latitude: 39.909 } as LocationObject);
Anne_LXM's avatar
Anne_LXM 已提交
323 324
  const rotate = ref(0);
  const skew = ref(0);
Anne_LXM's avatar
Anne_LXM 已提交
325
  // 自动化测试
Anne_LXM's avatar
Anne_LXM 已提交
326
  const autoTest = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
327
  const updateAutoTest = (value : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
328 329 330 331 332
    autoTest.value = value
  }


  const jestResult = reactive({
333 334
    translateMarkerMsg: "",
    animationEnd: false,
Anne_LXM's avatar
Anne_LXM 已提交
335
    centerPoints: {
336 337
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
338 339
    },
    southwest: {
340 341
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
342 343
    },
    northeast: {
344 345
      latitude: 0,
      longitude: 0
Anne_LXM's avatar
Anne_LXM 已提交
346
    },
347 348
    moveToLocationMsg: "",
    scale: 0,
349
    eventDetailJsonStringify: "{}"
Anne_LXM's avatar
Anne_LXM 已提交
350 351
  } as TypeJestResult);

352

Anne_LXM's avatar
Anne_LXM 已提交
353
  onReady(() => {
DCloud-WZF's avatar
DCloud-WZF 已提交
354
    mapContext.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
Anne_LXM's avatar
Anne_LXM 已提交
355 356
  });

Anne_LXM's avatar
Anne_LXM 已提交
357
  const scale = ref(13);
Anne_LXM's avatar
Anne_LXM 已提交
358
  const confirm_scale_input = (value : number) => {
Anne_LXM's avatar
Anne_LXM 已提交
359 360 361
    scale.value = value
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
362
  const controls = ref([] as Control[]);
Anne_LXM's avatar
Anne_LXM 已提交
363
  const addControls = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
364
    controls.value = [{
Anne_LXM's avatar
Anne_LXM 已提交
365 366 367 368 369 370
      id: 1,
      position: {
        left: 5,
        top: 180,
        width: 30,
        height: 30
DCloud-WZF's avatar
DCloud-WZF 已提交
371
      } as ControlPosition,
Anne_LXM's avatar
Anne_LXM 已提交
372 373
      iconPath: '../../../static/uni.png',
      clickable: true
374
    } as Control]
375
  }
Anne_LXM's avatar
Anne_LXM 已提交
376

Anne_LXM's avatar
Anne_LXM 已提交
377
  const showLocation = ref(false);
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
378 379 380 381 382 383 384 385
  const enable3D = ref(false);
  const showCompass = ref(false);
  const enableOverlooking = ref(false);
  const enableRotate = ref(false);
  const enableZoom = ref(true);
  const enableScroll = ref(true);
  const enableSatellite = ref(false);
  const enableTraffic = ref(false);
Anne_LXM's avatar
Anne_LXM 已提交
386
  const change_show_location = (checked : boolean) => {
Anne_LXM's avatar
Anne_LXM 已提交
387 388 389
    showLocation.value = checked
  }

taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
  const change_enable_3d = (checked : boolean) => {
    enable3D.value = checked
  }

  const change_show_campass = (checked : boolean) => {
    showCompass.value = checked
  }

  const change_enable_overlooking = (checked : boolean) => {
    enableOverlooking.value = checked
  }

  const change_enable_rotate = (checked : boolean) => {
    enableRotate.value = checked
  }

  const change_enable_zoom = (checked : boolean) => {
    enableZoom.value = checked
  }

  const change_enable_scroll = (checked : boolean) => {
    enableScroll.value = checked
  }

  const change_enable_satellite = (checked : boolean) => {
    enableSatellite.value = checked
  }

  const change_enable_traffic = (checked : boolean) => {
    enableTraffic.value = checked
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
422
  const includePoints = ref([] as LocationObject[]);
Anne_LXM's avatar
Anne_LXM 已提交
423 424 425 426 427
  const includePoint = () => {
    includePoints.value = testIncludePoints;
  };


DCloud-WZF's avatar
DCloud-WZF 已提交
428
  let markers = ref([] as Marker[]);
Anne_LXM's avatar
Anne_LXM 已提交
429
  const addMarkers = () => {
Anne_LXM's avatar
Anne_LXM 已提交
430
    scale.value = 11
DCloud-WZF's avatar
DCloud-WZF 已提交
431 432
    const temp = JSON.parse<Marker[]>(JSON.stringify(testMarkers))!
    markers.value = temp
Anne_LXM's avatar
Anne_LXM 已提交
433 434
  };

Anne_LXM's avatar
Anne_LXM 已提交
435
  const removeMarker = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
436 437 438 439 440 441 442 443 444 445 446
    // #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 已提交
447 448 449 450 451
      uni.showToast({
        title: '未找到该标记点',
        icon: 'none'
      });
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
452
    // #endif
Anne_LXM's avatar
Anne_LXM 已提交
453 454
  };

455
  // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
456
  const addMarkersLabel = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
457
    markers.value.forEach((marker, index) => {
Anne_LXM's avatar
Anne_LXM 已提交
458
      marker.label = {
459
        content: 'Hello Label' + (index + 1),
Anne_LXM's avatar
Anne_LXM 已提交
460 461 462 463
        color: '#aa00ff',
        fontSize: 12,
        x: 5,
        y: 0,
464 465
        borderColor: '#333300',
        borderWidth: 2,
Anne_LXM's avatar
Anne_LXM 已提交
466 467 468 469 470 471
        borderRadius: 20,
        bgColor: '#aaffff',
        padding: 10
      };
    });
  };
DCloud-WZF's avatar
DCloud-WZF 已提交
472
  // #endif
Anne_LXM's avatar
Anne_LXM 已提交
473 474 475 476


  const polyline = ref([] as Polyline[]);
  const addPolyline = () => {
Anne_LXM's avatar
Anne_LXM 已提交
477
    scale.value = 11;
DCloud-WZF's avatar
DCloud-WZF 已提交
478
    polyline.value = JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!;
Anne_LXM's avatar
Anne_LXM 已提交
479
  };
Anne_LXM's avatar
Anne_LXM 已提交
480 481
  const removePolyline = () => {
    if (polyline.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
482
      polyline.value = JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!.splice(0, 1);
Anne_LXM's avatar
Anne_LXM 已提交
483 484
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
485 486


DCloud-WZF's avatar
DCloud-WZF 已提交
487
  const polygons = ref([] as Polygon[]);
Anne_LXM's avatar
Anne_LXM 已提交
488 489
  const addPolygons = () => {
    scale.value = 10;
DCloud-WZF's avatar
DCloud-WZF 已提交
490
    polygons.value = JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!;
Anne_LXM's avatar
Anne_LXM 已提交
491
  };
Anne_LXM's avatar
Anne_LXM 已提交
492 493
  const removePolygon = () => {
    if (polygons.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
494
      polygons.value = JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!.splice(0, 1);
Anne_LXM's avatar
Anne_LXM 已提交
495 496
    }
  };
Anne_LXM's avatar
Anne_LXM 已提交
497 498


DCloud-WZF's avatar
DCloud-WZF 已提交
499
  const circles = ref([] as Circle[]);
Anne_LXM's avatar
Anne_LXM 已提交
500 501
  const addCircles = () => {
    scale.value = 10;
DCloud-WZF's avatar
DCloud-WZF 已提交
502
    circles.value = JSON.parse<Circle[]>(JSON.stringify(testCircles))!;
Anne_LXM's avatar
Anne_LXM 已提交
503
  };
Anne_LXM's avatar
Anne_LXM 已提交
504 505
  const removeCircle = () => {
    if (circles.value.length > 1) {
DCloud-WZF's avatar
DCloud-WZF 已提交
506
      circles.value = JSON.parse<Circle[]>(JSON.stringify(testCircles))!.slice(1);
Anne_LXM's avatar
Anne_LXM 已提交
507 508 509
    }
  };

Anne_LXM's avatar
Anne_LXM 已提交
510
  const handleGetCenterLocation = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
511
      mapContext.value?.getCenterLocation({
Anne_LXM's avatar
Anne_LXM 已提交
512
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
513
          // console.log('getCenterLocation',ret);
Anne_LXM's avatar
Anne_LXM 已提交
514
          jestResult.centerPoints = ret;
515
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
516 517 518 519
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
520 521 522 523 524
        }
      });
  };

  const handleGetRegion = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
525
      mapContext.value?.getRegion({
Anne_LXM's avatar
Anne_LXM 已提交
526
        success: ret => {
Anne_LXM's avatar
Anne_LXM 已提交
527
          // console.log('getRegion',JSON.stringify(ret));
Anne_LXM's avatar
Anne_LXM 已提交
528 529
          jestResult.southwest = ret.southwest;
          jestResult.northeast = ret.northeast
530
          if (!autoTest.value) {
Anne_LXM's avatar
Anne_LXM 已提交
531 532 533 534
            uni.showModal({
              content: JSON.stringify(ret)
            });
          }
Anne_LXM's avatar
Anne_LXM 已提交
535 536 537 538
        }
      });
  };

Anne_LXM's avatar
Anne_LXM 已提交
539

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

Anne_LXM's avatar
Anne_LXM 已提交
584 585

  const handleGetScale = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
586
      mapContext.value?.getScale({
Anne_LXM's avatar
Anne_LXM 已提交
587
        success: res => {
588 589 590 591 592 593 594 595
          // 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 已提交
596 597
        },
        fail: error => {
598
          console.log(error)
Anne_LXM's avatar
Anne_LXM 已提交
599 600 601 602 603
        },
      });
  };

  const handleMoveToLocation = () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
604
      mapContext.value?.moveToLocation({
605 606 607
        latitude: 39.909,
        longitude: 116.39742,
        success: res => {
608
          console.log('moveToLocation',res);
DCloud-WZF's avatar
DCloud-WZF 已提交
609
          const result = res as UTSJSONObject
610
          jestResult.moveToLocationMsg = result["errMsg"] as string;
DCloud-WZF's avatar
DCloud-WZF 已提交
611

612 613 614 615
          if (!autoTest.value) {
            uni.showModal({
              content: JSON.stringify(res)
            });
Anne_LXM's avatar
Anne_LXM 已提交
616
          }
617 618 619 620
        },
        fail: error => {
          console.log(error)
        }
Anne_LXM's avatar
Anne_LXM 已提交
621 622 623
      });
  };

taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636
  const handleMoveToMyLocation = () => {
    mapContext.value?.moveToLocation({
      success: res => {
        uni.showModal({
          content: '地图中心已经移动到当前位置'
        })
      },
      fail: error => {
        console.log(error);
      }
    })
  }

taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
637
  const maptap = (e : UniMapTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
638
    // console.log('点击地图时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
639
    uni.showModal({
640
      content: JSON.stringify(e.detail)
Anne_LXM's avatar
Anne_LXM 已提交
641 642 643
    });
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
644
  const onmarkertap = (e : UniMapMarkerTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
645
    // console.log('点击标记点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
646
    uni.showModal({
647
      content: JSON.stringify(e.detail)
Anne_LXM's avatar
Anne_LXM 已提交
648 649 650
    });
  };

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

Anne_LXM's avatar
Anne_LXM 已提交
658
  const oncallouttap = (e : UniEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
659
    // console.log('点击标记点对应的气泡时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
660 661 662 663 664
    uni.showModal({
      content: JSON.stringify(e)
    });
  };

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

DCloud-WZF's avatar
DCloud-WZF 已提交
669
  const onregionchange = (e : UniMapRegionChangeEvent) => {
670
    console.log('视野发生变化时触发', e.detail)
671
    jestResult.eventDetailJsonStringify = JSON.stringify(e.detail)
Anne_LXM's avatar
Anne_LXM 已提交
672 673
  };

DCloud-WZF's avatar
DCloud-WZF 已提交
674
  const onpoitap = (e : UniMapPoiTapEvent) => {
Anne_LXM's avatar
Anne_LXM 已提交
675
    // console.log('点击地图poi点时触发',e)
Anne_LXM's avatar
Anne_LXM 已提交
676
    uni.showModal({
677
      content: JSON.stringify(e.detail)
Anne_LXM's avatar
Anne_LXM 已提交
678 679 680
    });
  };

Anne_LXM's avatar
Anne_LXM 已提交
681 682 683 684 685 686
  defineExpose({
    jestResult,
    autoTest,
    updateAutoTest,
    addControls,
    addMarkers,
687
    // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
688
    addMarkersLabel,
DCloud-WZF's avatar
DCloud-WZF 已提交
689
    // #endif
Anne_LXM's avatar
Anne_LXM 已提交
690
    removeMarker,
Anne_LXM's avatar
Anne_LXM 已提交
691
    addPolyline,
Anne_LXM's avatar
Anne_LXM 已提交
692
    removePolyline,
Anne_LXM's avatar
Anne_LXM 已提交
693
    addPolygons,
Anne_LXM's avatar
Anne_LXM 已提交
694
    removePolygon,
Anne_LXM's avatar
Anne_LXM 已提交
695
    addCircles,
Anne_LXM's avatar
Anne_LXM 已提交
696
    removeCircle,
Anne_LXM's avatar
Anne_LXM 已提交
697 698 699 700 701 702 703
    includePoint,
    handleGetCenterLocation,
    handleGetRegion,
    handleTranslateMarker,
    handleMoveToLocation,
    handleGetScale
  })
Anne_LXM's avatar
Anne_LXM 已提交
704
</script>
705

Anne_LXM's avatar
Anne_LXM 已提交
706
<style>
707 708 709 710 711 712
  .content {
    flex: 1;
  }

  .map {
    width: 100%;
Anne_LXM's avatar
Anne_LXM 已提交
713
    height: 300px;
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
    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;
  }
737 738 739 740 741 742

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