map組件如何展示marker的callout氣泡


場景描述

marker 可以通過點擊或者常顯的方式顯示一個文本為用來描述和對應 marker 相關的信息。

實現思路

如下示例展示了在對應的 marker 上展示常顯文本氣泡。

由於文本氣泡是無法自定義寬高的,即氣泡根據文本內容自適應寬高,那么也就說明textAlign屬性,只有文本內容中包含換行符("\n")的時候,才會有直觀的可視效果。

解決方法

代碼如下:

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
<template>
   <div>
     <map
       style= "width:{{width}}; height:{{height}}"
       scale= "{{scale}}"
       markers= "{{markers}}"
     >
     </map>
   </div>
</template>
<script>
   const COORDTYPE =  'wgs84'
   const MARKER_PATH =  '/Common/marker.png'
   const BEI_JING_WGS = {
     latitude: 39.9073728469,
     longitude: 116.3913445961,
     coordType: COORDTYPE
   }
   export  default  {
     private: {
       scale: 17,
       markers: [
         {
           width:  '100%' ,
           height:  '50%' ,
           latitude: BEI_JING_WGS.latitude,
           longitude: BEI_JING_WGS.longitude,
           coordType: BEI_JING_WGS.coordType,
           iconPath: MARKER_PATH,
           width:  '100px' ,
           callout: {
             content:  '這里是\n北京' ,
             padding:  '20px 5px 20px 5px' ,
             borderRadius:  '20px' ,
             textAlign:  'left' ,
             display:  'always'
           }
         }
       ]
     }
   }
</script>

更多參考

Map組件:

https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-component-map

 

原文鏈接:https://developer.huawei.com/...
原作者:Mayism


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM